]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow users to drag-reorder action bar (#32552)
authoreoineoineoin <github@eoinrul.es>
Thu, 3 Oct 2024 14:01:01 +0000 (15:01 +0100)
committerGitHub <noreply@github.com>
Thu, 3 Oct 2024 14:01:01 +0000 (16:01 +0200)
* Avoid rebuilding all buttons on action state change

Allows for drag events to continue when actions change

* Remove excess action buttons

---------

Co-authored-by: Eoin Mcloughlin <helloworld@eoinrul.es>
Content.Client/UserInterface/Systems/Actions/ActionUIController.cs
Content.Client/UserInterface/Systems/Actions/Controls/ActionButtonContainer.cs

index 1dffeb8d2d449757fad866e01078098b6d16ee8d..a6c1cfc94f81e4571bc9724cb40661f087d00fd2 100644 (file)
@@ -398,10 +398,6 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
     {
         QueueWindowUpdate();
 
-        // TODO ACTIONS allow buttons to persist across state applications
-        // Then we don't have to interrupt drags any time the buttons get rebuilt.
-        _menuDragHelper.EndDrag();
-
         if (_actionsSystem != null)
             _container?.SetActionData(_actionsSystem, _actions.ToArray());
     }
index 38c08dc47216f3a92d192c23386dc9e332cffc9f..67b96d03307cfbba49b8fee6aaf6629f599706c5 100644 (file)
@@ -28,14 +28,26 @@ public class ActionButtonContainer : GridContainer
         get => (ActionButton) GetChild(index);
     }
 
-    private void BuildActionButtons(int count)
+    public void SetActionData(ActionsSystem system, params EntityUid?[] actionTypes)
     {
+        var uniqueCount = Math.Min(system.GetClientActions().Count(), actionTypes.Length + 1);
         var keys = ContentKeyFunctions.GetHotbarBoundKeys();
 
-        Children.Clear();
-        for (var index = 0; index < count; index++)
+        for (var i = 0; i < uniqueCount; i++)
+        {
+            if (i >= ChildCount)
+            {
+                AddChild(MakeButton(i));
+            }
+
+            if (!actionTypes.TryGetValue(i, out var action))
+                action = null;
+            ((ActionButton) GetChild(i)).UpdateData(action, system);
+        }
+
+        for (var i = ChildCount - 1; i >= uniqueCount; i--)
         {
-            Children.Add(MakeButton(index));
+            RemoveChild(GetChild(i));
         }
 
         ActionButton MakeButton(int index)
@@ -55,20 +67,6 @@ public class ActionButtonContainer : GridContainer
         }
     }
 
-    public void SetActionData(ActionsSystem system, params EntityUid?[] actionTypes)
-    {
-        var uniqueCount = Math.Min(system.GetClientActions().Count(), actionTypes.Length + 1);
-        if (ChildCount != uniqueCount)
-            BuildActionButtons(uniqueCount);
-
-        for (var i = 0; i < uniqueCount; i++)
-        {
-            if (!actionTypes.TryGetValue(i, out var action))
-                action = null;
-            ((ActionButton) GetChild(i)).UpdateData(action, system);
-        }
-    }
-
     public void ClearActionData()
     {
         foreach (var button in Children)