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.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<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);
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;
}
}

View File

@@ -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)