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();