Files
Delta-v/Content.Shared/Chat/TypingIndicator/TypingIndicatorEvents.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

63 lines
2.1 KiB
C#

using Robust.Shared.Serialization;
using Content.Shared.Inventory;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Exceptions;
namespace Content.Shared.Chat.TypingIndicator;
/// <summary>
/// Networked event from client.
/// Send to server when client started/stopped typing in chat input field.
/// </summary>
[Serializable, NetSerializable]
public sealed class TypingChangedEvent : EntityEventArgs
{
public readonly bool IsTyping;
public readonly ProtoId<TypingIndicatorPrototype>? OverrideIndicator; // DeltaV
public TypingChangedEvent(bool isTyping, ProtoId<TypingIndicatorPrototype>? proto = null) // DeltaV
{
IsTyping = isTyping;
OverrideIndicator = proto; // DeltaV
}
}
/// <summary>
/// This event will be broadcast right before displaying an entities typing indicator.
/// If _overrideIndicator is not null after the event is finished it will be used.
/// </summary>
[Serializable, NetSerializable]
public sealed class BeforeShowTypingIndicatorEvent : IInventoryRelayEvent
{
public SlotFlags TargetSlots { get; } = SlotFlags.WITHOUT_POCKET;
private ProtoId<TypingIndicatorPrototype>? _overrideIndicator = null;
private TimeSpan? _latestEquipTime = null;
public BeforeShowTypingIndicatorEvent()
{
_overrideIndicator = null;
_latestEquipTime = null;
}
/// <summary>
/// Will only update the time and indicator if the given time is more recent than
/// the stored time or if the stored time is null.
/// </summary>
/// <returns>
/// True if the given time is more recent than the stored time, and false otherwise.
/// </returns>
public bool TryUpdateTimeAndIndicator(ProtoId<TypingIndicatorPrototype>? indicator, TimeSpan? equipTime)
{
if (equipTime != null && (_latestEquipTime == null || _latestEquipTime < equipTime))
{
_latestEquipTime = equipTime;
_overrideIndicator = indicator;
return true;
}
return false;
}
public ProtoId<TypingIndicatorPrototype>? GetMostRecentIndicator()
{
return _overrideIndicator;
}
}