From c06f52a4564bfc9cb15e875eb370d20fa2f8cdc3 Mon Sep 17 00:00:00 2001 From: ike709 Date: Thu, 11 Nov 2021 16:10:21 -0600 Subject: [PATCH] Adds a UI for gas mixers (#5165) Co-authored-by: E F R <602406+Efruit@users.noreply.github.com> Co-authored-by: Paul Ritter Co-authored-by: ike709 --- .../Atmos/UI/GasMixerBoundUserInteface.cs | 91 +++++++++++++++++ Content.Client/Atmos/UI/GasMixerWindow.xaml | 38 ++++++++ .../Atmos/UI/GasMixerWindow.xaml.cs | 97 +++++++++++++++++++ .../EntitySystems/GasPressurePumpSystem.cs | 12 ++- .../EntitySystems/GasVolumePumpSystem.cs | 12 ++- .../Trinary/EntitySystems/GasFilterSystem.cs | 13 ++- .../Trinary/EntitySystems/GasMixerSystem.cs | 60 ++++++++++++ .../Components/SharedGasMixerComponent.cs | 63 ++++++++++++ .../en-US/components/gas-filter-component.ftl | 2 + .../en-US/components/gas-mixer-component.ftl | 13 +++ .../en-US/components/gas-pump-component.ftl | 2 + .../Piping/Atmospherics/trinary.yml | 4 + 12 files changed, 401 insertions(+), 6 deletions(-) create mode 100644 Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs create mode 100644 Content.Client/Atmos/UI/GasMixerWindow.xaml create mode 100644 Content.Client/Atmos/UI/GasMixerWindow.xaml.cs create mode 100644 Content.Shared/Atmos/Piping/Trinary/Components/SharedGasMixerComponent.cs create mode 100644 Resources/Locale/en-US/components/gas-mixer-component.ftl diff --git a/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs b/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs new file mode 100644 index 0000000000..5be7a367f7 --- /dev/null +++ b/Content.Client/Atmos/UI/GasMixerBoundUserInteface.cs @@ -0,0 +1,91 @@ +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 GasMixerBoundUserInterface : BoundUserInterface + { + + private GasMixerWindow? _window; + private const float MaxPressure = Atmospherics.MaxOutputPressure; + + public GasMixerBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + _window = new GasMixerWindow(); + + if(State != null) + UpdateState(State); + + _window.OpenCentered(); + + _window.OnClose += Close; + + _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; + _window.MixerOutputPressureChanged += OnMixerOutputPressurePressed; + _window.MixerNodePercentageChanged += OnMixerSetPercentagePressed; + } + + private void OnToggleStatusButtonPressed() + { + if (_window is null) return; + SendMessage(new GasMixerToggleStatusMessage(_window.MixerStatus)); + } + + private void OnMixerOutputPressurePressed(string value) + { + float pressure = float.TryParse(value, out var parsed) ? parsed : 0f; + if (pressure > MaxPressure) pressure = MaxPressure; + + SendMessage(new GasMixerChangeOutputPressureMessage(pressure)); + } + + private void OnMixerSetPercentagePressed(string value) + { + // We don't need to send both nodes because it's just 1.0f - node + float node = float.TryParse(value, out var parsed) ? parsed : 1.0f; + + if(_window is not null) node = _window.NodeOneLastEdited ? node : 1.0f - node; + + SendMessage(new GasMixerChangeNodePercentageMessage(node)); + } + + /// + /// Update the UI state based on server-sent info + /// + /// + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not GasMixerBoundUserInterfaceState cast) + return; + + _window.Title = (cast.MixerLabel); + _window.SetMixerStatus(cast.Enabled); + _window.SetOutputPressure(cast.OutputPressure); + _window.SetNodePercentages(cast.NodeOne); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) return; + _window?.Dispose(); + } + } +} diff --git a/Content.Client/Atmos/UI/GasMixerWindow.xaml b/Content.Client/Atmos/UI/GasMixerWindow.xaml new file mode 100644 index 0000000000..9d69d9bf4c --- /dev/null +++ b/Content.Client/Atmos/UI/GasMixerWindow.xaml @@ -0,0 +1,38 @@ + + + +