Fix smoking visuals, but properly this time. (#6051)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-01-14 03:09:46 +13:00
committed by GitHub
parent eb4c8da449
commit 8179a50bdb
4 changed files with 48 additions and 1 deletions

View File

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

View File

@@ -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<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<ClientInventoryComponent, ItemPrefixChangeEvent>(OnPrefixChanged);
SubscribeLocalEvent<SpriteComponent, DidUnequipEvent>(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<SpriteComponent>(args.Equipee, out var sprite) || !TryComp<ClientInventoryComponent>(args.Equipee, out var invComp))
{
return;

View File

@@ -26,6 +26,7 @@ namespace Content.Shared.Hands
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerRemoved);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerModified);
SubscribeLocalEvent<SharedHandsComponent, ItemPrefixChangeEvent>(OnPrefixChanged);
CommandBinds.Builder
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
@@ -33,6 +34,15 @@ namespace Content.Shared.Hands
.Register<SharedHandsSystem>();
}
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();

View File

@@ -121,7 +121,7 @@ namespace Content.Shared.Item
private void OnEquippedPrefixChange()
{
if (Owner.TryGetContainer(out var container))
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisuals(container.Owner);
_entMan.EventBus.RaiseLocalEvent(container.Owner, new ItemPrefixChangeEvent(Owner, container.ID));
}
public void RemovedFromSlot()
@@ -154,6 +154,23 @@ namespace Content.Shared.Item
}
}
/// <summary>
/// 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.
/// </summary>
[Serializable, NetSerializable]
public class ItemPrefixChangeEvent : EntityEventArgs
{
public readonly EntityUid Item;
public readonly string ContainerId;
public ItemPrefixChangeEvent(EntityUid item, string containerId)
{
Item = item;
ContainerId = containerId;
}
}
/// <summary>
/// Reference sizes for common containers and items.
/// </summary>