diff --git a/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs b/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs index 54e16bc862..74a8166962 100644 --- a/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs +++ b/Content.Client/Atmos/EntitySystems/GasPressurePumpSystem.cs @@ -1,4 +1,3 @@ -using Content.Client.Atmos.UI; using Content.Shared.Atmos.Components; using Content.Shared.Atmos.EntitySystems; using Content.Shared.Atmos.Piping.Binary.Components; @@ -15,7 +14,12 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem private void OnPumpUpdate(Entity ent, ref AfterAutoHandleStateEvent args) { - if (UserInterfaceSystem.TryGetOpenUi(ent.Owner, GasPressurePumpUiKey.Key, out var bui)) + UpdateUi(ent); + } + + protected override void UpdateUi(Entity ent) + { + 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 0c07eec402..a80959b7b4 100644 --- a/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasPressurePumpBoundUserInterface.cs @@ -12,7 +12,7 @@ namespace Content.Client.Atmos.UI; /// Initializes a and updates it when new server messages are received. /// [UsedImplicitly] -public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface +public sealed class GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey) { [ViewVariables] private const float MaxPressure = Atmospherics.MaxOutputPressure; @@ -20,10 +20,6 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface [ViewVariables] private GasPressurePumpWindow? _window; - public GasPressurePumpBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) - { - } - protected override void Open() { base.Open(); @@ -35,7 +31,7 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface Update(); } - public void Update() + public override void Update() { if (_window == null) return; @@ -52,7 +48,9 @@ public sealed class GasPressurePumpBoundUserInterface : BoundUserInterface private void OnToggleStatusButtonPressed() { - if (_window is null) return; + if (_window is null) + return; + SendPredictedMessage(new GasPressurePumpToggleStatusMessage(_window.PumpStatus)); } diff --git a/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs index aa86a1aa03..56c07e7fac 100644 --- a/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs +++ b/Content.Client/Atmos/UI/GasPressurePumpWindow.xaml.cs @@ -1,7 +1,6 @@ using Content.Client.UserInterface.Controls; using Content.Shared.Atmos; using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; namespace Content.Client.Atmos.UI diff --git a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs index 5f0092f377..63944cd530 100644 --- a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs +++ b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasPressurePumpSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Atmos.Piping.Components; using Content.Server.NodeContainer.EntitySystems; using Content.Server.NodeContainer.Nodes; using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; using Content.Shared.Atmos; using Content.Shared.Atmos.Components; using Content.Shared.Atmos.EntitySystems; @@ -17,6 +18,7 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!; [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; + [Dependency] private readonly PowerReceiverSystem _power = default!; public override void Initialize() { @@ -25,33 +27,33 @@ public sealed class GasPressurePumpSystem : SharedGasPressurePumpSystem SubscribeLocalEvent(OnPumpUpdated); } - private void OnPumpUpdated(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceUpdateEvent args) + private void OnPumpUpdated(Entity ent, ref AtmosDeviceUpdateEvent args) { - if (!pump.Enabled - || (TryComp(uid, out var power) && !power.Powered) - || !_nodeContainer.TryGetNodes(uid, pump.InletName, pump.OutletName, out PipeNode? inlet, out PipeNode? outlet)) + if (!ent.Comp.Enabled + || !_power.IsPowered(ent) + || !_nodeContainer.TryGetNodes(ent.Owner, ent.Comp.InletName, ent.Comp.OutletName, out PipeNode? inlet, out PipeNode? outlet)) { - _ambientSoundSystem.SetAmbience(uid, false); + _ambientSoundSystem.SetAmbience(ent, false); return; } var outputStartingPressure = outlet.Air.Pressure; - if (outputStartingPressure >= pump.TargetPressure) + if (outputStartingPressure >= ent.Comp.TargetPressure) { - _ambientSoundSystem.SetAmbience(uid, false); + _ambientSoundSystem.SetAmbience(ent, false); return; // No need to pump gas if target has been reached. } if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0) { // We calculate the necessary moles to transfer using our good ol' friend PV=nRT. - var pressureDelta = pump.TargetPressure - outputStartingPressure; + var pressureDelta = ent.Comp.TargetPressure - outputStartingPressure; var transferMoles = (pressureDelta * outlet.Air.Volume) / (inlet.Air.Temperature * Atmospherics.R); var removed = inlet.Air.Remove(transferMoles); _atmosphereSystem.Merge(outlet.Air, removed); - _ambientSoundSystem.SetAmbience(uid, removed.TotalMoles > 0f); + _ambientSoundSystem.SetAmbience(ent, removed.TotalMoles > 0f); } } } diff --git a/Content.Shared/Atmos/Components/GasPressurePumpComponent.cs b/Content.Shared/Atmos/Components/GasPressurePumpComponent.cs index 850a2a7a29..f0ffad0b0e 100644 --- a/Content.Shared/Atmos/Components/GasPressurePumpComponent.cs +++ b/Content.Shared/Atmos/Components/GasPressurePumpComponent.cs @@ -3,7 +3,7 @@ using Robust.Shared.GameStates; namespace Content.Shared.Atmos.Components; -[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] public sealed partial class GasPressurePumpComponent : Component { [DataField, AutoNetworkedField] diff --git a/Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs b/Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs index 77444eb3c5..140597971d 100644 --- a/Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs +++ b/Content.Shared/Atmos/EntitySystems/SharedGasPressurePumpSystem.cs @@ -5,18 +5,15 @@ using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Components; using Content.Shared.Database; using Content.Shared.Examine; -using Content.Shared.Popups; using Content.Shared.Power; -using Content.Shared.Power.Components; using Content.Shared.Power.EntitySystems; -using Content.Shared.UserInterface; namespace Content.Shared.Atmos.EntitySystems; public abstract class SharedGasPressurePumpSystem : EntitySystem { [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; - [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!; [Dependency] protected readonly SharedUserInterfaceSystem UserInterfaceSystem = default!; @@ -36,62 +33,71 @@ public abstract class SharedGasPressurePumpSystem : EntitySystem SubscribeLocalEvent(OnExamined); } - private void OnExamined(EntityUid uid, GasPressurePumpComponent pump, ExaminedEvent args) + private void OnExamined(Entity ent, ref ExaminedEvent args) { - if (!Transform(uid).Anchored) + if (!Transform(ent).Anchored) return; - if (Loc.TryGetString("gas-pressure-pump-system-examined", out var str, + if (Loc.TryGetString("gas-pressure-pump-system-examined", + out var str, ("statusColor", "lightblue"), // TODO: change with pressure? - ("pressure", pump.TargetPressure) + ("pressure", ent.Comp.TargetPressure) )) { args.PushMarkup(str); } } - private void OnInit(EntityUid uid, GasPressurePumpComponent pump, ComponentInit args) + private void OnInit(Entity ent, ref ComponentInit args) { - UpdateAppearance(uid, pump); + UpdateAppearance(ent); } - private void OnPowerChanged(EntityUid uid, GasPressurePumpComponent component, ref PowerChangedEvent args) + private void OnPowerChanged(Entity ent, ref PowerChangedEvent args) { - UpdateAppearance(uid, component); + UpdateAppearance(ent); } - private void UpdateAppearance(EntityUid uid, GasPressurePumpComponent? pump = null, AppearanceComponent? appearance = null) + private void UpdateAppearance(Entity ent) { - if (!Resolve(uid, ref pump, ref appearance, false)) + if (!Resolve(ent, ref ent.Comp2, false)) return; - var pumpOn = pump.Enabled && _receiver.IsPowered(uid); - Appearance.SetData(uid, PumpVisuals.Enabled, pumpOn, appearance); + var pumpOn = ent.Comp1.Enabled && _receiver.IsPowered(ent.Owner); + _appearance.SetData(ent, PumpVisuals.Enabled, pumpOn, ent.Comp2); } - private void OnToggleStatusMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpToggleStatusMessage args) + private void OnToggleStatusMessage(Entity ent, ref GasPressurePumpToggleStatusMessage args) { - pump.Enabled = args.Enabled; - _adminLogger.Add(LogType.AtmosPowerChanged, LogImpact.Medium, - $"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(uid):device} to {args.Enabled}"); - Dirty(uid, pump); - UpdateAppearance(uid, pump); + ent.Comp.Enabled = args.Enabled; + _adminLogger.Add(LogType.AtmosPowerChanged, + LogImpact.Medium, + $"{ToPrettyString(args.Actor):player} set the power on {ToPrettyString(ent):device} to {args.Enabled}"); + Dirty(ent); + UpdateAppearance(ent); + UpdateUi(ent); } - private void OnOutputPressureChangeMessage(EntityUid uid, GasPressurePumpComponent pump, GasPressurePumpChangeOutputPressureMessage args) + private void OnOutputPressureChangeMessage(Entity ent, ref GasPressurePumpChangeOutputPressureMessage args) { - pump.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure); - _adminLogger.Add(LogType.AtmosPressureChanged, LogImpact.Medium, - $"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(uid):device} to {args.Pressure}kPa"); - Dirty(uid, pump); + ent.Comp.TargetPressure = Math.Clamp(args.Pressure, 0f, Atmospherics.MaxOutputPressure); + _adminLogger.Add(LogType.AtmosPressureChanged, + LogImpact.Medium, + $"{ToPrettyString(args.Actor):player} set the pressure on {ToPrettyString(ent):device} to {args.Pressure}kPa"); + Dirty(ent); + UpdateUi(ent); } - private void OnPumpLeaveAtmosphere(EntityUid uid, GasPressurePumpComponent pump, ref AtmosDeviceDisabledEvent args) + private void OnPumpLeaveAtmosphere(Entity ent, ref AtmosDeviceDisabledEvent args) { - pump.Enabled = false; - Dirty(uid, pump); - UpdateAppearance(uid, pump); + ent.Comp.Enabled = false; + Dirty(ent); + UpdateAppearance(ent); - UserInterfaceSystem.CloseUi(uid, GasPressurePumpUiKey.Key); + UserInterfaceSystem.CloseUi(ent.Owner, GasPressurePumpUiKey.Key); + } + + protected virtual void UpdateUi(Entity ent) + { } }