From 8179a50bdbd70d3cef3274a6e45ad5640905bbe3 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Fri, 14 Jan 2022 03:09:46 +1300 Subject: [PATCH] Fix smoking visuals, but properly this time. (#6051) Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- Content.Client/Clothing/ClothingComponent.cs | 2 ++ Content.Client/Clothing/ClothingSystem.cs | 18 ++++++++++++++++++ Content.Shared/Hands/SharedHandsSystem.cs | 10 ++++++++++ Content.Shared/Item/SharedItemComponent.cs | 19 ++++++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Content.Client/Clothing/ClothingComponent.cs b/Content.Client/Clothing/ClothingComponent.cs index 1e6c9efcf7..c868938dd4 100644 --- a/Content.Client/Clothing/ClothingComponent.cs +++ b/Content.Client/Clothing/ClothingComponent.cs @@ -18,6 +18,8 @@ namespace Content.Client.Clothing [ViewVariables(VVAccess.ReadWrite)] [DataField("femaleMask")] public FemaleClothingMask FemaleMask { get; } = FemaleClothingMask.UniformFull; + + public string? InSlot; } public enum FemaleClothingMask : byte diff --git a/Content.Client/Clothing/ClothingSystem.cs b/Content.Client/Clothing/ClothingSystem.cs index decd235742..e630bae637 100644 --- a/Content.Client/Clothing/ClothingSystem.cs +++ b/Content.Client/Clothing/ClothingSystem.cs @@ -4,6 +4,7 @@ using Content.Shared.CharacterAppearance; using Content.Shared.Clothing; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; +using Content.Shared.Item; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.ResourceManagement; @@ -46,9 +47,24 @@ public class ClothingSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + SubscribeLocalEvent(OnPrefixChanged); SubscribeLocalEvent(OnDidUnequip); } + private void OnPrefixChanged(EntityUid uid, ClientInventoryComponent component, ItemPrefixChangeEvent args) + { + if (!TryComp(args.Item, out ClothingComponent? clothing) || clothing.InSlot == null) + return; + + RenderEquipment(uid, args.Item, clothing.InSlot, component, null, clothing); + } + + private void OnGotUnequipped(EntityUid uid, ClothingComponent component, GotUnequippedEvent args) + { + component.InSlot = null; + } + private void OnDidUnequip(EntityUid uid, SpriteComponent component, DidUnequipEvent args) { component.LayerSetVisible(args.Slot, false); @@ -71,6 +87,8 @@ public class ClothingSystem : EntitySystem private void OnGotEquipped(EntityUid uid, ClothingComponent component, GotEquippedEvent args) { + component.InSlot = args.Slot; + if (!TryComp(args.Equipee, out var sprite) || !TryComp(args.Equipee, out var invComp)) { return; diff --git a/Content.Shared/Hands/SharedHandsSystem.cs b/Content.Shared/Hands/SharedHandsSystem.cs index 81d5f36424..83804fb8e0 100644 --- a/Content.Shared/Hands/SharedHandsSystem.cs +++ b/Content.Shared/Hands/SharedHandsSystem.cs @@ -26,6 +26,7 @@ namespace Content.Shared.Hands SubscribeAllEvent(HandleSetHand); SubscribeLocalEvent(HandleContainerRemoved); SubscribeLocalEvent(HandleContainerModified); + SubscribeLocalEvent(OnPrefixChanged); CommandBinds.Builder .Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed)) @@ -33,6 +34,15 @@ namespace Content.Shared.Hands .Register(); } + private void OnPrefixChanged(EntityUid uid, SharedHandsComponent component, ItemPrefixChangeEvent args) + { + // update hands visuals if this item is in a hand (rather then inventory or other container). + if (component.HasHand(args.ContainerId)) + { + UpdateHandVisuals(uid, component); + } + } + public override void Shutdown() { base.Shutdown(); diff --git a/Content.Shared/Item/SharedItemComponent.cs b/Content.Shared/Item/SharedItemComponent.cs index bab87b15b6..d10437300a 100644 --- a/Content.Shared/Item/SharedItemComponent.cs +++ b/Content.Shared/Item/SharedItemComponent.cs @@ -121,7 +121,7 @@ namespace Content.Shared.Item private void OnEquippedPrefixChange() { if (Owner.TryGetContainer(out var container)) - EntitySystem.Get().UpdateHandVisuals(container.Owner); + _entMan.EventBus.RaiseLocalEvent(container.Owner, new ItemPrefixChangeEvent(Owner, container.ID)); } public void RemovedFromSlot() @@ -154,6 +154,23 @@ namespace Content.Shared.Item } } + /// + /// Raised when an item's EquippedPrefix is changed. The event is directed at the entity that contains this item, so + /// that it can properly update its sprite/GUI. + /// + [Serializable, NetSerializable] + public class ItemPrefixChangeEvent : EntityEventArgs + { + public readonly EntityUid Item; + public readonly string ContainerId; + + public ItemPrefixChangeEvent(EntityUid item, string containerId) + { + Item = item; + ContainerId = containerId; + } + } + /// /// Reference sizes for common containers and items. ///