diff --git a/Content.Client/Anomaly/Effects/ClientInnerBodySystem.cs b/Content.Client/Anomaly/Effects/ClientInnerBodySystem.cs index 15ebc8a993d..8d7292d468b 100644 --- a/Content.Client/Anomaly/Effects/ClientInnerBodySystem.cs +++ b/Content.Client/Anomaly/Effects/ClientInnerBodySystem.cs @@ -45,7 +45,7 @@ private void OnCompShutdown(Entity ent, ref Component if (!TryComp(ent, out var sprite)) return; - var index = _sprite.LayerMapGet((ent.Owner, sprite), ent.Comp.LayerMap); - _sprite.LayerSetVisible((ent.Owner, sprite), index, false); + if (sprite.LayerMapTryGet(ent.Comp.LayerMap, out var index)) // imp. added this check to prevent errors on anomalites - not having it was bad code on upstream's part + sprite.LayerSetVisible(index, false); } } diff --git a/Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs b/Content.Client/Atmos/EntitySystems/GasPressureRegulatorSystem.cs new file mode 100644 index 00000000000..6f12297ff02 --- /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 00000000000..9d66a9985f9 --- /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 00000000000..b6a55f769e5 --- /dev/null +++ b/Content.Client/Atmos/UI/GasPressureRegulatorWindow.xaml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +