From f874459092d1a0914b3c6ea59a7127d5a9c92d3b Mon Sep 17 00:00:00 2001 From: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com> Date: Thu, 3 Jul 2025 09:00:34 -0700 Subject: [PATCH] Pressure Relief Valve (#36708) * initial system (this math is probably WRONG) * General code cleanup and OnExamined support (holy moly this code sucks) * UICode and related events foundation TODO: - Actually write the XAML UI and the underlying system - Un-shitcode the entire thing - Actually test everything... * Working UI code TODO: Make predicted, as this certainly isn't predicted. Even though I said it was. It isn't. * Remove one TODO for unshitcoding the examine code * Add reminder yea * Make predicted (defenitely isn't) (also defenitely isn't a copypaste from pressure pump code) * It's predicted! TODO: - Give it snazzy predicted visuals! - Have a different field for pressure entry, lest it gets bulldozed every UI update. * Improve gas pressure relief valve UI TODO: Reminder to reduce amount of dirties using deltafields * Implement DirtyField prediction * Entity cleanup A lot of Entity conversions and lukewarm cleanup. Also got caught copy pasting code in 4K UHD but it's not like you couldn't tell. * More cleanup and comments * Remove TODO comment on bulldozing window title * """refactoring""" - Move appearance out of shared and finally fix it. Pointless to predict appearance in this instance. - More Entity conversions because I like them. - Move UI creation handling over entirely to the ActivatableUI system. - Fix a hardcoded locale string (why????). * Add visuals * Revert debugging variable replacememt yea * Revert skissue * Remove unused using directives and remove TODO * Localize, cleanup, document * Fix adminlogging discrepancy * Add ability to construct, add guidebook entry * Clear up comment * Add guidebook tooltip to valve * Convert GasPressureReliefValveBoundUserInterface declaration into primary constructor * Adds more input handling and adds autofill on open * Un-deepfry input validator shitcode Genuinely what was I smoking * improve visuals logic * Refactor again - Update math to the correct implementation - Moved code that could be re-used in the future into a helper method under AtmosphereSystem.Gases.cs * I'm sorry but I hate warnings * Remove unused using directive in AtmosphereSystem.Gases.cs * Review and cleanup * Lukewarm UI glossup * Maintainer for the upstream project btw * Remove redundant state sets and messy logic * Unduplicate valve updater code * Redo UI (im sorry Slarti) * run tests * Test refactored UI messaging * Second round of UI improvements - God please find a way to improve this system. Feels bad. * Update loop implementation * Further predict UI * Clear up SetToCurrentThreshold * cleanup * Update to master + pipe layers and bug fixes want to run tests * fixes * Deploy rename pipebomb * Documentation and requested changes * Rename the method that wiggled away * Undo rounding changes * Fix comment * Rename and cleanup * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- .../GasPressureRegulatorSystem.cs | 31 +++ .../GasPressureRegulatorBoundUserInterface.cs | 58 +++++ .../Atmos/UI/GasPressureRegulatorWindow.xaml | 96 ++++++++ .../UI/GasPressureRegulatorWindow.xaml.cs | 129 ++++++++++ .../EntitySystems/AtmosphereSystem.Gases.cs | 122 ++++++++++ .../GasPressureRegulatorSystem.cs | 202 ++++++++++++++++ .../SharedGasPressureRegulatorSystem.cs | 70 ++++++ .../GasPressureRegulatorComponent.cs | 88 +++++++ .../SharedGasPressureRegulatorComponent.cs | 25 ++ .../Atmos/Piping/EnabledAtmosDeviceVisuals.cs | 6 + .../atmos/gas-pressure-regulator-system.ftl | 7 + .../gas-pressure-regulator-component.ftl | 19 ++ Resources/Locale/en-US/guidebook/guides.ftl | 1 + .../Structures/Piping/Atmospherics/binary.yml | 56 +++++ .../Prototypes/Guidebook/engineering.yml | 6 + .../Graphs/utilities/atmos_binary.yml | 22 ++ .../Recipes/Construction/utilities.yml | 11 + .../Guidebook/Engineering/GasManipulation.xml | 1 + .../Engineering/PressureRegulator.xml | 23 ++ .../Guidebook/Engineering/Valves.xml | 1 + .../Piping/Atmospherics/pump.rsi/meta.json | 223 +++++++++++++----- .../Atmospherics/pump.rsi/pumpPressure.png | Bin 5258 -> 1338 bytes .../pump.rsi/pumpPressureRegulator.png | Bin 0 -> 743 bytes .../pump.rsi/pumpPressureRegulatorOn.png | Bin 0 -> 742 bytes .../Atmospherics/pump_alt1.rsi/meta.json | 28 ++- .../pump_alt1.rsi/pumpPressure.png | Bin 1350 -> 1344 bytes .../pump_alt1.rsi/pumpPressureRegulator.png | Bin 0 -> 618 bytes .../pump_alt1.rsi/pumpPressureRegulatorOn.png | Bin 0 -> 618 bytes .../Atmospherics/pump_alt2.rsi/meta.json | 28 ++- .../pump_alt2.rsi/pumpPressure.png | Bin 1347 -> 1341 bytes .../pump_alt2.rsi/pumpPressureRegulator.png | Bin 0 -> 618 bytes .../pump_alt2.rsi/pumpPressureRegulatorOn.png | Bin 0 -> 618 bytes 32 files changed, 1173 insertions(+), 80 deletions(-) create mode 100644 Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs create mode 100644 Content.Client/Atmos/UI/GasPressureRegulatorBoundUserInterface.cs create mode 100644 Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml create mode 100644 Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml.cs create mode 100644 Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressureRegulatorSystem.cs create mode 100644 Content.Shared/Atmos/EntitySystems/SharedGasPressureRegulatorSystem.cs create mode 100644 Content.Shared/Atmos/Piping/Binary/Components/GasPressureRegulatorComponent.cs create mode 100644 Content.Shared/Atmos/Piping/Binary/Components/SharedGasPressureRegulatorComponent.cs create mode 100644 Resources/Locale/en-US/atmos/gas-pressure-regulator-system.ftl create mode 100644 Resources/Locale/en-US/components/gas-pressure-regulator-component.ftl create mode 100644 Resources/ServerInfo/Guidebook/Engineering/PressureRegulator.xml create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump.rsi/pumpPressureRegulator.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump.rsi/pumpPressureRegulatorOn.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump_alt1.rsi/pumpPressureRegulator.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump_alt1.rsi/pumpPressureRegulatorOn.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump_alt2.rsi/pumpPressureRegulator.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/pump_alt2.rsi/pumpPressureRegulatorOn.png diff --git a/Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs b/Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs new file mode 100644 index 0000000000..6f12297ff0 --- /dev/null +++ b/Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs @@ -0,0 +1,31 @@ +using Content.Shared.Atmos.EntitySystems; +using Content.Shared.Atmos.Piping.Binary.Components; + +namespace Content.Client.Atmos.EntitySystems; + +/// +/// Represents the client system responsible for managing and updating the gas pressure regulator interface. +/// Inherits from the shared system . +/// +public sealed partial class GasPressureRegulatorSystem : SharedGasPressureRegulatorSystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnValveUpdate); + } + + private void OnValveUpdate(Entity ent, ref AfterAutoHandleStateEvent args) + { + UpdateUi(ent); + } + + protected override void UpdateUi(Entity ent) + { + if (UserInterfaceSystem.TryGetOpenUi(ent.Owner, GasPressureRegulatorUiKey.Key, out var bui)) + { + bui.Update(); + } + } +} diff --git a/Content.Client/Atmos/UI/GasPressureRegulatorBoundUserInterface.cs b/Content.Client/Atmos/UI/GasPressureRegulatorBoundUserInterface.cs new file mode 100644 index 0000000000..9d66a9985f --- /dev/null +++ b/Content.Client/Atmos/UI/GasPressureRegulatorBoundUserInterface.cs @@ -0,0 +1,58 @@ +using Content.Shared.Atmos.Piping.Binary.Components; +using Content.Shared.IdentityManagement; +using Content.Shared.Localizations; +using Robust.Client.UserInterface; + +namespace Content.Client.Atmos.UI; + +public sealed class GasPressureRegulatorBoundUserInterface(EntityUid owner, Enum uiKey) + : BoundUserInterface(owner, uiKey) +{ + private GasPressureRegulatorWindow? _window; + + protected override void Open() + { + base.Open(); + + _window = this.CreateWindow(); + + _window.SetEntity(Owner); + + _window.ThresholdPressureChanged += OnThresholdChanged; + + if (EntMan.TryGetComponent(Owner, out GasPressureRegulatorComponent? comp)) + _window.SetThresholdPressureInput(comp.Threshold); + + Update(); + } + + public override void Update() + { + if (_window == null) + return; + + _window.Title = Identity.Name(Owner, EntMan); + + if (!EntMan.TryGetComponent(Owner, out GasPressureRegulatorComponent? comp)) + return; + + _window.SetThresholdPressureLabel(comp.Threshold); + _window.UpdateInfo(comp.InletPressure, comp.OutletPressure, comp.FlowRate); + } + + private void OnThresholdChanged(string newThreshold) + { + var sentThreshold = 0f; + + if (UserInputParser.TryFloat(newThreshold, out var parsedNewThreshold) && parsedNewThreshold >= 0 && + !float.IsInfinity(parsedNewThreshold)) + { + sentThreshold = parsedNewThreshold; + } + + // Autofill to zero if the user inputs an invalid value. + _window?.SetThresholdPressureInput(sentThreshold); + + SendPredictedMessage(new GasPressureRegulatorChangeThresholdMessage(sentThreshold)); + } +} diff --git a/Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml b/Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml new file mode 100644 index 0000000000..b6a55f769e --- /dev/null +++ b/Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +