1
0

RCDMenuBoundUserInterface.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Shared.RCD;
  2. using Content.Shared.RCD.Components;
  3. using JetBrains.Annotations;
  4. using Robust.Client.Graphics;
  5. using Robust.Client.Input;
  6. using Robust.Client.UserInterface;
  7. using Robust.Shared.Prototypes;
  8. namespace Content.Client.RCD;
  9. [UsedImplicitly]
  10. public sealed class RCDMenuBoundUserInterface : BoundUserInterface
  11. {
  12. [Dependency] private readonly IClyde _displayManager = default!;
  13. [Dependency] private readonly IInputManager _inputManager = default!;
  14. private RCDMenu? _menu;
  15. public RCDMenuBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  16. {
  17. IoCManager.InjectDependencies(this);
  18. }
  19. protected override void Open()
  20. {
  21. base.Open();
  22. _menu = this.CreateWindow<RCDMenu>();
  23. _menu.SetEntity(Owner);
  24. _menu.SendRCDSystemMessageAction += SendRCDSystemMessage;
  25. // Open the menu, centered on the mouse
  26. var vpSize = _displayManager.ScreenSize;
  27. _menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / vpSize);
  28. }
  29. public void SendRCDSystemMessage(ProtoId<RCDPrototype> protoId)
  30. {
  31. // A predicted message cannot be used here as the RCD UI is closed immediately
  32. // after this message is sent, which will stop the server from receiving it
  33. SendMessage(new RCDSystemMessage(protoId));
  34. }
  35. }