mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +03:00
# Description https://github.com/Simple-Station/Parkstation-Friendly-Chainsaw/issues/2 https://github.com/space-wizards/space-station-14/pull/21352 --- <details><summary><h1>Media</h1></summary> <p> <!-- https://github.com/user-attachments/assets/701512ce-1bf2-4020-a2eb-ba1e35b18669 --> https://github.com/user-attachments/assets/d01f01b9-dae7-4d05-91db-ac6e3de30e9f </p> </details> --- # Changelog 🆑 - tweak: Added back support for the action bar to have "loadouts" or quick layouts of actions (man, how many things are called loadouts?) (cherry picked from commit 6cd17d7957b34cc45bf1bf0f9d338b5bfd87297d)
112 lines
3.3 KiB
C#
112 lines
3.3 KiB
C#
using System.Linq;
|
|
using Content.Client.Actions;
|
|
using Content.Shared.Input;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.UserInterface.Systems.Actions.Controls;
|
|
|
|
[Virtual]
|
|
public class ActionButtonContainer : GridContainer
|
|
{
|
|
[Dependency] private readonly IEntityManager _entity = default!;
|
|
[Dependency] private readonly IInputManager _input = default!;
|
|
|
|
public event Action<GUIBoundKeyEventArgs, ActionButton>? ActionPressed;
|
|
public event Action<GUIBoundKeyEventArgs, ActionButton>? ActionUnpressed;
|
|
public event Action<ActionButton>? ActionFocusExited;
|
|
|
|
public ActionButtonContainer() => IoCManager.InjectDependencies(this);
|
|
|
|
public ActionButton this[int index] => (ActionButton) GetChild(index);
|
|
|
|
private void BuildActionButtons(int count)
|
|
{
|
|
var keys = ContentKeyFunctions.GetHotbarBoundKeys();
|
|
|
|
Children.Clear();
|
|
for (var i = 0; i < count; i++)
|
|
AddChild(MakeButton(i));
|
|
return;
|
|
|
|
ActionButton MakeButton(int index)
|
|
{
|
|
var button = new ActionButton(_entity);
|
|
|
|
if (!keys.TryGetValue(index, out var boundKey))
|
|
return button;
|
|
|
|
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.Max(ContentKeyFunctions.GetHotbarBoundKeys().Length, 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)
|
|
((ActionButton) button).ClearData();
|
|
}
|
|
|
|
protected override void ChildAdded(Control newChild)
|
|
{
|
|
base.ChildAdded(newChild);
|
|
|
|
if (newChild is not ActionButton button)
|
|
return;
|
|
|
|
button.ActionPressed += ActionPressed;
|
|
button.ActionUnpressed += ActionUnpressed;
|
|
button.ActionFocusExited += ActionFocusExited;
|
|
}
|
|
|
|
protected override void ChildRemoved(Control newChild)
|
|
{
|
|
if (newChild is not ActionButton button)
|
|
return;
|
|
|
|
button.ActionPressed -= ActionPressed;
|
|
button.ActionUnpressed -= ActionUnpressed;
|
|
button.ActionFocusExited -= ActionFocusExited;
|
|
}
|
|
|
|
public bool TryGetButtonIndex(ActionButton button, out int position)
|
|
{
|
|
if (button.Parent != this)
|
|
{
|
|
position = 0;
|
|
return false;
|
|
}
|
|
|
|
position = button.GetPositionInParent();
|
|
return true;
|
|
}
|
|
|
|
public IEnumerable<ActionButton> GetButtons()
|
|
{
|
|
foreach (var control in Children)
|
|
if (control is ActionButton button)
|
|
yield return button;
|
|
}
|
|
|
|
~ActionButtonContainer() => UserInterfaceManager.GetUIController<ActionUIController>().RemoveActionContainer();
|
|
}
|