TypingIndicatorEvents.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Robust.Shared.Serialization;
  2. using Content.Shared.Inventory;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Serialization.Manager.Exceptions;
  5. namespace Content.Shared.Chat.TypingIndicator;
  6. /// <summary>
  7. /// Networked event from client.
  8. /// Send to server when client started/stopped typing in chat input field.
  9. /// </summary>
  10. [Serializable, NetSerializable]
  11. public sealed class TypingChangedEvent : EntityEventArgs
  12. {
  13. public readonly bool IsTyping;
  14. public TypingChangedEvent(bool isTyping)
  15. {
  16. IsTyping = isTyping;
  17. }
  18. }
  19. /// <summary>
  20. /// This event will be broadcast right before displaying an entities typing indicator.
  21. /// If _overrideIndicator is not null after the event is finished it will be used.
  22. /// </summary>
  23. [Serializable, NetSerializable]
  24. public sealed class BeforeShowTypingIndicatorEvent : IInventoryRelayEvent
  25. {
  26. public SlotFlags TargetSlots { get; } = SlotFlags.WITHOUT_POCKET;
  27. private ProtoId<TypingIndicatorPrototype>? _overrideIndicator = null;
  28. private TimeSpan? _latestEquipTime = null;
  29. public BeforeShowTypingIndicatorEvent()
  30. {
  31. _overrideIndicator = null;
  32. _latestEquipTime = null;
  33. }
  34. /// <summary>
  35. /// Will only update the time and indicator if the given time is more recent than
  36. /// the stored time or if the stored time is null.
  37. /// </summary>
  38. /// <returns>
  39. /// True if the given time is more recent than the stored time, and false otherwise.
  40. /// </returns>
  41. public bool TryUpdateTimeAndIndicator(ProtoId<TypingIndicatorPrototype>? indicator, TimeSpan? equipTime)
  42. {
  43. if (equipTime != null && (_latestEquipTime == null || _latestEquipTime < equipTime))
  44. {
  45. _latestEquipTime = equipTime;
  46. _overrideIndicator = indicator;
  47. return true;
  48. }
  49. return false;
  50. }
  51. public ProtoId<TypingIndicatorPrototype>? GetMostRecentIndicator()
  52. {
  53. return _overrideIndicator;
  54. }
  55. }