]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make two inventories not dance around as much when opening/closing them (#35041)
authorpathetic meowmeow <uhhadd@gmail.com>
Sat, 19 Apr 2025 14:40:49 +0000 (10:40 -0400)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 14:40:49 +0000 (10:40 -0400)
* Make two inventories not dance around as much when opening/closing them

* Use .Any

Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml
Content.Client/UserInterface/Systems/Storage/StorageUIController.cs
Content.IntegrationTests/Tests/Storage/StorageInteractionTest.cs

index 153e02bd55856ea0f58945d488e2ac0a315f3390..b9602c64e5a3e4fcc9f2e51678062c4fd861dc02 100644 (file)
@@ -9,12 +9,32 @@
     Orientation="Vertical"
     HorizontalAlignment="Center">
     <BoxContainer Orientation="Vertical">
-        <BoxContainer Name="StorageContainer"
+        <BoxContainer Name="SingleStorageContainer"
                       Access="Public"
                       HorizontalAlignment="Center"
                       HorizontalExpand="True"
                       Margin="10">
         </BoxContainer>
+        <BoxContainer Name="DoubleStorageContainer"
+                      Access="Public"
+                      HorizontalAlignment="Stretch"
+                      HorizontalExpand="True"
+                      Margin="10">
+            <BoxContainer Name="LeftStorageContainer"
+                          Access="Public"
+                          HorizontalAlignment="Left"
+                          HorizontalExpand="True"
+                          VerticalAlignment="Bottom"
+                          Margin="10">
+            </BoxContainer>
+            <BoxContainer Name="RightStorageContainer"
+                          Access="Public"
+                          HorizontalAlignment="Right"
+                          HorizontalExpand="True"
+                          VerticalAlignment="Bottom"
+                          Margin="10">
+            </BoxContainer>
+        </BoxContainer>
         <BoxContainer Orientation="Horizontal" Name="Hotbar" HorizontalAlignment="Center">
             <inventory:ItemSlotButtonContainer
                 Name="SecondHotbar"
index ca2bc5729b48b2ac3832218575bb7fc49bc2f5e8..69cf6909e5f66941332afd48a200659f0698dc9b 100644 (file)
@@ -1,3 +1,4 @@
+using System.Linq;
 using System.Numerics;
 using Content.Client.Examine;
 using Content.Client.Hands.Systems;
@@ -48,6 +49,7 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
     public Angle DraggingRotation = Angle.Zero;
     public bool StaticStorageUIEnabled;
     public bool OpaqueStorageWindow;
+    private int _openStorageLimit = -1;
 
     public bool IsDragging => _menuDragHelper.IsDragging;
     public ItemGridPiece? CurrentlyDragging => _menuDragHelper.Dragged;
@@ -66,6 +68,12 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
         _configuration.OnValueChanged(CCVars.StaticStorageUI, OnStaticStorageChanged, true);
         _configuration.OnValueChanged(CCVars.OpaqueStorageWindow, OnOpaqueWindowChanged, true);
         _configuration.OnValueChanged(CCVars.StorageWindowTitle, OnStorageWindowTitle, true);
+        _configuration.OnValueChanged(CCVars.StorageLimit, OnStorageLimitChanged, true);
+    }
+
+    private void OnStorageLimitChanged(int obj)
+    {
+        _openStorageLimit = obj;
     }
 
     private void OnStorageWindowTitle(bool obj)
@@ -99,7 +107,43 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
 
         if (StaticStorageUIEnabled)
         {
-            UIManager.GetActiveUIWidgetOrNull<HotbarGui>()?.StorageContainer.AddChild(window);
+            var hotbar = UIManager.GetActiveUIWidgetOrNull<HotbarGui>();
+            // 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<Control?, Control> 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
index 8d0de707f3b287c4741f45d0006a2bb7413d8e9d..60d9ddd7fcef0d1f2b662ff549206fed703548f3 100644 (file)
@@ -81,7 +81,7 @@ public sealed class StorageInteractionTest : InteractionTest
     {
         var uid = ToClient(target);
         var hotbar = GetWidget<HotbarGui>();
-        var storageContainer  = GetControlFromField<Control>(nameof(HotbarGui.StorageContainer), hotbar);
+        var storageContainer  = GetControlFromField<Control>(nameof(HotbarGui.SingleStorageContainer), hotbar);
         return GetControlFromChildren<ItemGridPiece>(c => c.Entity == uid, storageContainer);
     }
 }