Add support for multi-layer in-hand and clothing sprites (#6252)

This commit is contained in:
Leon Friedrich
2022-02-07 16:37:57 +13:00
committed by GitHub
parent aad52dfd35
commit 470e4f8bdc
17 changed files with 529 additions and 262 deletions

View File

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

View File

@@ -3,8 +3,6 @@ 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;
@@ -18,6 +16,7 @@ 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
{
@@ -708,47 +707,6 @@ 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,13 +1,67 @@
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,7 +2,6 @@ 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;
@@ -11,7 +10,6 @@ using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using System.Collections.Generic;
namespace Content.Shared.Hands
{
@@ -25,8 +23,7 @@ namespace Content.Shared.Hands
SubscribeAllEvent<RequestSetHandEvent>(HandleSetHand);
SubscribeLocalEvent<SharedHandsComponent, EntRemovedFromContainerMessage>(HandleContainerRemoved);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerModified);
SubscribeLocalEvent<SharedHandsComponent, ItemPrefixChangeEvent>(OnPrefixChanged);
SubscribeLocalEvent<SharedHandsComponent, EntInsertedIntoContainerMessage>(HandleContainerInserted);
CommandBinds.Builder
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
@@ -34,15 +31,6 @@ 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();
@@ -136,43 +124,25 @@ 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
#region visuals
private void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args)
protected virtual void HandleContainerModified(EntityUid uid, SharedHandsComponent hands, ContainerModifiedMessage args)
{
UpdateHandVisuals(uid, hands);
// client updates hand visuals here.
}
/// <summary>
/// Update the In-Hand sprites
/// </summary>
public virtual void UpdateHandVisuals(EntityUid uid, SharedHandsComponent? handComp = null, AppearanceComponent? appearance = null)
private void HandleContainerInserted(EntityUid uid, SharedHandsComponent component, EntInsertedIntoContainerMessage args)
{
if (!Resolve(uid, ref handComp, ref appearance, false))
return;
// un-rotate entities. needed for things like directional flashlights
Transform(args.Entity).LocalRotation = 0;
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));
HandleContainerModified(uid, component, args);
}
#endregion
private void HandleSetHand(RequestSetHandEvent msg, EntitySessionEventArgs eventArgs)
{