diff --git a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs index 74e040398e..4b465454fe 100644 --- a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs @@ -6,6 +6,7 @@ using System.Linq; using Content.Client.Interfaces.GameObjects; using Content.Client.UserInterface; using Content.Shared.GameObjects; +using Mono.Cecil; using Robust.Client.GameObjects; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; @@ -116,7 +117,19 @@ namespace Content.Client.GameObjects return; } - var item = entity.GetComponent(); + SetInHands(hand, entity); + } + + private void SetInHands(string hand, IEntity entity) + { + if (entity == null) + { + _sprite.LayerSetVisible($"hand-{hand}", false); + + return; + } + + if (!entity.TryGetComponent(out ItemComponent item)) return; var maybeInhands = item.GetInHandStateInfo(hand); if (!maybeInhands.HasValue) { @@ -130,6 +143,14 @@ namespace Content.Client.GameObjects } } + public void RefreshInHands() + { + foreach (var (hand, entity) in _hands) + { + SetInHands(hand, entity); + } + } + public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); @@ -168,6 +189,9 @@ namespace Content.Client.GameObjects case PlayerDetachedMsg _: _gui.Parent?.RemoveChild(_gui); break; + case RefreshInHandsMsg _: + RefreshInHands(); + break; } } diff --git a/Content.Client/GameObjects/Components/Items/ItemComponent.cs b/Content.Client/GameObjects/Components/Items/ItemComponent.cs index 4140314c55..4c6a1d0402 100644 --- a/Content.Client/GameObjects/Components/Items/ItemComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ItemComponent.cs @@ -3,8 +3,10 @@ using Content.Shared.GameObjects.Components.Items; using Robust.Client.Graphics; using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.ResourceManagement; +using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components.Renderable; +using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.IoC; using Robust.Shared.Serialization; using Robust.Shared.Utility; @@ -26,7 +28,13 @@ namespace Content.Client.GameObjects public string EquippedPrefix { get => _equippedPrefix; - set => _equippedPrefix = value; + set + { + _equippedPrefix = value; + if (!ContainerHelpers.TryGetContainer(Owner, out IContainer container)) return; + if(container.Owner.TryGetComponent(out HandsComponent hands)) + hands.RefreshInHands(); + } } public (RSI rsi, RSI.StateId stateId)? GetInHandStateInfo(string hand) diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs index ab265e3693..b336e1b9c0 100644 --- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs @@ -406,6 +406,11 @@ namespace Content.Server.GameObjects return hands.ContainsKey(index); } + public void RefreshInHands() + { + SendNetworkMessage(new RefreshInHandsMsg()); + } + /// /// Get the name of the slot passed to the inventory component. /// diff --git a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs index d50c346adc..4c8cde4ae8 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs @@ -13,6 +13,7 @@ using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Physics; using Robust.Shared.Interfaces.Random; @@ -48,8 +49,8 @@ namespace Content.Server.GameObjects } set { - Dirty(); _equippedPrefix = value; + Dirty(); } } diff --git a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs index 27a11740f7..e1154fb4f9 100644 --- a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs +++ b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs @@ -191,6 +191,11 @@ namespace Content.Server.Interfaces.GameObjects /// True if the hand exists, false otherwise. bool HasHand(string index); + /// + /// Refresh all in-hands sprites. + /// + void RefreshInHands(); + void HandleSlotModifiedMaybe(ContainerModifiedMessage message); } } diff --git a/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs b/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs index dc3604eae6..617c54e983 100644 --- a/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs +++ b/Content.Shared/GameObjects/Components/Items/SharedHandsComponent.cs @@ -75,4 +75,16 @@ namespace Content.Shared.GameObjects Index = index; } } + + /// + /// A message that tells the client to refresh in-hands. + /// + [Serializable, NetSerializable] + public class RefreshInHandsMsg : ComponentMessage + { + public RefreshInHandsMsg() + { + Directed = true; + } + } }