1
0

SpawnExplosionEui.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Content.Client.Eui;
  2. using Content.Shared.Administration;
  3. using Content.Shared.Eui;
  4. using JetBrains.Annotations;
  5. using Robust.Client.Graphics;
  6. using Robust.Shared.Map;
  7. namespace Content.Client.Administration.UI.SpawnExplosion;
  8. [UsedImplicitly]
  9. public sealed class SpawnExplosionEui : BaseEui
  10. {
  11. [Dependency] private readonly EntityManager _entManager = default!;
  12. [Dependency] private readonly IOverlayManager _overlayManager = default!;
  13. private readonly SpawnExplosionWindow _window;
  14. private ExplosionDebugOverlay? _debugOverlay;
  15. public SpawnExplosionEui()
  16. {
  17. IoCManager.InjectDependencies(this);
  18. _window = new SpawnExplosionWindow(this);
  19. _window.OnClose += SendClosedMessage;
  20. }
  21. public override void Opened()
  22. {
  23. base.Opened();
  24. _window.OpenCentered();
  25. }
  26. public override void Closed()
  27. {
  28. base.Closed();
  29. _window.OnClose -= SendClosedMessage;
  30. _window.Close();
  31. ClearOverlay();
  32. }
  33. public void SendClosedMessage()
  34. {
  35. SendMessage(new CloseEuiMessage());
  36. }
  37. public void ClearOverlay()
  38. {
  39. if (_overlayManager.HasOverlay<ExplosionDebugOverlay>())
  40. _overlayManager.RemoveOverlay<ExplosionDebugOverlay>();
  41. _debugOverlay = null;
  42. }
  43. public void RequestPreviewData(MapCoordinates epicenter, string typeId, float totalIntensity, float intensitySlope, float maxIntensity)
  44. {
  45. var msg = new SpawnExplosionEuiMsg.PreviewRequest(epicenter, typeId, totalIntensity, intensitySlope, maxIntensity);
  46. SendMessage(msg);
  47. }
  48. /// <summary>
  49. /// Receive explosion preview data and add a client-side explosion preview overlay
  50. /// </summary>
  51. /// <param name="msg"></param>
  52. public override void HandleMessage(EuiMessageBase msg)
  53. {
  54. if (msg is not SpawnExplosionEuiMsg.PreviewData data)
  55. return;
  56. if (_debugOverlay == null)
  57. {
  58. _debugOverlay = new();
  59. _overlayManager.AddOverlay(_debugOverlay);
  60. }
  61. var tiles = new Dictionary<EntityUid, Dictionary<int, List<Vector2i>>>();
  62. _debugOverlay.Tiles.Clear();
  63. foreach (var (nent, det) in data.Explosion.Tiles)
  64. {
  65. tiles[_entManager.GetEntity(nent)] = det;
  66. }
  67. _debugOverlay.Tiles = tiles;
  68. _debugOverlay.SpaceTiles = data.Explosion.SpaceTiles;
  69. _debugOverlay.Intensity = data.Explosion.Intensity;
  70. _debugOverlay.Slope = data.Slope;
  71. _debugOverlay.TotalIntensity = data.TotalIntensity;
  72. _debugOverlay.Map = data.Explosion.Epicenter.MapId;
  73. _debugOverlay.SpaceMatrix = data.Explosion.SpaceMatrix;
  74. _debugOverlay.SpaceTileSize = data.Explosion.SpaceTileSize;
  75. }
  76. }