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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +