feat(ui): D.2b-A — UiRoot named-window registry (Show/Hide/Toggle)

A Dictionary<string,UiElement> registry on UiRoot with RegisterWindow +
Show/Hide/Toggle. Show/Hide flip UiElement.Visible (already gates
Draw/Tick/HitTest); Toggle returns the new visibility; unknown names are
no-ops. WindowNames.Inventory const shared by mount/registry/toggle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-20 21:30:22 +02:00
parent 8457bf0006
commit 6409038576
3 changed files with 76 additions and 0 deletions

View file

@ -474,6 +474,42 @@ public sealed class UiRoot : UiElement
public void SetCapture(UiElement e) => Captured = e;
public void ReleaseCapture() => Captured = null;
// ── Window manager (named top-level windows: Show / Hide / Toggle) ───
private readonly Dictionary<string, UiElement> _windows = new();
/// <summary>Register a top-level window under a name for Show/Hide/Toggle.
/// Does NOT add it to the tree — the caller mounts via AddChild and controls
/// initial Visible. Idempotent (re-register replaces). The dict is the source
/// of truth — independent of UiElement.Name (init-only, not set here).</summary>
public void RegisterWindow(string name, UiElement window) => _windows[name] = window;
/// <summary>Make the named window visible. No-op (returns false) if unknown.</summary>
public bool ShowWindow(string name)
{
if (!_windows.TryGetValue(name, out var w)) return false;
w.Visible = true;
return true;
}
/// <summary>Hide the named window. No-op (returns false) if unknown.</summary>
public bool HideWindow(string name)
{
if (!_windows.TryGetValue(name, out var w)) return false;
w.Visible = false;
return true;
}
/// <summary>Flip the named window's visibility (Show if hidden, Hide if shown).
/// Returns the new IsVisible state (false for an unknown name).</summary>
public bool ToggleWindow(string name)
{
if (!_windows.TryGetValue(name, out var w)) return false;
if (w.Visible) { HideWindow(name); return false; }
ShowWindow(name);
return true;
}
// ── Drag-drop (retail event chain 0x15 → 0x21 → 0x1C → 0x3E) ────────
private void BeginDrag(UiElement source)

View file

@ -0,0 +1,8 @@
namespace AcDream.App.UI;
/// <summary>Canonical registry names for top-level retail-UI windows, so the
/// mount, the window registry, and the toggle keybind all agree on one literal.</summary>
public static class WindowNames
{
public const string Inventory = "inventory";
}