fix(ui): share primary panel placement

Port gmPanelUI's persistent parent placement semantics across Inventory, Character, and Magic while preserving each imported child's content and resize policy. Synchronize typed retained-window handles so drag, switching, close/reopen, and layout persistence all observe one canonical location; keep effect panels independent.

User-verified in normal Release. Release build and all 5,770 tests passed with five intentional skips.

Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-17 09:13:31 +02:00
parent 124e046976
commit 3f3cfdac30
7 changed files with 460 additions and 9 deletions

View file

@ -1,3 +1,4 @@
using AcDream.App.UI;
using AcDream.App.UI.Layout;
namespace AcDream.App.Tests.UI.Layout;
@ -74,6 +75,71 @@ public sealed class RetailPanelUiControllerTests
Assert.Equal(2u, controller.ActivePanelId);
}
[Fact]
public void MainPanels_ShareOneCanonicalPlacementAcrossMoveCloseAndSwitch()
{
var root = new UiRoot { Width = 1280f, Height = 720f };
RetailWindowHandle inventory = Mount(root, WindowNames.Inventory, 40f, 60f);
RetailWindowHandle character = Mount(root, WindowNames.Character, 540f, 18f);
RetailWindowHandle spellbook = Mount(root, WindowNames.Spellbook, 18f, 18f);
using var controller = Create(root);
controller.RegisterMainPanel(7u, WindowNames.Inventory, inventory);
controller.RegisterMainPanel(11u, WindowNames.Character, character);
controller.RegisterMainPanel(13u, WindowNames.Spellbook, spellbook);
int characterMoves = 0;
int spellbookMoves = 0;
character.Moved += _ => characterMoves++;
spellbook.Moved += _ => spellbookMoves++;
controller.SetPanelVisibility(7u, visible: true);
inventory.MoveTo(312f, 147f);
Assert.Equal((312f, 147f), (character.Left, character.Top));
Assert.Equal((312f, 147f), (spellbook.Left, spellbook.Top));
Assert.True(characterMoves > 0);
Assert.True(spellbookMoves > 0);
controller.SetPanelVisibility(11u, visible: true);
Assert.False(inventory.IsVisible);
Assert.True(character.IsVisible);
Assert.Equal((312f, 147f), (character.Left, character.Top));
controller.SetPanelVisibility(11u, visible: false);
controller.SetPanelVisibility(13u, visible: true);
Assert.False(character.IsVisible);
Assert.True(spellbook.IsVisible);
Assert.Equal((312f, 147f), (spellbook.Left, spellbook.Top));
}
[Fact]
public void RestorePreviousEffect_DoesNotReplaceMainPanelPlacement()
{
var root = new UiRoot { Width = 1280f, Height = 720f };
RetailWindowHandle inventory = Mount(root, WindowNames.Inventory, 40f, 60f);
RetailWindowHandle character = Mount(root, WindowNames.Character, 540f, 18f);
RetailWindowHandle effect = Mount(root, WindowNames.PositiveEffects, 900f, 30f);
using var controller = Create(root);
controller.RegisterMainPanel(7u, WindowNames.Inventory, inventory);
controller.RegisterMainPanel(11u, WindowNames.Character, character);
controller.Register(4u, WindowNames.PositiveEffects, restorePrevious: true);
controller.SetPanelVisibility(7u, visible: true);
inventory.MoveTo(280f, 120f);
controller.SetPanelVisibility(4u, visible: true);
Assert.Equal((900f, 30f), (effect.Left, effect.Top));
Assert.False(inventory.IsVisible);
Assert.True(effect.IsVisible);
controller.SetPanelVisibility(4u, visible: false);
Assert.True(inventory.IsVisible);
Assert.Equal((280f, 120f), (inventory.Left, inventory.Top));
controller.SetPanelVisibility(11u, visible: true);
Assert.Equal((280f, 120f), (character.Left, character.Top));
}
private static RetailPanelUiController Create(Dictionary<string, bool> visible)
=> new(
name => visible[name],
@ -87,4 +153,28 @@ public sealed class RetailPanelUiControllerTests
visible[name] = false;
return true;
});
private static RetailPanelUiController Create(UiRoot root)
=> new(root.IsWindowVisible, root.ShowWindow, root.HideWindow);
private static RetailWindowHandle Mount(
UiRoot root,
string name,
float left,
float top)
{
var content = new UiPanel { Width = 300f, Height = 500f };
return RetailWindowFrame.Mount(
root,
content,
_ => (0u, 0, 0),
new RetailWindowFrame.Options
{
WindowName = name,
Left = left,
Top = top,
Visible = false,
ConstrainDragToParent = true,
});
}
}