GasPressurePumpBoundUserInterface.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Shared.Atmos;
  2. using Content.Shared.Atmos.Components;
  3. using Content.Shared.Atmos.Piping.Binary.Components;
  4. using Content.Shared.IdentityManagement;
  5. using Content.Shared.Localizations;
  6. using JetBrains.Annotations;
  7. using Robust.Client.UserInterface;
  8. namespace Content.Client.Atmos.UI;
  9. /// <summary>
  10. /// Initializes a <see cref="GasPressurePumpWindow"/> and updates it when new server messages are received.
  11. /// </summary>
  12. [UsedImplicitly]
  13. public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface
  14. {
  15. [ViewVariables]
  16. private const float MaxPressure = Atmospherics.MaxOutputPressure;
  17. [ViewVariables]
  18. private GasPressurePumpWindow? _window;
  19. public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
  20. {
  21. }
  22. protected override void Open()
  23. {
  24. base.Open();
  25. _window = this.CreateWindow<GasPressurePumpWindow>();
  26. _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
  27. _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed;
  28. Update();
  29. }
  30. public void Update()
  31. {
  32. if (_window == null)
  33. return;
  34. _window.Title = Identity.Name(Owner, EntMan);
  35. if (!EntMan.TryGetComponent(Owner, out GasPressurePumpComponent? pump))
  36. return;
  37. _window.SetPumpStatus(pump.Enabled);
  38. _window.MaxPressure = pump.MaxTargetPressure;
  39. _window.SetOutputPressure(pump.TargetPressure);
  40. }
  41. private void OnToggleStatusButtonPressed()
  42. {
  43. if (_window is null) return;
  44. SendPredictedMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus));
  45. }
  46. private void OnPumpOutputPressurePressed(float value)
  47. {
  48. SendPredictedMessage(new GasPressurePumpChangeOutputPressureMessage(value));
  49. }
  50. }