From 17e1b7827edc7ff6768aad8a03e5f7f5f50abecd Mon Sep 17 00:00:00 2001 From: ike709 Date: Thu, 4 Nov 2021 19:41:56 -0500 Subject: [PATCH] Adds UIs for volume and pressure pumps (#5155) * Adds UIs for volume and pressure pumps * Update Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs * Update Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs Co-authored-by: ike709 --- .../UI/GasPressurePumpBoundUserInterface.cs | 79 +++++++++++++++++++ .../Atmos/UI/GasPressurePumpWindow.xaml | 23 ++++++ .../Atmos/UI/GasPressurePumpWindow.xaml.cs | 65 +++++++++++++++ .../UI/GasVolumePumpBoundUserInterface.cs | 76 ++++++++++++++++++ .../Atmos/UI/GasVolumePumpWindow.xaml | 23 ++++++ .../Atmos/UI/GasVolumePumpWindow.xaml.cs | 65 +++++++++++++++ .../EntitySystems/GasPressurePumpSystem.cs | 42 ++++++++++ .../EntitySystems/GasVolumePumpSystem.cs | 43 ++++++++++ .../SharedGasPressurePumpComponent.cs | 49 ++++++++++++ .../SharedGasVolumePumpComponent.cs | 49 ++++++++++++ .../en-US/components/gas-pump-component.ftl | 10 +++ .../Structures/Piping/Atmospherics/binary.yml | 8 ++ 12 files changed, 532 insertions(+) create mode 100644 Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs create mode 100644 Content.Client/Atmos/UI/GasPressurePumpWindow.xaml create mode 100644 Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs create mode 100644 Content.Client/Atmos/UI/GasVolumePumpBoundUserInterface.cs create mode 100644 Content.Client/Atmos/UI/GasVolumePumpWindow.xaml create mode 100644 Content.Client/Atmos/UI/GasVolumePumpWindow.xaml.cs create mode 100644 Content.Shared/Atmos/Piping/Binary/Components/SharedGasPressurePumpComponent.cs create mode 100644 Content.Shared/Atmos/Piping/Binary/Components/SharedGasVolumePumpComponent.cs create mode 100644 Resources/Locale/en-US/components/gas-pump-component.ftl diff --git a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs new file mode 100644 index 0000000000..95b305a99d --- /dev/null +++ b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs @@ -0,0 +1,79 @@ +using System; +using Content.Client.Atmos.EntitySystems; +using Content.Shared.Atmos; +using Content.Shared.Atmos.Piping.Binary.Components; +using Content.Shared.Atmos.Piping.Trinary.Components; +using JetBrains.Annotations; +using Robust.Client.GameObjects; +using Robust.Shared.GameObjects; + +namespace Content.Client.Atmos.UI +{ + /// + /// Initializes a and updates it when new server messages are received. + /// + [UsedImplicitly] + public class GasPressurePumpBoundUserInterface : BoundUserInterface + { + + private GasPressurePumpWindow? _window; + private const float MaxPressure = Atmospherics.MaxOutputPressure; + + public GasPressurePumpBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + _window = new GasPressurePumpWindow(); + + if(State != null) + UpdateState(State); + + _window.OpenCentered(); + + _window.OnClose += Close; + + _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; + _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; + } + + private void OnToggleStatusButtonPressed() + { + if (_window is null) return; + SendMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); + } + + private void OnPumpOutputPressurePressed(string value) + { + float pressure = float.TryParse(value, out var parsed) ? parsed : 0f; + if (pressure > MaxPressure) pressure = MaxPressure; + + SendMessage(new GasPressurePumpChangeOutputPressureMessage(pressure)); + } + + /// + /// Update the UI state based on server-sent info + /// + /// + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not GasPressurePumpBoundUserInterfaceState cast) + return; + + _window.Title = (cast.PumpLabel); + _window.SetPumpStatus(cast.Enabled); + _window.SetOutputPressure(cast.OutputPressure); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) return; + _window?.Dispose(); + } + } +} diff --git a/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml new file mode 100644 index 0000000000..94520a584d --- /dev/null +++ b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml @@ -0,0 +1,23 @@ + + + +