{
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());
}
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)
}
}
- 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)