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

@ -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,
};
}