Lawyer badge changes typing indicator (#13445)

This commit is contained in:
Morb
2023-01-12 15:33:57 +03:00
committed by GitHub
parent ab073d9571
commit 76f8a7e91e
7 changed files with 67 additions and 32 deletions

View File

@@ -9,42 +9,26 @@ public sealed class TypingIndicatorVisualizerSystem : VisualizerSystem<TypingInd
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override void Initialize() protected override void OnAppearanceChange(EntityUid uid, TypingIndicatorComponent component, ref AppearanceChangeEvent args)
{ {
base.Initialize(); if (args.Sprite == null)
SubscribeLocalEvent<TypingIndicatorComponent, ComponentInit>(OnInit);
}
private void OnInit(EntityUid uid, TypingIndicatorComponent component, ComponentInit args)
{
if (!TryComp(uid, out SpriteComponent? sprite))
return; return;
if (!_prototypeManager.TryIndex<TypingIndicatorPrototype>(component.Prototype, out var proto)) if (!_prototypeManager.TryIndex<TypingIndicatorPrototype>(component.Prototype, out var proto))
{ {
Logger.Error($"Unknown typing indicator id: {component.Prototype}"); Logger.Error($"Unknown typing indicator id: {component.Prototype}");
return; 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); args.Component.TryGetData(TypingIndicatorVisuals.IsTyping, out bool isTyping);
if (sprite.LayerMapTryGet(TypingIndicatorLayers.Base, out var layer)) var layerExists = args.Sprite.LayerMapTryGet(TypingIndicatorLayers.Base, out var layer);
{ if (!layerExists)
sprite.LayerSetVisible(layer, isTyping); 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);
} }
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Chat.TypingIndicator; using Content.Shared.Chat.TypingIndicator;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Players;
namespace Content.Server.Chat.TypingIndicator; namespace Content.Server.Chat.TypingIndicator;

View File

@@ -1,9 +1,42 @@
namespace Content.Shared.Chat.TypingIndicator; using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
namespace Content.Shared.Chat.TypingIndicator;
/// <summary> /// <summary>
/// Sync typing indicator icon between client and server. /// Sync typing indicator icon between client and server.
/// </summary> /// </summary>
public abstract class SharedTypingIndicatorSystem : EntitySystem public abstract class SharedTypingIndicatorSystem : EntitySystem
{ {
/// <summary>
/// Default ID of <see cref="TypingIndicatorPrototype"/>
/// </summary>
public const string InitialIndicatorId = "default";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TypingIndicatorClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<TypingIndicatorClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
}
private void OnGotEquipped(EntityUid uid, TypingIndicatorClothingComponent component, GotEquippedEvent args)
{
if (!TryComp<ClothingComponent>(uid, out var clothing) ||
!TryComp<TypingIndicatorComponent>(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<TypingIndicatorComponent>(args.Equipee, out var indicator))
return;
indicator.Prototype = SharedTypingIndicatorSystem.InitialIndicatorId;
}
} }

View File

@@ -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<TypingIndicatorPrototype>))]
public string Prototype = default!;
}

View File

@@ -14,7 +14,7 @@ public sealed class TypingIndicatorComponent : Component
/// <summary> /// <summary>
/// Prototype id that store all visual info about typing indicator. /// Prototype id that store all visual info about typing indicator.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadOnly)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<TypingIndicatorPrototype>))] [DataField("proto", customTypeSerializer: typeof(PrototypeIdSerializer<TypingIndicatorPrototype>))]
public string Prototype = "default"; public string Prototype = SharedTypingIndicatorSystem.InitialIndicatorId;
} }

View File

@@ -42,3 +42,5 @@
sprite: Clothing/Neck/Misc/lawyerbadge.rsi sprite: Clothing/Neck/Misc/lawyerbadge.rsi
- type: Clothing - type: Clothing
sprite: Clothing/Neck/Misc/lawyerbadge.rsi sprite: Clothing/Neck/Misc/lawyerbadge.rsi
- type: TypingIndicatorClothing
proto: lawyer

View File

@@ -17,3 +17,7 @@
- type: typingIndicator - type: typingIndicator
id: holo id: holo
typingState: holo0 typingState: holo0
- type: typingIndicator
id: lawyer
typingState: lawyer0