DisposalRouterBoundUserInterface.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using JetBrains.Annotations;
  2. using Robust.Client.GameObjects;
  3. using Robust.Client.UserInterface;
  4. using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
  5. namespace Content.Client.Disposal.UI
  6. {
  7. /// <summary>
  8. /// Initializes a <see cref="DisposalRouterWindow"/> and updates it when new server messages are received.
  9. /// </summary>
  10. [UsedImplicitly]
  11. public sealed class DisposalRouterBoundUserInterface : BoundUserInterface
  12. {
  13. [ViewVariables]
  14. private DisposalRouterWindow? _window;
  15. public DisposalRouterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  16. {
  17. }
  18. protected override void Open()
  19. {
  20. base.Open();
  21. _window = this.CreateWindow<DisposalRouterWindow>();
  22. _window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
  23. _window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
  24. }
  25. private void ButtonPressed(UiAction action, string tag)
  26. {
  27. SendMessage(new UiActionMessage(action, tag));
  28. Close();
  29. }
  30. protected override void UpdateState(BoundUserInterfaceState state)
  31. {
  32. base.UpdateState(state);
  33. if (state is not DisposalRouterUserInterfaceState cast)
  34. {
  35. return;
  36. }
  37. _window?.UpdateState(cast);
  38. }
  39. }
  40. }