1
0

RadarConsoleSystem.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Numerics;
  2. using Content.Server.UserInterface;
  3. using Content.Shared.Shuttles.BUIStates;
  4. using Content.Shared.Shuttles.Components;
  5. using Content.Shared.Shuttles.Systems;
  6. using Content.Shared.PowerCell;
  7. using Content.Shared.Movement.Components;
  8. using Robust.Server.GameObjects;
  9. using Robust.Shared.Map;
  10. namespace Content.Server.Shuttles.Systems;
  11. public sealed class RadarConsoleSystem : SharedRadarConsoleSystem
  12. {
  13. [Dependency] private readonly ShuttleConsoleSystem _console = default!;
  14. [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<RadarConsoleComponent, ComponentStartup>(OnRadarStartup);
  19. }
  20. private void OnRadarStartup(EntityUid uid, RadarConsoleComponent component, ComponentStartup args)
  21. {
  22. UpdateState(uid, component);
  23. }
  24. protected override void UpdateState(EntityUid uid, RadarConsoleComponent component)
  25. {
  26. var xform = Transform(uid);
  27. var onGrid = xform.ParentUid == xform.GridUid;
  28. EntityCoordinates? coordinates = onGrid ? xform.Coordinates : null;
  29. Angle? angle = onGrid ? xform.LocalRotation : null;
  30. if (component.FollowEntity)
  31. {
  32. coordinates = new EntityCoordinates(uid, Vector2.Zero);
  33. angle = Angle.Zero;
  34. }
  35. if (_uiSystem.HasUi(uid, RadarConsoleUiKey.Key))
  36. {
  37. NavInterfaceState state;
  38. var docks = _console.GetAllDocks();
  39. if (coordinates != null && angle != null)
  40. {
  41. state = _console.GetNavState(uid, docks, coordinates.Value, angle.Value);
  42. }
  43. else
  44. {
  45. state = _console.GetNavState(uid, docks);
  46. }
  47. state.RotateWithEntity = !component.FollowEntity;
  48. _uiSystem.SetUiState(uid, RadarConsoleUiKey.Key, new NavBoundUserInterfaceState(state));
  49. }
  50. }
  51. }