From 8e24308714f7a645fe913d1f3ef0f2fd2c838cc7 Mon Sep 17 00:00:00 2001 From: pathetic meowmeow Date: Sat, 19 Apr 2025 10:40:49 -0400 Subject: [PATCH] Make two inventories not dance around as much when opening/closing them (#35041) * Make two inventories not dance around as much when opening/closing them * Use .Any --- .../Systems/Hotbar/Widgets/HotbarGui.xaml | 22 ++++++++- .../Systems/Storage/StorageUIController.cs | 46 ++++++++++++++++++- .../Tests/Storage/StorageInteractionTest.cs | 2 +- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml b/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml index 153e02bd55..b9602c64e5 100644 --- a/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml +++ b/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml @@ -9,12 +9,32 @@ Orientation="Vertical" HorizontalAlignment="Center"> - + + + + + + _menuDragHelper.IsDragging; public ItemGridPiece? CurrentlyDragging => _menuDragHelper.Dragged; @@ -66,6 +68,12 @@ public sealed class StorageUIController : UIController, IOnSystemChanged()?.StorageContainer.AddChild(window); + var hotbar = UIManager.GetActiveUIWidgetOrNull(); + // this lambda handles the nested storage case + // during nested storage, a parent window hides and a child window is + // immediately inserted to the end of the list + // we can reorder the newly inserted to the same index as the invisible + // window in order to prevent an invisible window from being replaced + // with a visible one in a different position + Action reorder = (parent, child) => + { + if (parent is null) + return; + + var parentChildren = parent.Children.ToList(); + var invisibleIndex = parentChildren.FindIndex(c => c.Visible == false); + if (invisibleIndex == -1) + return; + child.SetPositionInParent(invisibleIndex); + }; + + if (_openStorageLimit == 2) + { + if (hotbar?.LeftStorageContainer.Children.Any(c => c.Visible) == false) // we're comparing booleans because it's bool? and not bool from the optional chaining + { + hotbar?.LeftStorageContainer.AddChild(window); + reorder(hotbar?.LeftStorageContainer, window); + } + else + { + hotbar?.RightStorageContainer.AddChild(window); + reorder(hotbar?.RightStorageContainer, window); + } + } + else + { + hotbar?.SingleStorageContainer.AddChild(window); + reorder(hotbar?.SingleStorageContainer, window); + } _closeRecentWindowUIController.SetMostRecentlyInteractedWindow(window); } else diff --git a/Content.IntegrationTests/Tests/Storage/StorageInteractionTest.cs b/Content.IntegrationTests/Tests/Storage/StorageInteractionTest.cs index 8d0de707f3..60d9ddd7fc 100644 --- a/Content.IntegrationTests/Tests/Storage/StorageInteractionTest.cs +++ b/Content.IntegrationTests/Tests/Storage/StorageInteractionTest.cs @@ -81,7 +81,7 @@ public sealed class StorageInteractionTest : InteractionTest { var uid = ToClient(target); var hotbar = GetWidget(); - var storageContainer = GetControlFromField(nameof(HotbarGui.StorageContainer), hotbar); + var storageContainer = GetControlFromField(nameof(HotbarGui.SingleStorageContainer), hotbar); return GetControlFromChildren(c => c.Entity == uid, storageContainer); } } -- 2.51.2