From: eoineoineoin Date: Thu, 3 Oct 2024 14:01:01 +0000 (+0100) Subject: Allow users to drag-reorder action bar (#32552) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=a8982b88affc0d6c9b61fb9a59f46fab5614d5c2;p=space-station-14.git Allow users to drag-reorder action bar (#32552) * 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 --- diff --git a/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs b/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs index 1dffeb8d2d..a6c1cfc94f 100644 --- a/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs +++ b/Content.Client/UserInterface/Systems/Actions/ActionUIController.cs @@ -398,10 +398,6 @@ public sealed class ActionUIController : UIController, IOnStateChanged (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)