Files
Delta-v/Content.Shared/Chat/TypingIndicator/SharedTypingIndicatorSystem.cs
T
73363b9ff5 More Chat Indicators (#4679)
* emote whisper and OOC bubbles

Signed-off-by: Nesoryo-jpeg <joem365289@gmail.com>

* Update meta.json

added entries for OOC, Emote, and Whisper

Signed-off-by: Nesoryo-jpeg <joem365289@gmail.com>

* Update meta.json

added copyright info for OOC, Emote, and Whispering

Signed-off-by: Nesoryo-jpeg <joem365289@gmail.com>

* Update typing_indicator.yml

Added Whisper, OOC, and Emote indicators

Signed-off-by: Nesoryo-jpeg <joem365289@gmail.com>

* added indicator logic

* added radio sprite state

* initialized logic for chat bubbles

* refresh indicator change

* fixed emote sprite

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* nicer comments

* cleaned up and sorted namespaces

* oh my god

* cleanup...

* cleanup two

* cleanup 3 (my god)

* YESSSS

---------

Signed-off-by: Nesoryo-jpeg <joem365289@gmail.com>
Co-authored-by: Nesoryo-jpeg <joem365289@gmail.com>
Co-authored-by: nkokic <nikola1.kokic@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-12-04 10:59:08 -06:00

108 lines
4.2 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Shared.Clothing;
using Content.Shared.Inventory;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.Chat.TypingIndicator;
/// <summary>
/// Supports typing indicators on entities.
/// </summary>
public abstract class SharedTypingIndicatorSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IGameTiming _timing = default!;
/// <summary>
/// Default ID of <see cref="TypingIndicatorPrototype"/>
/// </summary>
public static readonly ProtoId<TypingIndicatorPrototype> InitialIndicatorId = "default";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<TypingIndicatorComponent, PlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<TypingIndicatorClothingComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<TypingIndicatorClothingComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<TypingIndicatorClothingComponent, InventoryRelayedEvent<BeforeShowTypingIndicatorEvent>>(BeforeShow);
SubscribeAllEvent<TypingChangedEvent>(OnTypingChanged);
}
private void OnPlayerAttached(PlayerAttachedEvent ev)
{
// when player poses entity we want to make sure that there is typing indicator
EnsureComp<TypingIndicatorComponent>(ev.Entity);
// we also need appearance component to sync visual state
EnsureComp<AppearanceComponent>(ev.Entity);
}
private void OnPlayerDetached(EntityUid uid, TypingIndicatorComponent component, PlayerDetachedEvent args)
{
// player left entity body - hide typing indicator
SetTypingIndicatorState(uid, TypingIndicatorState.None);
}
private void OnGotEquipped(Entity<TypingIndicatorClothingComponent> entity, ref ClothingGotEquippedEvent args)
{
entity.Comp.GotEquippedTime = _timing.CurTime;
}
private void OnGotUnequipped(Entity<TypingIndicatorClothingComponent> entity, ref ClothingGotUnequippedEvent args)
{
entity.Comp.GotEquippedTime = null;
}
private void BeforeShow(Entity<TypingIndicatorClothingComponent> entity, ref InventoryRelayedEvent<BeforeShowTypingIndicatorEvent> args)
{
args.Args.TryUpdateTimeAndIndicator(entity.Comp.TypingIndicatorPrototype, entity.Comp.GotEquippedTime);
}
private void OnTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args)
{
var uid = args.SenderSession.AttachedEntity;
if (!Exists(uid))
{
Log.Warning($"Client {args.SenderSession} sent TypingChangedEvent without an attached entity.");
return;
}
// check if this entity can speak or emote
if (!_actionBlocker.CanEmote(uid.Value) && !_actionBlocker.CanSpeak(uid.Value))
{
// nah, make sure that typing indicator is disabled
SetTypingIndicatorState(uid.Value, TypingIndicatorState.None);
return;
}
if(ev.State != TypingIndicatorState.Idle) // DeltaV - don't remove override when transitioning to idle
SetTypingOverride(uid.Value, ev.OverrideIndicator); // DeltaV
SetTypingIndicatorState(uid.Value, ev.State);
}
private void SetTypingIndicatorState(EntityUid uid, TypingIndicatorState state, AppearanceComponent? appearance = null)
{
if (!Resolve(uid, ref appearance, false))
return;
_appearance.SetData(uid, TypingIndicatorVisuals.State, state, appearance);
}
/// <summary>
/// DeltaV: Adds an override to the TypingIndicator visuals
/// </summary>
/// <param name="protoId">The TypingIndicator to use in place of default or clothing indicators. Clears overrides when null.</param>
private void SetTypingOverride(EntityUid uid, ProtoId<TypingIndicatorPrototype>? protoId)
{
var comp = EnsureComp<TypingIndicatorComponent>(uid);
comp.TypingIndicatorOverridePrototype = protoId;
Dirty(uid, comp);
}
}