]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix stripping window for more than 2 hands (#37577)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Sat, 7 Jun 2025 22:23:46 +0000 (00:23 +0200)
committerGitHub <noreply@github.com>
Sat, 7 Jun 2025 22:23:46 +0000 (15:23 -0700)
Content.Client/Inventory/StrippableBoundUserInterface.cs
Content.Client/Strip/StrippingMenu.cs

index 295d4848e5b096682ced7708545337dae19770d7..a9a937d5d85896ab1798f5c5100e5c1b05f36ed7 100644 (file)
@@ -50,6 +50,18 @@ namespace Content.Client.Inventory
         [ViewVariables]
         private readonly EntityUid _virtualHiddenEntity;
 
+        /// <summary>
+        /// The current amount of added hand buttons.
+        /// </summary>
+        [ViewVariables]
+        private int _handCount;
+
+        /// <summary>
+        /// The current shape of the inventory, needed to calculate the window size.
+        /// </summary>
+        [ViewVariables]
+        private Vector2i _inventoryDimensions;
+
         public StrippableBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
         {
             _examine = EntMan.System<ExamineSystem>();
@@ -93,6 +105,8 @@ namespace Content.Client.Inventory
                 return;
 
             _strippingMenu.ClearButtons();
+            _handCount = 0;
+            _inventoryDimensions = Vector2i.Zero;
 
             if (EntMan.TryGetComponent<InventoryComponent>(Owner, out var inv))
             {
@@ -152,9 +166,15 @@ namespace Content.Client.Inventory
             // TODO allow windows to resize based on content's desired size
 
             // for now: shit-code
-            // this breaks for drones (too many hands, lots of empty vertical space), and looks shit for monkeys and the like.
-            // but the window is realizable, so eh.
-            _strippingMenu.SetSize = new Vector2(220, snare?.IsEnsnared == true ? 550 : 530);
+            // calculate the window size manually
+            // +20 horizontally and vertically from the ContentsContainer margin
+            // +16 vertically from the BoxContainer margin
+            // +27 vertically from the window header
+            var horizontalMenuSize = Math.Max(200, Math.Max(_handCount, _inventoryDimensions.X + 1) * (SlotControl.DefaultButtonSize + ButtonSeparation) + 20);
+            var verticalMenuSize = Math.Max(200, (_inventoryDimensions.Y + (_handCount > 0 ? 2 : 1)) * (SlotControl.DefaultButtonSize + ButtonSeparation) + 53);
+            if (snare?.IsEnsnared == true)
+                verticalMenuSize += 20;
+            _strippingMenu.SetSize = new Vector2(horizontalMenuSize, verticalMenuSize);
         }
 
         private void AddHandButton(Hand hand)
@@ -172,6 +192,8 @@ namespace Content.Client.Inventory
 
             UpdateEntityIcon(button, hand.HeldEntity);
             _strippingMenu!.HandsContainer.AddChild(button);
+            LayoutContainer.SetPosition(button, new Vector2i(_handCount, 0) * (SlotControl.DefaultButtonSize + ButtonSeparation));
+            _handCount++;
         }
 
         private void SlotPressed(GUIBoundKeyEventArgs ev, SlotControl slot)
@@ -220,6 +242,10 @@ namespace Content.Client.Inventory
             UpdateEntityIcon(button, entity);
 
             LayoutContainer.SetPosition(button, slotDef.StrippingWindowPos * (SlotControl.DefaultButtonSize + ButtonSeparation));
+            if (slotDef.StrippingWindowPos.X > _inventoryDimensions.X)
+                _inventoryDimensions = new Vector2i(slotDef.StrippingWindowPos.X, _inventoryDimensions.Y);
+            if (slotDef.StrippingWindowPos.Y > _inventoryDimensions.Y)
+                _inventoryDimensions = new Vector2i(_inventoryDimensions.X, slotDef.StrippingWindowPos.Y);
         }
 
         private void UpdateEntityIcon(SlotControl button, EntityUid? entity)
index 1c46b4be35c889cb08034246b7b19ad8216678ed..531e5fb44d8b86b8bc9219cf362105a532418df2 100644 (file)
@@ -8,7 +8,7 @@ namespace Content.Client.Strip
     public sealed class StrippingMenu : DefaultWindow
     {
         public LayoutContainer InventoryContainer = new();
-        public BoxContainer HandsContainer = new() { Orientation = LayoutOrientation.Horizontal };
+        public LayoutContainer HandsContainer = new();
         public BoxContainer SnareContainer = new();
         public bool Dirty = true;