1
0

StationMapSystem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Content.Server.PowerCell;
  2. using Content.Shared.Pinpointer;
  3. using Robust.Server.GameObjects;
  4. using Robust.Shared.Player;
  5. namespace Content.Server.Pinpointer;
  6. public sealed class StationMapSystem : EntitySystem
  7. {
  8. [Dependency] private readonly UserInterfaceSystem _ui = default!;
  9. [Dependency] private readonly PowerCellSystem _cell = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
  14. Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
  15. {
  16. subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
  17. subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
  18. });
  19. }
  20. private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args)
  21. {
  22. if (!Equals(args.UiKey, StationMapUiKey.Key))
  23. return;
  24. RemCompDeferred<StationMapUserComponent>(args.Actor);
  25. }
  26. private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
  27. {
  28. _ui.CloseUi(component.Map, StationMapUiKey.Key, uid);
  29. }
  30. private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
  31. {
  32. if (!_cell.TryUseActivatableCharge(uid))
  33. return;
  34. var comp = EnsureComp<StationMapUserComponent>(args.Actor);
  35. comp.Map = uid;
  36. }
  37. }