Files
Delta-v/Content.Client/Chat/TypingIndicator/TypingIndicatorSystem.cs
T
OxdeceptionandOxdeception 04c7e4d633 Adds a typing indicator to the AAC (#3595)
* Adds a typing indicator to the AAC

* Removes duplicate TypingChangedEvent constructor

* Updates sprite attribution

* Corrects fork addition comment style

* Moves typing indicator override from Appearance to TypingIndicatorComponent

* Reduces retrievals of TypingIndicatorSystem in the AAC BUI

* Moves ClientAlternateTyping to _DV

* Adds missing comment

* Sets TypingIndicatorComponent Dirty

* Caches ShowTypingIndicator in AlternateTypingIndicator

* Removes unnecessary default assignment

---------

Co-authored-by: Oxdeception <9624-oxdeception@users.noreply.gitgud.io>
2025-05-03 23:36:13 +01:00

87 lines
2.6 KiB
C#

using Content.Shared.CCVar;
using Content.Shared.Chat.TypingIndicator;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
namespace Content.Client.Chat.TypingIndicator;
// Client-side typing system tracks user input in chat box
public sealed partial class TypingIndicatorSystem : SharedTypingIndicatorSystem // DeltaV - Made partial
{
[Dependency] private readonly IGameTiming _time = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
private readonly TimeSpan _typingTimeout = TimeSpan.FromSeconds(2);
private TimeSpan _lastTextChange;
private bool _isClientTyping;
public override void Initialize()
{
base.Initialize();
Subs.CVar(_cfg, CCVars.ChatShowTypingIndicator, OnShowTypingChanged);
InitializeAlternateTyping(); // DeltaV
}
public void ClientChangedChatText()
{
// don't update it if player don't want to show typing indicator
if (!_cfg.GetCVar(CCVars.ChatShowTypingIndicator))
return;
// client typed something - show typing indicator
ClientUpdateTyping(true);
_lastTextChange = _time.CurTime;
}
public void ClientSubmittedChatText()
{
// don't update it if player don't want to show typing
if (!_cfg.GetCVar(CCVars.ChatShowTypingIndicator))
return;
// client submitted text - hide typing indicator
ClientUpdateTyping(false);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
// check if client didn't changed chat text box for a long time
if (_isClientTyping)
{
var dif = _time.CurTime - _lastTextChange;
if (dif > _typingTimeout)
{
// client didn't typed anything for a long time - hide indicator
ClientUpdateTyping(false);
}
}
}
private void ClientUpdateTyping(bool isClientTyping)
{
if (_isClientTyping == isClientTyping)
return;
// check if player controls any entity.
if (_playerManager.LocalEntity == null)
return;
_isClientTyping = isClientTyping;
RaisePredictiveEvent(new TypingChangedEvent(isClientTyping));
}
private void OnShowTypingChanged(bool showTyping)
{
// hide typing indicator immediately if player don't want to show it anymore
if (!showTyping)
{
ClientUpdateTyping(false);
}
}
}