feat(ui): complete retail cursor state machine

Port every reachable ClientUISystem cursor branch through the production DAT enum map, preserve global-default versus widget-local event ordering, and surface the registered OS fallback. Route all four toolbar stance indicators through the same combat toggle command as the key binding, with golden DAT and transition conformance coverage.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-11 08:31:40 +02:00
parent 05f6222865
commit 6fcc510d5d
16 changed files with 535 additions and 164 deletions

View file

@ -1,4 +1,5 @@
using AcDream.App.UI;
using AcDream.Core.Combat;
using AcDream.Core.Items;
namespace AcDream.App.Tests.UI;
@ -72,9 +73,15 @@ public sealed class CursorFeedbackControllerTests
Assert.True(interaction.ActivateItem(Source));
Assert.Equal(CursorFeedbackKind.TargetValid,
c.Resolve(new CursorFeedbackSnapshot(HoverUi: true, HoverTargetGuid: Player)).Kind);
c.Resolve(new CursorFeedbackSnapshot(
HoverUi: true,
HoverTargetGuid: Player,
HoverTargetCompatible: true)).Kind);
Assert.Equal(CursorFeedbackKind.TargetInvalid,
c.Resolve(new CursorFeedbackSnapshot(HoverUi: true, HoverTargetGuid: 0x5000BADu)).Kind);
c.Resolve(new CursorFeedbackSnapshot(
HoverUi: true,
HoverTargetGuid: 0x5000BADu,
HoverTargetCompatible: false)).Kind);
// Retail UpdateCursorState: no found object → PENDING, including over
// UI chrome (the HoverUi→Invalid arm was a non-retail invention).
Assert.Equal(CursorFeedbackKind.TargetPending,
@ -84,7 +91,7 @@ public sealed class CursorFeedbackControllerTests
}
[Fact]
public void UpdateFromRoot_slotItemDrivesTargetCursor_withStateArt()
public void UpdateFromRoot_slotItemDrivesGlobalTargetCursor_withoutInventingWidgetState()
{
var objects = SeedTargetObjects();
objects.Get(Source)!.TargetType = (uint)ItemType.Misc; // a tool that targets items
@ -118,7 +125,8 @@ public sealed class CursorFeedbackControllerTests
var feedback = c.Update(root);
Assert.Equal(CursorFeedbackKind.TargetValid, feedback.Kind);
Assert.Equal(acceptCursor, feedback.Cursor);
Assert.Equal(RetailGlobalCursorKind.TargetValid, feedback.GlobalKind);
Assert.False(feedback.Cursor.IsValid);
}
[Fact]
@ -149,6 +157,79 @@ public sealed class CursorFeedbackControllerTests
Assert.Equal(CursorFeedbackKind.TargetPending, c.Update(root).Kind);
}
public static TheoryData<CursorFeedbackSnapshot, RetailGlobalCursorKind> GlobalCursorCases => new()
{
{ new(), RetailGlobalCursorKind.Default },
{ new(HoverTargetGuid: Target), RetailGlobalCursorKind.DefaultFound },
{ new(CombatMode: CombatMode.Melee), RetailGlobalCursorKind.MeleeOrMissile },
{ new(HoverTargetGuid: Target, CombatMode: CombatMode.Melee), RetailGlobalCursorKind.MeleeOrMissileFound },
{ new(CombatMode: CombatMode.Missile), RetailGlobalCursorKind.MeleeOrMissile },
{ new(CombatMode: CombatMode.Magic), RetailGlobalCursorKind.Magic },
{ new(HoverTargetGuid: Target, CombatMode: CombatMode.Magic), RetailGlobalCursorKind.MagicFound },
{ new(TargetMode: RetailCursorTargetMode.Examine), RetailGlobalCursorKind.Examine },
{ new(HoverTargetGuid: Target, TargetMode: RetailCursorTargetMode.Examine), RetailGlobalCursorKind.ExamineFound },
{ new(TargetMode: RetailCursorTargetMode.Use), RetailGlobalCursorKind.Use },
{ new(HoverTargetGuid: Target, TargetMode: RetailCursorTargetMode.Use), RetailGlobalCursorKind.UseFound },
{ new(BusyCount: 1), RetailGlobalCursorKind.Busy },
{ new(HoverTargetGuid: Target, BusyCount: 1), RetailGlobalCursorKind.BusyFound },
{ new(TargetMode: RetailCursorTargetMode.UseTarget), RetailGlobalCursorKind.TargetPending },
{ new(HoverTargetGuid: Target, HoverTargetCompatible: true, TargetMode: RetailCursorTargetMode.UseTarget), RetailGlobalCursorKind.TargetValid },
{ new(HoverTargetGuid: Target, HoverTargetCompatible: false, TargetMode: RetailCursorTargetMode.UseTarget), RetailGlobalCursorKind.TargetInvalid },
};
[Theory]
[MemberData(nameof(GlobalCursorCases))]
public void GlobalCursorDecisionTree_matchesUpdateCursorState(
CursorFeedbackSnapshot snapshot,
RetailGlobalCursorKind expected)
{
var c = new CursorFeedbackController();
Assert.Equal(expected, c.Resolve(snapshot).GlobalKind);
}
[Fact]
public void BusyGlobalCursor_winsOverTargetAndCombat()
{
var c = new CursorFeedbackController();
var snapshot = new CursorFeedbackSnapshot(
HoverTargetGuid: Target,
HoverTargetCompatible: true,
BusyCount: 1,
TargetMode: RetailCursorTargetMode.UseTarget,
CombatMode: CombatMode.Magic);
Assert.Equal(RetailGlobalCursorKind.BusyFound, c.Resolve(snapshot).GlobalKind);
}
[Fact]
public void WidgetCursorPrecedence_isCapturedThenHoveredThenGlobalDefault()
{
var root = new UiRoot { Width = 200, Height = 100 };
var captured = new UiPanel { Left = 0, Top = 0, Width = 50, Height = 50 };
var hovered = new UiPanel { Left = 60, Top = 0, Width = 50, Height = 50 };
var capturedCursor = new UiCursorMedia(0x06001001u, 1, 2);
var hoveredCursor = new UiCursorMedia(0x06001002u, 3, 4);
captured.SetStateCursors(new Dictionary<string, UiCursorMedia> { [""] = capturedCursor });
hovered.SetStateCursors(new Dictionary<string, UiCursorMedia> { [""] = hoveredCursor });
root.AddChild(captured);
root.AddChild(hovered);
var c = new CursorFeedbackController();
root.OnMouseMove(10, 10);
root.OnMouseDown(UiMouseButton.Left, 10, 10);
root.OnMouseMove(70, 10);
Assert.Equal(capturedCursor, c.Update(root).Cursor);
root.OnMouseUp(UiMouseButton.Left, 70, 10);
Assert.Equal(hoveredCursor, c.Update(root).Cursor);
root.OnMouseMove(150, 75);
var fallback = c.Update(root);
Assert.False(fallback.Cursor.IsValid);
Assert.Equal(RetailGlobalCursorKind.Default, fallback.GlobalKind);
}
private static ClientObjectTable SeedTargetObjects()
{
var objects = new ClientObjectTable();

View file

@ -30,11 +30,12 @@ public class ToolbarControllerTests
var root = new UiPanel();
foreach (var id in Row1) AddSlot(id);
foreach (var id in Row2) AddSlot(id);
// Add combat indicator elements as plain UiPanels keyed by id.
// Combat indicators are retail UiButtons; one is visible at a time,
// and every stance-specific instance dispatches the same toggle command.
foreach (var id in CombatIds)
{
var e = new UiPanel { Visible = true };
dict[id] = e; indicators[id] = e; root.AddChild(e);
AddButton(id);
indicators[id] = dict[id];
}
AddButton(CharacterButtonId);
AddButton(InventoryButtonId);
@ -232,6 +233,27 @@ public class ToolbarControllerTests
// ── C1: combat-mode indicator tests ─────────────────────────────────────
[Fact]
public void CombatIndicators_allDispatchSharedRetailToggleCommand()
{
var (layout, _, indicators) = FakeToolbar();
var repo = new ClientObjectTable();
int toggles = 0;
ToolbarController.Bind(
layout,
repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
iconIds: (_, _, _, _, _) => 0u,
useItem: _ => { },
toggleCombat: () => toggles++);
foreach (uint id in CombatIds)
((UiButton)indicators[id]).OnClick?.Invoke();
Assert.Equal(CombatIds.Length, toggles);
}
/// <summary>
/// At bind time (default NonCombat), only the peace indicator (0x10000192) is visible;
/// the melee/missile/magic indicators (0x10000193/4/5) are hidden.

View file

@ -9,11 +9,23 @@ namespace AcDream.App.Tests.UI;
public sealed class RetailCursorCatalogTests
{
[Theory]
[InlineData(CursorFeedbackKind.TargetPending, 0x27u, 14, 14)]
[InlineData(CursorFeedbackKind.TargetValid, 0x28u, 14, 14)]
[InlineData(CursorFeedbackKind.TargetInvalid, 0x29u, 14, 14)]
public void TargetUseCursorSpecs_matchClientUISystemUpdateCursorState(
CursorFeedbackKind kind,
[InlineData(RetailGlobalCursorKind.Default, 0x01u, 0, 0)]
[InlineData(RetailGlobalCursorKind.DefaultFound, 0x02u, 0, 0)]
[InlineData(RetailGlobalCursorKind.MeleeOrMissile, 0x03u, 0, 0)]
[InlineData(RetailGlobalCursorKind.MeleeOrMissileFound, 0x04u, 0, 0)]
[InlineData(RetailGlobalCursorKind.Magic, 0x05u, 0, 0)]
[InlineData(RetailGlobalCursorKind.MagicFound, 0x06u, 0, 0)]
[InlineData(RetailGlobalCursorKind.Examine, 0x0Au, 0, 0)]
[InlineData(RetailGlobalCursorKind.ExamineFound, 0x0Bu, 0, 0)]
[InlineData(RetailGlobalCursorKind.Use, 0x0Cu, 14, 14)]
[InlineData(RetailGlobalCursorKind.UseFound, 0x0Du, 14, 14)]
[InlineData(RetailGlobalCursorKind.Busy, 0x0Eu, 0, 0)]
[InlineData(RetailGlobalCursorKind.BusyFound, 0x0Fu, 0, 0)]
[InlineData(RetailGlobalCursorKind.TargetPending, 0x27u, 14, 14)]
[InlineData(RetailGlobalCursorKind.TargetValid, 0x28u, 14, 14)]
[InlineData(RetailGlobalCursorKind.TargetInvalid, 0x29u, 14, 14)]
public void GlobalCursorSpecs_matchClientUISystemUpdateCursorState(
RetailGlobalCursorKind kind,
uint expectedEnum,
int expectedHotspotX,
int expectedHotspotY)
@ -28,7 +40,7 @@ public sealed class RetailCursorCatalogTests
}
[Fact]
public void TargetUseCursorSpecs_resolveGoldenDatSurfaces()
public void ReachableGlobalCursorSpecs_resolveGoldenDatSurfaces()
{
string? datDir = ResolveDatDir();
if (datDir is null)
@ -37,13 +49,30 @@ public sealed class RetailCursorCatalogTests
using var dats = new DatCollection(datDir, DatAccessType.Read);
var resolver = new RetailCursorResolver(dats, new object());
Assert.True(resolver.TryResolve(new RetailCursorSpec(0x27u, 14, 14), out var pending));
Assert.True(resolver.TryResolve(new RetailCursorSpec(0x28u, 14, 14), out var valid));
Assert.True(resolver.TryResolve(new RetailCursorSpec(0x29u, 14, 14), out var invalid));
var expected = new Dictionary<RetailGlobalCursorKind, UiCursorMedia>
{
[RetailGlobalCursorKind.Default] = new(0x06004D68u, 0, 0),
[RetailGlobalCursorKind.DefaultFound] = new(0x06004D69u, 0, 0),
[RetailGlobalCursorKind.MeleeOrMissile] = new(0x06004D6Au, 0, 0),
[RetailGlobalCursorKind.MeleeOrMissileFound] = new(0x06004D6Bu, 0, 0),
[RetailGlobalCursorKind.Magic] = new(0x06004D6Cu, 0, 0),
[RetailGlobalCursorKind.MagicFound] = new(0x06004D6Du, 0, 0),
[RetailGlobalCursorKind.Examine] = new(0x06004D71u, 0, 0),
[RetailGlobalCursorKind.ExamineFound] = new(0x06004D71u, 0, 0),
[RetailGlobalCursorKind.Use] = new(0x06004D72u, 14, 14),
[RetailGlobalCursorKind.UseFound] = new(0x06004D72u, 14, 14),
[RetailGlobalCursorKind.Busy] = new(0x06004D74u, 0, 0),
[RetailGlobalCursorKind.BusyFound] = new(0x06004D75u, 0, 0),
[RetailGlobalCursorKind.TargetPending] = new(0x06004D73u, 14, 14),
[RetailGlobalCursorKind.TargetValid] = new(0x06005E6Bu, 14, 14),
[RetailGlobalCursorKind.TargetInvalid] = new(0x06005E6Au, 14, 14),
};
Assert.Equal(new UiCursorMedia(0x06004D73u, 14, 14), pending);
Assert.Equal(new UiCursorMedia(0x06005E6Bu, 14, 14), valid);
Assert.Equal(new UiCursorMedia(0x06005E6Au, 14, 14), invalid);
foreach (var (kind, cursor) in expected)
{
Assert.True(resolver.TryResolve(kind, out var actual), kind.ToString());
Assert.Equal(cursor, actual);
}
}
private static string? ResolveDatDir()

View file

@ -0,0 +1,62 @@
using AcDream.App.Rendering;
using AcDream.App.UI;
namespace AcDream.App.Tests.UI;
public sealed class RetailCursorManagerTests
{
private static readonly UiCursorMedia WidgetA = new(0x06001001u, 1, 2);
private static readonly UiCursorMedia WidgetB = new(0x06001002u, 3, 4);
[Fact]
public void InitialState_appliesGlobalDefaultThenWidgetOverride()
{
var plan = RetailCursorManager.PlanApplication(
hasLayerState: false,
previousGlobal: default,
previousWidget: default,
currentGlobal: RetailGlobalCursorKind.Default,
currentWidget: WidgetA);
Assert.Equal(new[] { RetailCursorLayer.Global, RetailCursorLayer.Widget }, plan);
}
[Fact]
public void GlobalChange_reassertsDefaultWithoutReapplyingUnchangedWidget()
{
var plan = RetailCursorManager.PlanApplication(
hasLayerState: true,
previousGlobal: RetailGlobalCursorKind.Default,
previousWidget: WidgetA,
currentGlobal: RetailGlobalCursorKind.TargetPending,
currentWidget: WidgetA);
Assert.Equal(new[] { RetailCursorLayer.Global }, plan);
}
[Fact]
public void LaterWidgetTransition_overridesUnchangedGlobalDefault()
{
var plan = RetailCursorManager.PlanApplication(
hasLayerState: true,
previousGlobal: RetailGlobalCursorKind.TargetPending,
previousWidget: WidgetA,
currentGlobal: RetailGlobalCursorKind.TargetPending,
currentWidget: WidgetB);
Assert.Equal(new[] { RetailCursorLayer.Widget }, plan);
}
[Fact]
public void ClearingWidgetCursor_restoresGlobalDefault()
{
var plan = RetailCursorManager.PlanApplication(
hasLayerState: true,
previousGlobal: RetailGlobalCursorKind.TargetPending,
previousWidget: WidgetA,
currentGlobal: RetailGlobalCursorKind.TargetPending,
currentWidget: default);
Assert.Equal(new[] { RetailCursorLayer.Global }, plan);
}
}