diff --git a/Content.Client/Chat/TypingIndicator/TypingIndicatorVisualizerSystem.cs b/Content.Client/Chat/TypingIndicator/TypingIndicatorVisualizerSystem.cs index 0f261b69ef..02fd18899b 100644 --- a/Content.Client/Chat/TypingIndicator/TypingIndicatorVisualizerSystem.cs +++ b/Content.Client/Chat/TypingIndicator/TypingIndicatorVisualizerSystem.cs @@ -9,42 +9,26 @@ public sealed class TypingIndicatorVisualizerSystem : VisualizerSystem(OnInit); - } - - private void OnInit(EntityUid uid, TypingIndicatorComponent component, ComponentInit args) - { - if (!TryComp(uid, out SpriteComponent? sprite)) + if (args.Sprite == null) return; - + if (!_prototypeManager.TryIndex(component.Prototype, out var proto)) { Logger.Error($"Unknown typing indicator id: {component.Prototype}"); return; } - var layer = sprite.LayerMapReserveBlank(TypingIndicatorLayers.Base); - sprite.LayerSetRSI(layer, proto.SpritePath); - sprite.LayerSetState(layer, proto.TypingState); - sprite.LayerSetShader(layer, proto.Shader); - sprite.LayerSetOffset(layer, proto.Offset); - sprite.LayerSetVisible(layer, false); - } - - protected override void OnAppearanceChange(EntityUid uid, TypingIndicatorComponent component, ref AppearanceChangeEvent args) - { - base.OnAppearanceChange(uid, component, ref args); - - if (!TryComp(uid, out SpriteComponent? sprite)) - return; - args.Component.TryGetData(TypingIndicatorVisuals.IsTyping, out bool isTyping); - if (sprite.LayerMapTryGet(TypingIndicatorLayers.Base, out var layer)) - { - sprite.LayerSetVisible(layer, isTyping); - } + var layerExists = args.Sprite.LayerMapTryGet(TypingIndicatorLayers.Base, out var layer); + if (!layerExists) + layer = args.Sprite.LayerMapReserveBlank(TypingIndicatorLayers.Base); + + args.Sprite.LayerSetRSI(layer, proto.SpritePath); + args.Sprite.LayerSetState(layer, proto.TypingState); + args.Sprite.LayerSetShader(layer, proto.Shader); + args.Sprite.LayerSetOffset(layer, proto.Offset); + args.Sprite.LayerSetVisible(layer, isTyping); } } diff --git a/Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs b/Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs index c33ebe05da..b255d76fb4 100644 --- a/Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs +++ b/Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs @@ -1,7 +1,6 @@ using Content.Shared.ActionBlocker; using Content.Shared.Chat.TypingIndicator; using Robust.Server.GameObjects; -using Robust.Shared.Players; namespace Content.Server.Chat.TypingIndicator; diff --git a/Content.Shared/Chat/TypingIndicator/SharedTypingIndicatorSystem.cs b/Content.Shared/Chat/TypingIndicator/SharedTypingIndicatorSystem.cs index 4c5ac2ca80..ae1cd534fe 100644 --- a/Content.Shared/Chat/TypingIndicator/SharedTypingIndicatorSystem.cs +++ b/Content.Shared/Chat/TypingIndicator/SharedTypingIndicatorSystem.cs @@ -1,9 +1,42 @@ -namespace Content.Shared.Chat.TypingIndicator; +using Content.Shared.Clothing.Components; +using Content.Shared.Inventory.Events; + +namespace Content.Shared.Chat.TypingIndicator; /// /// Sync typing indicator icon between client and server. /// public abstract class SharedTypingIndicatorSystem : EntitySystem { + /// + /// Default ID of + /// + public const string InitialIndicatorId = "default"; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGotEquipped); + SubscribeLocalEvent(OnGotUnequipped); + } + private void OnGotEquipped(EntityUid uid, TypingIndicatorClothingComponent component, GotEquippedEvent args) + { + if (!TryComp(uid, out var clothing) || + !TryComp(args.Equipee, out var indicator)) + return; + + var isCorrectSlot = clothing.Slots.HasFlag(args.SlotFlags); + if (!isCorrectSlot) return; + + indicator.Prototype = component.Prototype; + } + + private void OnGotUnequipped(EntityUid uid, TypingIndicatorClothingComponent component, GotUnequippedEvent args) + { + if (!TryComp(args.Equipee, out var indicator)) + return; + + indicator.Prototype = SharedTypingIndicatorSystem.InitialIndicatorId; + } } diff --git a/Content.Shared/Chat/TypingIndicator/TypingIndicatorClothingComponent.cs b/Content.Shared/Chat/TypingIndicator/TypingIndicatorClothingComponent.cs new file mode 100644 index 0000000000..1bffa2a89a --- /dev/null +++ b/Content.Shared/Chat/TypingIndicator/TypingIndicatorClothingComponent.cs @@ -0,0 +1,13 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Shared.Chat.TypingIndicator; + +[RegisterComponent, NetworkedComponent] +[Access(typeof(SharedTypingIndicatorSystem))] +public sealed class TypingIndicatorClothingComponent : Component +{ + [ViewVariables(VVAccess.ReadWrite)] + [DataField("proto", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] + public string Prototype = default!; +} diff --git a/Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs b/Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs index e8d370e0cf..24da9f2185 100644 --- a/Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs +++ b/Content.Shared/Chat/TypingIndicator/TypingIndicatorComponent.cs @@ -14,7 +14,7 @@ public sealed class TypingIndicatorComponent : Component /// /// Prototype id that store all visual info about typing indicator. /// - [ViewVariables(VVAccess.ReadOnly)] + [ViewVariables(VVAccess.ReadWrite)] [DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string Prototype = "default"; + public string Prototype = SharedTypingIndicatorSystem.InitialIndicatorId; } diff --git a/Resources/Prototypes/Entities/Clothing/Neck/misc.yml b/Resources/Prototypes/Entities/Clothing/Neck/misc.yml index d0f98dd5ea..daf167b3f7 100644 --- a/Resources/Prototypes/Entities/Clothing/Neck/misc.yml +++ b/Resources/Prototypes/Entities/Clothing/Neck/misc.yml @@ -42,3 +42,5 @@ sprite: Clothing/Neck/Misc/lawyerbadge.rsi - type: Clothing sprite: Clothing/Neck/Misc/lawyerbadge.rsi + - type: TypingIndicatorClothing + proto: lawyer diff --git a/Resources/Prototypes/typing_indicator.yml b/Resources/Prototypes/typing_indicator.yml index bc6f32e31e..6c1fc02daa 100644 --- a/Resources/Prototypes/typing_indicator.yml +++ b/Resources/Prototypes/typing_indicator.yml @@ -17,3 +17,7 @@ - type: typingIndicator id: holo typingState: holo0 + +- type: typingIndicator + id: lawyer + typingState: lawyer0