Add copy threshold button to air alarms (#34346)
This commit is contained in:
@@ -130,8 +130,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
if (!_pumps.TryGetValue(addr, out var pumpControl))
|
||||
{
|
||||
var control= new PumpControl(pump, addr);
|
||||
control.PumpDataChanged += AtmosDeviceDataChanged!.Invoke;
|
||||
control.PumpDataCopied += AtmosDeviceDataCopied!.Invoke;
|
||||
control.PumpDataChanged += AtmosDeviceDataChanged;
|
||||
control.PumpDataCopied += AtmosDeviceDataCopied;
|
||||
_pumps.Add(addr, control);
|
||||
CVentContainer.AddChild(control);
|
||||
}
|
||||
@@ -145,8 +145,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
if (!_scrubbers.TryGetValue(addr, out var scrubberControl))
|
||||
{
|
||||
var control = new ScrubberControl(scrubber, addr);
|
||||
control.ScrubberDataChanged += AtmosDeviceDataChanged!.Invoke;
|
||||
control.ScrubberDataCopied += AtmosDeviceDataCopied!.Invoke;
|
||||
control.ScrubberDataChanged += AtmosDeviceDataChanged;
|
||||
control.ScrubberDataCopied += AtmosDeviceDataCopied;
|
||||
_scrubbers.Add(addr, control);
|
||||
CScrubberContainer.AddChild(control);
|
||||
}
|
||||
@@ -161,6 +161,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
{
|
||||
var control = new SensorInfo(sensor, addr);
|
||||
control.OnThresholdUpdate += AtmosAlarmThresholdChanged;
|
||||
control.SensorDataCopied += AtmosDeviceDataCopied;
|
||||
_sensors.Add(addr, control);
|
||||
CSensorContainer.AddChild(control);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
<CollapsibleHeading Name="SensorAddress" />
|
||||
<CollapsibleBody Margin="20 2 2 2">
|
||||
<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">
|
||||
<RichTextLabel Name="AlarmStateLabel" />
|
||||
<RichTextLabel Name="PressureLabel" />
|
||||
|
||||
@@ -12,12 +12,14 @@ namespace Content.Client.Atmos.Monitor.UI.Widgets;
|
||||
public sealed partial class SensorInfo : BoxContainer
|
||||
{
|
||||
public Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? OnThresholdUpdate;
|
||||
public event Action<AtmosSensorData>? SensorDataCopied;
|
||||
private string _address;
|
||||
|
||||
private ThresholdControl _pressureThreshold;
|
||||
private ThresholdControl _temperatureThreshold;
|
||||
private Dictionary<Gas, ThresholdControl> _gasThresholds = new();
|
||||
private Dictionary<Gas, RichTextLabel> _gasLabels = new();
|
||||
private Button _copySettings => CCopySettings;
|
||||
|
||||
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.ThresholdDataChanged += (type, alarmThreshold, arg3) =>
|
||||
{
|
||||
OnThresholdUpdate!(_address, type, alarmThreshold, arg3);
|
||||
OnThresholdUpdate?.Invoke(_address, type, alarmThreshold, arg3);
|
||||
};
|
||||
|
||||
_gasThresholds.Add(gas, gasThresholdControl);
|
||||
@@ -72,12 +74,17 @@ public sealed partial class SensorInfo : BoxContainer
|
||||
|
||||
_pressureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
|
||||
{
|
||||
OnThresholdUpdate!(_address, type, threshold, arg3);
|
||||
OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
|
||||
};
|
||||
|
||||
_temperatureThreshold.ThresholdDataChanged += (type, threshold, arg3) =>
|
||||
{
|
||||
OnThresholdUpdate!(_address, type, threshold, arg3);
|
||||
OnThresholdUpdate?.Invoke(_address, type, threshold, arg3);
|
||||
};
|
||||
|
||||
_copySettings.OnPressed += _ =>
|
||||
{
|
||||
SensorDataCopied?.Invoke(data);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,19 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
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>
|
||||
/// Sync this air alarm's mode with the rest of the network.
|
||||
/// </summary>
|
||||
@@ -341,6 +354,13 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
SetData(uid, addr, args.Data);
|
||||
}
|
||||
break;
|
||||
|
||||
case AtmosSensorData sensorData:
|
||||
foreach (string addr in component.SensorData.Keys)
|
||||
{
|
||||
SetAllThresholds(uid, addr, sensorData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,11 @@ public sealed class AtmosMonitorSystem : EntitySystem
|
||||
|
||||
// Commands
|
||||
public const string AtmosMonitorSetThresholdCmd = "atmos_monitor_set_threshold";
|
||||
public const string AtmosMonitorSetAllThresholdsCmd = "atmos_monitor_set_all_thresholds";
|
||||
|
||||
// Packet 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 AtmosMonitorThresholdGasType = "atmos_monitor_threshold_gas";
|
||||
@@ -138,7 +139,12 @@ public sealed class AtmosMonitorSystem : EntitySystem
|
||||
args.Data.TryGetValue(AtmosMonitorThresholdGasType, out Gas? gas);
|
||||
SetThreshold(uid, thresholdType.Value, thresholdData, gas);
|
||||
}
|
||||
|
||||
break;
|
||||
case AtmosMonitorSetAllThresholdsCmd:
|
||||
if (args.Data.TryGetValue(AtmosMonitorAllThresholdData, out AtmosSensorData? allThresholdData))
|
||||
{
|
||||
SetAllThresholds(uid, allThresholdData);
|
||||
}
|
||||
break;
|
||||
case AtmosDeviceNetworkSystem.SyncData:
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,3 +69,5 @@ air-alarm-ui-thresholds-upper-bound = Danger above
|
||||
air-alarm-ui-thresholds-lower-bound = Danger below
|
||||
air-alarm-ui-thresholds-upper-warning-bound = Warning above
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user