Minimalist Action Bar (#21352)
This commit is contained in:
@@ -49,6 +49,8 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
private readonly SpriteView _smallItemSpriteView;
|
||||
private readonly SpriteView _bigItemSpriteView;
|
||||
|
||||
private Texture? _buttonBackgroundTexture;
|
||||
|
||||
public EntityUid? ActionId { get; private set; }
|
||||
private BaseActionComponent? _action;
|
||||
public bool Locked { get; set; }
|
||||
@@ -138,9 +140,9 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
});
|
||||
Cooldown = new CooldownGraphic {Visible = false};
|
||||
|
||||
AddChild(Button);
|
||||
AddChild(_bigActionIcon);
|
||||
AddChild(_bigItemSpriteView);
|
||||
AddChild(Button);
|
||||
AddChild(HighlightRect);
|
||||
AddChild(Label);
|
||||
AddChild(Cooldown);
|
||||
@@ -167,7 +169,7 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
protected override void OnThemeUpdated()
|
||||
{
|
||||
base.OnThemeUpdated();
|
||||
Button.Texture = Theme.ResolveTexture("SlotBackground");
|
||||
_buttonBackgroundTexture = Theme.ResolveTexture("SlotBackground");
|
||||
Label.FontColorOverride = Theme.ResolveColorOrSpecified("whiteText");
|
||||
}
|
||||
|
||||
@@ -263,6 +265,7 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
public void UpdateIcons()
|
||||
{
|
||||
UpdateItemIcon();
|
||||
UpdateBackground();
|
||||
|
||||
if (_action == null)
|
||||
{
|
||||
@@ -278,6 +281,18 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
SetActionIcon(_action.Icon != null ? _spriteSys.Frame0(_action.Icon) : null);
|
||||
}
|
||||
|
||||
public void UpdateBackground()
|
||||
{
|
||||
if (_action == null)
|
||||
{
|
||||
Button.Texture = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Button.Texture = _buttonBackgroundTexture;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryReplaceWith(EntityUid actionId, ActionsSystem system)
|
||||
{
|
||||
if (Locked)
|
||||
@@ -363,7 +378,8 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
|
||||
public void DrawModeChanged()
|
||||
{
|
||||
HighlightRect.Visible = _beingHovered;
|
||||
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
|
||||
HighlightRect.Visible = _beingHovered && (_action != null || _controller.IsDragging);
|
||||
|
||||
// always show the normal empty button style if no action in this slot
|
||||
if (_action == null)
|
||||
@@ -373,8 +389,7 @@ public sealed class ActionButton : Control, IEntityControl
|
||||
}
|
||||
|
||||
// show a hover only if the action is usable or another action is being dragged on top of this
|
||||
_controller ??= UserInterfaceManager.GetUIController<ActionUIController>();
|
||||
if (_beingHovered && (_controller.IsDragging || _action.Enabled))
|
||||
if (_beingHovered && (_controller.IsDragging || _action!.Enabled))
|
||||
{
|
||||
SetOnlyStylePseudoClass(ContainerButton.StylePseudoClassHover);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
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;
|
||||
@@ -14,7 +21,6 @@ public class ActionButtonContainer : GridContainer
|
||||
public ActionButtonContainer()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
UserInterfaceManager.GetUIController<ActionUIController>().RegisterActionContainer(this);
|
||||
}
|
||||
|
||||
public ActionButton this[int index]
|
||||
@@ -22,17 +28,42 @@ public class ActionButtonContainer : GridContainer
|
||||
get => (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));
|
||||
}
|
||||
|
||||
ActionButton MakeButton(int index)
|
||||
{
|
||||
var button = new ActionButton(_entity);
|
||||
|
||||
if (keys.TryGetValue(index, out var boundKey))
|
||||
{
|
||||
button.KeyBind = boundKey;
|
||||
|
||||
var binding = _input.GetKeyBinding(boundKey);
|
||||
button.Label.Text = binding.GetKeyString();
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetActionData(ActionsSystem system, params EntityUid?[] actionTypes)
|
||||
{
|
||||
ClearActionData();
|
||||
var uniqueCount = Math.Min(system.GetClientActions().Count(), actionTypes.Length + 1);
|
||||
BuildActionButtons(uniqueCount);
|
||||
|
||||
for (var i = 0; i < actionTypes.Length; i++)
|
||||
for (var i = 0; i < uniqueCount; i++)
|
||||
{
|
||||
var action = actionTypes[i];
|
||||
if (action == null)
|
||||
continue;
|
||||
|
||||
((ActionButton) GetChild(i)).UpdateData(action.Value, system);
|
||||
if (!actionTypes.TryGetValue(i, out var action))
|
||||
action = null;
|
||||
((ActionButton) GetChild(i)).UpdateData(action, system);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user