sensor UI
This commit is contained in:
@@ -37,11 +37,9 @@ namespace Content.Client.Atmos.Monitor.UI
|
||||
|
||||
private Dictionary<string, PumpControl> _pumps = new();
|
||||
private Dictionary<string, ScrubberControl> _scrubbers = new();
|
||||
private Dictionary<string, SensorInfo> _sensors = new();
|
||||
private Button _resyncDevices => CResyncButton;
|
||||
|
||||
private ThresholdControl? _pressureThresholdControl;
|
||||
private ThresholdControl? _temperatureThresholdControl;
|
||||
private Dictionary<Gas, ThresholdControl> _gasThresholdControls = new();
|
||||
|
||||
private Dictionary<Gas, Label> _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;
|
||||
}
|
||||
|
||||
|
||||
21
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml
Normal file
21
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml
Normal file
@@ -0,0 +1,21 @@
|
||||
<BoxContainer xmlns="https://spacestation14.io"
|
||||
xmlns:widgets="clr-namespace:Content.Client.Atmos.Monitor.UI.Widgets">
|
||||
<Collapsible Orientation="Vertical">
|
||||
<CollapsibleHeading Name="SensorAddress" />
|
||||
<CollapsibleBody>
|
||||
<RichTextLabel Name="PressureLabel"></RichTextLabel>
|
||||
<RichTextLabel Name="TemperatureLabel"></RichTextLabel>
|
||||
<RichTextLabel Name="TotalMolesLabel" />
|
||||
<RichTextLabel Name="AlarmStateLabel" />
|
||||
<BoxContainer Name="GasContainer" />
|
||||
<Collapsible Orientation="Vertical" Margin="2">
|
||||
<CollapsibleHeading Title="{Loc 'air-alarm-ui-sensor-thresholds'}" />
|
||||
<CollapsibleBody>
|
||||
<Control Name="PressureThresholdContainer" />
|
||||
<Control Name="TemperatureThresholdContainer" />
|
||||
<BoxContainer Name="GasThresholds" Orientation="Vertical" />
|
||||
</CollapsibleBody>
|
||||
</Collapsible>
|
||||
</CollapsibleBody>
|
||||
</Collapsible>
|
||||
</BoxContainer>
|
||||
102
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs
Normal file
102
Content.Client/Atmos/Monitor/UI/Widgets/SensorInfo.xaml.cs
Normal file
@@ -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<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? OnThresholdUpdate;
|
||||
private string _address;
|
||||
|
||||
private ThresholdControl _pressureThreshold;
|
||||
private ThresholdControl _temperatureThreshold;
|
||||
private Dictionary<Gas, ThresholdControl> _gasThresholds = new();
|
||||
private Dictionary<Gas, Label> _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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user