From 9365e3a99bad75f7426fcc07fa6f406ba23e9620 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:39:52 +1100 Subject: [PATCH] Predicted gas pumps (#33717) * Predicted gas pumps I wanted to try out atmos and first thing I found. * a * Remove details range --- .../EntitySystems/GasPressurePumpSystem.cs | 23 +++ .../UI/GasPressurePumpBoundUserInterface.cs | 90 +++++---- .../Atmos/UI/GasPressurePumpWindow.xaml | 22 +-- .../Atmos/UI/GasPressurePumpWindow.xaml.cs | 35 ++-- .../Monitor/Systems/AtmosMonitoringSystem.cs | 1 + .../Components/GasPressurePumpComponent.cs | 31 --- .../EntitySystems/GasPressurePumpSystem.cs | 180 ++++-------------- .../Binary/EntitySystems/GasRecyclerSystem.cs | 1 + .../EntitySystems/GasVolumePumpSystem.cs | 1 + .../Piping/Components/AtmosDeviceComponent.cs | 12 -- .../Piping/EntitySystems/AtmosDeviceSystem.cs | 1 + .../Trinary/EntitySystems/GasFilterSystem.cs | 1 + .../Trinary/EntitySystems/GasMixerSystem.cs | 1 + .../PressureControlledValveSystem.cs | 1 + .../Unary/EntitySystems/GasVentPumpSystem.cs | 1 + .../EntitySystems/GasVentScrubberSystem.cs | 1 + .../Components/GasPressurePumpComponent.cs | 25 +++ .../SharedGasPressurePumpSystem.cs | 97 ++++++++++ .../SharedGasPressurePumpComponent.cs | 60 ++---- .../Components/AtmosDeviceDisabledEvent.cs | 7 + .../Components/AtmosDeviceEnabledEvent.cs | 7 + .../ActivatableUIRequiresAnchorComponent.cs | 13 ++ .../ActivatableUIRequiresAnchorSystem.cs | 41 ++++ .../en-US/components/gas-pump-component.ftl | 2 - Resources/Locale/en-US/ui/general.ftl | 2 + .../Structures/Piping/Atmospherics/binary.yml | 7 +- 26 files changed, 355 insertions(+), 308 deletions(-) create mode 100644 Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs delete mode 100644 Content.Server/Atmos/Piping/Binary/Components/GasPressurePumpComponent.cs create mode 100644 Content.Shared/Atmos/Components/GasPressurePumpComponent.cs create mode 100644 Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs create mode 100644 Content.Shared/Atmos/Piping/Components/AtmosDeviceDisabledEvent.cs create mode 100644 Content.Shared/Atmos/Piping/Components/AtmosDeviceEnabledEvent.cs create mode 100644 Content.Shared/UserInterface/ActivatableUIRequiresAnchorComponent.cs create mode 100644 Content.Shared/UserInterface/ActivatableUIRequiresAnchorSystem.cs diff --git a/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs b/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs new file mode 100644 index 0000000000..54e16bc862 --- /dev/null +++ b/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs @@ -0,0 +1,23 @@ +using Content.Client.Atmos.UI; +using Content.Shared.Atmos.Components; +using Content.Shared.Atmos.EntitySystems; +using Content.Shared.Atmos.Piping.Binary.Components; + +namespace Content.Client.Atmos.EntitySystems; + +public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem +{ + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnPumpUpdate); + } + + private void OnPumpUpdate(Entity ent, ref AfterAutoHandleStateEvent args) + { + if (UserInterfaceSystem.TryGetOpenUi(ent.Owner, GasPressurePumpUiKey.Key, out var bui)) + { + bui.Update(); + } + } +} diff --git a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs index 220fdbe875..0c07eec402 100644 --- a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs @@ -1,65 +1,63 @@ using Content.Shared.Atmos; +using Content.Shared.Atmos.Components; using Content.Shared.Atmos.Piping.Binary.Components; +using Content.Shared.IdentityManagement; using Content.Shared.Localizations; using JetBrains.Annotations; -using Robust.Client.GameObjects; using Robust.Client.UserInterface; -namespace Content.Client.Atmos.UI +namespace Content.Client.Atmos.UI; + +/// +/// Initializes a and updates it when new server messages are received. +/// +[UsedImplicitly] +public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface { - /// - /// Initializes a and updates it when new server messages are received. - /// - [UsedImplicitly] - public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface + [ViewVariables] + private const float MaxPressure = Atmospherics.MaxOutputPressure; + + [ViewVariables] + private GasPressurePumpWindow? _window; + + public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { - [ViewVariables] - private const float MaxPressure = Atmospherics.MaxOutputPressure; + } - [ViewVariables] - private GasPressurePumpWindow? _window; + protected override void Open() + { + base.Open(); - public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) - { - } + _window = this.CreateWindow(); - protected override void Open() - { - base.Open(); + _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; + _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; + Update(); + } - _window = this.CreateWindow(); + public void Update() + { + if (_window == null) + return; - _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; - _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; - } + _window.Title = Identity.Name(Owner, EntMan); - private void OnToggleStatusButtonPressed() - { - if (_window is null) return; - SendMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); - } + if (!EntMan.TryGetComponent(Owner, out GasPressurePumpComponent? pump)) + return; - private void OnPumpOutputPressurePressed(string value) - { - var pressure = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f; - if (pressure > MaxPressure) pressure = MaxPressure; + _window.SetPumpStatus(pump.Enabled); + _window.MaxPressure = pump.MaxTargetPressure; + _window.SetOutputPressure(pump.TargetPressure); + } - SendMessage(new GasPressurePumpChangeOutputPressureMessage(pressure)); - } + private void OnToggleStatusButtonPressed() + { + if (_window is null) return; + SendPredictedMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); + } - /// - /// 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); - } + private void OnPumpOutputPressurePressed(float value) + { + SendPredictedMessage(new GasPressurePumpChangeOutputPressureMessage(value)); } } diff --git a/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml index a0896a7b41..f2c2c7cec5 100644 --- a/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml +++ b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml @@ -1,22 +1,18 @@ - + xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" + SetSize="340 110" MinSize="340 110" Title="Pressure Pump"> -