CatStation/Content.Server/Chat/TypingIndicator/TypingIndicatorSystem.cs
Morb0 636bea81df Merge remote-tracking branch 'upstream/master' into upstream-sync
# Conflicts:
#	.github/CODEOWNERS
#	Content.Client/Entry/EntryPoint.cs
#	Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs
#	Content.Server/Zombies/ZombifyOnDeathSystem.cs
#	Resources/Prototypes/Corvax/Roles/Jobs/Engineering/chief_engineer.yml
#	Resources/Prototypes/Datasets/Names/cargo_shuttle.yml
#	Resources/Prototypes/Datasets/tips.yml
#	Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml
#	Resources/Prototypes/Entities/Mobs/Species/base.yml
#	Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
#	Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml
#	Resources/Prototypes/Roles/Jobs/Command/captain.yml
#	Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml
#	Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml
#	Resources/Prototypes/Roles/Jobs/Science/research_director.yml
#	Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml
#	Resources/Prototypes/Voice/speech_emotes.yml
#	Resources/ServerInfo/Guidebook/Science/Robotics.xml
#	Resources/Textures/Clothing/Head/Bandanas/brown.rsi/meta.json
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/equipped-HELMET.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-equipped-HELMET.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-inhand-left.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight-inhand-right.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/headlight.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/icon.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/inhand-left.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/inhand-right.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/meta.json
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-equipped-HELMET.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-inhand-left.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit-inhand-right.png
#	Resources/Textures/Clothing/Head/Helmets/syndicate.rsi/visorlit.png
#	Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/equipped-OUTERCLOTHING.png
#	Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/icon.png
#	Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/inhand-left.png
#	Resources/Textures/Clothing/OuterClothing/Suits/syndicate.rsi/inhand-right.png
#	Resources/Textures/Effects/speech.rsi/meta.json
#	Resources/Textures/Objects/Misc/bureaucracy.rsi/meta.json
#	Resources/Textures/Objects/Misc/stock_parts.rsi/adv_capacitor.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/advanced_matter_bin.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/bluespace_matter_bin.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/capacitor.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/femto_mani.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/matter_bin.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/micro_mani.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/nano_mani.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/pico_mani.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/quadratic_capacitor.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/super_capacitor.png
#	Resources/Textures/Objects/Misc/stock_parts.rsi/super_matter_bin.png
#	Resources/Textures/Structures/Furniture/chairs.rsi/meta.json
2023-06-19 21:06:28 +03:00

64 lines
2.5 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Shared.Chat.TypingIndicator;
using Robust.Server.GameObjects;
namespace Content.Server.Chat.TypingIndicator;
// Server-side typing system
// It receives networked typing events from clients
// And sync typing indicator using appearance component
public sealed class TypingIndicatorSystem : SharedTypingIndicatorSystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<TypingIndicatorComponent, PlayerDetachedEvent>(OnPlayerDetached);
SubscribeNetworkEvent<TypingChangedEvent>(OnClientTypingChanged);
}
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); // Corvax-TypingIndicator
}
private void OnClientTypingChanged(TypingChangedEvent ev, EntitySessionEventArgs args)
{
var uid = args.SenderSession.AttachedEntity;
if (!Exists(uid))
{
Logger.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); // Corvax-TypingIndicator
return;
}
SetTypingIndicatorState(uid.Value, ev.State); // Corvax-TypingIndicator
}
private void SetTypingIndicatorState(EntityUid uid, TypingIndicatorState state, AppearanceComponent? appearance = null) // Corvax-TypingIndicator
{
// if (!Resolve(uid, ref appearance, false)) // Corvax-TypingIndicator
// return;
_appearance.SetData(uid, TypingIndicatorVisuals.State, state); // Corvax-TypingIndicator
}
}