feat(studio): UX pass — selection highlight, in-studio panel picker, fixed layout
Fix 1 (Selection highlight): StudioInspector.DrawCanvas draws a bright-green 2px outline over Selected using the window draw list. ScreenPosition maps directly to FBO pixel space; rectMin offsets into screen space. Fix 2 (In-studio panel picker): DrawToolbar (BeginCombo over ListSlugs output). StudioWindow resolves _dumpFile once in OnLoad, tracks _currentSlug, and calls LoadDumpPanel on combo change. LoadDumpPanel removes old root via RemoveChild, loads new slug, resets Selected. No relaunch needed. Fix 3 (Fixed layout): All four panes use SetNextWindowPos + SetNextWindowSize with ImGuiCond.FirstUseEver. Toolbar (0,0 x windowW x 40), tree (0,40 x 280), canvas (280,40 x centre), props (right-340,40 x 340). User can drag from these. Build + dotnet test green (609 passed, 0 failed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2fe7b4a057
commit
c03a241884
2 changed files with 163 additions and 17 deletions
|
|
@ -49,6 +49,11 @@ public sealed class StudioWindow : IDisposable
|
|||
private StudioInspector? _inspector;
|
||||
private UiElement? _panelRoot; // top-level element added to UiRoot (for hit-test + tree)
|
||||
|
||||
// UX-pass additions: panel picker + current-slug tracking.
|
||||
private string? _currentSlug; // slug of the panel currently displayed (null = non-dump mode)
|
||||
private string? _dumpFile; // resolved dump file path (once, in OnLoad)
|
||||
private IReadOnlyList<string> _dumpSlugs = Array.Empty<string>(); // all slugs from the dump
|
||||
|
||||
// Task 4: sample data table — built once in OnLoad and kept alive for the window's lifetime
|
||||
// so the controller subscriptions (ObjectAdded/ObjectMoved etc.) fire correctly.
|
||||
private AcDream.Core.Items.ClientObjectTable? _objects;
|
||||
|
|
@ -123,11 +128,17 @@ public sealed class StudioWindow : IDisposable
|
|||
// Task 4b: --dump <slug> uses DumpLayout (static retail mockup, no controllers).
|
||||
// All other modes use LayoutSource + FixtureProvider (production path).
|
||||
_source = new LayoutSource(_dats, _stack.ResolveChrome, _stack.VitalsDatFont);
|
||||
|
||||
// Resolve the dump file once (used by OnLoad + by LoadDumpPanel at runtime).
|
||||
_dumpFile = _opts.ResolveDumpFile();
|
||||
if (_dumpFile is not null)
|
||||
_dumpSlugs = UiDumpModel.ListSlugs(_dumpFile)
|
||||
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
UiElement? root;
|
||||
if (_opts.DumpSlug is not null)
|
||||
{
|
||||
var dumpFile = _opts.ResolveDumpFile();
|
||||
if (dumpFile is null)
|
||||
if (_dumpFile is null)
|
||||
{
|
||||
Console.Error.WriteLine("[studio] --dump: retail UI dump file not found. " +
|
||||
"Expected docs/research/2026-06-25-retail-ui-layout-dump.json in the source tree, " +
|
||||
|
|
@ -136,9 +147,11 @@ public sealed class StudioWindow : IDisposable
|
|||
}
|
||||
else
|
||||
{
|
||||
root = DumpLayout.Load(dumpFile, _opts.DumpSlug, _stack.ResolveChrome, out var dumpErr);
|
||||
root = DumpLayout.Load(_dumpFile, _opts.DumpSlug, _stack.ResolveChrome, out var dumpErr);
|
||||
if (root is null)
|
||||
Console.Error.WriteLine($"[studio] dump load failed: {dumpErr}");
|
||||
else
|
||||
_currentSlug = _opts.DumpSlug;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -265,12 +278,33 @@ public sealed class StudioWindow : IDisposable
|
|||
// 4. Begin the ImGui frame.
|
||||
_imgui.BeginFrame((float)dt);
|
||||
|
||||
// 5. Canvas pane — show the FBO texture; detect clicks.
|
||||
// ── Layout constants (fixed pane arrangement, FirstUseEver) ──────────────
|
||||
// Toolbar: full width, 40px tall at y=0.
|
||||
// Tree: 280px wide on the left, below toolbar.
|
||||
// Canvas: centre strip between tree and properties.
|
||||
// Props: 340px wide on the right, below toolbar.
|
||||
const int kToolbarH = 40;
|
||||
const int kTreeW = 280;
|
||||
const int kPropsW = 340;
|
||||
int canvasX = kTreeW;
|
||||
int canvasW = Math.Max(1, iw - kTreeW - kPropsW);
|
||||
int propsX = iw - kPropsW;
|
||||
int paneY = kToolbarH;
|
||||
int paneH = Math.Max(1, ih - kToolbarH);
|
||||
|
||||
// 5. Toolbar pane — slug picker.
|
||||
string? pickedSlug = _inspector.DrawToolbar(_dumpSlugs, _currentSlug, iw);
|
||||
if (pickedSlug is not null)
|
||||
LoadDumpPanel(pickedSlug);
|
||||
|
||||
// 6. Canvas pane — show the FBO texture; detect clicks.
|
||||
(int x, int y)? click = null;
|
||||
if (panelTex != 0)
|
||||
click = _inspector.DrawCanvas((nint)panelTex, iw, ih);
|
||||
click = _inspector.DrawCanvas(
|
||||
(nint)panelTex, iw, ih,
|
||||
canvasX, canvasW, paneY, paneH);
|
||||
|
||||
// 6. If the user clicked inside the canvas, hit-test the whole UI tree (UiRoot.Pick honors
|
||||
// 7. If the user clicked inside the canvas, hit-test the whole UI tree (UiRoot.Pick honors
|
||||
// Z-order + modal exclusivity) and select the topmost element. The canvas click coord is
|
||||
// in the same root-space the FBO was drawn in, so it maps 1:1.
|
||||
if (click is { } c)
|
||||
|
|
@ -280,17 +314,55 @@ public sealed class StudioWindow : IDisposable
|
|||
_inspector.Selected = hit;
|
||||
}
|
||||
|
||||
// 7. Element tree pane.
|
||||
// 8. Element tree pane.
|
||||
if (_panelRoot is not null)
|
||||
_inspector.DrawTree(_panelRoot);
|
||||
_inspector.DrawTree(_panelRoot, 0, paneY, kTreeW, paneH);
|
||||
|
||||
// 8. Properties pane.
|
||||
_inspector.DrawProperties();
|
||||
// 9. Properties pane.
|
||||
_inspector.DrawProperties(propsX, paneY, kPropsW, paneH);
|
||||
|
||||
// 9. Finalise ImGui and flush draw data to the window.
|
||||
_imgui.Render();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a different dump panel at runtime (no relaunch required).
|
||||
/// Removes the current <see cref="_panelRoot"/> from the UI tree,
|
||||
/// loads the named slug from the dump, and installs the new root.
|
||||
/// Resets <see cref="StudioInspector.Selected"/> to null.
|
||||
/// No-op when the dump file is not available or the slug fails to load.
|
||||
/// </summary>
|
||||
public void LoadDumpPanel(string slug)
|
||||
{
|
||||
if (_stack is null || _inspector is null) return;
|
||||
if (_dumpFile is null)
|
||||
{
|
||||
Console.Error.WriteLine("[studio] LoadDumpPanel: dump file not available.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the existing panel root from the tree.
|
||||
if (_panelRoot is not null)
|
||||
{
|
||||
_stack.UiHost.Root.RemoveChild(_panelRoot);
|
||||
_panelRoot = null;
|
||||
}
|
||||
|
||||
// Load the new panel.
|
||||
var newRoot = DumpLayout.Load(_dumpFile, slug, _stack.ResolveChrome, out var err);
|
||||
if (newRoot is null)
|
||||
{
|
||||
Console.Error.WriteLine($"[studio] LoadDumpPanel('{slug}') failed: {err}");
|
||||
_currentSlug = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_stack.UiHost.Root.AddChild(newRoot);
|
||||
_panelRoot = newRoot;
|
||||
_currentSlug = slug;
|
||||
_inspector.Selected = null;
|
||||
}
|
||||
|
||||
private void OnClosing()
|
||||
{
|
||||
_imgui?.Dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue