Add copy threshold button to air alarms (#34346)

This commit is contained in:
Southbridge
2025-01-10 01:55:05 -05:00
committed by GitHub
parent 0b1ed3ec7e
commit edbc861c78
8 changed files with 72 additions and 17 deletions

View File

@@ -130,8 +130,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
if (!_pumps.TryGetValue(addr, out var pumpControl)) if (!_pumps.TryGetValue(addr, out var pumpControl))
{ {
var control= new PumpControl(pump, addr); var control= new PumpControl(pump, addr);
control.PumpDataChanged += AtmosDeviceDataChanged!.Invoke; control.PumpDataChanged += AtmosDeviceDataChanged;
control.PumpDataCopied += AtmosDeviceDataCopied!.Invoke; control.PumpDataCopied += AtmosDeviceDataCopied;
_pumps.Add(addr, control); _pumps.Add(addr, control);
CVentContainer.AddChild(control); CVentContainer.AddChild(control);
} }
@@ -145,8 +145,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
if (!_scrubbers.TryGetValue(addr, out var scrubberControl)) if (!_scrubbers.TryGetValue(addr, out var scrubberControl))
{ {
var control = new ScrubberControl(scrubber, addr); var control = new ScrubberControl(scrubber, addr);
control.ScrubberDataChanged += AtmosDeviceDataChanged!.Invoke; control.ScrubberDataChanged += AtmosDeviceDataChanged;
control.ScrubberDataCopied += AtmosDeviceDataCopied!.Invoke; control.ScrubberDataCopied += AtmosDeviceDataCopied;
_scrubbers.Add(addr, control); _scrubbers.Add(addr, control);
CScrubberContainer.AddChild(control); CScrubberContainer.AddChild(control);
} }
@@ -161,6 +161,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
{ {
var control = new SensorInfo(sensor, addr); var control = new SensorInfo(sensor, addr);
control.OnThresholdUpdate += AtmosAlarmThresholdChanged; control.OnThresholdUpdate += AtmosAlarmThresholdChanged;
control.SensorDataCopied += AtmosDeviceDataCopied;
_sensors.Add(addr, control); _sensors.Add(addr, control);
CSensorContainer.AddChild(control); CSensorContainer.AddChild(control);
} }

View File

@@ -3,6 +3,9 @@
<CollapsibleHeading Name="SensorAddress" /> <CollapsibleHeading Name="SensorAddress" />
<CollapsibleBody Margin="20 2 2 2"> <CollapsibleBody Margin="20 2 2 2">
<BoxContainer Orientation="Vertical" HorizontalExpand="True"> <BoxContainer Orientation="Vertical" HorizontalExpand="True">
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-thresholds-copy'}" ToolTip="{Loc 'air-alarm-ui-thresholds-copy-tooltip'}" />
</BoxContainer>
<BoxContainer Orientation="Vertical" Margin="0 0 2 0" HorizontalExpand="True"> <BoxContainer Orientation="Vertical" Margin="0 0 2 0" HorizontalExpand="True">
<RichTextLabel Name="AlarmStateLabel" /> <RichTextLabel Name="AlarmStateLabel" />
<RichTextLabel Name="PressureLabel" /> <RichTextLabel Name="PressureLabel" />

View File

@@ -12,12 +12,14 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets;
public sealed partial class SensorInfo : BoxContainer public sealed partial class SensorInfo : BoxContainer
{ {
public Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? OnThresholdUpdate; public Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? OnThresholdUpdate;
public event Action<AtmosSensorData>? SensorDataCopied;
private string _address; private string _address;
private ThresholdControl _pressureThreshold; private ThresholdControl _pressureThreshold;
private ThresholdControl _temperatureThreshold; private ThresholdControl _temperatureThreshold;
private Dictionary<Gas, ThresholdControl> _gasThresholds = new(); private Dictionary<Gas, ThresholdControl> _gasThresholds = new();
private Dictionary<Gas, RichTextLabel> _gasLabels = new(); private Dictionary<Gas, RichTextLabel> _gasLabels = new();
private Button _copySettings => CCopySettings;
public SensorInfo(AtmosSensorData data, string address) public SensorInfo(AtmosSensorData data, string address)
{ {
@@ -56,7 +58,7 @@ public sealed partial class SensorInfo : BoxContainer
gasThresholdControl.Margin = new Thickness(20, 2, 2, 2); gasThresholdControl.Margin = new Thickness(20, 2, 2, 2);
gasThresholdControl.ThresholdDataChanged += (type, alarmThreshold, arg3) => gasThresholdControl.ThresholdDataChanged += (type, alarmThreshold, arg3) =>
{ {
OnThresholdUpdate!(_address, type, alarmThreshold, arg3); OnThresholdUpdate?.Invoke(_address, type, alarmThreshold, arg3);
}; };
_gasThresholds.Add(gas, gasThresholdControl); _gasThresholds.Add(gas, gasThresholdControl);
@@ -72,12 +74,17 @@ public sealed partial class SensorInfo : BoxContainer
_pressureThreshold.ThresholdDataChanged += (type, threshold, arg3) => _pressureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
{ {
OnThresholdUpdate!(_address, type, threshold, arg3); OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
}; };
_temperatureThreshold.ThresholdDataChanged += (type, threshold, arg3) => _temperatureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
{ {
OnThresholdUpdate!(_address, type, threshold, arg3); OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
};
_copySettings.OnPressed += _ =>
{
SensorDataCopied?.Invoke(data);
}; };
} }

View File

@@ -131,6 +131,19 @@ public sealed class AirAlarmSystem : EntitySystem
SyncDevice(uid, address); SyncDevice(uid, address);
} }
private void SetAllThresholds(EntityUid uid, string address, AtmosSensorData data)
{
var payload = new NetworkPayload
{
[DeviceNetworkConstants.Command] = AtmosMonitorSystem.AtmosMonitorSetAllThresholdsCmd,
[AtmosMonitorSystem.AtmosMonitorAllThresholdData] = data
};
_deviceNet.QueuePacket(uid, address, payload);
SyncDevice(uid, address);
}
/// <summary> /// <summary>
/// Sync this air alarm's mode with the rest of the network. /// Sync this air alarm's mode with the rest of the network.
/// </summary> /// </summary>
@@ -341,6 +354,13 @@ public sealed class AirAlarmSystem : EntitySystem
SetData(uid, addr, args.Data); SetData(uid, addr, args.Data);
} }
break; break;
case AtmosSensorData sensorData:
foreach (string addr in component.SensorData.Keys)
{
SetAllThresholds(uid, addr, sensorData);
}
break;
} }
} }

View File

@@ -33,10 +33,11 @@ public sealed class AtmosMonitorSystem : EntitySystem
// Commands // Commands
public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold"; public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
public const string AtmosMonitorSetAllThresholdsCmd = "atmos_monitor_set_all_thresholds";
// Packet data // Packet data
public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data"; public const string AtmosMonitorThresholdData = "atmos_monitor_threshold_data";
public const string AtmosMonitorAllThresholdData = "atmos_monitor_all_threshold_data";
public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type"; public const string AtmosMonitorThresholdDataType = "atmos_monitor_threshold_type";
public const string AtmosMonitorThresholdGasType = "atmos_monitor_threshold_gas"; public const string AtmosMonitorThresholdGasType = "atmos_monitor_threshold_gas";
@@ -138,7 +139,12 @@ public sealed class AtmosMonitorSystem : EntitySystem
args.Data.TryGetValue(AtmosMonitorThresholdGasType, out Gas? gas); args.Data.TryGetValue(AtmosMonitorThresholdGasType, out Gas? gas);
SetThreshold(uid, thresholdType.Value, thresholdData, gas); SetThreshold(uid, thresholdType.Value, thresholdData, gas);
} }
break;
case AtmosMonitorSetAllThresholdsCmd:
if (args.Data.TryGetValue(AtmosMonitorAllThresholdData, out AtmosSensorData? allThresholdData))
{
SetAllThresholds(uid, allThresholdData);
}
break; break;
case AtmosDeviceNetworkSystem.SyncData: case AtmosDeviceNetworkSystem.SyncData:
var payload = new NetworkPayload(); var payload = new NetworkPayload();
@@ -403,4 +409,20 @@ public sealed class AtmosMonitorSystem : EntitySystem
} }
} }
/// <summary>
/// Sets all of a monitor's thresholds at once according to the incoming
/// AtmosSensorData object's thresholds.
/// </summary>
/// <param name="uid">The entity's uid</param>
/// <param name="allThresholdData">An AtmosSensorData object from which the thresholds will be loaded.</param>
public void SetAllThresholds(EntityUid uid, AtmosSensorData allThresholdData)
{
SetThreshold(uid, AtmosMonitorThresholdType.Temperature, allThresholdData.TemperatureThreshold);
SetThreshold(uid, AtmosMonitorThresholdType.Pressure, allThresholdData.PressureThreshold);
foreach (var gas in Enum.GetValues<Gas>())
{
SetThreshold(uid, AtmosMonitorThresholdType.Gas, allThresholdData.GasThresholds[gas], gas);
}
}
} }

View File

@@ -69,3 +69,5 @@ air-alarm-ui-thresholds-upper-bound = Danger above
air-alarm-ui-thresholds-lower-bound = Danger below air-alarm-ui-thresholds-lower-bound = Danger below
air-alarm-ui-thresholds-upper-warning-bound = Warning above air-alarm-ui-thresholds-upper-warning-bound = Warning above
air-alarm-ui-thresholds-lower-warning-bound = Warning below air-alarm-ui-thresholds-lower-warning-bound = Warning below
air-alarm-ui-thresholds-copy = Copy thresholds to all devices
air-alarm-ui-thresholds-copy-tooltip = Copies the sensor thresholds of this device to all devices in this air alarm tab.