PopupSystem.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using Content.Shared.Popups;
  2. using Robust.Server.GameObjects;
  3. using Robust.Server.Player;
  4. using Robust.Shared.Configuration;
  5. using Robust.Shared.Map;
  6. using Robust.Shared.Player;
  7. namespace Content.Server.Popups
  8. {
  9. public sealed class PopupSystem : SharedPopupSystem
  10. {
  11. [Dependency] private readonly IPlayerManager _player = default!;
  12. [Dependency] private readonly IConfigurationManager _cfg = default!;
  13. [Dependency] private readonly SharedTransformSystem _transform = default!;
  14. public override void PopupCursor(string? message, PopupType type = PopupType.Small)
  15. {
  16. // No local user.
  17. }
  18. public override void PopupCursor(string? message, ICommonSession recipient, PopupType type = PopupType.Small)
  19. {
  20. if (message == null)
  21. return;
  22. RaiseNetworkEvent(new PopupCursorEvent(message, type), recipient);
  23. }
  24. public override void PopupCursor(string? message, EntityUid recipient, PopupType type = PopupType.Small)
  25. {
  26. if (message == null)
  27. return;
  28. if (TryComp(recipient, out ActorComponent? actor))
  29. RaiseNetworkEvent(new PopupCursorEvent(message, type), actor.PlayerSession);
  30. }
  31. public override void PopupCoordinates(string? message, EntityCoordinates coordinates, Filter filter, bool replayRecord, PopupType type = PopupType.Small)
  32. {
  33. if (message == null)
  34. return;
  35. RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter, replayRecord);
  36. }
  37. public override void PopupCoordinates(string? message, EntityCoordinates coordinates, PopupType type = PopupType.Small)
  38. {
  39. if (message == null)
  40. return;
  41. var mapPos = _transform.ToMapCoordinates(coordinates);
  42. var filter = Filter.Empty().AddPlayersByPvs(mapPos, entManager: EntityManager, playerMan: _player, cfgMan: _cfg);
  43. RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter);
  44. }
  45. public override void PopupCoordinates(string? message, EntityCoordinates coordinates, ICommonSession recipient, PopupType type = PopupType.Small)
  46. {
  47. if (message == null)
  48. return;
  49. RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), recipient);
  50. }
  51. public override void PopupCoordinates(string? message, EntityCoordinates coordinates, EntityUid recipient, PopupType type = PopupType.Small)
  52. {
  53. if (message == null)
  54. return;
  55. if (TryComp(recipient, out ActorComponent? actor))
  56. RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), actor.PlayerSession);
  57. }
  58. public override void PopupPredictedCoordinates(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small)
  59. {
  60. if (message == null)
  61. return;
  62. var mapPos = _transform.ToMapCoordinates(coordinates);
  63. var filter = Filter.Empty().AddPlayersByPvs(mapPos, entManager: EntityManager, playerMan: _player, cfgMan: _cfg);
  64. if (recipient != null)
  65. {
  66. // Don't send to recipient, since they predicted it locally
  67. filter = filter.RemovePlayerByAttachedEntity(recipient.Value);
  68. }
  69. RaiseNetworkEvent(new PopupCoordinatesEvent(message, type, GetNetCoordinates(coordinates)), filter);
  70. }
  71. public override void PopupEntity(string? message, EntityUid uid, PopupType type = PopupType.Small)
  72. {
  73. if (message == null)
  74. return;
  75. var filter = Filter.Empty().AddPlayersByPvs(uid, entityManager: EntityManager, playerMan: _player, cfgMan: _cfg);
  76. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter);
  77. }
  78. public override void PopupEntity(string? message, EntityUid uid, EntityUid recipient, PopupType type = PopupType.Small)
  79. {
  80. if (message == null)
  81. return;
  82. if (TryComp(recipient, out ActorComponent? actor))
  83. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), actor.PlayerSession);
  84. }
  85. public override void PopupClient(string? message, EntityUid? recipient, PopupType type = PopupType.Small)
  86. {
  87. }
  88. public override void PopupClient(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small)
  89. {
  90. // do nothing duh its for client only
  91. }
  92. public override void PopupClient(string? message, EntityCoordinates coordinates, EntityUid? recipient, PopupType type = PopupType.Small)
  93. {
  94. }
  95. public override void PopupEntity(string? message, EntityUid uid, ICommonSession recipient, PopupType type = PopupType.Small)
  96. {
  97. if (message == null)
  98. return;
  99. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), recipient);
  100. }
  101. public override void PopupEntity(string? message, EntityUid uid, Filter filter, bool recordReplay, PopupType type = PopupType.Small)
  102. {
  103. if (message == null)
  104. return;
  105. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter, recordReplay);
  106. }
  107. public override void PopupPredicted(string? message, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small)
  108. {
  109. if (message == null)
  110. return;
  111. if (recipient != null)
  112. {
  113. // Don't send to recipient, since they predicted it locally
  114. var filter = Filter.PvsExcept(recipient.Value, entityManager: EntityManager);
  115. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)), filter);
  116. }
  117. else
  118. {
  119. // With no recipient, send to everyone (in PVS range)
  120. RaiseNetworkEvent(new PopupEntityEvent(message, type, GetNetEntity(uid)));
  121. }
  122. }
  123. public override void PopupPredicted(string? recipientMessage, string? othersMessage, EntityUid uid, EntityUid? recipient, PopupType type = PopupType.Small)
  124. {
  125. PopupPredicted(othersMessage, uid, recipient, type);
  126. }
  127. }
  128. }