Revert "Add support for multi-layer in-hand and clothing sprites" (#6521)

This commit is contained in:
metalgearsloth
2022-02-07 14:59:22 +11:00
committed by GitHub
parent 470e4f8bdc
commit f9e32fb0c1
17 changed files with 262 additions and 529 deletions

View File

@@ -1,60 +0,0 @@
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Shared.Clothing;
/// <summary>
/// Raised directed at a piece of clothing to get the set of layers to show on the wearer's sprite
/// </summary>
public class GetEquipmentVisualsEvent : EntityEventArgs
{
/// <summary>
/// Entity that is wearing the item.
/// </summary>
public readonly EntityUid Equipee;
public readonly string Slot;
/// <summary>
/// The layers that will be added to the entity that is wearing this item.
/// </summary>
/// <remarks>
/// Note that the actual ordering of the layers depends on the order in which they are added to this list;
/// </remarks>
public List<(string, PrototypeLayerData)> Layers = new();
public GetEquipmentVisualsEvent(EntityUid equipee, string slot)
{
Equipee = equipee;
Slot = slot;
}
}
/// <summary>
/// Raised directed at a piece of clothing after its visuals have been updated.
/// </summary>
/// <remarks>
/// Useful for systems/components that modify the visual layers that an item adds to a player. (e.g. RGB memes)
/// </remarks>
public class EquipmentVisualsUpdatedEvent : EntityEventArgs
{
/// <summary>
/// Entity that is wearing the item.
/// </summary>
public readonly EntityUid Equipee;
public readonly string Slot;
/// <summary>
/// The layers that this item is now revealing.
/// </summary>
public HashSet<string> RevealedLayers;
public EquipmentVisualsUpdatedEvent(EntityUid equipee, string slot, HashSet<string> revealedLayers)
{
Equipee = equipee;
Slot = slot;
RevealedLayers = revealedLayers;
}
}

View File

@@ -1,5 +1,4 @@
using System;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
@@ -41,7 +40,7 @@ namespace Content.Shared.Hands.Components
// update hands GUI with new entity.
if (Owner.TryGetContainer(out var containter))
EntitySystem.Get<SharedItemSystem>().VisualsChanged(Owner);
EntitySystem.Get<SharedHandsSystem>().UpdateHandVisuals(containter.Owner);
}
[Serializable, NetSerializable]

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Robust.Shared.Containers;
@@ -16,7 +18,6 @@ using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Shared.Hands.Components
{
@@ -707,6 +708,47 @@ namespace Content.Shared.Hands.Components
}
}
#region visualizerData
[Serializable, NetSerializable]
public enum HandsVisuals : byte
{
VisualState
}
[Serializable, NetSerializable]
public class HandsVisualState : ICloneable
{
public List<HandVisualState> Hands { get; } = new();
public HandsVisualState(List<HandVisualState> hands)
{
Hands = hands;
}
public object Clone()
{
return new HandsVisualState(new List<HandVisualState>(Hands));
}
}
[Serializable, NetSerializable]
public struct HandVisualState
{
public string RsiPath { get; }
public string? EquippedPrefix { get; }
public HandLocation Location { get; }
public Color Color { get; }
public HandVisualState(string rsiPath, string? equippedPrefix, HandLocation location, Color color)
{
RsiPath = rsiPath;
EquippedPrefix = equippedPrefix;
Location = location;
Color = color;
}
}
#endregion
[Serializable, NetSerializable]
public class Hand
{

View File

@@ -1,67 +1,13 @@
using System;
using System.Collections.Generic;
using Content.Shared.Hands.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Shared.Hands
{
/// <summary>
/// Raised directed at an item that needs to update its in-hand sprites/layers.
/// </summary>
public class GetInhandVisualsEvent : EntityEventArgs
{
/// <summary>
/// Entity that owns the hand holding the item.
/// </summary>
public readonly EntityUid User;
public readonly HandLocation Location;
/// <summary>
/// The layers that will be added to the entity that is holding this item.
/// </summary>
/// <remarks>
/// Note that the actual ordering of the layers depends on the order in which they are added to this list;
/// </remarks>
public List<(string, PrototypeLayerData)> Layers = new();
public GetInhandVisualsEvent(EntityUid user, HandLocation location)
{
User = user;
Location = location;
}
}
/// <summary>
/// Raised directed at an item after its visuals have been updated.
/// </summary>
/// <remarks>
/// Useful for systems/components that modify the visual layers that an item adds to a player. (e.g. RGB memes)
/// </remarks>
public class HeldVisualsUpdatedEvent : EntityEventArgs
{
/// <summary>
/// Entity that is holding the item.
/// </summary>
public readonly EntityUid User;
/// <summary>
/// The layers that this item is now revealing.
/// </summary>
public HashSet<string> RevealedLayers;
public HeldVisualsUpdatedEvent(EntityUid user, HashSet<string> revealedLayers)
{
User = user;
RevealedLayers = revealedLayers;
}
}
/// <summary>
/// Raised when an entity item in a hand is deselected.
/// </summary>

View File

@@ -2,6 +2,7 @@ using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Item;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
@@ -10,6 +11,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using System.Collections.Generic;
namespace Content.Shared.Hands
{
@@ -23,7 +25,8 @@ namespace Content.Shared.Hands
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerRemoved);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerInserted);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerModified);
SubscribeLocalEvent<SharedHandsComponent, ItemPrefixChangeEvent>(OnPrefixChanged);
CommandBinds.Builder
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
@@ -31,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();
@@ -124,25 +136,43 @@ namespace Content.Shared.Hands
public abstract void PickupAnimation(EntityUid item, EntityCoordinates initialPosition, Vector2 finalPosition,
EntityUid? exclude);
#endregion
protected virtual void HandleContainerRemoved(EntityUid uid, SharedHandsComponent component, ContainerModifiedMessage args)
{
HandleContainerModified(uid, component, args);
}
#endregion
protected virtual void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args)
#region visuals
private void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args)
{
// client updates hand visuals here.
UpdateHandVisuals(uid, hands);
}
private void HandleContainerInserted(EntityUid uid, SharedHandsComponent component, EntInsertedIntoContainerMessage args)
/// <summary>
/// Update the In-Hand sprites
/// </summary>
public virtual void UpdateHandVisuals(EntityUid uid, SharedHandsComponent? handComp = null, AppearanceComponent? appearance = null)
{
// un-rotate entities. needed for things like directional flashlights
Transform(args.Entity).LocalRotation = 0;
if (!Resolve(uid, ref handComp, ref appearance, false))
return;
HandleContainerModified(uid, component, args);
var handsVisuals = new List<HandVisualState>();
foreach (var hand in handComp.Hands)
{
if (hand.HeldEntity == null)
continue;
if (!TryComp(hand.HeldEntity.Value, out SharedItemComponent? item) || item.RsiPath == null)
continue;
var handState = new HandVisualState(item.RsiPath, item.EquippedPrefix, hand.Location, item.Color);
handsVisuals.Add(handState);
}
appearance.SetData(HandsVisuals.VisualState, new HandsVisualState(handsVisuals));
}
#endregion
private void HandleSetHand(RequestSetHandEvent msg, EntitySessionEventArgs eventArgs)
{

View File

@@ -53,9 +53,6 @@ public abstract partial class InventorySystem
if(!TryGetSlot(uid, args.Container.ID, out var slotDef, inventory: component))
return;
// un-rotate entities. needed for things like directional flashlights on hardsuit helmets
Transform(args.Entity).LocalRotation = 0;
var equippedEvent = new DidEquipEvent(uid, args.Entity, slotDef);
RaiseLocalEvent(uid, equippedEvent);

View File

@@ -4,11 +4,10 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Localization;
using System;
namespace Content.Shared.Item
{
public abstract class SharedItemSystem : EntitySystem
public class ItemSystem : EntitySystem
{
public override void Initialize()
{
@@ -29,11 +28,13 @@ namespace Content.Shared.Item
component.Size = state.Size;
component.EquippedPrefix = state.EquippedPrefix;
component.Color = state.Color;
component.RsiPath = state.RsiPath;
}
private void OnGetState(EntityUid uid, SharedItemComponent component, ref ComponentGetState args)
{
args.State = new ItemComponentState(component.Size, component.EquippedPrefix);
args.State = new ItemComponentState(component.Size, component.EquippedPrefix, component.Color, component.RsiPath);
}
private void OnUnequipped(EntityUid uid, SharedSpriteComponent component, GotUnequippedEvent args)
@@ -69,11 +70,5 @@ namespace Content.Shared.Item
args.Verbs.Add(verb);
}
/// <summary>
/// Notifies any entity that is holding or wearing this item that they may need to update their sprite.
/// </summary>
public virtual void VisualsChanged(EntityUid owner, SharedItemComponent? item = null)
{ }
}
}

View File

@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Inventory;
using Content.Shared.Sound;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.IoC;
@@ -12,7 +13,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using static Robust.Shared.GameObjects.SharedSpriteComponent;
namespace Content.Shared.Item
{
@@ -40,18 +40,10 @@ namespace Content.Shared.Item
[DataField("size")]
private int _size;
[DataField("inhandVisuals")]
public Dictionary<HandLocation, List<PrototypeLayerData>> InhandVisuals = new();
[DataField("clothingVisuals")]
public Dictionary<string, List<PrototypeLayerData>> ClothingVisuals = new();
/// <summary>
/// Part of the state of the sprite shown on the player when this item is in their hands or inventory.
/// Part of the state of the sprite shown on the player when this item is in their hands.
/// </summary>
/// <remarks>
/// Only used if <see cref="InhandVisuals"/> or <see cref="ClothingVisuals"/> are unspecified.
/// </remarks>
// todo paul make this update slotvisuals on client on change
[ViewVariables(VVAccess.ReadWrite)]
public string? EquippedPrefix
{
@@ -59,7 +51,7 @@ namespace Content.Shared.Item
set
{
_equippedPrefix = value;
EntitySystem.Get<SharedItemSystem>().VisualsChanged(Owner, this);
OnEquippedPrefixChange();
Dirty();
}
}
@@ -73,7 +65,6 @@ namespace Content.Shared.Item
[DataField("EquipSound")]
public SoundSpecifier? EquipSound { get; set; } = default!;
// TODO REMOVE. Currently nonfunctional and only used by RGB system. #6253 Fixes this but requires #6252
/// <summary>
/// Color of the sprite shown on the player when this item is in their hands.
/// </summary>
@@ -91,11 +82,20 @@ namespace Content.Shared.Item
private Color _color = Color.White;
/// <summary>
/// Rsi of the sprite shown on the player when this item is in their hands. Used to generate a default entry for <see cref="InhandVisuals"/>
/// Rsi of the sprite shown on the player when this item is in their hands.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public string? RsiPath
{
get => _rsiPath;
set
{
_rsiPath = value;
Dirty();
}
}
[DataField("sprite")]
public readonly string? RsiPath;
private string? _rsiPath;
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
@@ -116,6 +116,12 @@ namespace Content.Shared.Item
return hands.TryPickupEntityToActiveHand(Owner, animateUser: true);
}
private void OnEquippedPrefixChange()
{
if (Owner.TryGetContainer(out var container))
_entMan.EventBus.RaiseLocalEvent(container.Owner, new ItemPrefixChangeEvent(Owner, container.ID));
}
public void RemovedFromSlot()
{
if (_entMan.TryGetComponent(Owner, out SharedSpriteComponent component))
@@ -134,25 +140,29 @@ namespace Content.Shared.Item
{
public int Size { get; }
public string? EquippedPrefix { get; }
public Color Color { get; }
public string? RsiPath { get; }
public ItemComponentState(int size, string? equippedPrefix)
public ItemComponentState(int size, string? equippedPrefix, Color color, string? rsiPath)
{
Size = size;
EquippedPrefix = equippedPrefix;
Color = color;
RsiPath = rsiPath;
}
}
/// <summary>
/// Raised when an item's visual state is changed. The event is directed at the entity that contains this item, so
/// that it can properly update its hands or inventory sprites and GUI.
/// 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 VisualsChangedEvent : EntityEventArgs
public class ItemPrefixChangeEvent : EntityEventArgs
{
public readonly EntityUid Item;
public readonly string ContainerId;
public VisualsChangedEvent(EntityUid item, string containerId)
public ItemPrefixChangeEvent(EntityUid item, string containerId)
{
Item = item;
ContainerId = containerId;