Skip to content

Commit

Permalink
allow moving actions to bound slots
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Dec 11, 2024
1 parent ecde5ed commit e1485f5
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ public class ActionButtonContainer : GridContainer
public event Action<GUIBoundKeyEventArgs, ActionButton>? ActionUnpressed;
public event Action<ActionButton>? ActionFocusExited;

public ActionButtonContainer()
{
IoCManager.InjectDependencies(this);
}
public ActionButtonContainer() => IoCManager.InjectDependencies(this);

public ActionButton this[int index]
{
get => (ActionButton) GetChild(index);
}
public ActionButton this[int index] => (ActionButton) GetChild(index);

private void BuildActionButtons(int count)
{
var keys = ContentKeyFunctions.GetHotbarBoundKeys();

Children.Clear();
for (var index = 0; index < count; index++)
{
Children.Add(MakeButton(index));
}
for (var i = 0; i < count; i++)
AddChild(MakeButton(i));
return;

ActionButton MakeButton(int index)
{
Expand All @@ -47,17 +40,15 @@ ActionButton MakeButton(int index)

button.KeyBind = boundKey;
if (_input.TryGetKeyBinding(boundKey, out var binding))
{
button.Label.Text = binding.GetKeyString();
}

return button;
}
}

public void SetActionData(ActionsSystem system, params EntityUid?[] actionTypes)
{
var uniqueCount = Math.Min(system.GetClientActions().Count(), actionTypes.Length + 1);
var uniqueCount = Math.Max(ContentKeyFunctions.GetHotbarBoundKeys().Length, actionTypes.Length + 1);
if (ChildCount != uniqueCount)
BuildActionButtons(uniqueCount);

Expand All @@ -72,9 +63,7 @@ public void SetActionData(ActionsSystem system, params EntityUid?[] actionTypes)
public void ClearActionData()
{
foreach (var button in Children)
{
((ActionButton) button).ClearData();
}
}

protected override void ChildAdded(Control newChild)
Expand Down Expand Up @@ -114,14 +103,9 @@ public bool TryGetButtonIndex(ActionButton button, out int position)
public IEnumerable<ActionButton> GetButtons()
{
foreach (var control in Children)
{
if (control is ActionButton button)
yield return button;
}
}

~ActionButtonContainer()
{
UserInterfaceManager.GetUIController<ActionUIController>().RemoveActionContainer();
}
~ActionButtonContainer() => UserInterfaceManager.GetUIController<ActionUIController>().RemoveActionContainer();
}

0 comments on commit e1485f5

Please sign in to comment.