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:
@@ -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++)
|
||||
{
|
||||
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)
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user