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 <helloworld@eoinrul.es>
This commit is contained in:
eoineoineoin
2024-10-03 15:01:01 +01:00
committed by GitHub
parent 568fb235fa
commit a8982b88af
2 changed files with 16 additions and 22 deletions

View File

@@ -398,10 +398,6 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
{ {
QueueWindowUpdate(); 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) if (_actionsSystem != null)
_container?.SetActionData(_actionsSystem, _actions.ToArray()); _container?.SetActionData(_actionsSystem, _actions.ToArray());
} }

View File

@@ -28,14 +28,26 @@ public class ActionButtonContainer : GridContainer
get => (ActionButton) GetChild(index); 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(); var keys = ContentKeyFunctions.GetHotbarBoundKeys();
Children.Clear(); for (var i = 0; i < uniqueCount; i++)
for (var index = 0; index < count; index++)
{ {
Children.Add(MakeButton(index)); 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--)
{
RemoveChild(GetChild(i));
} }
ActionButton MakeButton(int index) 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() public void ClearActionData()
{ {
foreach (var button in Children) foreach (var button in Children)