1
0

SurveillanceCameraSetupBoundUi.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Content.Shared.SurveillanceCamera;
  2. using Robust.Client.GameObjects;
  3. namespace Content.Client.SurveillanceCamera.UI;
  4. public sealed class SurveillanceCameraSetupBoundUi : BoundUserInterface
  5. {
  6. [ViewVariables]
  7. private readonly SurveillanceCameraSetupUiKey _type;
  8. [ViewVariables]
  9. private SurveillanceCameraSetupWindow? _window;
  10. public SurveillanceCameraSetupBoundUi(EntityUid component, Enum uiKey) : base(component, uiKey)
  11. {
  12. if (uiKey is not SurveillanceCameraSetupUiKey key)
  13. return;
  14. _type = key;
  15. }
  16. protected override void Open()
  17. {
  18. base.Open();
  19. _window = new();
  20. if (_type == SurveillanceCameraSetupUiKey.Router)
  21. {
  22. _window.HideNameSelector();
  23. }
  24. _window.OpenCentered();
  25. _window.OnNameConfirm += SendDeviceName;
  26. _window.OnNetworkConfirm += SendSelectedNetwork;
  27. _window.OnClose += Close;
  28. }
  29. private void SendSelectedNetwork(int idx)
  30. {
  31. SendMessage(new SurveillanceCameraSetupSetNetwork(idx));
  32. }
  33. private void SendDeviceName(string name)
  34. {
  35. SendMessage(new SurveillanceCameraSetupSetName(name));
  36. }
  37. protected override void UpdateState(BoundUserInterfaceState state)
  38. {
  39. base.UpdateState(state);
  40. if (_window == null || state is not SurveillanceCameraSetupBoundUiState cast)
  41. {
  42. return;
  43. }
  44. _window.UpdateState(cast.Name, cast.NameDisabled, cast.NetworkDisabled);
  45. _window.LoadAvailableNetworks(cast.Network, cast.Networks);
  46. }
  47. protected override void Dispose(bool disposing)
  48. {
  49. base.Dispose(disposing);
  50. if (disposing)
  51. {
  52. _window?.Dispose();
  53. _window = null;
  54. }
  55. }
  56. }