diff --git a/Content.Client/Actions/ActionsSystem.cs b/Content.Client/Actions/ActionsSystem.cs index 7b13233bab5..b594817701e 100644 --- a/Content.Client/Actions/ActionsSystem.cs +++ b/Content.Client/Actions/ActionsSystem.cs @@ -258,13 +258,13 @@ public void UnlinkAllActions() public void LinkAllActions(ActionsComponent? actions = null) { - if (_playerManager.LocalEntity is not { } user || - !Resolve(user, ref actions, false)) - { - return; - } + if (_playerManager.LocalEntity is not { } user || + !Resolve(user, ref actions, false)) + { + return; + } - LinkActions?.Invoke(actions); + LinkActions?.Invoke(actions); } public override void Shutdown() diff --git a/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs b/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs new file mode 100644 index 00000000000..54e16bc8621 --- /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 220fdbe875c..0c07eec4025 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 const float MaxPressure = Atmospherics.MaxOutputPressure; + + [ViewVariables] + private GasPressurePumpWindow? _window; - [ViewVariables] - private GasPressurePumpWindow? _window; + public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } - public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) - { - } + protected override void Open() + { + base.Open(); - protected override void Open() - { - base.Open(); + _window = this.CreateWindow(); - _window = this.CreateWindow(); + _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; + _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; + Update(); + } - _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; - _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; - } + public void Update() + { + if (_window == null) + return; - private void OnToggleStatusButtonPressed() - { - if (_window is null) return; - SendMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); - } + _window.Title = Identity.Name(Owner, EntMan); - private void OnPumpOutputPressurePressed(string value) - { - var pressure = UserInputParser.TryFloat(value, out var parsed) ? parsed : 0f; - if (pressure > MaxPressure) pressure = MaxPressure; + if (!EntMan.TryGetComponent(Owner, out GasPressurePumpComponent? pump)) + return; - SendMessage(new GasPressurePumpChangeOutputPressureMessage(pressure)); - } + _window.SetPumpStatus(pump.Enabled); + _window.MaxPressure = pump.MaxTargetPressure; + _window.SetOutputPressure(pump.TargetPressure); + } - /// - /// 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; + private void OnToggleStatusButtonPressed() + { + if (_window is null) return; + SendPredictedMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); + } - _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 a0896a7b41e..f2c2c7cec50 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"> -