SharedPopupSystem.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using Robust.Shared.Map;
  2. using Robust.Shared.Player;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.Popups
  5. {
  6. /// <summary>
  7. /// System for displaying small text popups on users' screens.
  8. /// </summary>
  9. public abstract class SharedPopupSystem : EntitySystem
  10. {
  11. /// <summary>
  12. /// Shows a popup at the local users' cursor. Does nothing on the server.
  13. /// </summary>
  14. /// <param name="message">The message to display.</param>
  15. /// <param name="type">Used to customize how this popup should appear visually.</param>
  16. public abstract void PopupCursor(string? message, PopupType type = PopupType.Small);
  17. /// <summary>
  18. /// Shows a popup at a users' cursor.
  19. /// </summary>
  20. /// <param name="message">The message to display.</param>
  21. /// <param name="recipient">Client that will see this popup.</param>
  22. /// <param name="type">Used to customize how this popup should appear visually.</param>
  23. public abstract void PopupCursor(string? message, ICommonSession recipient, PopupType type = PopupType.Small);
  24. /// <summary>
  25. /// Shows a popup at a users' cursor.
  26. /// </summary>
  27. /// <param name="message">The message to display.</param>
  28. /// <param name="recipient">Client that will see this popup.</param>
  29. /// <param name="type">Used to customize how this popup should appear visually.</param>
  30. public abstract void PopupCursor(string? message, EntityUid recipient, PopupType type = PopupType.Small);
  31. /// <summary>
  32. /// Shows a popup at a world location to every entity in PVS range.
  33. /// </summary>
  34. /// <param name="message">The message to display.</param>
  35. /// <param name="coordinates">The coordinates where to display the message.</param>
  36. /// <param name="type">Used to customize how this popup should appear visually.</param>
  37. public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, PopupType type = PopupType.Small);
  38. /// <summary>
  39. /// Filtered variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/>, which should only be used
  40. /// if the filtering has to be more specific than simply PVS range based.
  41. /// </summary>
  42. /// <param name="filter">Filter for the players that will see the popup.</param>
  43. /// <param name="recordReplay">If true, this pop-up will be considered as a globally visible pop-up that gets shown during replays.</param>
  44. public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, Filter filter, bool recordReplay, PopupType type = PopupType.Small);
  45. /// <summary>
  46. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to the player attached to some entity.
  47. /// </summary>
  48. public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small);
  49. /// <summary>
  50. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that sends a pop-up to a specific player.
  51. /// </summary>
  52. public abstract void PopupCoordinates(string? message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small);
  53. /// <summary>
  54. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> for use with prediction. The local client will
  55. /// the popup to the recipient, and the server will show it to every other player in PVS range. If recipient is null, the local
  56. // client will do nothing and the server will show the message to every player in PVS range.
  57. /// </summary>
  58. public abstract void PopupPredictedCoordinates(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small);
  59. /// <summary>
  60. /// Shows a popup above an entity for every player in pvs range.
  61. /// </summary>
  62. /// <param name="message">The message to display.</param>
  63. /// <param name="uid">The UID of the entity.</param>
  64. /// <param name="type">Used to customize how this popup should appear visually.</param>
  65. public abstract void PopupEntity(string? message, EntityUid uid, PopupType type=PopupType.Small);
  66. /// <summary>
  67. /// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client.
  68. /// </summary>
  69. public abstract void PopupEntity(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small);
  70. /// <summary>
  71. /// Variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/> that shows the popup only to some specific client.
  72. /// </summary>
  73. public abstract void PopupEntity(string? message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small);
  74. /// <summary>
  75. /// Filtered variant of <see cref="PopupEntity(string, EntityUid, PopupType)"/>, which should only be used
  76. /// if the filtering has to be more specific than simply PVS range based.
  77. /// </summary>
  78. public abstract void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small);
  79. /// <summary>
  80. /// Variant of <see cref="PopupCursor(string, EntityUid, PopupType)"/> that only runs on the client, outside of prediction.
  81. /// Useful for shared code that is always ran by both sides to avoid duplicate popups.
  82. /// </summary>
  83. public abstract void PopupClient(string? message, EntityUid? recipient, PopupType type = PopupType.Small);
  84. /// <summary>
  85. /// Variant of <see cref="PopupEntity(string, EntityUid, EntityUid, PopupType)"/> that only runs on the client, outside of prediction.
  86. /// Useful for shared code that is always ran by both sides to avoid duplicate popups.
  87. /// </summary>
  88. public abstract void PopupClient(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small);
  89. /// <summary>
  90. /// Variant of <see cref="PopupCoordinates(string, EntityCoordinates, PopupType)"/> that only runs on the client, outside of prediction.
  91. /// Useful for shared code that is always ran by both sides to avoid duplicate popups.
  92. /// </summary>
  93. public abstract void PopupClient(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small);
  94. /// <summary>
  95. /// Variant of <see cref="PopupEntity(string, EntityUid, EntityUid, PopupType)"/> for use with prediction. The local client will show
  96. /// the popup to the recipient, and the server will show it to every other player in PVS range. If recipient is null, the local client
  97. /// will do nothing and the server will show the message to every player in PVS range.
  98. /// </summary>
  99. public abstract void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small);
  100. /// <summary>
  101. /// Variant of <see cref="PopupPredicted(string?, EntityUid, EntityUid?, PopupType)"/> that displays <paramref name="recipientMessage"/>
  102. /// to the recipient and <paramref name="othersMessage"/> to everyone else in PVS range.
  103. /// </summary>
  104. public abstract void PopupPredicted(string? recipientMessage, string? othersMessage, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small);
  105. }
  106. /// <summary>
  107. /// Common base for all popup network events.
  108. /// </summary>
  109. [Serializable, NetSerializable]
  110. public abstract class PopupEvent : EntityEventArgs
  111. {
  112. public string Message { get; }
  113. public PopupType Type { get; }
  114. protected PopupEvent(string message, PopupType type)
  115. {
  116. Message = message;
  117. Type = type;
  118. }
  119. }
  120. /// <summary>
  121. /// Network event for displaying a popup on the user's cursor.
  122. /// </summary>
  123. [Serializable, NetSerializable]
  124. public sealed class PopupCursorEvent : PopupEvent
  125. {
  126. public PopupCursorEvent(string message, PopupType type) : base(message, type)
  127. {
  128. }
  129. }
  130. /// <summary>
  131. /// Network event for displaying a popup at a world location.
  132. /// </summary>
  133. [Serializable, NetSerializable]
  134. public sealed class PopupCoordinatesEvent : PopupEvent
  135. {
  136. public NetCoordinates Coordinates { get; }
  137. public PopupCoordinatesEvent(string message, PopupType type, NetCoordinates coordinates) : base(message, type)
  138. {
  139. Coordinates = coordinates;
  140. }
  141. }
  142. /// <summary>
  143. /// Network event for displaying a popup above an entity.
  144. /// </summary>
  145. [Serializable, NetSerializable]
  146. public sealed class PopupEntityEvent : PopupEvent
  147. {
  148. public NetEntity Uid { get; }
  149. public PopupEntityEvent(string message, PopupType type, NetEntity uid) : base(message, type)
  150. {
  151. Uid = uid;
  152. }
  153. }
  154. /// <summary>
  155. /// Used to determine how a popup should appear visually to the client. Caution variants simply have a red color.
  156. /// </summary>
  157. /// <remarks>
  158. /// Actions which can fail or succeed should use a smaller popup for failure and a larger popup for success.
  159. /// Actions which have different popups for the user vs. others should use a larger popup for the user and a smaller popup for others.
  160. /// Actions which result in harm or are otherwise dangerous should always show as the caution variant.
  161. /// </remarks>
  162. [Serializable, NetSerializable]
  163. public enum PopupType : byte
  164. {
  165. /// <summary>
  166. /// Small popups are the default, and denote actions that may be spammable or are otherwise unimportant.
  167. /// </summary>
  168. Small,
  169. SmallCaution,
  170. /// <summary>
  171. /// Medium popups should be used for actions which are not spammable but may not be particularly important.
  172. /// </summary>
  173. Medium,
  174. MediumCaution,
  175. /// <summary>
  176. /// Large popups should be used for actions which may be important or very important to one or more users,
  177. /// but is not life-threatening.
  178. /// </summary>
  179. Large,
  180. LargeCaution
  181. }
  182. }