From 376f4c89721bf98c9b8675457be952dd22c760cf Mon Sep 17 00:00:00 2001 From: vulppine Date: Thu, 18 Aug 2022 23:54:39 -0700 Subject: [PATCH] sensor UI --- .../Atmos/Monitor/UI/AirAlarmWindow.xaml.cs | 18 +++- .../Atmos/Monitor/UI/Widgets/SensorInfo.xaml | 21 ++++ .../Monitor/UI/Widgets/SensorInfo.xaml.cs | 102 ++++++++++++++++++ .../UI/Widgets/ThresholdControl.xaml.cs | 2 + 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml create mode 100644 Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs diff --git a/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs b/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs index 2540694d64..3d77db0914 100644 --- a/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/AirAlarmWindow.xaml.cs @@ -37,11 +37,9 @@ namespace Content.Client.Atmos.Monitor.UI private Dictionary _pumps = new(); private Dictionary _scrubbers = new(); + private Dictionary _sensors = new(); private Button _resyncDevices => CResyncButton; - private ThresholdControl? _pressureThresholdControl; - private ThresholdControl? _temperatureThresholdControl; - private Dictionary _gasThresholdControls = new(); private Dictionary _gasLabels = new(); @@ -156,6 +154,20 @@ namespace Content.Client.Atmos.Monitor.UI scrubberControl.ChangeData(scrubber); } + break; + case AtmosSensorData sensor: + if (!_sensors.TryGetValue(addr, out var sensorControl)) + { + var control = new SensorInfo(sensor, addr); + control.OnThresholdUpdate += AtmosAlarmThresholdChanged; + _sensors.Add(addr, control); + CSensorContainer.AddChild(control); + } + else + { + sensorControl.ChangeData(sensor); + } + break; } diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml b/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml new file mode 100644 index 0000000000..cda3c9a4fe --- /dev/null +++ b/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs b/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs new file mode 100644 index 0000000000..30ae8de850 --- /dev/null +++ b/Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs @@ -0,0 +1,102 @@ +using Content.Client.Message; +using Content.Shared.Atmos; +using Content.Shared.Atmos.Monitor; +using Content.Shared.Temperature; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; + +namespace Content.Client.Atmos.Monitor.UI.Widgets; + +[GenerateTypedNameReferences] +public sealed partial class SensorInfo : BoxContainer +{ + public Action? OnThresholdUpdate; + private string _address; + + private ThresholdControl _pressureThreshold; + private ThresholdControl _temperatureThreshold; + private Dictionary _gasThresholds = new(); + private Dictionary _gasLabels = new(); + + public SensorInfo(AtmosSensorData data, string address) + { + RobustXamlLoader.Load(this); + + _address = address; + + SensorAddress.Title = address; + + PressureLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-pressure", ("pressure", $"{data.Pressure:0.##}"))); + TemperatureLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-temperature", ("tempC", $"{TemperatureHelpers.KelvinToCelsius(data.Temperature):0.#}"), ("temperature", $"{data.Temperature:0.##}"))); + AlarmStateLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-alarm-state", ("state", $"{data.AlarmState}"))); + + foreach (var (gas, amount) in data.Gases) + { + var label = new Label(); + label.Text = Loc.GetString("air-alarm-ui-gases", ("gas", $"{gas}"), + ("amount", $"{(amount / data.TotalMoles):0.##}")); + GasContainer.AddChild(label); + _gasLabels.Add(gas, label); + } + + _pressureThreshold = + new ThresholdControl("Pressure", data.PressureThreshold, AtmosMonitorThresholdType.Pressure); + PressureThresholdContainer.AddChild(_pressureThreshold); + _temperatureThreshold = new ThresholdControl("Temperature", data.TemperatureThreshold, + AtmosMonitorThresholdType.Temperature); + TemperatureThresholdContainer.AddChild(_temperatureThreshold); + + _pressureThreshold.ThresholdDataChanged += (type, threshold, arg3) => + { + OnThresholdUpdate!(_address, type, threshold, arg3); + }; + + _temperatureThreshold.ThresholdDataChanged += (type, threshold, arg3) => + { + OnThresholdUpdate!(_address, type, threshold, arg3); + }; + + foreach (var (gas, threshold) in data.GasThresholds) + { + var gasThresholdControl = new ThresholdControl(gas.ToString(), threshold, AtmosMonitorThresholdType.Gas, gas); + gasThresholdControl.ThresholdDataChanged += (type, threshold, arg3) => + { + OnThresholdUpdate!(_address, type, threshold, arg3); + }; + + _gasThresholds.Add(gas, gasThresholdControl); + GasThresholds.AddChild(gasThresholdControl); + } + } + + public void ChangeData(AtmosSensorData data) + { + PressureLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-pressure", ("pressure", $"{data.Pressure:0.##}"))); + TemperatureLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-temperature", ("tempC", $"{TemperatureHelpers.KelvinToCelsius(data.Temperature):0.#}"), ("temperature", $"{data.Temperature:0.##}"))); + AlarmStateLabel.SetMarkup(Loc.GetString("air-alarm-ui-window-alarm-state", ("state", $"{data.AlarmState}"))); + + foreach (var (gas, amount) in data.Gases) + { + if (!_gasLabels.TryGetValue(gas, out var label)) + { + continue; + } + + label.Text = Loc.GetString("air-alarm-ui-gases", ("gas", $"{gas}"), + ("amount", $"{(amount / data.TotalMoles):0.##}")); + } + + _pressureThreshold.UpdateThresholdData(data.PressureThreshold); + _temperatureThreshold.UpdateThresholdData(data.TemperatureThreshold); + foreach (var (gas, control) in _gasThresholds) + { + if (!data.GasThresholds.TryGetValue(gas, out var threshold)) + { + continue; + } + + control.UpdateThresholdData(threshold); + } + } +} diff --git a/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs b/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs index d05d92f8f2..b3da0b2d6c 100644 --- a/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs +++ b/Content.Client/Atmos/Monitor/UI/Widgets/ThresholdControl.xaml.cs @@ -8,6 +8,8 @@ using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Localization; +// holy FUCK +// this technically works because some of this you can *not* do in XAML but holy FUCK namespace Content.Client.Atmos.Monitor.UI.Widgets {