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:
parent
05f6222865
commit
6fcc510d5d
16 changed files with 535 additions and 164 deletions
|
|
@ -15,8 +15,12 @@ public sealed class RetailCursorManager
|
|||
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;
|
||||
private readonly HashSet<RetailGlobalCursorKind> _reportedFallbacks = new();
|
||||
private bool _hasLayerState;
|
||||
private RetailGlobalCursorKind _lastGlobalKind;
|
||||
private UiCursorMedia _lastWidgetCursor;
|
||||
private UiCursorMedia _lastAppliedCursor;
|
||||
private StandardCursor? _lastStandardCursor;
|
||||
|
||||
public RetailCursorManager(DatCollection dats, object datLock)
|
||||
{
|
||||
|
|
@ -27,31 +31,51 @@ public sealed class RetailCursorManager
|
|||
|
||||
public void Apply(IEnumerable<IMouse> mice, CursorFeedback feedback)
|
||||
{
|
||||
if (feedback.Cursor.IsValid && TryGetImage(feedback.Cursor.File, out var image))
|
||||
foreach (RetailCursorLayer layer in PlanApplication(
|
||||
_hasLayerState,
|
||||
_lastGlobalKind,
|
||||
_lastWidgetCursor,
|
||||
feedback.GlobalKind,
|
||||
feedback.Cursor))
|
||||
{
|
||||
ApplyCustom(mice, feedback.Cursor, image);
|
||||
_lastKind = feedback.Kind;
|
||||
_lastCursor = feedback.Cursor;
|
||||
return;
|
||||
if (layer == RetailCursorLayer.Widget
|
||||
&& feedback.Cursor.IsValid
|
||||
&& TryGetImage(feedback.Cursor.File, out var image))
|
||||
{
|
||||
ApplyCustom(mice, feedback.Cursor, image);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyGlobal(mice, feedback.GlobalKind);
|
||||
}
|
||||
}
|
||||
|
||||
if (_globalCursors.TryResolve(feedback.Kind, out var globalCursor)
|
||||
_hasLayerState = true;
|
||||
_lastGlobalKind = feedback.GlobalKind;
|
||||
_lastWidgetCursor = feedback.Cursor;
|
||||
}
|
||||
|
||||
private void ApplyGlobal(IEnumerable<IMouse> mice, RetailGlobalCursorKind kind)
|
||||
{
|
||||
if (_globalCursors.TryResolve(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;
|
||||
if (_reportedFallbacks.Add(kind))
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
$"[D.2b] retail cursor {kind} could not be resolved from DAT; " +
|
||||
"using the registered OS cursor adaptation (AP-72).");
|
||||
}
|
||||
ApplyStandard(mice, StandardCursorFor(kind));
|
||||
}
|
||||
|
||||
private void ApplyCustom(IEnumerable<IMouse> mice, UiCursorMedia cursorMedia, RawImage image)
|
||||
{
|
||||
if (_lastCursor.Equals(cursorMedia))
|
||||
if (_lastStandardCursor is null && _lastAppliedCursor.Equals(cursorMedia))
|
||||
return;
|
||||
|
||||
foreach (var mouse in mice)
|
||||
|
|
@ -63,12 +87,14 @@ public sealed class RetailCursorManager
|
|||
if (cursor.Type != CursorType.Custom)
|
||||
cursor.Type = CursorType.Custom;
|
||||
}
|
||||
|
||||
_lastAppliedCursor = cursorMedia;
|
||||
_lastStandardCursor = null;
|
||||
}
|
||||
|
||||
private void ApplyStandard(IEnumerable<IMouse> mice, StandardCursor desired)
|
||||
{
|
||||
if (_lastCursor.Equals(default(UiCursorMedia)) && _lastKind != (CursorFeedbackKind)(-1)
|
||||
&& StandardCursorFor(_lastKind) == desired)
|
||||
if (_lastStandardCursor == desired)
|
||||
return;
|
||||
|
||||
foreach (var mouse in mice)
|
||||
|
|
@ -85,6 +111,9 @@ public sealed class RetailCursorManager
|
|||
if (cursor.StandardCursor != standard)
|
||||
cursor.StandardCursor = standard;
|
||||
}
|
||||
|
||||
_lastAppliedCursor = default;
|
||||
_lastStandardCursor = desired;
|
||||
}
|
||||
|
||||
private bool TryGetImage(uint renderSurfaceId, out RawImage image)
|
||||
|
|
@ -122,21 +151,47 @@ public sealed class RetailCursorManager
|
|||
}
|
||||
}
|
||||
|
||||
private static StandardCursor StandardCursorFor(CursorFeedbackKind kind)
|
||||
internal static IReadOnlyList<RetailCursorLayer> PlanApplication(
|
||||
bool hasLayerState,
|
||||
RetailGlobalCursorKind previousGlobal,
|
||||
UiCursorMedia previousWidget,
|
||||
RetailGlobalCursorKind currentGlobal,
|
||||
UiCursorMedia currentWidget)
|
||||
{
|
||||
bool globalChanged = !hasLayerState || previousGlobal != currentGlobal;
|
||||
bool widgetChanged = !hasLayerState || previousWidget != currentWidget;
|
||||
if (!globalChanged && !widgetChanged)
|
||||
return Array.Empty<RetailCursorLayer>();
|
||||
|
||||
var result = new List<RetailCursorLayer>(2);
|
||||
if (globalChanged)
|
||||
result.Add(RetailCursorLayer.Global);
|
||||
|
||||
if (widgetChanged)
|
||||
{
|
||||
RetailCursorLayer widgetResult = currentWidget.IsValid
|
||||
? RetailCursorLayer.Widget
|
||||
: RetailCursorLayer.Global;
|
||||
if (result.Count == 0 || result[^1] != widgetResult)
|
||||
result.Add(widgetResult);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static StandardCursor StandardCursorFor(RetailGlobalCursorKind 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,
|
||||
RetailGlobalCursorKind.Use or RetailGlobalCursorKind.UseFound => StandardCursor.Hand,
|
||||
RetailGlobalCursorKind.TargetPending => StandardCursor.Crosshair,
|
||||
RetailGlobalCursorKind.TargetValid => StandardCursor.ResizeAll,
|
||||
RetailGlobalCursorKind.TargetInvalid => StandardCursor.NotAllowed,
|
||||
_ => StandardCursor.Arrow,
|
||||
};
|
||||
}
|
||||
|
||||
internal enum RetailCursorLayer
|
||||
{
|
||||
Global,
|
||||
Widget,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue