In-hands are now refreshed when the prefix is changed

This commit is contained in:
zumorica
2020-05-14 15:44:05 +02:00
parent 1dd7eb8677
commit 2132ff41d4
6 changed files with 58 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ using System.Linq;
using Content.Client.Interfaces.GameObjects; using Content.Client.Interfaces.GameObjects;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Mono.Cecil;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components; using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -116,7 +117,19 @@ namespace Content.Client.GameObjects
return; return;
} }
var item = entity.GetComponent<ItemComponent>(); 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); var maybeInhands = item.GetInHandStateInfo(hand);
if (!maybeInhands.HasValue) 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) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
@@ -168,6 +189,9 @@ namespace Content.Client.GameObjects
case PlayerDetachedMsg _: case PlayerDetachedMsg _:
_gui.Parent?.RemoveChild(_gui); _gui.Parent?.RemoveChild(_gui);
break; break;
case RefreshInHandsMsg _:
RefreshInHands();
break;
} }
} }

View File

@@ -3,8 +3,10 @@ using Content.Shared.GameObjects.Components.Items;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Renderable; using Robust.Shared.GameObjects.Components.Renderable;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -26,7 +28,13 @@ namespace Content.Client.GameObjects
public string EquippedPrefix public string EquippedPrefix
{ {
get => _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) public (RSI rsi, RSI.StateId stateId)? GetInHandStateInfo(string hand)

View File

@@ -406,6 +406,11 @@ namespace Content.Server.GameObjects
return hands.ContainsKey(index); return hands.ContainsKey(index);
} }
public void RefreshInHands()
{
SendNetworkMessage(new RefreshInHandsMsg());
}
/// <summary> /// <summary>
/// Get the name of the slot passed to the inventory component. /// Get the name of the slot passed to the inventory component.
/// </summary> /// </summary>

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Physics; using Robust.Shared.Interfaces.Physics;
using Robust.Shared.Interfaces.Random; using Robust.Shared.Interfaces.Random;
@@ -48,8 +49,8 @@ namespace Content.Server.GameObjects
} }
set set
{ {
Dirty();
_equippedPrefix = value; _equippedPrefix = value;
Dirty();
} }
} }

View File

@@ -191,6 +191,11 @@ namespace Content.Server.Interfaces.GameObjects
/// <returns>True if the hand exists, false otherwise.</returns> /// <returns>True if the hand exists, false otherwise.</returns>
bool HasHand(string index); bool HasHand(string index);
/// <summary>
/// Refresh all in-hands sprites.
/// </summary>
void RefreshInHands();
void HandleSlotModifiedMaybe(ContainerModifiedMessage message); void HandleSlotModifiedMaybe(ContainerModifiedMessage message);
} }
} }

View File

@@ -75,4 +75,16 @@ namespace Content.Shared.GameObjects
Index = index; Index = index;
} }
} }
/// <summary>
/// A message that tells the client to refresh in-hands.
/// </summary>
[Serializable, NetSerializable]
public class RefreshInHandsMsg : ComponentMessage
{
public RefreshInHandsMsg()
{
Directed = true;
}
}
} }