From 98843511014e1b5fce34b7e1215179dd3d0f94c8 Mon Sep 17 00:00:00 2001 From: Menshin Date: Wed, 28 Feb 2024 19:27:29 +0100 Subject: [PATCH] Add space heaters (#25250) --- .../Atmos/UI/SpaceHeaterBoundUserInterface.cs | 90 +++++++++ .../Atmos/UI/SpaceHeaterWindow.xaml | 34 ++++ .../Atmos/UI/SpaceHeaterWindow.xaml.cs | 73 +++++++ .../EntitySystems/GasThermoMachineSystem.cs | 3 + .../Atmos/Portable/SpaceHeaterComponent.cs | 58 ++++++ .../Atmos/Portable/SpaceHeaterSystem.cs | 191 ++++++++++++++++++ .../Components/SharedSpaceHeaterComponent.cs | 90 +++++++++ .../Atmos/Visuals/SpaceHeaterVisuals.cs | 27 +++ .../components/space-heater-component.ftl | 18 ++ Resources/Locale/en-US/wires/wire-names.ftl | 1 + .../Circuitboards/Machine/production.yml | 18 +- .../Entities/Structures/Machines/lathe.yml | 1 + .../Piping/Atmospherics/portable.yml | 120 +++++++++-- .../Prototypes/Recipes/Lathes/electronics.yml | 10 + Resources/Prototypes/Research/industrial.yml | 1 + .../Portable/portable_sheater.rsi/meta.json | 50 +++++ .../portable_sheater.rsi/sheaterCool.png | Bin 0 -> 994 bytes .../portable_sheater.rsi/sheaterHeat.png | Bin 0 -> 911 bytes .../portable_sheater.rsi/sheaterOff.png | Bin 0 -> 6028 bytes .../portable_sheater.rsi/sheaterPanelOpen.png | Bin 0 -> 187 bytes .../portable_sheater.rsi/sheaterStandby.png | Bin 0 -> 338 bytes 21 files changed, 770 insertions(+), 15 deletions(-) create mode 100644 Content.Client/Atmos/UI/SpaceHeaterBoundUserInterface.cs create mode 100644 Content.Client/Atmos/UI/SpaceHeaterWindow.xaml create mode 100644 Content.Client/Atmos/UI/SpaceHeaterWindow.xaml.cs create mode 100644 Content.Server/Atmos/Portable/SpaceHeaterComponent.cs create mode 100644 Content.Server/Atmos/Portable/SpaceHeaterSystem.cs create mode 100644 Content.Shared/Atmos/Portable/Components/SharedSpaceHeaterComponent.cs create mode 100644 Content.Shared/Atmos/Visuals/SpaceHeaterVisuals.cs create mode 100644 Resources/Locale/en-US/components/space-heater-component.ftl create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/meta.json create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/sheaterCool.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/sheaterHeat.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/sheaterOff.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/sheaterPanelOpen.png create mode 100644 Resources/Textures/Structures/Piping/Atmospherics/Portable/portable_sheater.rsi/sheaterStandby.png diff --git a/Content.Client/Atmos/UI/SpaceHeaterBoundUserInterface.cs b/Content.Client/Atmos/UI/SpaceHeaterBoundUserInterface.cs new file mode 100644 index 00000000000000..4d8d1191e912c1 --- /dev/null +++ b/Content.Client/Atmos/UI/SpaceHeaterBoundUserInterface.cs @@ -0,0 +1,90 @@ +using Content.Shared.Atmos.Piping.Portable.Components; +using JetBrains.Annotations; +using Robust.Client.UserInterface.Controls; + +namespace Content.Client.Atmos.UI; + +/// +/// Initializes a and updates it when new server messages are received. +/// +[UsedImplicitly] +public sealed class SpaceHeaterBoundUserInterface : BoundUserInterface +{ + [ViewVariables] + private SpaceHeaterWindow? _window; + + public SpaceHeaterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + _window = new SpaceHeaterWindow(); + + if (State != null) + UpdateState(State); + + _window.OpenCentered(); + + _window.OnClose += Close; + + _window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed(); + _window.IncreaseTempRange.OnPressed += _ => OnTemperatureRangeChanged(_window.TemperatureChangeDelta); + _window.DecreaseTempRange.OnPressed += _ => OnTemperatureRangeChanged(-_window.TemperatureChangeDelta); + _window.ModeSelector.OnItemSelected += OnModeChanged; + + _window.PowerLevelSelector.OnItemSelected += OnPowerLevelChange; + } + + private void OnToggleStatusButtonPressed() + { + _window?.SetActive(!_window.Active); + SendMessage(new SpaceHeaterToggleMessage()); + } + + private void OnTemperatureRangeChanged(float changeAmount) + { + SendMessage(new SpaceHeaterChangeTemperatureMessage(changeAmount)); + } + + private void OnModeChanged(OptionButton.ItemSelectedEventArgs args) + { + _window?.ModeSelector.SelectId(args.Id); + SendMessage(new SpaceHeaterChangeModeMessage((SpaceHeaterMode)args.Id)); + } + + private void OnPowerLevelChange(RadioOptionItemSelectedEventArgs args) + { + _window?.PowerLevelSelector.Select(args.Id); + SendMessage(new SpaceHeaterChangePowerLevelMessage((SpaceHeaterPowerLevel)args.Id)); + } + + /// + /// Update the UI state based on server-sent info + /// + /// + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not SpaceHeaterBoundUserInterfaceState cast) + return; + + _window.SetActive(cast.Enabled); + _window.ModeSelector.SelectId((int)cast.Mode); + _window.PowerLevelSelector.Select((int)cast.PowerLevel); + + _window.MinTemp = cast.MinTemperature; + _window.MaxTemp = cast.MaxTemperature; + _window.SetTemperature(cast.TargetTemperature); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) + return; + _window?.Dispose(); + } +} diff --git a/Content.Client/Atmos/UI/SpaceHeaterWindow.xaml b/Content.Client/Atmos/UI/SpaceHeaterWindow.xaml new file mode 100644 index 00000000000000..1b7bd490b85dfb --- /dev/null +++ b/Content.Client/Atmos/UI/SpaceHeaterWindow.xaml @@ -0,0 +1,34 @@ + + + + + + +