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:
@@ -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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user