feat(ui): D.2b item interaction + retail cursors + live character sheet

Lands the codex-worktree D.2b stream plus the extraction the 2026-07-02
UI architecture review mandated before commit:

- ItemInteractionController: single owner of double-click use/equip/
  container-open, targeted-use mode (health kits), drag-out drop;
  toolbar shortcut drags don't drop the real item. ItemEquipRules for
  multi-slot (coat) coverage via equip masks.
- Cursor phase: CursorFeedbackController (semantic priority chain:
  drag > resize > window-move > target-mode > text) + RetailCursorCatalog
  (enums 0x27/0x28/0x29, hotspot 14,14; ClientUISystem::UpdateCursorState
  0x00564630) resolved through the portal EnumIDMap chain by
  RetailCursorResolver; RetailCursorManager applies dat cursor art to the
  OS cursor. Register row AP-72 covers the OS standard-cursor fallback.
- Character window goes live: CharacterSheetProvider owns sheet assembly,
  XP-curve/raise-cost math and the raise flow — extracted out of
  GameWindow per Code Structure Rule 1 instead of committing the ~430-line
  feature body there. Optimistic XP/credit debits go through eventful
  store APIs (new ClientObjectTable.UpdateInt64Property +
  LocalPlayerState.DebitIntProperty/DebitInt64Property) instead of raw
  property-dictionary writes; register row AP-73 covers the still-missing
  raise ledger (#163).
- RetailWindowFrame: the shared nine-slice window mount recipe; the
  character window uses it, remaining windows migrate via #164.
- Status-bar buttons toggle inventory/character windows; retail row-major
  backpack ordering; WorldSession.SendUseWithTarget + raise/train sends.

GameWindow shrinks 14,214 -> 13,877 lines despite the new features; the
sheet/raise logic is unit-tested in CharacterSheetProviderTests instead
of trapped in the god object. Build green; full suite 3,286 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-03 09:18:43 +02:00
parent e3fc7ac5ba
commit b7dc91a053
74 changed files with 6669 additions and 238 deletions

View file

@ -659,8 +659,12 @@ public sealed class GameWindow : IDisposable
private AcDream.UI.Abstractions.Panels.Vitals.VitalsVM? _vitalsVm;
// Phase D.2b — retail-look UI tree (dormant UiHost wired here). Null unless ACDREAM_RETAIL_UI=1.
private AcDream.App.UI.UiHost? _uiHost;
private AcDream.App.UI.Testing.RetailUiAutomationScriptRunner? _uiAutomationRunner;
private AcDream.App.UI.CursorFeedbackController? _cursorFeedbackController;
private RetailCursorManager? _retailCursorManager;
// Phase D.5.1 — toolbar controller (kept for lifetime clarity; mirrors _chatWindowController pattern).
private AcDream.App.UI.Layout.ToolbarController? _toolbarController;
private AcDream.App.UI.ItemInteractionController? _itemInteractionController;
// Phase D.5.3a — selected-object strip controller (name, overlay state, health meter).
private AcDream.App.UI.Layout.SelectedObjectController? _selectedObjectController;
// Phase D.2b-B — inventory controller (backpack grid + pack-selector + burden meter).
@ -764,6 +768,9 @@ public sealed class GameWindow : IDisposable
// and out keeps the right skills.
private int _lastSeenRunSkill = -1;
private int _lastSeenJumpSkill = -1;
// Phase D.2b-C — live character-sheet assembly + raise flow (extracted
// feature class; GameWindow only wires it). Null unless ACDREAM_RETAIL_UI=1.
private AcDream.App.UI.Layout.CharacterSheetProvider? _characterSheetProvider;
// K.1b: this field is RESERVED — written when entering / leaving player
// mode and previously fed mouse-X into MovementInput.MouseDeltaX. Now
// never consumed by MovementInput (mouse never drives character yaw —
@ -1829,6 +1836,28 @@ public sealed class GameWindow : IDisposable
{
_vitalsVm ??= new AcDream.UI.Abstractions.Panels.Vitals.VitalsVM(Combat, LocalPlayer);
_uiHost = new AcDream.App.UI.UiHost(_gl, shadersDir, _debugFont);
_itemInteractionController = new AcDream.App.UI.ItemInteractionController(
Objects,
playerGuid: () => _playerServerGuid,
sendUse: g => _liveSession?.SendUse(g),
sendUseWithTarget: (source, target) => _liveSession?.SendUseWithTarget(source, target),
sendWield: (item, mask) => _liveSession?.SendGetAndWieldItem(item, mask),
sendDrop: item => _liveSession?.SendDropItem(item),
toast: text => _debugVm?.AddToast(text));
_cursorFeedbackController = new AcDream.App.UI.CursorFeedbackController(_itemInteractionController);
_retailCursorManager = new RetailCursorManager(_dats!, _datLock);
_characterSheetProvider = new AcDream.App.UI.Layout.CharacterSheetProvider(
Objects, LocalPlayer,
playerGuid: () => _playerServerGuid,
activeToonName: () => _activeToonKey,
fallbackSheet: AcDream.App.Studio.SampleData.SampleCharacter,
canSendRaise: () => _liveSession is not null
&& _liveSession.CurrentState == AcDream.Core.Net.WorldSession.State.InWorld,
sendRaiseAttribute: (statId, cost) => _liveSession?.SendRaiseAttribute(statId, cost),
sendRaiseVital: (statId, cost) => _liveSession?.SendRaiseVital(statId, cost),
sendRaiseSkill: (statId, cost) => _liveSession?.SendRaiseSkill(statId, cost),
sendTrainSkill: (statId, credits) => _liveSession?.SendTrainSkill(statId, credits));
_uiHost.Root.DragReleasedOutsideUi += OnUiDragReleasedOutside;
// Feed Silk input to the UiRoot tree so windows drag / close / select.
// UiRoot consumes UI events; the game InputDispatcher (subscribed to the
@ -2079,6 +2108,7 @@ public sealed class GameWindow : IDisposable
peaceDigits: toolbarPeaceDigits,
warDigits: toolbarWarDigits,
emptyDigits: toolbarEmptyDigits,
itemInteraction: _itemInteractionController,
sendAddShortcut: (i, g) => _liveSession?.SendAddShortcut(i, g),
sendRemoveShortcut: i => _liveSession?.SendRemoveShortcut(i));
@ -2176,6 +2206,47 @@ public sealed class GameWindow : IDisposable
}
else Console.WriteLine("[D.5.1] toolbar: LayoutDesc 0x21000016 not found.");
// Phase D.2b-C: live Character window (Attributes / Skills / Titles) from
// LayoutDesc 0x2100002E. Starts hidden and is toggled by the status-bar
// character button; stats use the same retail-bound sheet shape as the studio
// until the live character stat feed is wired.
AcDream.App.UI.Layout.ImportedLayout? characterLayout;
lock (_datLock)
characterLayout = AcDream.App.UI.Layout.LayoutImporter.Import(
_dats!, 0x2100002Eu, ResolveChrome, vitalsDatFont, ResolveDatFont);
if (characterLayout is not null)
{
AcDream.App.UI.Layout.CharacterStatController.Bind(
characterLayout,
data: _characterSheetProvider!.BuildSheet,
datFont: vitalsDatFont,
rowDatFont: ResolveDatFont(0x40000001u) ?? vitalsDatFont,
spriteResolve: ResolveChrome,
onRaiseRequest: _characterSheetProvider.HandleRaiseRequest,
onClose: () => CloseRetailWindow(AcDream.App.UI.WindowNames.Character));
// Retail-authored content is 380px tall but the skill list wants to
// grow: bottom-edge-only resize up to 760px, X locked to the dat width.
AcDream.App.UI.Layout.RetailWindowFrame.Mount(
_uiHost.Root, characterLayout.Root, ResolveChrome,
new AcDream.App.UI.Layout.RetailWindowFrame.Options
{
Left = 540f,
Top = 18f,
MaxHeight = 760f,
ResizeX = false,
ResizableEdges = AcDream.App.UI.ResizeEdges.Bottom,
Visible = false,
ContentAnchors = AcDream.App.UI.AnchorEdges.Left | AcDream.App.UI.AnchorEdges.Top
| AcDream.App.UI.AnchorEdges.Bottom,
ContentClickThrough = false,
WindowName = AcDream.App.UI.WindowNames.Character,
});
Console.WriteLine("[D.2b-C] retail character window from LayoutDesc importer (0x2100002E).");
}
else Console.WriteLine("[D.2b-C] character: LayoutDesc 0x2100002E not found.");
// Drain plugin-registered markup panels (buffered before the GL
// window opened) into the same UiRoot tree. A faulty plugin markup
// file is isolated — logged + skipped, never crashes the client.
@ -2294,13 +2365,16 @@ public sealed class GameWindow : IDisposable
AcDream.Core.Player.LocalPlayerState.AttributeKind.Strength) is { } sa
? (int?)sa.Current : null,
datFont: vitalsDatFont,
ownerName: _characterSheetProvider!.CharacterName,
contentsEmptySprite: contentsEmpty,
sideBagEmptySprite: sideBagEmpty,
mainPackEmptySprite: mainPackEmpty,
sendUse: g => _liveSession?.SendUse(g),
sendNoLongerViewing: g => _liveSession?.SendNoLongerViewingContents(g),
sendPutItemInContainer: (item, container, placement) =>
_liveSession?.SendPutItemInContainer(item, container, placement));
_liveSession?.SendPutItemInContainer(item, container, placement),
itemInteraction: _itemInteractionController,
onClose: () => CloseRetailWindow(AcDream.App.UI.WindowNames.Inventory));
// Slice 1: bind the paperdoll equip slots (same imported subtree) — show equipped gear +
// wield-on-drop. Unwield is handled by InventoryController (drag an equipped item to the grid).
@ -2312,7 +2386,8 @@ public sealed class GameWindow : IDisposable
// Empty equip slots show a visible frame (same square as the inventory grid) so every
// slot position is seen + usable; the live 3D character (the doll) is Slice 2.
emptySlotSprite: contentsEmpty,
datFont: vitalsDatFont); // Slice 2: caption the "Slots" toggle button
datFont: vitalsDatFont,
itemInteraction: _itemInteractionController); // Slice 2: caption the "Slots" toggle button
// Slice 2: capture the doll viewport widget (Type 0xD, element 0x100001D5) + the inventory
// frame so the per-frame pre-UI hook can render the 3-D doll into the widget's texture only
@ -2324,6 +2399,25 @@ public sealed class GameWindow : IDisposable
Console.WriteLine("[D.2b-B] retail inventory window from LayoutDesc importer (0x21000023).");
}
else Console.WriteLine("[D.2b-B] inventory: LayoutDesc 0x21000023 not found.");
_toolbarController?.BindWindowToggles(
toggleInventory: () => ToggleRetailWindow(AcDream.App.UI.WindowNames.Inventory),
toggleCharacter: () => ToggleRetailWindow(AcDream.App.UI.WindowNames.Character));
SyncToolbarWindowButtons();
if (_options.UiProbeEnabled)
{
void ProbeLog(string message) => Console.WriteLine("[UI-PROBE] " + message);
var probe = new AcDream.App.UI.Testing.RetailUiAutomationProbe(
_uiHost.Root,
Objects,
ProbeLog);
_uiAutomationRunner = new AcDream.App.UI.Testing.RetailUiAutomationScriptRunner(
probe,
_options.UiProbeScript,
_options.UiProbeDump,
ProbeLog);
}
}
// Phase N.4+N.5 — WB rendering pipeline foundation. The modern path is
@ -2689,6 +2783,13 @@ public sealed class GameWindow : IDisposable
// and jumps undershot retail by ~30 % at typical
// attribute levels.
var skillTable = _dats?.Get<DatReaderWriter.DBObjs.SkillTable>(0x0E000004u);
if (_characterSheetProvider is not null && _dats is not null)
{
_characterSheetProvider.SkillTable = skillTable;
_characterSheetProvider.ExperienceTable =
AcDream.App.UI.Layout.CharacterSheetProvider.LoadExperienceTable(
_dats, Console.WriteLine);
}
AcDream.Core.Net.GameEventWiring.WireAll(
_liveSession.GameEvents, Objects, Combat, SpellBook, Chat, LocalPlayer,
@ -9498,6 +9599,8 @@ public sealed class GameWindow : IDisposable
if (_options.RetailUi && _uiHost is not null)
{
_uiHost.Tick(deltaSeconds);
_uiAutomationRunner?.Tick(deltaSeconds);
UpdateRetailCursorFeedback();
_uiHost.Draw(new System.Numerics.Vector2(_window!.Size.X, _window.Size.Y));
}
@ -11654,6 +11757,42 @@ public sealed class GameWindow : IDisposable
// first EnterWorld.
private AcDream.UI.Abstractions.Panels.Settings.SettingsStore? _settingsStore;
private string _activeToonKey = "default";
private bool ToggleRetailWindow(string name)
{
bool visible = _uiHost?.ToggleWindow(name) ?? false;
SyncToolbarWindowButtons();
return visible;
}
private void CloseRetailWindow(string name)
{
_uiHost?.HideWindow(name);
SyncToolbarWindowButtons();
}
private void SyncToolbarWindowButtons()
{
if (_toolbarController is null || _uiHost is null) return;
_toolbarController.SetInventoryOpen(_uiHost.IsWindowVisible(AcDream.App.UI.WindowNames.Inventory));
_toolbarController.SetCharacterOpen(_uiHost.IsWindowVisible(AcDream.App.UI.WindowNames.Character));
}
private void UpdateRetailCursorFeedback()
{
if (_uiHost is null || _cursorFeedbackController is null || _retailCursorManager is null || _input is null)
return;
var feedback = _cursorFeedbackController.Update(_uiHost.Root);
_retailCursorManager.Apply(_input.Mice, feedback);
}
private void OnUiDragReleasedOutside(object payload, int x, int y)
{
if (payload is AcDream.App.UI.ItemDragPayload itemPayload)
_itemInteractionController?.DropToWorld(itemPayload);
}
// L.0 follow-up: persisted-settings cache populated by
// LoadAndApplyPersistedSettings (runs unconditionally in OnLoad,
// not gated on DevToolsEnabled). The Settings PANEL construction
@ -12046,7 +12185,7 @@ public sealed class GameWindow : IDisposable
// Retail F12 (rebindable). Gated upstream by WantsKeyboard, so it
// does not fire while the chat input holds focus. Null _uiHost =
// retail UI off (ACDREAM_RETAIL_UI unset) → no-op.
_uiHost?.ToggleWindow(AcDream.App.UI.WindowNames.Inventory);
ToggleRetailWindow(AcDream.App.UI.WindowNames.Inventory);
break;
case AcDream.UI.Abstractions.Input.InputAction.AcdreamToggleDebugPanel:
@ -12153,7 +12292,9 @@ public sealed class GameWindow : IDisposable
break;
case AcDream.UI.Abstractions.Input.InputAction.EscapeKey:
if (_cameraController?.IsFlyMode == true)
if (_itemInteractionController?.IsTargetModeActive == true)
_itemInteractionController.CancelTargetMode();
else if (_cameraController?.IsFlyMode == true)
_cameraController.ToggleFly(); // exit fly, release cursor
else if (_playerMode)
{
@ -12291,6 +12432,12 @@ public sealed class GameWindow : IDisposable
if (picked is uint guid)
{
if (_itemInteractionController?.IsTargetModeActive == true)
{
_itemInteractionController.AcquireTarget(guid);
return;
}
SelectedGuid = guid;
string label = DescribeLiveEntity(guid);
Console.WriteLine($"[B.4b] pick guid=0x{guid:X8} name={label}");
@ -12324,6 +12471,8 @@ public sealed class GameWindow : IDisposable
}
else
{
if (_itemInteractionController?.IsTargetModeActive == true)
return;
_debugVm?.AddToast("Nothing to select");
}
}

View file

@ -0,0 +1,142 @@
using AcDream.App.UI;
using AcDream.Core.Textures;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
using Silk.NET.Core;
using Silk.NET.Input;
namespace AcDream.App.Rendering;
/// <summary>Applies retail cursor feedback to Silk using dat MediaDescCursor art when available.</summary>
public sealed class RetailCursorManager
{
private readonly DatCollection _dats;
private readonly object _datLock;
private readonly RetailCursorResolver _globalCursors;
private readonly Dictionary<uint, RawImage> _imagesBySurface = new();
private readonly HashSet<uint> _missingSurfaces = new();
private CursorFeedbackKind _lastKind = (CursorFeedbackKind)(-1);
private UiCursorMedia _lastCursor;
public RetailCursorManager(DatCollection dats, object datLock)
{
_dats = dats;
_datLock = datLock;
_globalCursors = new RetailCursorResolver(dats, datLock);
}
public void Apply(IEnumerable<IMouse> mice, CursorFeedback feedback)
{
if (feedback.Cursor.IsValid && TryGetImage(feedback.Cursor.File, out var image))
{
ApplyCustom(mice, feedback.Cursor, image);
_lastKind = feedback.Kind;
_lastCursor = feedback.Cursor;
return;
}
if (_globalCursors.TryResolve(feedback.Kind, out var globalCursor)
&& TryGetImage(globalCursor.File, out var globalImage))
{
ApplyCustom(mice, globalCursor, globalImage);
_lastKind = feedback.Kind;
_lastCursor = globalCursor;
return;
}
ApplyStandard(mice, StandardCursorFor(feedback.Kind));
_lastKind = feedback.Kind;
_lastCursor = default;
}
private void ApplyCustom(IEnumerable<IMouse> mice, UiCursorMedia cursorMedia, RawImage image)
{
if (_lastCursor.Equals(cursorMedia))
return;
foreach (var mouse in mice)
{
var cursor = mouse.Cursor;
cursor.Image = image;
cursor.HotspotX = cursorMedia.HotspotX;
cursor.HotspotY = cursorMedia.HotspotY;
if (cursor.Type != CursorType.Custom)
cursor.Type = CursorType.Custom;
}
}
private void ApplyStandard(IEnumerable<IMouse> mice, StandardCursor desired)
{
if (_lastCursor.Equals(default(UiCursorMedia)) && _lastKind != (CursorFeedbackKind)(-1)
&& StandardCursorFor(_lastKind) == desired)
return;
foreach (var mouse in mice)
{
var cursor = mouse.Cursor;
var standard = desired;
if (!cursor.IsSupported(standard))
standard = StandardCursor.Arrow;
if (!cursor.IsSupported(standard))
continue;
if (cursor.Type != CursorType.Standard)
cursor.Type = CursorType.Standard;
if (cursor.StandardCursor != standard)
cursor.StandardCursor = standard;
}
}
private bool TryGetImage(uint renderSurfaceId, out RawImage image)
{
if (_imagesBySurface.TryGetValue(renderSurfaceId, out image))
return true;
if (_missingSurfaces.Contains(renderSurfaceId))
return false;
DecodedTexture? decoded = DecodeCursorSurface(renderSurfaceId);
if (decoded is null || decoded.Width <= 0 || decoded.Height <= 0 || decoded.Rgba8.Length == 0)
{
_missingSurfaces.Add(renderSurfaceId);
image = default;
return false;
}
image = new RawImage(decoded.Width, decoded.Height, decoded.Rgba8);
_imagesBySurface[renderSurfaceId] = image;
return true;
}
private DecodedTexture? DecodeCursorSurface(uint renderSurfaceId)
{
lock (_datLock)
{
if (!_dats.Portal.TryGet<RenderSurface>(renderSurfaceId, out var rs)
&& !_dats.HighRes.TryGet<RenderSurface>(renderSurfaceId, out rs))
return null;
Palette? palette = rs.DefaultPaletteId != 0
? _dats.Get<Palette>(rs.DefaultPaletteId)
: null;
return SurfaceDecoder.DecodeRenderSurface(rs, palette);
}
}
private static StandardCursor StandardCursorFor(CursorFeedbackKind kind)
=> kind switch
{
CursorFeedbackKind.Text => StandardCursor.IBeam,
CursorFeedbackKind.WindowMove => StandardCursor.ResizeAll,
CursorFeedbackKind.ResizeHorizontal => StandardCursor.HResize,
CursorFeedbackKind.ResizeVertical => StandardCursor.VResize,
CursorFeedbackKind.ResizeDiagonalNwse => StandardCursor.NwseResize,
CursorFeedbackKind.ResizeDiagonalNesw => StandardCursor.NeswResize,
CursorFeedbackKind.Drag => StandardCursor.Hand,
CursorFeedbackKind.DragAccept => StandardCursor.ResizeAll,
CursorFeedbackKind.DragReject => StandardCursor.NotAllowed,
CursorFeedbackKind.TargetPending => StandardCursor.Crosshair,
CursorFeedbackKind.TargetValid => StandardCursor.ResizeAll,
CursorFeedbackKind.TargetInvalid => StandardCursor.NotAllowed,
_ => StandardCursor.Arrow,
};
}

View file

@ -0,0 +1,76 @@
using AcDream.App.UI;
using DatReaderWriter;
using DatReaderWriter.DBObjs;
namespace AcDream.App.Rendering;
/// <summary>Resolves retail global cursor enum IDs through the portal EnumIDMap chain.</summary>
internal sealed class RetailCursorResolver
{
private readonly DatCollection _dats;
private readonly object _datLock;
private readonly Dictionary<uint, uint> _didByEnum = new();
private readonly HashSet<uint> _missingEnums = new();
public RetailCursorResolver(DatCollection dats, object datLock)
{
_dats = dats;
_datLock = datLock;
}
public bool TryResolve(CursorFeedbackKind kind, out UiCursorMedia cursor)
{
cursor = default;
if (!RetailCursorCatalog.TryGetGlobalCursor(kind, out var spec))
return false;
return TryResolve(spec, out cursor);
}
internal bool TryResolve(RetailCursorSpec spec, out UiCursorMedia cursor)
{
cursor = default;
if (!spec.IsValid)
return false;
if (_didByEnum.TryGetValue(spec.EnumId, out uint cachedDid))
{
cursor = new UiCursorMedia(cachedDid, spec.HotspotX, spec.HotspotY);
return true;
}
if (_missingEnums.Contains(spec.EnumId))
return false;
uint did = ResolveDidByEnum(spec.EnumId);
if (did == 0)
{
_missingEnums.Add(spec.EnumId);
return false;
}
cursor = new UiCursorMedia(did, spec.HotspotX, spec.HotspotY);
_didByEnum[spec.EnumId] = did;
return true;
}
private uint ResolveDidByEnum(uint cursorEnum)
{
lock (_datLock)
{
uint masterDid = (uint)_dats.Portal.Header.MasterMapId;
if (masterDid == 0)
return 0;
if (!_dats.Portal.TryGet<EnumIDMap>(masterDid, out var master) || master is null)
return 0;
if (!master.ClientEnumToID.TryGetValue(RetailCursorCatalog.CursorEnumTable, out uint cursorMapDid))
return 0;
if (!_dats.Portal.TryGet<EnumIDMap>(cursorMapDid, out var cursorMap) || cursorMap is null)
return 0;
return cursorMap.ClientEnumToID.TryGetValue(cursorEnum, out uint did) ? did : 0;
}
}
}