diff --git a/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs
new file mode 100644
index 0000000000..eb809e6f7c
--- /dev/null
+++ b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs
@@ -0,0 +1,92 @@
+using Content.Shared.Atmos;
+using Content.Shared.Atmos.Piping.Binary.Components;
+using Content.Shared.Atmos.Piping.Unary.Components;
+using JetBrains.Annotations;
+using Robust.Client.GameObjects;
+using Robust.Shared.GameObjects;
+
+namespace Content.Client.Atmos.UI
+{
+ ///
+ /// Initializes a and updates it when new server messages are received.
+ ///
+ [UsedImplicitly]
+ public sealed class GasThermomachineBoundUserInterface : BoundUserInterface
+ {
+ private GasThermomachineWindow? _window;
+
+ private float _minTemp = 0.0f;
+ private float _maxTemp = 0.0f;
+
+ public GasThermomachineBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
+ {
+ }
+
+ protected override void Open()
+ {
+ base.Open();
+
+ _window = new GasThermomachineWindow();
+
+ if(State != null)
+ UpdateState(State);
+
+ _window.OpenCentered();
+
+ _window.OnClose += Close;
+
+ _window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
+ _window.TemperatureSpinbox.OnValueChanged += _ => OnTemperatureChanged(_window.TemperatureSpinbox.Value);
+ }
+
+ private void OnToggleStatusButtonPressed()
+ {
+ if (_window is null) return;
+
+ _window.SetActive(!_window.Active);
+ SendMessage(new GasThermomachineToggleMessage());
+ }
+
+ private void OnTemperatureChanged(float value)
+ {
+ var actual = Math.Clamp(value, _minTemp, _maxTemp);
+ if (!MathHelper.CloseTo(actual, value, 0.09))
+ {
+ _window?.SetTemperature(actual);
+ return;
+ }
+
+ SendMessage(new GasThermomachineChangeTemperatureMessage(actual));
+ }
+
+ ///
+ /// Update the UI state based on server-sent info
+ ///
+ ///
+ protected override void UpdateState(BoundUserInterfaceState state)
+ {
+ base.UpdateState(state);
+ if (_window == null || state is not GasThermomachineBoundUserInterfaceState cast)
+ return;
+
+ _minTemp = cast.MinTemperature;
+ _maxTemp = cast.MaxTemperature;
+
+ _window.SetTemperature(cast.Temperature);
+ _window.SetActive(cast.Enabled);
+ _window.Title = cast.Mode switch
+ {
+ ThermoMachineMode.Freezer => Loc.GetString("comp-gas-thermomachine-ui-title-freezer"),
+ ThermoMachineMode.Heater => Loc.GetString("comp-gas-thermomachine-ui-title-heater"),
+ _ => string.Empty
+ };
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ if (!disposing) return;
+ _window?.Dispose();
+ }
+ }
+}
diff --git a/Content.Client/Atmos/UI/GasThermomachineWindow.xaml b/Content.Client/Atmos/UI/GasThermomachineWindow.xaml
new file mode 100644
index 0000000000..65bd918888
--- /dev/null
+++ b/Content.Client/Atmos/UI/GasThermomachineWindow.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Content.Client/Atmos/UI/GasThermomachineWindow.xaml.cs b/Content.Client/Atmos/UI/GasThermomachineWindow.xaml.cs
new file mode 100644
index 0000000000..691d5ea910
--- /dev/null
+++ b/Content.Client/Atmos/UI/GasThermomachineWindow.xaml.cs
@@ -0,0 +1,41 @@
+using Robust.Client.AutoGenerated;
+using Robust.Client.UserInterface.Controls;
+using Robust.Client.UserInterface.CustomControls;
+using Robust.Client.UserInterface.XAML;
+
+namespace Content.Client.Atmos.UI;
+
+[GenerateTypedNameReferences]
+public sealed partial class GasThermomachineWindow : DefaultWindow
+{
+ public bool Active = true;
+
+ public FloatSpinBox TemperatureSpinbox;
+
+ public GasThermomachineWindow()
+ {
+ RobustXamlLoader.Load(this);
+
+ SpinboxHBox.AddChild(
+ TemperatureSpinbox = new FloatSpinBox(.1f, 2) { MaxWidth = 150, HorizontalExpand = true }
+ );
+ }
+
+ public void SetActive(bool active)
+ {
+ Active = active;
+ if (active)
+ {
+ ToggleStatusButton.Text = Loc.GetString("comp-gas-thermomachine-ui-status-enabled");
+ }
+ else
+ {
+ ToggleStatusButton.Text = Loc.GetString("comp-gas-thermomachine-ui-status-disabled");
+ }
+ }
+
+ public void SetTemperature(float temperature)
+ {
+ TemperatureSpinbox.Value = temperature;
+ }
+}
diff --git a/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs b/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs
index 0560554dbb..410c8ca7f3 100644
--- a/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs
+++ b/Content.Server/Atmos/Piping/Unary/Components/GasThermoMachineComponent.cs
@@ -1,4 +1,5 @@
using Content.Shared.Atmos;
+using Content.Shared.Atmos.Piping.Unary.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
@@ -42,10 +43,4 @@ namespace Content.Server.Atmos.Piping.Unary.Components
InitialMaxTemperature = MaxTemperature;
}
}
-
- public enum ThermoMachineMode : byte
- {
- Freezer = 0,
- Heater = 1,
- }
}
diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs
index 4b52b6afb8..5c1918f55e 100644
--- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs
+++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs
@@ -6,7 +6,9 @@ using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping;
+using Content.Shared.Atmos.Piping.Unary.Components;
using JetBrains.Annotations;
+using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -16,6 +18,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
public sealed class GasThermoMachineSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
+ [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
public override void Initialize()
{
@@ -24,6 +27,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
SubscribeLocalEvent(OnThermoMachineUpdated);
SubscribeLocalEvent(OnThermoMachineLeaveAtmosphere);
SubscribeLocalEvent(OnGasThermoRefreshParts);
+
+ // UI events
+ SubscribeLocalEvent(OnToggleMessage);
+ SubscribeLocalEvent(OnChangeTemperature);
}
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args)
@@ -34,6 +41,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet))
{
+ DirtyUI(uid, thermoMachine);
appearance?.SetData(ThermoMachineVisuals.Enabled, false);
return;
}
@@ -58,6 +66,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
{
appearance.SetData(ThermoMachineVisuals.Enabled, false);
}
+
+ DirtyUI(uid, component);
}
private void OnGasThermoRefreshParts(EntityUid uid, GasThermoMachineComponent component, RefreshPartsEvent args)
@@ -91,6 +101,32 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
component.MinTemperature = MathF.Max(Atmospherics.T0C - component.InitialMinTemperature + laserRating * 15f, Atmospherics.TCMB);
break;
}
+
+ DirtyUI(uid, component);
+ }
+
+ private void OnToggleMessage(EntityUid uid, GasThermoMachineComponent component, GasThermomachineToggleMessage args)
+ {
+ component.Enabled = !component.Enabled;
+
+ DirtyUI(uid, component);
+ }
+
+ private void OnChangeTemperature(EntityUid uid, GasThermoMachineComponent component, GasThermomachineChangeTemperatureMessage args)
+ {
+ component.TargetTemperature =
+ Math.Clamp(args.Temperature, component.MinTemperature, component.MaxTemperature);
+
+ DirtyUI(uid, component);
+ }
+
+ private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermo, ServerUserInterfaceComponent? ui=null)
+ {
+ if (!Resolve(uid, ref thermo, ref ui, false))
+ return;
+
+ _userInterfaceSystem.TrySetUiState(uid, ThermomachineUiKey.Key,
+ new GasThermomachineBoundUserInterfaceState(thermo.MinTemperature, thermo.MaxTemperature, thermo.TargetTemperature, thermo.Enabled, thermo.Mode), null, ui);
}
}
}
diff --git a/Content.Shared/Atmos/Piping/Unary/Components/SharedGasThermomachineComponent.cs b/Content.Shared/Atmos/Piping/Unary/Components/SharedGasThermomachineComponent.cs
new file mode 100644
index 0000000000..d48a113f39
--- /dev/null
+++ b/Content.Shared/Atmos/Piping/Unary/Components/SharedGasThermomachineComponent.cs
@@ -0,0 +1,56 @@
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.Atmos.Piping.Unary.Components;
+
+[Serializable]
+[NetSerializable]
+public enum ThermomachineUiKey
+{
+ Key
+}
+
+[Serializable]
+[NetSerializable]
+public enum ThermoMachineMode : byte
+{
+ Freezer = 0,
+ Heater = 1,
+}
+
+[Serializable]
+[NetSerializable]
+public sealed class GasThermomachineToggleMessage : BoundUserInterfaceMessage
+{
+}
+
+[Serializable]
+[NetSerializable]
+public sealed class GasThermomachineChangeTemperatureMessage : BoundUserInterfaceMessage
+{
+ public float Temperature { get; }
+
+ public GasThermomachineChangeTemperatureMessage(float temperature)
+ {
+ Temperature = temperature;
+ }
+}
+
+[Serializable]
+[NetSerializable]
+public sealed class GasThermomachineBoundUserInterfaceState : BoundUserInterfaceState
+{
+ public float MinTemperature { get; }
+ public float MaxTemperature { get; }
+ public float Temperature { get; }
+ public bool Enabled { get; }
+ public ThermoMachineMode Mode { get; }
+
+ public GasThermomachineBoundUserInterfaceState(float minTemperature, float maxTemperature, float temperature, bool enabled, ThermoMachineMode mode)
+ {
+ MinTemperature = minTemperature;
+ MaxTemperature = maxTemperature;
+ Temperature = temperature;
+ Enabled = enabled;
+ Mode = mode;
+ }
+}
diff --git a/Resources/Locale/en-US/components/gas-thermomachine-component.ftl b/Resources/Locale/en-US/components/gas-thermomachine-component.ftl
new file mode 100644
index 0000000000..5afd87e988
--- /dev/null
+++ b/Resources/Locale/en-US/components/gas-thermomachine-component.ftl
@@ -0,0 +1,7 @@
+comp-gas-thermomachine-ui-title-freezer = Freezer
+comp-gas-thermomachine-ui-title-heater = Heater
+
+comp-gas-thermomachine-ui-temperature = Temperature (K):
+comp-gas-thermomachine-ui-toggle = Toggle
+comp-gas-thermomachine-ui-status-disabled = Off
+comp-gas-thermomachine-ui-status-enabled = On
diff --git a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml
index ad975b07f0..09fa30a05b 100644
--- a/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml
+++ b/Resources/Prototypes/Entities/Structures/Piping/Atmospherics/unary.yml
@@ -148,6 +148,13 @@
- type: GasThermoMachine
- type: AtmosPipeColor
- type: AtmosDevice
+ - type: UserInterface
+ interfaces:
+ - key: enum.ThermomachineUiKey.Key
+ type: GasThermomachineBoundUserInterface
+ - type: ActivatableUI
+ inHandsOnly: false
+ key: enum.ThermomachineUiKey.Key
- type: Construction
graph: Machine
node: machine