feat(ui): #25 Phase K.3 — Settings panel + click-to-rebind + Phase K shipped
Phase K final commit. Settings panel with click-to-rebind UX on top of the K.1+K.2 input architecture, plus the roadmap / ISSUES / memory updates that retire Phase K. InputDispatcher gains BeginCapture / CancelCapture / IsCapturing / SetBindings — modal capture suppresses normal action firing for the next chord. Esc cancels (returns sentinel default chord); modifier-only keys don't complete capture; non-modifier key down with current modifier mask completes. IPanelRenderer + ImGuiPanelRenderer + FakePanelRenderer gain BeginMainMenuBar / EndMainMenuBar / BeginMenu / EndMenu / MenuItem primitives. SettingsVM owns a draft copy of KeyBindings with explicit Save / Cancel / Reset semantics. Click-to-rebind enters dispatcher capture mode; on chord captured, conflict-detect against draft (excluding the action being rebound itself); surface a ConflictPrompt when the chord collides; ResolveConflict(replace=true|false) commits or reverts. ResetActionToDefault restores a single action to RetailDefaults(); ResetAllToDefaults rebuilds the entire draft. Save invokes the onSave callback (which writes JSON + swaps the live dispatcher's bindings). SettingsPanel renders 8 retail-keymap-categorized CollapsingHeader sections (Movement, Postures, Camera, Combat, UI panels, Chat, Hotbar, Emotes). Per action: name + current binding(s) summary + "Rebind"/"Reset" buttons. Conflict prompt at the top when pending. Save / Cancel / "Reset all to retail defaults" at the top. GameWindow registers SettingsPanel + wires F11 → ToggleOptionsPanel → IsVisible toggle, plus a top-of-frame ImGui MainMenuBar with View → Settings/Vitals/Chat/Debug entries (calls ImGui directly — the abstraction methods exist for backend portability but the host doesn't own a menu-bar surface). Tests: +37 across InputDispatcherCaptureTests (7), IPanelRendererMainMenuBarTests (9), SettingsVMTests (13), SettingsPanelTests (8). Solution total 1220 green. Roadmap (docs/plans/2026-04-11-roadmap.md) appends Phase K shipped section after Phase J with K.1a–K.3 commit SHAs. ISSUES.md files Phase L deferred work as #L.1–#L.8 (hotbar UI, spellbook favorites, combat-mode dispatch, F-key panels, floating chat windows, UI layout save/load, joystick bindings, plugin input subscription) and adds #21–#25 to Recently closed. project_input_pipeline.md updated to shipped state. CLAUDE.md gets an input-pipeline reference. Closes Phase K. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
af74eac0c2
commit
f42c164b90
14 changed files with 1567 additions and 5 deletions
|
|
@ -34,10 +34,15 @@ public sealed class InputDispatcher
|
|||
{
|
||||
private readonly IKeyboardSource _keyboard;
|
||||
private readonly IMouseSource _mouse;
|
||||
private readonly KeyBindings _bindings;
|
||||
private KeyBindings _bindings;
|
||||
private readonly Stack<InputScope> _scopes = new();
|
||||
private readonly HashSet<KeyChord> _heldHoldChords = new();
|
||||
|
||||
/// <summary>K.3 modal-rebind hook: when non-null, the next non-modifier
|
||||
/// chord is reported via this callback INSTEAD of firing actions. Esc
|
||||
/// cancels (callback receives <c>default(KeyChord)</c>).</summary>
|
||||
private Action<KeyChord>? _captureCallback;
|
||||
|
||||
/// <summary>Fires every time a binding matches a press / release / hold tick.
|
||||
/// Multicast — every subscriber gets every event in subscription order.</summary>
|
||||
public event Action<InputAction, ActivationType>? Fired;
|
||||
|
|
@ -61,6 +66,51 @@ public sealed class InputDispatcher
|
|||
/// <summary>Topmost scope on the stack — what the dispatcher looks up first.</summary>
|
||||
public InputScope ActiveScope => _scopes.Peek();
|
||||
|
||||
/// <summary>True iff a <see cref="BeginCapture"/> is in progress.</summary>
|
||||
public bool IsCapturing => _captureCallback is not null;
|
||||
|
||||
/// <summary>
|
||||
/// Enter modal capture mode. The next non-modifier chord pressed
|
||||
/// (with whatever modifiers are held at that moment) is reported
|
||||
/// via <paramref name="onCaptured"/> and the dispatcher does NOT
|
||||
/// fire normal action events for that chord. Esc cancels —
|
||||
/// <paramref name="onCaptured"/> receives a sentinel
|
||||
/// <c>default(KeyChord)</c>. Modifier-only key transitions
|
||||
/// (Shift / Ctrl / Alt / Win held alone) are NOT captured; only a
|
||||
/// non-modifier key down completes capture, so the user can dial
|
||||
/// in modifier combinations before pressing the trigger key.
|
||||
/// </summary>
|
||||
public void BeginCapture(Action<KeyChord> onCaptured)
|
||||
{
|
||||
_captureCallback = onCaptured ?? throw new ArgumentNullException(nameof(onCaptured));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an active capture. Invokes the callback with a sentinel
|
||||
/// <c>default(KeyChord)</c> so the caller can treat it as a user
|
||||
/// cancel. No-op if no capture is active.
|
||||
/// </summary>
|
||||
public void CancelCapture()
|
||||
{
|
||||
var cb = _captureCallback;
|
||||
if (cb is null) return;
|
||||
_captureCallback = null;
|
||||
cb(default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace the active bindings table. Used by the Settings panel's
|
||||
/// Save flow — the in-memory <see cref="InputDispatcher"/> picks up
|
||||
/// the new bindings without a process restart. Held-Hold-chord
|
||||
/// tracking is reset; any previously held chord that no longer maps
|
||||
/// will simply stop firing on the next <see cref="Tick"/>.
|
||||
/// </summary>
|
||||
public void SetBindings(KeyBindings bindings)
|
||||
{
|
||||
_bindings = bindings ?? throw new ArgumentNullException(nameof(bindings));
|
||||
_heldHoldChords.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Per-frame "is this action's chord currently held" query. Walks every
|
||||
/// binding for the given action; returns true if any of them has its
|
||||
|
|
@ -165,6 +215,30 @@ public sealed class InputDispatcher
|
|||
|
||||
private void OnKeyDown(Key key, ModifierMask mods)
|
||||
{
|
||||
// K.3 modal capture (used by Settings panel's "Rebind" UX) takes
|
||||
// precedence over both WantCaptureKeyboard gating AND normal
|
||||
// binding lookup. Esc cancels capture; modifier-only keys don't
|
||||
// complete it (so the user can dial in Shift/Ctrl/Alt before
|
||||
// pressing the trigger key); every other key completes capture
|
||||
// with the current modifier state.
|
||||
if (_captureCallback is not null)
|
||||
{
|
||||
if (key == Key.Escape)
|
||||
{
|
||||
var cb = _captureCallback;
|
||||
_captureCallback = null;
|
||||
cb(default);
|
||||
return;
|
||||
}
|
||||
if (IsModifierKey(key)) return; // dial more mods, don't complete
|
||||
|
||||
var captured = new KeyChord(key, mods, Device: 0);
|
||||
var cb2 = _captureCallback;
|
||||
_captureCallback = null;
|
||||
cb2(captured);
|
||||
return; // SUPPRESS the action — don't run binding lookup below
|
||||
}
|
||||
|
||||
if (_mouse.WantCaptureKeyboard) return;
|
||||
var chord = new KeyChord(key, mods, Device: 0);
|
||||
|
||||
|
|
@ -181,6 +255,18 @@ public sealed class InputDispatcher
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>True for Shift/Ctrl/Alt/Win left+right variants — keys
|
||||
/// that don't complete a capture by themselves. The user holds them
|
||||
/// to dial in modifier combinations before pressing the trigger key.</summary>
|
||||
private static bool IsModifierKey(Key key) => key switch
|
||||
{
|
||||
Key.ShiftLeft or Key.ShiftRight => true,
|
||||
Key.ControlLeft or Key.ControlRight => true,
|
||||
Key.AltLeft or Key.AltRight => true,
|
||||
Key.SuperLeft or Key.SuperRight => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private void OnKeyUp(Key key, ModifierMask mods)
|
||||
{
|
||||
// Release fires regardless of WantCaptureKeyboard so we don't
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue