diff --git a/docs/architecture/retail-divergence-register.md b/docs/architecture/retail-divergence-register.md
index c2267360..1dcb1d44 100644
--- a/docs/architecture/retail-divergence-register.md
+++ b/docs/architecture/retail-divergence-register.md
@@ -144,8 +144,7 @@ accepted-divergence entries (#96, #49, #50).
| AP-41 | Scrollbar thumb 3-slice cap fallback only: single-tile draw (`0x06004C63`) used only when `ThumbTopSprite`/`ThumbBotSprite` are unset; the chat controller passes all three cap ids so the 3-slice path is drawn in practice | `src/AcDream.App/UI/UiScrollbar.cs:35` | The fallback single-tile path is unreachable when caps are bound (chat controller always sets them); the 3-slice path is the active code path | Only if a future caller omits the cap ids will the fallback fire — no visual regression in the chat window | `UIElement_Scrollbar::UpdateLayout @0x4710d0`; cap sprites `0x06004C60` (top) + `0x06004C66` (bottom) from base layout `0x2100003E` |
| AP-42 | `UiMenu` item model is flat (label + opaque payload, single-level popup); retail `UIElement_Menu::MakePopup @0x46d310` supports hierarchical nested submenus via recursive popup chain | `src/AcDream.App/UI/UiMenu.cs` | The chat talk-focus menu is single-level (14 rows, 2 columns, no submenu); hierarchy is latent and unreachable through the chat window — no behavioral difference in the current usage | A future menu with nested submenus would render flat (only the top-level items drawn, no drill-down) | `UIElement_Menu::MakePopup` @0x46d310 |
| AP-45 | `PublicUpdatePropertyInt (0x02CE)` sequence byte parsed-past but not honored; last update wins (no freshness check against sequence number) | `src/AcDream.Core.Net/Messages/PublicUpdatePropertyInt.cs` | Loopback ACE rarely reorders; latest-wins matches `PrivateUpdateVital`/`UpdatePosition`'s existing non-sequence behavior. Sequence tracking added when needed alongside TS-26. | A reordered 0x02CE on a real network could apply a stale UiEffects value — item icon temporarily shows the wrong effect state, corrected on next update | `PublicUpdatePropertyInt` sequence byte (ACE GameMessagePublicUpdatePropertyInt) |
-| AP-46 | Health-meter gate approximation: retail shows the health meter for `IsPlayer() || pet_owner || ObjectIsAttackable()`; acdream uses `IsLiveCreatureTarget` (the `ItemType.Creature` flag) | `src/AcDream.App/UI/Layout/SelectedObjectController.cs` (`HandleSelectionChanged` analogue) | `IsLiveCreatureTarget` is already wired for Tab/Q combat-target gating and is the correct proxy for M1.5 scope (no pet system, no PK); the only practical gap is a friendly non-attackable NPC, which is rare in the ACE dev loop | A friendly (non-attackable) NPC shows a health meter where retail would show name+overlay only — false meter on non-combat NPCs | `gmToolbarUI::HandleSelectionChanged` acclient_2013_pseudo_c.txt:198754 |
-| AP-47 | Meter-visible timing: acdream shows the health meter immediately on select; retail shows it from `RecvNotice_UpdateObjectHealth` when the queried value arrives | `src/AcDream.App/UI/Layout/SelectedObjectController.cs` (`OnSelectionChanged`) | Avoids a one-round-trip blank-then-pop; the fill polls `GetHealthPercent` which returns 1.0 until the reply — visually indistinguishable for a full-HP target and self-corrects within one RTT for a damaged target | A freshly-selected off-screen-damaged target reads full for one server round-trip before the `QueryHealth` reply lands | `gmToolbarUI::HandleSelectionChanged` acclient_2013_pseudo_c.txt:198757 |
+| AP-46 | Health-meter gate approximation: retail shows the health meter for `IsPlayer() || pet_owner || ClientCombatSystem::ObjectIsAttackable()` (full PK/faction logic); acdream's `GameWindow.IsHealthBarTarget` uses the server PWD bits `BF_ATTACKABLE (0x10)` OR `BF_PLAYER (0x8)` | `src/AcDream.App/Rendering/GameWindow.cs` (`IsHealthBarTarget`) → `SelectedObjectController` | The PWD `BF_ATTACKABLE`/`BF_PLAYER` bits distinguish monsters + players (bar) from friendly/vendor NPCs (name-only) for the M1.5 dev loop; the pet case and the full ObjectIsAttackable PK/faction refinement (free-PK, PK-vs-PK, PKLite) are not ported | A PK/faction edge (e.g. a hostile-flagged player whose `BF_ATTACKABLE` is unset, or a pet) could show/hide the bar where retail differs — no impact on the non-PK PvE dev loop | `ClientCombatSystem::ObjectIsAttackable` acclient_2013_pseudo_c.txt:375385; `BF_ATTACKABLE` acclient.h:6437 |
---
diff --git a/src/AcDream.App/Rendering/GameWindow.cs b/src/AcDream.App/Rendering/GameWindow.cs
index b8f65d99..980558ac 100644
--- a/src/AcDream.App/Rendering/GameWindow.cs
+++ b/src/AcDream.App/Rendering/GameWindow.cs
@@ -2026,9 +2026,11 @@ public sealed class GameWindow : IDisposable
_selectedObjectController = AcDream.App.UI.Layout.SelectedObjectController.Bind(
toolbarLayout,
subscribeSelectionChanged: h => SelectionChanged += h,
- isHealthTarget: IsLiveCreatureTarget,
+ subscribeHealthChanged: h => Combat.HealthChanged += h,
+ isHealthTarget: IsHealthBarTarget,
name: g => Objects.Get(g)?.Name,
healthPercent: g => Combat.GetHealthPercent(g),
+ hasHealth: g => Combat.HasHealth(g),
stackSize: g => (uint)(Objects.Get(g)?.StackSize ?? 0),
sendQueryHealth: g => _liveSession?.SendQueryHealth(g),
datFont: vitalsDatFont);
@@ -7410,6 +7412,10 @@ public sealed class GameWindow : IDisposable
// that actually consume the events.
_inputDispatcher?.Tick();
+ // Phase D.5.3a — advance the selected-object overlay flash (0.25s green pulse
+ // on selection, then revert). No-op when nothing is flashing.
+ _selectedObjectController?.Tick(dt);
+
// Phase K.2 — re-evaluate WantCaptureMouse for the MMB
// mouse-look state machine. Detect rising/falling edges so the
// state suspends correctly when ImGui claims the cursor while
@@ -12016,6 +12022,40 @@ public sealed class GameWindow : IDisposable
return (LiveItemType(guid) & AcDream.Core.Items.ItemType.Creature) != 0;
}
+ // PublicWeenieDesc _bitfield flags (acclient.h:6431-6463) — same bitfield RadarBlipColors reads.
+ private const uint BfPlayer = 0x8u; // BF_PLAYER (acclient.h:6434)
+ private const uint BfAttackable = 0x10u; // BF_ATTACKABLE (acclient.h:6437)
+
+ ///
+ /// True if the selected-object strip should show a Health meter for .
+ /// Approximates retail's IsPlayer() || pet_owner || ClientCombatSystem::ObjectIsAttackable()
+ /// gate (gmToolbarUI::HandleSelectionChanged :198754) using the server-provided PWD flags:
+ /// the BF_ATTACKABLE bit (monsters) or the BF_PLAYER bit (other players).
+ /// A friendly NPC (e.g. a vendor) has neither bit set → name-only, matching retail.
+ /// The full PK/faction logic of ObjectIsAttackable + the pet case are not ported (divergence AP-46).
+ ///
+ private bool IsHealthBarTarget(uint guid)
+ {
+ if (guid == _playerServerGuid)
+ return false;
+ if (!_entitiesByServerGuid.ContainsKey(guid))
+ return false;
+
+ uint pwd = _lastSpawnByGuid.TryGetValue(guid, out var spawn)
+ && spawn.ObjectDescriptionFlags is { } odf ? odf : 0u;
+
+ // Another player → health bar (retail IsPlayer branch).
+ if ((pwd & BfPlayer) != 0)
+ return true;
+
+ // Attackable branch: retail ObjectIsAttackable requires the object to be a CREATURE
+ // first (InqType() & 0x10, acclient_2013_pseudo_c.txt:375406), THEN attackable. A Door
+ // carries the BF_ATTACKABLE bit but is ItemType Misc, so it is never a health-bar target —
+ // require the Creature flag here too (matches retail; excludes attackable doors/objects).
+ bool isCreature = (LiveItemType(guid) & AcDream.Core.Items.ItemType.Creature) != 0;
+ return isCreature && (pwd & BfAttackable) != 0;
+ }
+
///
/// 2026-05-16 — retail-faithful port of
diff --git a/src/AcDream.App/Rendering/TextureCache.cs b/src/AcDream.App/Rendering/TextureCache.cs
index 250a69e4..bbc7d4b5 100644
--- a/src/AcDream.App/Rendering/TextureCache.cs
+++ b/src/AcDream.App/Rendering/TextureCache.cs
@@ -121,9 +121,11 @@ public sealed unsafe class TextureCache : Wb.ITextureCachePerInstance, IDisposab
/// Surface→SurfaceTexture chain that uses
/// for world-geometry materials. This is the correct path for retail UI
/// chrome + font glyph sheets, which reference RenderSurface directly.
- /// Palette is null for now (a paletted INDEX16/P8 UI sprite would return
- /// Magenta — wire a UI palette when one is actually encountered). Returns a
- /// 1x1 magenta handle on miss.
+ /// Paletted (PFID_P8 / PFID_INDEX16) UI sprites — e.g. the selected-object
+ /// health-bar track 0x0600193E — are decoded against the RenderSurface's own
+ /// DefaultPaletteId (same starting palette
+ /// uses); non-paletted formats have DefaultPaletteId==0 → palette null. Returns
+ /// a 1x1 magenta handle on miss.
///
public uint GetOrUploadRenderSurface(uint renderSurfaceId, out int width, out int height, bool nearest = false)
{
@@ -138,7 +140,14 @@ public sealed unsafe class TextureCache : Wb.ITextureCachePerInstance, IDisposab
if (_dats.Portal.TryGet(renderSurfaceId, out var rs)
|| _dats.HighRes.TryGet(renderSurfaceId, out rs))
{
- decoded = SurfaceDecoder.DecodeRenderSurface(rs, palette: null);
+ // Resolve the surface's own default palette so paletted UI sprites decode
+ // correctly instead of the magenta fallback (the back-track 0x0600193E behind
+ // the selected-object health bar is PFID_P8/INDEX16). Non-paletted formats
+ // (DefaultPaletteId==0) keep the previous null-palette behaviour unchanged.
+ Palette? palette = rs.DefaultPaletteId != 0
+ ? _dats.Get(rs.DefaultPaletteId)
+ : null;
+ decoded = SurfaceDecoder.DecodeRenderSurface(rs, palette);
}
else
{
diff --git a/src/AcDream.App/UI/Layout/SelectedObjectController.cs b/src/AcDream.App/UI/Layout/SelectedObjectController.cs
index 1e37cddd..74dfe76e 100644
--- a/src/AcDream.App/UI/Layout/SelectedObjectController.cs
+++ b/src/AcDream.App/UI/Layout/SelectedObjectController.cs
@@ -5,74 +5,108 @@ using AcDream.App.UI;
namespace AcDream.App.UI.Layout;
///
-/// Controller for the action bar's selected-object strip (ids 0x1000019F–0x100001A1).
+/// Controller for the action bar's selected-object strip (ids 0x1000019E–0x100001A1).
/// Analogue of retail gmToolbarUI::HandleSelectionChanged
-/// (docs/research/named-retail/acclient_2013_pseudo_c.txt:198635).
+/// (docs/research/named-retail/acclient_2013_pseudo_c.txt:198635) +
+/// RecvNotice_UpdateObjectHealth (:196213).
///
///
-/// On selection change: clears the strip (name, overlay state, health meter), then
-/// if a guid is provided it sets the name, puts the overlay field into the appropriate
-/// state ("ObjectSelected" or "StackedItemSelected"), and for health-bearing targets
-/// shows the health meter and sends a QueryHealth (0x01BF) request.
+/// On selection change: clears the strip (name, overlay flash, health meter), then if a
+/// guid is provided it sets the name, flashes the selection overlay briefly, and (for
+/// health-bearing targets) sends a QueryHealth (0x01BF) request. The Health meter
+/// becomes visible only when the server actually reports health for the selected guid —
+/// either an UpdateHealth (0x01C0) arrives (retail
+/// RecvNotice_UpdateObjectHealth → SetVisible(1)) or the value is already
+/// cached. So a friendly NPC you have not assessed shows name-only (no bar), and a
+/// monster's bar appears after damage / a successful assess — matching retail.
///
///
///
-/// Divergence — meter-visible timing.
-/// Retail makes the health meter visible from RecvNotice_UpdateObjectHealth
-/// (when the queried value arrives, cite HandleSelectionChanged:198757).
-/// acdream shows it immediately on select (fill polls
-/// which returns 1.0 until the reply lands). Recorded in the divergence register.
+/// Retail element roles (PostInit, :198119): m_pSelObjectField
+/// is the container 0x1000019E whose SetState(0x1000000b/0c) drives a
+/// 0.25s Pause→Normal flash that cascades to the overlay child's green frame.
+/// acdream has no state-cascade / transition-animation system, so this controller drives
+/// the overlay element 0x100001A0 directly and reverts it after the same
+/// to reproduce the brief flash. The name element
+/// 0x1000019F is bumped to the top of the strip's z-order so it draws OVER the
+/// overlay frame and the health bar (retail draws the name over the bar — see the
+/// "Drudge Slinker" reference shot).
///
///
///
/// Divergence — health-target gate approximation.
-/// Retail gates on IsPlayer() || pet_owner || ObjectIsAttackable()
-/// (cite HandleSelectionChanged:198754). acdream uses IsLiveCreatureTarget
-/// (the ItemType.Creature flag). Recorded in the divergence register.
+/// Retail sends Event_QueryHealth for IsPlayer() || pet_owner || ObjectIsAttackable()
+/// (:198754). acdream uses IsLiveCreatureTarget (the ItemType.Creature
+/// flag) to gate the QueryHealth send. Visibility itself is health-data-driven (above), so
+/// the gate only affects whether we proactively query; recorded in the divergence register.
///
///
public sealed class SelectedObjectController
{
// ── Element ids (toolbar LayoutDesc 0x21000016) ─────────────────────────
- /// Selected-object name element id.
+ /// Selected-object container / field element id (retail m_pSelObjectField).
+ public const uint ContainerId = 0x1000019E;
+ /// Selected-object name element id (retail m_pSelObjectName, UIElement_Text).
public const uint NameId = 0x1000019F;
- /// Selected-object overlay field element id (states: ObjectSelected / StackedItemSelected).
+ /// Selected-object overlay element id (states: ObjectSelected / StackedItemSelected).
public const uint OverlayId = 0x100001A0;
- /// Selected-object health meter element id.
+ /// Selected-object health meter element id (retail m_pSelObjectHealthMeter).
public const uint HealthMeterId = 0x100001A1;
+ /// Selection-overlay flash duration — retail's container ObjectSelected state is a
+ /// Pause(0.25s)→Normal transition (toolbar dump, element 0x1000019E).
+ private const double FlashSeconds = 0.25;
+
+ /// Z-order for the name so it draws OVER the overlay frame + health bar.
+ /// The strip's other children sit at ReadOrder 1–4; this floats the name to the top.
+ private const int NameZOrderOnTop = 1_000_000;
+
+ /// Z-order for the selection-flash overlay — above the health meter (so the green
+ /// flash isn't hidden by the bar) but below the name (so the name stays readable).
+ private const int OverlayZOrder = NameZOrderOnTop - 1;
+
+ /// Height (px) of the black name band at the top of the 31px bar sprite. The name
+ /// label is constrained to this band (top-aligned) so the health bar shows below it —
+ /// retail "name on the black, bar below". The bar sprite's colored region starts ~y14.
+ private const float NameBandHeight = 15f;
+
// ── Found elements (any may be null for partial/test layouts) ───────────
private readonly UiElement? _name;
private readonly UiDatElement? _overlay;
private readonly UiMeter? _healthMeter;
// ── Captured delegates ───────────────────────────────────────────────────
- private readonly Func _isHealthTarget;
- private readonly Func _name_;
- private readonly Func _healthPercent;
- private readonly Func _stackSize;
- private readonly Action _sendQueryHealth;
+ private readonly Func _isHealthTarget;
+ private readonly Func _resolveName;
+ private readonly Func _healthPercent;
+ private readonly Func _hasHealth;
+ private readonly Func _stackSize;
+ private readonly Action _sendQueryHealth;
// ── Live state (read by closures on the per-frame draw path) ────────────
private uint? _current;
private string? _currentName;
+ private double _flashRemaining; // > 0 while the selection overlay is flashing
/// White label color for the name line.
private static readonly Vector4 NameColor = new(1f, 1f, 1f, 1f);
private SelectedObjectController(
ImportedLayout layout,
- Action> subscribeSelectionChanged,
+ Action> subscribeSelectionChanged,
+ Action> subscribeHealthChanged,
Func isHealthTarget,
Func name,
Func healthPercent,
+ Func hasHealth,
Func stackSize,
Action sendQueryHealth,
UiDatFont? datFont)
{
_isHealthTarget = isHealthTarget;
- _name_ = name;
+ _resolveName = name;
_healthPercent = healthPercent;
+ _hasHealth = hasHealth;
_stackSize = stackSize;
_sendQueryHealth = sendQueryHealth;
@@ -81,26 +115,36 @@ public sealed class SelectedObjectController
_overlay = layout.FindElement(OverlayId) as UiDatElement;
_healthMeter = layout.FindElement(HealthMeterId) as UiMeter;
+ // The selection-flash overlay must draw OVER the health meter (which spans the whole
+ // strip) — otherwise the meter hides the green flash whenever a bar is visible (i.e.
+ // for players/monsters). Float it just below the name so the name stays readable.
+ if (_overlay is not null) _overlay.ZOrder = OverlayZOrder;
+
// This controller owns the health meter's initial-hidden state.
if (_healthMeter is not null)
{
_healthMeter.Visible = false;
// Fill polls live: _current holds the currently-selected guid (or null).
- // Returns 0f when nothing is selected (empty bar), healthPercent(g) otherwise.
_healthMeter.Fill = () => _current is uint g ? _healthPercent(g) : (float?)0f;
}
// Attach a centered UiText child to the name element for the object name display.
- // Mirrors VitalsController.BindMeter's number attach (same decoration style).
+ // Mirrors VitalsController.BindMeter's number attach. The name is floated to the
+ // top of the strip's z-order so it draws OVER the overlay frame and the health bar
+ // (retail renders the object name over the bar).
+ //
+ // The bar sprite (0x0600193E/F, 146x31) carries a ~14px BLACK name band across its
+ // TOP with the colored bar in the lower portion (confirmed from the dat). Retail
+ // draws the object name in that black band with the health bar BELOW it — so the
+ // label is TOP-aligned by constraining its height to the band, not centered over the
+ // whole 31px strip (which overlapped the bar's middle).
if (_name is not null)
{
+ _name.ZOrder = NameZOrderOnTop;
var label = new UiText
{
- Left = 0f,
- Top = 0f,
- Width = _name.Width,
- Height = _name.Height,
- Anchors = AnchorEdges.Left | AnchorEdges.Top | AnchorEdges.Right | AnchorEdges.Bottom,
+ Left = 0f, Top = 0f, Width = _name.Width, Height = NameBandHeight,
+ Anchors = AnchorEdges.Left | AnchorEdges.Top | AnchorEdges.Right,
Centered = true,
DatFont = datFont,
ClickThrough = true,
@@ -109,7 +153,6 @@ public sealed class SelectedObjectController
CapturesPointerDrag = false,
LinesProvider = () =>
{
- // Returns a single white line when a name is available; empty otherwise.
var n = _currentName;
return string.IsNullOrEmpty(n)
? Array.Empty()
@@ -119,90 +162,107 @@ public sealed class SelectedObjectController
_name.AddChild(label);
}
- // Register the handler LAST so the initial state is fully set up first.
+ // Register the handlers LAST so the initial state is fully set up first.
subscribeSelectionChanged(OnSelectionChanged);
+ subscribeHealthChanged(OnHealthChanged);
}
///
/// Create and bind a to .
- /// Port of retail gmToolbarUI::HandleSelectionChanged
- /// (acclient_2013_pseudo_c.txt:198635).
+ /// Port of retail gmToolbarUI::HandleSelectionChanged + RecvNotice_UpdateObjectHealth.
///
/// Imported toolbar layout (LayoutDesc 0x21000016).
- ///
- /// Called once with the controller's handler.
- /// Typical host: h => SelectionChanged += h — keeps the controller
- /// decoupled from GameWindow.
- ///
- ///
- /// Returns true for guids that should show a health meter (proxy for retail's
- /// IsPlayer() || pet_owner || ObjectIsAttackable()).
- ///
+ /// Called once with
+ /// (typical host: h => SelectionChanged += h).
+ /// Called once with
+ /// (typical host: h => Combat.HealthChanged += h) — drives meter visibility.
+ /// Returns true for guids that may show a health meter
+ /// (proxy for retail's IsPlayer() || pet_owner || ObjectIsAttackable()).
/// Returns the display name for a given guid (or null if unknown).
/// Returns the health fill fraction [0..1] for a given guid.
- /// Returns the stack size for a given guid (0 or 1 = non-stacked).
- ///
- /// Sends retail QueryHealth (0x01BF); server replies with UpdateHealth (0x01C0).
- /// May be a no-op when offline.
- ///
+ /// Returns true if real health has been received for a guid
+ /// (so a re-selected, already-known target shows its bar immediately).
+ /// Returns the stack size for a guid (0 or 1 = non-stacked).
+ /// Sends retail QueryHealth (0x01BF); may be a no-op offline.
/// Dat font for the name label; null = debug bitmap font fallback.
public static SelectedObjectController Bind(
ImportedLayout layout,
- Action> subscribeSelectionChanged,
+ Action> subscribeSelectionChanged,
+ Action> subscribeHealthChanged,
Func isHealthTarget,
Func name,
Func healthPercent,
+ Func hasHealth,
Func stackSize,
Action sendQueryHealth,
UiDatFont? datFont)
- {
- return new SelectedObjectController(
- layout, subscribeSelectionChanged,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont);
- }
+ => new SelectedObjectController(
+ layout, subscribeSelectionChanged, subscribeHealthChanged,
+ isHealthTarget, name, healthPercent, hasHealth, stackSize, sendQueryHealth, datFont);
///
- /// Port of gmToolbarUI::HandleSelectionChanged
- /// (acclient_2013_pseudo_c.txt:198635):
+ /// Port of gmToolbarUI::HandleSelectionChanged (:198635):
/// clear-then-populate the selected-object strip on any selection change.
- /// Registered via subscribeSelectionChanged at bind time; called by
- /// GameWindow.SelectionChanged and by the despawn-clear path.
///
public void OnSelectionChanged(uint? guid)
{
- // ── 1. Clear first (retail: UIElement_Text::SetText + m_pSelObjectField->SetState(0)
- // + SetVisible(0) on the health meter). ──────────────────────────────────────
+ // ── 1. Clear first (retail: SetText("") + m_pSelObjectField->SetState(0)
+ // + SetVisible(0) on the meters). ──────────────────────────────────────
if (_healthMeter is not null) _healthMeter.Visible = false;
- if (_overlay is not null) _overlay.ActiveState = "";
- _currentName = null;
+ _currentName = null;
+ _current = guid;
- // Update the backing current guid so the Fill closure reflects the new state.
- _current = guid;
-
- // ── 2. Selection == null → strip stays cleared, done. ───────────────────────────
- if (guid is null) return;
+ if (guid is null)
+ {
+ // Deselect: clear the overlay flash immediately too.
+ SetOverlayState("");
+ _flashRemaining = 0;
+ return;
+ }
uint g = guid.Value;
- // ── 3. Selection != null — populate the strip. ──────────────────────────────────
+ // ── 2. Name (displayed via the UiText child's LinesProvider reading _currentName). ──
+ _currentName = _resolveName(g);
- // Name (displayed via the UiText child's LinesProvider reading _currentName).
- _currentName = _name_(g);
+ // ── 3. Selection overlay: brief flash (retail container ObjectSelected
+ // = Pause(0.25s)→Normal). "StackedItemSelected" for stacks. ──────────────
+ SetOverlayState(_stackSize(g) > 1u ? "StackedItemSelected" : "ObjectSelected");
+ _flashRemaining = FlashSeconds;
- // Overlay state: "StackedItemSelected" for stacked items, "ObjectSelected" otherwise.
- // Retail ref: m_pSelObjectField->SetState(0x1000000b) = "ObjectSelected"
- // (acclient_2013_pseudo_c.txt:198754). Stack sprite id 0x06004CF4 confirmed in toolbar dump.
- if (_overlay is not null)
- _overlay.ActiveState = _stackSize(g) > 1u ? "StackedItemSelected" : "ObjectSelected";
-
- // Health meter: visible + QueryHealth for health-bearing targets.
- // Divergence: retail shows the meter only when RecvNotice_UpdateObjectHealth arrives;
- // acdream shows it immediately (fill reads GetHealthPercent = 1.0 until the reply).
- // Retail ref: CM_Combat::Event_QueryHealth (acclient_2013_pseudo_c.txt:198757).
+ // ── 4. Health: query, and show the meter only if real health is already known.
+ // Otherwise the meter appears when OnHealthChanged fires for this guid
+ // (retail RecvNotice_UpdateObjectHealth :196213). ──────────────────────────
if (_isHealthTarget(g))
{
- if (_healthMeter is not null) _healthMeter.Visible = true;
_sendQueryHealth(g);
+ if (_hasHealth(g) && _healthMeter is not null)
+ _healthMeter.Visible = true;
}
}
+
+ ///
+ /// Port of gmToolbarUI::RecvNotice_UpdateObjectHealth (:196213): when the
+ /// server reports health for the currently-selected guid, make the Health meter visible.
+ /// The fill value is read live by the meter's provider.
+ ///
+ public void OnHealthChanged(uint guid, float percent)
+ {
+ if (_current is uint c && c == guid && _isHealthTarget(guid) && _healthMeter is not null)
+ _healthMeter.Visible = true;
+ }
+
+ /// Per-frame tick: reverts the selection overlay after the brief flash window.
+ public void Tick(double deltaSeconds)
+ {
+ if (_flashRemaining <= 0) return;
+ _flashRemaining -= deltaSeconds;
+ if (_flashRemaining <= 0)
+ SetOverlayState(""); // flash done → overlay back to blank
+ }
+
+ private void SetOverlayState(string state)
+ {
+ if (_overlay is not null) _overlay.ActiveState = state;
+ }
}
diff --git a/src/AcDream.App/UI/Layout/ToolbarController.cs b/src/AcDream.App/UI/Layout/ToolbarController.cs
index 91f03fad..1279328a 100644
--- a/src/AcDream.App/UI/Layout/ToolbarController.cs
+++ b/src/AcDream.App/UI/Layout/ToolbarController.cs
@@ -39,11 +39,13 @@ public sealed class ToolbarController
// Ids confirmed from the toolbar LayoutDesc dump.
// 0x100001A1 (health meter) is now OWNED by SelectedObjectController (D.5.3a) —
// it hides A1 at bind and shows it on a health-target selection, so A1 is removed
- // from here to avoid double-ownership. 0x100001A2 (mana meter) and 0x100001A4
- // (stack slider) are DEFERRED features (mana #140, stack-split UI) with no controller
- // yet, so they stay hidden here — otherwise their dat back-track sprites render as
- // stray empty bars on the toolbar.
- private static readonly uint[] HiddenIds = { 0x100001A2, 0x100001A4 };
+ // from here to avoid double-ownership. 0x100001A2 (mana meter), 0x100001A3 (stack-size
+ // entry box) and 0x100001A4 (stack slider) are DEFERRED features (mana #140, stack-split
+ // UI) with no controller yet, so they stay hidden here — otherwise their dat sprites
+ // render as stray bars / a black box on the toolbar. Retail hides A3/A4 in
+ // gmToolbarUI::HandleSelectionChanged (acclient_2013_pseudo_c.txt:198660/198742),
+ // showing them only for a stacked-item selection.
+ private static readonly uint[] HiddenIds = { 0x100001A2, 0x100001A3, 0x100001A4 };
// Four mutually-exclusive combat-mode indicator elements — exactly one visible at a time.
// Index 0 = NonCombat (peace), 1 = Melee, 2 = Missile, 3 = Magic.
diff --git a/src/AcDream.App/UI/UiMeter.cs b/src/AcDream.App/UI/UiMeter.cs
index b5ee4a40..057402c7 100644
--- a/src/AcDream.App/UI/UiMeter.cs
+++ b/src/AcDream.App/UI/UiMeter.cs
@@ -135,9 +135,14 @@ public sealed class UiMeter : UiElement
{
if (clipW <= 0f) return;
float w = Width, h = Height;
- var (lt, lw, _) = resolve(leftId);
- var (mt, mw, _) = resolve(midId);
- var (rt, rw, _) = resolve(rightId);
+ // Only resolve a slice when its id is non-zero. resolve(0) returns the 1x1 MAGENTA
+ // placeholder with a NON-ZERO GL handle, so resolving a zero (absent) cap id and then
+ // testing `tex != 0` would draw a 1px magenta cap. The single-image meter (toolbar
+ // selected-object bar) has no left/right caps (ids 0); the 3-slice vitals meter sets
+ // all six ids. Guard on the id, not the resolved handle.
+ var (lt, lw, _) = leftId != 0 ? resolve(leftId) : (0u, 0, 0);
+ var (mt, mw, _) = midId != 0 ? resolve(midId) : (0u, 0, 0);
+ var (rt, rw, _) = rightId != 0 ? resolve(rightId) : (0u, 0, 0);
float capL = lt != 0 ? MathF.Min(lw, w) : 0f;
float capR = rt != 0 ? MathF.Min(rw, w - capL) : 0f;
diff --git a/src/AcDream.Core/Combat/CombatState.cs b/src/AcDream.Core/Combat/CombatState.cs
index 15018b0f..1143115e 100644
--- a/src/AcDream.Core/Combat/CombatState.cs
+++ b/src/AcDream.Core/Combat/CombatState.cs
@@ -92,6 +92,16 @@ public sealed class CombatState
public float GetHealthPercent(uint guid) =>
_healthByGuid.TryGetValue(guid, out var pct) ? pct : 1f;
+ ///
+ /// True if an UpdateHealth (0x01C0) has ever been received for this guid — i.e. the
+ /// server has reported real health for it (via damage broadcast or a successful
+ /// assess/QueryHealth reply). Distinguishes a known value from the 1.0 default that
+ /// returns for unseen guids. Used by the selected-object
+ /// meter to gate visibility (retail shows the bar only once health is known —
+ /// gmToolbarUI::RecvNotice_UpdateObjectHealth, acclient_2013_pseudo_c.txt:196213).
+ ///
+ public bool HasHealth(uint guid) => _healthByGuid.ContainsKey(guid);
+
public int TrackedTargetCount => _healthByGuid.Count;
// ── Inbound handlers (wired from WorldSession.GameEvents) ────────────────
diff --git a/tests/AcDream.App.Tests/UI/Layout/SelectedObjectControllerTests.cs b/tests/AcDream.App.Tests/UI/Layout/SelectedObjectControllerTests.cs
index fd6a2a93..cdefebc0 100644
--- a/tests/AcDream.App.Tests/UI/Layout/SelectedObjectControllerTests.cs
+++ b/tests/AcDream.App.Tests/UI/Layout/SelectedObjectControllerTests.cs
@@ -10,30 +10,21 @@ namespace AcDream.App.Tests.UI.Layout;
///
/// Unit tests for — the
-/// gmToolbarUI::HandleSelectionChanged analogue
-/// (acclient_2013_pseudo_c.txt:198635).
+/// gmToolbarUI::HandleSelectionChanged + RecvNotice_UpdateObjectHealth
+/// analogue (acclient_2013_pseudo_c.txt:198635 / :196213).
///
///
-/// Layout construction mirrors : build a minimal
-/// from a root + a
-/// keyed by element id. Elements are constructed
-/// directly (no importer / no dat / no GL) so tests are pure in-process.
+/// Key behavior under test: the Health meter is UpdateHealth-driven — it becomes
+/// visible only when real health is known for the selected guid (a HealthChanged
+/// fires for it, or it is already cached at select time via hasHealth). Selecting a
+/// target does NOT show the meter on its own. This matches retail: a friendly NPC you have
+/// not assessed shows name-only; a monster's bar appears after damage / assess.
///
///
public class SelectedObjectControllerTests
{
// ── Shared layout ────────────────────────────────────────────────────────
- ///
- /// Build a minimal toolbar layout containing the three selected-object elements:
- ///
- /// - 0x1000019F → a name container (100×20).
- /// - 0x100001A0 → a overlay with "ObjectSelected"
- /// and "StackedItemSelected" states wired to distinct file ids.
- /// - 0x100001A1 → a health meter.
- ///
- /// Additional element ids can be added by the caller for edge-case tests.
- ///
private static (
ImportedLayout layout,
UiPanel nameEl,
@@ -44,28 +35,25 @@ public class SelectedObjectControllerTests
var dict = new Dictionary();
var root = new UiPanel();
- // Name element: a plain panel that will have a UiText child attached by the controller.
var nameEl = new UiPanel { Width = 100, Height = 20 };
dict[SelectedObjectController.NameId] = nameEl;
root.AddChild(nameEl);
- // Overlay element: a UiDatElement with the two named states the controller switches between.
var overlayInfo = new ElementInfo
{
Id = SelectedObjectController.OverlayId,
- Type = 3, // Type 3 = container/chrome — the overlay field's dat type
+ Type = 3,
StateMedia =
{
- [""] = (0x06000001u, 3), // DirectState (blank)
- ["ObjectSelected"] = (0x06001937u, 3), // ObjectSelected sprite id from toolbar dump
- ["StackedItemSelected"] = (0x06004CF4u, 3), // StackedItemSelected sprite id
+ [""] = (0x06000001u, 3),
+ ["ObjectSelected"] = (0x06001937u, 3),
+ ["StackedItemSelected"] = (0x06004CF4u, 3),
},
};
var overlayEl = new UiDatElement(overlayInfo, _ => (0u, 0, 0));
dict[SelectedObjectController.OverlayId] = overlayEl;
root.AddChild(overlayEl);
- // Health meter element.
var healthMeterEl = new UiMeter { Width = 100, Height = 10, Visible = true };
dict[SelectedObjectController.HealthMeterId] = healthMeterEl;
root.AddChild(healthMeterEl);
@@ -75,387 +63,344 @@ public class SelectedObjectControllerTests
// ── Recording delegates ──────────────────────────────────────────────────
- ///
- /// Build a recording set of delegates. Name, health, stack are keyed by guid;
- /// accumulates every guid passed to sendQueryHealth.
- ///
- private static (
- Action> subscribe,
- Action fireSelection,
- Func isHealthTarget,
- Func name,
- Func healthPercent,
- Func stackSize,
- Action sendQueryHealth,
- List queryHealthCalls)
- MakeDelegates(
- Dictionary healthTargetMap,
- Dictionary nameMap,
- Dictionary healthMap,
- Dictionary stackMap)
+ private sealed class Harness
{
- Action? registeredHandler = null;
- var queryHealthCalls = new List();
+ public Action? SelectionHandler;
+ public Action? HealthHandler;
+ public readonly List QueryHealthCalls = new();
- Action> subscribe = h => registeredHandler = h;
- Action fireSelection = guid => registeredHandler?.Invoke(guid);
+ public readonly Dictionary HealthTargetMap = new();
+ public readonly Dictionary NameMap = new();
+ public readonly Dictionary HealthMap = new();
+ public readonly Dictionary HasHealthMap = new();
+ public readonly Dictionary StackMap = new();
- Func isHealthTarget = g => healthTargetMap.TryGetValue(g, out var v) && v;
- Func name = g => nameMap.TryGetValue(g, out var v) ? v : null;
- Func healthPercent = g => healthMap.TryGetValue(g, out var v) ? v : 1f;
- Func stackSize = g => stackMap.TryGetValue(g, out var v) ? v : 0u;
- Action sendQueryHealth = g => queryHealthCalls.Add(g);
+ public void FireSelection(uint? g) => SelectionHandler?.Invoke(g);
+ public void FireHealth(uint g, float pct) => HealthHandler?.Invoke(g, pct);
- return (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, queryHealthCalls);
+ public SelectedObjectController Bind(ImportedLayout layout, UiDatFont? datFont = null)
+ => SelectedObjectController.Bind(
+ layout,
+ subscribeSelectionChanged: h => SelectionHandler = h,
+ subscribeHealthChanged: h => HealthHandler = h,
+ isHealthTarget: g => HealthTargetMap.TryGetValue(g, out var v) && v,
+ name: g => NameMap.TryGetValue(g, out var v) ? v : null,
+ healthPercent: g => HealthMap.TryGetValue(g, out var v) ? v : 1f,
+ hasHealth: g => HasHealthMap.TryGetValue(g, out var v) && v,
+ stackSize: g => StackMap.TryGetValue(g, out var v) ? v : 0u,
+ sendQueryHealth: g => QueryHealthCalls.Add(g),
+ datFont: datFont);
}
// ── B1: Bind initialisation ──────────────────────────────────────────────
- ///
- /// After Bind:
- /// - the health meter is hidden (controller owns initial-hidden state).
- /// - the name element has exactly one UiText child (the name label).
- ///
[Fact]
- public void Bind_healthMeterHidden_andNameTextChildAttached()
+ public void Bind_healthMeterHidden_nameTextChildAttached_nameFloatedOnTop()
{
var (layout, nameEl, _, healthMeterEl) = FakeLayout();
- var (subscribe, _, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, _) =
- MakeDelegates(
- healthTargetMap: new(),
- nameMap: new(),
- healthMap: new(),
- stackMap: new());
+ new Harness().Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
+ Assert.False(healthMeterEl.Visible, "health meter must be Visible=false immediately after Bind");
- // Health meter must start hidden.
- Assert.False(healthMeterEl.Visible,
- "health meter must be Visible=false immediately after Bind");
-
- // A UiText child should have been attached to the name element.
var textChild = nameEl.Children.OfType().SingleOrDefault();
Assert.NotNull(textChild);
- Assert.True(textChild!.Centered, "name UiText must be Centered");
- Assert.True(textChild.ClickThrough, "name UiText must be ClickThrough (non-interactive decoration)");
+ Assert.True(textChild!.Centered, "name UiText must be Centered");
+ Assert.True(textChild.ClickThrough, "name UiText must be ClickThrough");
Assert.False(textChild.AcceptsFocus, "AcceptsFocus must be false on name label");
Assert.False(textChild.IsEditControl, "IsEditControl must be false on name label");
Assert.False(textChild.CapturesPointerDrag, "CapturesPointerDrag must be false on name label");
+
+ // The name element must be floated to the top of the strip's z-order so it draws
+ // OVER the overlay frame and the health bar (retail draws the name over the bar).
+ Assert.True(nameEl.ZOrder > 1000, "name element must be floated above the overlay/meter z-order");
}
- ///
- /// After Bind, the attached UiText's LinesProvider yields no lines (nothing selected yet).
- ///
[Fact]
public void Bind_nameLinesProvider_yieldsEmpty_whenNothingSelected()
{
var (layout, nameEl, _, _) = FakeLayout();
- var (subscribe, _, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, _) =
- MakeDelegates(new(), new(), new(), new());
-
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
+ new Harness().Bind(layout);
var textChild = nameEl.Children.OfType().Single();
- var lines = textChild.LinesProvider();
- Assert.Empty(lines);
+ Assert.Empty(textChild.LinesProvider());
}
- // ── H1: Select a health target (creature) ───────────────────────────────
+ // ── H1: Select a health target — meter does NOT show on select alone ─────
- ///
- /// Selecting a health target (stackSize=1, isHealthTarget=true):
- /// - overlay ActiveState == "ObjectSelected"
- /// - meter Visible == true
- /// - sendQueryHealth invoked exactly once with the guid
- /// - name LinesProvider yields a single white line with the expected name
- ///
[Fact]
- public void SelectHealthTarget_meterVisible_overlayObjectSelected_queryHealthFired()
+ public void SelectHealthTarget_unknownHealth_meterStaysHidden_queryFired_nameAndOverlaySet()
{
const uint Guid = 0xAA01u;
const string ExpectedName = "Drudge Prowler";
var (layout, nameEl, overlayEl, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, queryHealthCalls) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = true },
- nameMap: new() { [Guid] = ExpectedName },
- healthMap: new() { [Guid] = 0.75f },
- stackMap: new() { [Guid] = 1u }); // stackSize=1 → ObjectSelected
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.NameMap[Guid] = ExpectedName;
+ h.StackMap[Guid] = 1u; // ObjectSelected
+ // HasHealthMap[Guid] not set → false (no health known yet)
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
+ h.FireSelection(Guid);
- // Fire the selection.
- fireSelection(Guid);
-
- Assert.True(healthMeterEl.Visible,
- "health meter must become Visible after selecting a health target");
+ // Health not yet known → meter must stay hidden (retail: shows on UpdateHealth).
+ Assert.False(healthMeterEl.Visible,
+ "meter must stay hidden on select when no health is known yet");
+ // But QueryHealth is sent (retail Event_QueryHealth on select for a health target).
+ Assert.Single(h.QueryHealthCalls);
+ Assert.Equal(Guid, h.QueryHealthCalls[0]);
Assert.Equal("ObjectSelected", overlayEl.ActiveState);
- Assert.Single(queryHealthCalls);
- Assert.Equal(Guid, queryHealthCalls[0]);
- // Name label: the LinesProvider should yield the creature's name as a white line.
- var textChild = nameEl.Children.OfType().Single();
- var lines = textChild.LinesProvider();
+ var lines = nameEl.Children.OfType().Single().LinesProvider();
Assert.Single(lines);
Assert.Equal(ExpectedName, lines[0].Text);
Assert.Equal(new Vector4(1f, 1f, 1f, 1f), lines[0].Color);
}
- // ── H2: Select a stacked item ────────────────────────────────────────────
+ // ── H1b: Health arrives for the selected guid → meter appears ───────────
- ///
- /// Selecting a stacked item (stackSize > 1): overlay ActiveState == "StackedItemSelected".
- ///
[Fact]
- public void SelectStackedItem_overlayStackedItemSelected()
+ public void HealthChanged_forSelectedGuid_showsMeter()
+ {
+ const uint Guid = 0xAA02u;
+
+ var (layout, _, _, healthMeterEl) = FakeLayout();
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.NameMap[Guid] = "Drudge Slinker";
+ h.Bind(layout);
+
+ h.FireSelection(Guid);
+ Assert.False(healthMeterEl.Visible, "hidden until health arrives");
+
+ // Simulate UpdateHealth (0x01C0) for the selected guid.
+ h.FireHealth(Guid, 0.6f);
+ Assert.True(healthMeterEl.Visible, "meter must appear when health arrives for the selected guid");
+ }
+
+ [Fact]
+ public void HealthChanged_forOtherGuid_doesNotShowMeter()
+ {
+ const uint Sel = 0xAA03u, Other = 0xBB03u;
+
+ var (layout, _, _, healthMeterEl) = FakeLayout();
+ var h = new Harness();
+ h.HealthTargetMap[Sel] = true;
+ h.HealthTargetMap[Other] = true;
+ h.NameMap[Sel] = "Selected";
+ h.Bind(layout);
+
+ h.FireSelection(Sel);
+ h.FireHealth(Other, 0.5f); // health for a DIFFERENT entity
+
+ Assert.False(healthMeterEl.Visible, "health for a non-selected guid must not show the meter");
+ }
+
+ // ── H1c: Already-known health → meter shows immediately on select ───────
+
+ [Fact]
+ public void SelectHealthTarget_alreadyKnownHealth_meterVisibleImmediately()
+ {
+ const uint Guid = 0xAA04u;
+
+ var (layout, _, _, healthMeterEl) = FakeLayout();
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.HasHealthMap[Guid] = true; // health already cached (e.g. previously assessed)
+ h.HealthMap[Guid] = 0.9f;
+ h.NameMap[Guid] = "Olthoi";
+ h.Bind(layout);
+
+ h.FireSelection(Guid);
+ Assert.True(healthMeterEl.Visible,
+ "meter must show immediately when health is already known for the target");
+ }
+
+ // ── H2: Stacked item ─────────────────────────────────────────────────────
+
+ [Fact]
+ public void SelectStackedItem_overlayStackedItemSelected_meterHidden()
{
const uint Guid = 0xBB02u;
var (layout, _, overlayEl, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, _) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = false },
- nameMap: new() { [Guid] = "Heal Kits" },
- healthMap: new(),
- stackMap: new() { [Guid] = 5u }); // stackSize > 1
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = false;
+ h.NameMap[Guid] = "Heal Kits";
+ h.StackMap[Guid] = 5u; // stackSize > 1
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
-
- fireSelection(Guid);
+ h.FireSelection(Guid);
Assert.Equal("StackedItemSelected", overlayEl.ActiveState);
- // Not a health target → meter stays hidden.
Assert.False(healthMeterEl.Visible);
}
- // ── H3: Select a non-health target (friendly NPC / scenery) ─────────────
+ // ── H3: Non-health target (friendly NPC / scenery / Door) ───────────────
- ///
- /// Selecting a non-health target (isHealthTarget=false):
- /// - meter stays hidden
- /// - sendQueryHealth NOT invoked
- /// - name and overlay are still set
- ///
[Fact]
- public void SelectNonHealthTarget_meterHidden_noQueryHealth_nameSet()
+ public void SelectNonHealthTarget_meterHidden_noQuery_nameSet()
{
const uint Guid = 0xCC03u;
const string ExpectedName = "Town Crier";
var (layout, nameEl, overlayEl, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, queryHealthCalls) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = false },
- nameMap: new() { [Guid] = ExpectedName },
- healthMap: new(),
- stackMap: new() { [Guid] = 0u }); // non-stack → ObjectSelected
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = false;
+ h.NameMap[Guid] = ExpectedName;
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
-
- fireSelection(Guid);
+ h.FireSelection(Guid);
Assert.False(healthMeterEl.Visible, "meter must stay hidden for a non-health target");
- Assert.Empty(queryHealthCalls); // sendQueryHealth must NOT be invoked for a non-health target
-
- // Overlay and name are still populated.
+ Assert.Empty(h.QueryHealthCalls);
Assert.Equal("ObjectSelected", overlayEl.ActiveState);
- var textChild = nameEl.Children.OfType().Single();
- var lines = textChild.LinesProvider();
+
+ var lines = nameEl.Children.OfType().Single().LinesProvider();
Assert.Single(lines);
Assert.Equal(ExpectedName, lines[0].Text);
}
- // ── H4: Deselect (null) ──────────────────────────────────────────────────
+ // ── H4: Deselect clears the strip ────────────────────────────────────────
- ///
- /// Selecting null clears the strip:
- /// - meter Visible == false
- /// - overlay ActiveState == ""
- /// - name LinesProvider yields empty
- ///
[Fact]
public void SelectNull_clearsStrip()
{
const uint Guid = 0xDD04u;
var (layout, nameEl, overlayEl, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, _) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = true },
- nameMap: new() { [Guid] = "Wolf" },
- healthMap: new() { [Guid] = 0.5f },
- stackMap: new() { [Guid] = 0u });
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.HasHealthMap[Guid] = true; // so the meter is shown on select
+ h.HealthMap[Guid] = 0.5f;
+ h.NameMap[Guid] = "Wolf";
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
-
- // First select something...
- fireSelection(Guid);
+ h.FireSelection(Guid);
Assert.True(healthMeterEl.Visible);
- // ...then deselect.
- fireSelection(null);
+ h.FireSelection(null);
Assert.False(healthMeterEl.Visible, "meter must be hidden after deselect");
Assert.Equal("", overlayEl.ActiveState);
-
- var textChild = nameEl.Children.OfType().Single();
- var lines = textChild.LinesProvider();
- Assert.Empty(lines);
+ Assert.Empty(nameEl.Children.OfType().Single().LinesProvider());
}
- // ── H5: Clear → new selection (re-select) ────────────────────────────────
+ // ── H5: Re-select a different guid ───────────────────────────────────────
- ///
- /// Selecting one target then another should clear the first and apply the second.
- ///
[Fact]
public void ReSelect_differentGuid_clearsFirstThenAppliesSecond()
{
- const uint GuidA = 0xEE05u;
- const uint GuidB = 0xFF06u;
+ const uint GuidA = 0xEE05u, GuidB = 0xFF06u;
var (layout, nameEl, overlayEl, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, queryHealthCalls) =
- MakeDelegates(
- healthTargetMap: new() { [GuidA] = true, [GuidB] = false },
- nameMap: new() { [GuidA] = "Bandit", [GuidB] = "Chest" },
- healthMap: new() { [GuidA] = 1.0f },
- stackMap: new() { [GuidA] = 0u, [GuidB] = 0u });
+ var h = new Harness();
+ h.HealthTargetMap[GuidA] = true; h.HealthTargetMap[GuidB] = false;
+ h.HasHealthMap[GuidA] = true; // A shows its bar on select
+ h.NameMap[GuidA] = "Bandit"; h.NameMap[GuidB] = "Chest";
+ h.HealthMap[GuidA] = 1.0f;
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
-
- // Select A (health target).
- fireSelection(GuidA);
+ h.FireSelection(GuidA);
Assert.True(healthMeterEl.Visible);
- Assert.Single(queryHealthCalls);
+ Assert.Single(h.QueryHealthCalls);
- // Select B (non-health target) — must clear A's state and apply B.
- fireSelection(GuidB);
+ h.FireSelection(GuidB);
- Assert.False(healthMeterEl.Visible, "health meter must be cleared when switching to non-health target");
+ Assert.False(healthMeterEl.Visible, "meter must clear when switching to a non-health target");
Assert.Equal("ObjectSelected", overlayEl.ActiveState);
- // sendQueryHealth must NOT be called again (B is not a health target).
- Assert.Single(queryHealthCalls);
+ Assert.Single(h.QueryHealthCalls); // B is not a health target → no extra query
- // Name should reflect B.
- var textChild = nameEl.Children.OfType().Single();
- var lines = textChild.LinesProvider();
+ var lines = nameEl.Children.OfType().Single().LinesProvider();
Assert.Single(lines);
Assert.Equal("Chest", lines[0].Text);
}
- // ── H6: Partial layout (missing elements) ────────────────────────────────
+ // ── H6: Overlay flash reverts after the flash window (Tick) ─────────────
+
+ [Fact]
+ public void Tick_revertsOverlayFlash_afterDuration()
+ {
+ const uint Guid = 0xAB06u;
+
+ var (layout, _, overlayEl, _) = FakeLayout();
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = false;
+ h.NameMap[Guid] = "Lever";
+ var c = h.Bind(layout);
+
+ h.FireSelection(Guid);
+ Assert.Equal("ObjectSelected", overlayEl.ActiveState);
+
+ // A small tick before the window elapses → still flashing.
+ c.Tick(0.1);
+ Assert.Equal("ObjectSelected", overlayEl.ActiveState);
+
+ // Tick past the 0.25s window → overlay reverts to blank.
+ c.Tick(0.2);
+ Assert.Equal("", overlayEl.ActiveState);
+ }
+
+ // ── H7: Partial layout (missing elements) ────────────────────────────────
- ///
- /// When elements are absent (partial layout), Bind does not throw and
- /// OnSelectionChanged does not throw for any combination.
- ///
[Fact]
public void PartialLayout_noElements_doesNotThrow()
{
- // Empty layout — none of the three ids are present.
var root = new UiPanel();
var layout = new ImportedLayout(root, new Dictionary());
- Action? registeredHandler = null;
- var queryHealthCalls = new List();
+ var h = new Harness();
+ h.HealthTargetMap[0x12345678u] = true;
+ h.NameMap[0x12345678u] = "Something";
+ var c = h.Bind(layout);
- SelectedObjectController.Bind(
- layout,
- subscribeSelectionChanged: h => registeredHandler = h,
- isHealthTarget: _ => true,
- name: _ => "Something",
- healthPercent: _ => 1f,
- stackSize: _ => 0u,
- sendQueryHealth: g => queryHealthCalls.Add(g),
- datFont: null);
+ Assert.NotNull(h.SelectionHandler);
+ Assert.Null(Record.Exception(() => h.FireSelection(0x12345678u)));
+ Assert.Null(Record.Exception(() => h.FireHealth(0x12345678u, 0.5f)));
+ Assert.Null(Record.Exception(() => c.Tick(0.5)));
+ Assert.Null(Record.Exception(() => h.FireSelection(null)));
- Assert.NotNull(registeredHandler);
-
- // Firing selection / deselection on a partial layout must not throw.
- var ex = Record.Exception(() => registeredHandler!.Invoke(0x12345678u));
- Assert.Null(ex);
-
- ex = Record.Exception(() => registeredHandler!.Invoke(null));
- Assert.Null(ex);
-
- // QueryHealth must still be called (the delegate doesn't depend on the meter element).
- Assert.Single(queryHealthCalls);
- Assert.Equal(0x12345678u, queryHealthCalls[0]);
+ Assert.Single(h.QueryHealthCalls);
+ Assert.Equal(0x12345678u, h.QueryHealthCalls[0]);
}
- // ── H7: Fill closure reflects live healthPercent ─────────────────────────
+ // ── H8: Fill reflects live health; returns 0 when nothing selected ──────
- ///
- /// The meter's Fill closure reads the current guid's health percent from the
- /// healthPercent delegate on every poll — so if the server updates the
- /// health between polls the fill reflects the new value without re-selecting.
- ///
[Fact]
public void HealthMeterFill_reflectsLiveHealthPercent()
{
const uint Guid = 0xAA07u;
- float currentHealth = 0.5f;
var (layout, _, _, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, _, stackSize, sendQueryHealth, _) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = true },
- nameMap: new() { [Guid] = "Arwic Banderling" },
- healthMap: new(), // not used here
- stackMap: new() { [Guid] = 0u });
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.NameMap[Guid] = "Arwic Banderling";
+ h.HealthMap[Guid] = 0.5f;
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name,
- healthPercent: _ => currentHealth, // reads the captured variable
- stackSize, sendQueryHealth, datFont: null);
-
- fireSelection(Guid);
-
- // Fill should return the current health value.
+ h.FireSelection(Guid);
Assert.Equal(0.5f, healthMeterEl.Fill());
- // Simulate server updating health (as if UpdateHealth 0x01C0 arrived).
- currentHealth = 0.25f;
+ h.HealthMap[Guid] = 0.25f; // server updates health
Assert.Equal(0.25f, healthMeterEl.Fill());
}
- // ── H8: Fill returns 0 when nothing is selected ──────────────────────────
-
- ///
- /// After deselect, the meter Fill returns 0f (empty bar) rather than
- /// the last selected target's health value.
- ///
[Fact]
public void HealthMeterFill_returnsZero_whenNothingSelected()
{
const uint Guid = 0xAA08u;
var (layout, _, _, healthMeterEl) = FakeLayout();
- var (subscribe, fireSelection, isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, _) =
- MakeDelegates(
- healthTargetMap: new() { [Guid] = true },
- nameMap: new() { [Guid] = "Spider" },
- healthMap: new() { [Guid] = 0.8f },
- stackMap: new() { [Guid] = 0u });
+ var h = new Harness();
+ h.HealthTargetMap[Guid] = true;
+ h.NameMap[Guid] = "Spider";
+ h.HealthMap[Guid] = 0.8f;
+ h.Bind(layout);
- SelectedObjectController.Bind(layout, subscribe,
- isHealthTarget, name, healthPercent, stackSize, sendQueryHealth, datFont: null);
+ h.FireSelection(Guid);
+ Assert.Equal(0.8f, healthMeterEl.Fill());
- fireSelection(Guid);
- Assert.Equal(0.8f, healthMeterEl.Fill()); // sanity check
-
- fireSelection(null);
- // After deselect, Fill() must return 0f (or null coerced to 0f).
- var fill = healthMeterEl.Fill();
- Assert.Equal(0f, fill ?? 0f);
+ h.FireSelection(null);
+ Assert.Equal(0f, healthMeterEl.Fill() ?? 0f);
}
}