DisposalTaggerBoundUserInterface.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using JetBrains.Annotations;
  2. using Robust.Client.GameObjects;
  3. using Robust.Client.UserInterface;
  4. using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
  5. namespace Content.Client.Disposal.UI
  6. {
  7. /// <summary>
  8. /// Initializes a <see cref="DisposalTaggerWindow"/> and updates it when new server messages are received.
  9. /// </summary>
  10. [UsedImplicitly]
  11. public sealed class DisposalTaggerBoundUserInterface : BoundUserInterface
  12. {
  13. [ViewVariables]
  14. private DisposalTaggerWindow? _window;
  15. public DisposalTaggerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  16. {
  17. }
  18. protected override void Open()
  19. {
  20. base.Open();
  21. _window = this.CreateWindow<DisposalTaggerWindow>();
  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. // TODO: This looks copy-pasted with the other mailing stuff...
  28. SendMessage(new UiActionMessage(action, tag));
  29. Close();
  30. }
  31. protected override void UpdateState(BoundUserInterfaceState state)
  32. {
  33. base.UpdateState(state);
  34. if (state is not DisposalTaggerUserInterfaceState cast)
  35. {
  36. return;
  37. }
  38. _window?.UpdateState(cast);
  39. }
  40. }
  41. }