Fix action icons (#8436)

This commit is contained in:
Leon Friedrich
2022-05-26 20:47:03 +12:00
committed by GitHub
parent 7f97b17998
commit f55c4c6825
2 changed files with 29 additions and 4 deletions

View File

@@ -28,6 +28,8 @@ namespace Content.Client.Actions.UI
private static readonly string EnabledColor = "#7b7e9e"; private static readonly string EnabledColor = "#7b7e9e";
private static readonly string DisabledColor = "#950000"; private static readonly string DisabledColor = "#950000";
private bool _spriteViewDirty = false;
/// <summary> /// <summary>
/// Current action in this slot. /// Current action in this slot.
/// </summary> /// </summary>
@@ -40,6 +42,7 @@ namespace Content.Client.Actions.UI
public byte SlotIndex { get; } public byte SlotIndex { get; }
private readonly IGameTiming _gameTiming; private readonly IGameTiming _gameTiming;
private readonly IEntityManager _entMan;
private readonly RichTextLabel _number; private readonly RichTextLabel _number;
private readonly TextureRect _bigActionIcon; private readonly TextureRect _bigActionIcon;
private readonly TextureRect _smallActionIcon; private readonly TextureRect _smallActionIcon;
@@ -56,11 +59,12 @@ namespace Content.Client.Actions.UI
/// Creates an action slot for the specified number /// Creates an action slot for the specified number
/// </summary> /// </summary>
/// <param name="slotIndex">slot index this corresponds to, 0-9 (0 labeled as 1, 8, labeled "9", 9 labeled as "0".</param> /// <param name="slotIndex">slot index this corresponds to, 0-9 (0 labeled as 1, 8, labeled "9", 9 labeled as "0".</param>
public ActionSlot(ActionsUI actionsUI, ActionMenu actionMenu, byte slotIndex) public ActionSlot(ActionsUI actionsUI, ActionMenu actionMenu, byte slotIndex, IGameTiming timing, IEntityManager entMan)
{ {
_actionsUI = actionsUI; _actionsUI = actionsUI;
_actionMenu = actionMenu; _actionMenu = actionMenu;
_gameTiming = IoCManager.Resolve<IGameTiming>(); _gameTiming = timing;
_entMan = entMan;
SlotIndex = slotIndex; SlotIndex = slotIndex;
MouseFilter = MouseFilterMode.Stop; MouseFilter = MouseFilterMode.Stop;
@@ -422,7 +426,17 @@ namespace Content.Client.Actions.UI
private void UpdateItemIcon() private void UpdateItemIcon()
{ {
if (Action?.EntityIcon == null || !IoCManager.Resolve<IEntityManager>().TryGetComponent(Action.EntityIcon.Value, out SpriteComponent sprite)) if (Action?.EntityIcon != null && !_entMan.EntityExists(Action.EntityIcon))
{
// This is almost certainly because a player received/processed their own actions component state before
// being send the entity in their inventory that enabled this action.
// Defer updating icons to the next FrameUpdate().
_spriteViewDirty = true;
return;
}
if (Action?.EntityIcon == null || !_entMan.TryGetComponent(Action.EntityIcon.Value, out SpriteComponent sprite))
{ {
_bigItemSpriteView.Visible = false; _bigItemSpriteView.Visible = false;
_bigItemSpriteView.Sprite = null; _bigItemSpriteView.Sprite = null;
@@ -502,6 +516,13 @@ namespace Content.Client.Actions.UI
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
{ {
base.FrameUpdate(args); base.FrameUpdate(args);
if (_spriteViewDirty)
{
_spriteViewDirty = false;
UpdateIcons();
}
if (Action == null || Action.Cooldown == null || !Action.Enabled) if (Action == null || Action.Cooldown == null || !Action.Enabled)
{ {
_cooldownGraphic.Visible = false; _cooldownGraphic.Visible = false;

View File

@@ -26,6 +26,8 @@ namespace Content.Client.Actions.UI
private const float CustomTooltipDelay = 0.4f; private const float CustomTooltipDelay = 0.4f;
internal readonly ActionsSystem System; internal readonly ActionsSystem System;
private readonly IGameHud _gameHud; private readonly IGameHud _gameHud;
private readonly IEntityManager _entMan;
private readonly IGameTiming _timing;
/// <summary> /// <summary>
/// The action component of the currently attached entity. /// The action component of the currently attached entity.
@@ -79,6 +81,8 @@ namespace Content.Client.Actions.UI
System = system; System = system;
Component = component; Component = component;
_gameHud = IoCManager.Resolve<IGameHud>(); _gameHud = IoCManager.Resolve<IGameHud>();
_timing = IoCManager.Resolve<IGameTiming>();
_entMan = IoCManager.Resolve<IEntityManager>();
_menu = new ActionMenu(this); _menu = new ActionMenu(this);
LayoutContainer.SetGrowHorizontal(this, LayoutContainer.GrowDirection.End); LayoutContainer.SetGrowHorizontal(this, LayoutContainer.GrowDirection.End);
@@ -205,7 +209,7 @@ namespace Content.Client.Actions.UI
for (byte i = 0; i < ActionsSystem.Slots; i++) for (byte i = 0; i < ActionsSystem.Slots; i++)
{ {
var slot = new ActionSlot(this, _menu, i); var slot = new ActionSlot(this, _menu, i, _timing, _entMan);
_slotContainer.AddChild(slot); _slotContainer.AddChild(slot);
_slots[i] = slot; _slots[i] = slot;
} }