HolopadBoundUserInterface.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using Content.Shared.Holopad;
  2. using Content.Shared.Silicons.StationAi;
  3. using Robust.Client.Graphics;
  4. using Robust.Client.UserInterface;
  5. using Robust.Shared.Player;
  6. using System.Numerics;
  7. namespace Content.Client.Holopad;
  8. public sealed class HolopadBoundUserInterface : BoundUserInterface
  9. {
  10. [Dependency] private readonly ISharedPlayerManager _playerManager = default!;
  11. [Dependency] private readonly IClyde _displayManager = default!;
  12. [ViewVariables]
  13. private HolopadWindow? _window;
  14. public HolopadBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  15. {
  16. IoCManager.InjectDependencies(this);
  17. }
  18. protected override void Open()
  19. {
  20. base.Open();
  21. _window = this.CreateWindow<HolopadWindow>();
  22. _window.Title = Loc.GetString("holopad-window-title", ("title", EntMan.GetComponent<MetaDataComponent>(Owner).EntityName));
  23. if (this.UiKey is not HolopadUiKey)
  24. {
  25. Close();
  26. return;
  27. }
  28. var uiKey = (HolopadUiKey)this.UiKey;
  29. // AIs will see a different holopad interface to crew when interacting with them in the world
  30. if (uiKey == HolopadUiKey.InteractionWindow && EntMan.HasComponent<StationAiHeldComponent>(_playerManager.LocalEntity))
  31. uiKey = HolopadUiKey.InteractionWindowForAi;
  32. _window.SetState(Owner, uiKey);
  33. _window.UpdateState(new Dictionary<NetEntity, string>());
  34. // Set message actions
  35. _window.SendHolopadStartNewCallMessageAction += SendHolopadStartNewCallMessage;
  36. _window.SendHolopadAnswerCallMessageAction += SendHolopadAnswerCallMessage;
  37. _window.SendHolopadEndCallMessageAction += SendHolopadEndCallMessage;
  38. _window.SendHolopadStartBroadcastMessageAction += SendHolopadStartBroadcastMessage;
  39. _window.SendHolopadActivateProjectorMessageAction += SendHolopadActivateProjectorMessage;
  40. _window.SendHolopadRequestStationAiMessageAction += SendHolopadRequestStationAiMessage;
  41. // If this call is addressed to an AI, open the window in the bottom right hand corner of the screen
  42. if (uiKey == HolopadUiKey.AiRequestWindow)
  43. _window.OpenCenteredAt(new Vector2(1f, 1f));
  44. // Otherwise offset to the left so the holopad can still be seen
  45. else
  46. _window.OpenCenteredAt(new Vector2(0.3333f, 0.50f));
  47. }
  48. protected override void UpdateState(BoundUserInterfaceState state)
  49. {
  50. base.UpdateState(state);
  51. var castState = (HolopadBoundInterfaceState)state;
  52. EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
  53. _window?.UpdateState(castState.Holopads);
  54. }
  55. public void SendHolopadStartNewCallMessage(NetEntity receiver)
  56. {
  57. SendMessage(new HolopadStartNewCallMessage(receiver));
  58. }
  59. public void SendHolopadAnswerCallMessage()
  60. {
  61. SendMessage(new HolopadAnswerCallMessage());
  62. }
  63. public void SendHolopadEndCallMessage()
  64. {
  65. SendMessage(new HolopadEndCallMessage());
  66. }
  67. public void SendHolopadStartBroadcastMessage()
  68. {
  69. SendMessage(new HolopadStartBroadcastMessage());
  70. }
  71. public void SendHolopadActivateProjectorMessage()
  72. {
  73. SendMessage(new HolopadActivateProjectorMessage());
  74. }
  75. public void SendHolopadRequestStationAiMessage()
  76. {
  77. SendMessage(new HolopadStationAiRequestMessage());
  78. }
  79. }