StationAiSystem.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Content.Shared.Silicons.StationAi;
  2. using Robust.Client.Graphics;
  3. using Robust.Client.Player;
  4. using Robust.Shared.Player;
  5. namespace Content.Client.Silicons.StationAi;
  6. public sealed partial class StationAiSystem : SharedStationAiSystem
  7. {
  8. [Dependency] private readonly IOverlayManager _overlayMgr = default!;
  9. [Dependency] private readonly IPlayerManager _player = default!;
  10. private StationAiOverlay? _overlay;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. InitializeAirlock();
  15. InitializePowerToggle();
  16. SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerAttachedEvent>(OnAiAttached);
  17. SubscribeLocalEvent<StationAiOverlayComponent, LocalPlayerDetachedEvent>(OnAiDetached);
  18. SubscribeLocalEvent<StationAiOverlayComponent, ComponentInit>(OnAiOverlayInit);
  19. SubscribeLocalEvent<StationAiOverlayComponent, ComponentRemove>(OnAiOverlayRemove);
  20. }
  21. private void OnAiOverlayInit(Entity<StationAiOverlayComponent> ent, ref ComponentInit args)
  22. {
  23. var attachedEnt = _player.LocalEntity;
  24. if (attachedEnt != ent.Owner)
  25. return;
  26. AddOverlay();
  27. }
  28. private void OnAiOverlayRemove(Entity<StationAiOverlayComponent> ent, ref ComponentRemove args)
  29. {
  30. var attachedEnt = _player.LocalEntity;
  31. if (attachedEnt != ent.Owner)
  32. return;
  33. RemoveOverlay();
  34. }
  35. private void AddOverlay()
  36. {
  37. if (_overlay != null)
  38. return;
  39. _overlay = new StationAiOverlay();
  40. _overlayMgr.AddOverlay(_overlay);
  41. }
  42. private void RemoveOverlay()
  43. {
  44. if (_overlay == null)
  45. return;
  46. _overlayMgr.RemoveOverlay(_overlay);
  47. _overlay = null;
  48. }
  49. private void OnAiAttached(Entity<StationAiOverlayComponent> ent, ref LocalPlayerAttachedEvent args)
  50. {
  51. AddOverlay();
  52. }
  53. private void OnAiDetached(Entity<StationAiOverlayComponent> ent, ref LocalPlayerDetachedEvent args)
  54. {
  55. RemoveOverlay();
  56. }
  57. public override void Shutdown()
  58. {
  59. base.Shutdown();
  60. _overlayMgr.RemoveOverlay<StationAiOverlay>();
  61. }
  62. }