copy-settings-to-all-similar for scrubbers and vents in air alarms (#18363)
This commit is contained in:
@@ -31,6 +31,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.AtmosDeviceDataChanged += OnDeviceDataChanged;
|
||||
_window.AtmosDeviceDataCopied += OnDeviceDataCopied;
|
||||
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
|
||||
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
|
||||
_window.AutoModeChanged += OnAutoModeChanged;
|
||||
@@ -48,6 +49,11 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
|
||||
}
|
||||
|
||||
private void OnDeviceDataCopied(IAtmosDeviceData data)
|
||||
{
|
||||
SendMessage(new AirAlarmCopyDeviceDataMessage(data));
|
||||
}
|
||||
|
||||
private void OnAirAlarmModeChanged(AirAlarmMode mode)
|
||||
{
|
||||
SendMessage(new AirAlarmUpdateAlarmModeMessage(mode));
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Content.Client.Atmos.Monitor.UI;
|
||||
public sealed partial class AirAlarmWindow : FancyWindow
|
||||
{
|
||||
public event Action<string, IAtmosDeviceData>? AtmosDeviceDataChanged;
|
||||
public event Action<IAtmosDeviceData>? AtmosDeviceDataCopied;
|
||||
public event Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? AtmosAlarmThresholdChanged;
|
||||
public event Action<AirAlarmMode>? AirAlarmModeChanged;
|
||||
public event Action<bool>? AutoModeChanged;
|
||||
@@ -137,6 +138,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
{
|
||||
var control= new PumpControl(pump, addr);
|
||||
control.PumpDataChanged += AtmosDeviceDataChanged!.Invoke;
|
||||
control.PumpDataCopied += AtmosDeviceDataCopied!.Invoke;
|
||||
_pumps.Add(addr, control);
|
||||
CVentContainer.AddChild(control);
|
||||
}
|
||||
@@ -151,6 +153,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
{
|
||||
var control = new ScrubberControl(scrubber, addr);
|
||||
control.ScrubberDataChanged += AtmosDeviceDataChanged!.Invoke;
|
||||
control.ScrubberDataCopied += AtmosDeviceDataCopied!.Invoke;
|
||||
_scrubbers.Add(addr, control);
|
||||
CScrubberContainer.AddChild(control);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<OptionButton Name="CPressureCheck" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<!-- Lower row: pressure bounds -->
|
||||
<!-- Lower row: pressure bounds, copy settings -->
|
||||
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'air-alarm-ui-vent-external-bound-label'}" Margin="0 0 0 1" />
|
||||
@@ -30,6 +30,9 @@
|
||||
<FloatSpinBox Name="CInternalBound" HorizontalExpand="True" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
|
||||
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-widget-copy'}" ToolTip="{Loc 'air-alarm-ui-widget-copy-tooltip'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</CollapsibleBody>
|
||||
</Collapsible>
|
||||
|
||||
@@ -17,6 +17,7 @@ public sealed partial class PumpControl : BoxContainer
|
||||
private string _address;
|
||||
|
||||
public event Action<string, IAtmosDeviceData>? PumpDataChanged;
|
||||
public event Action<IAtmosDeviceData>? PumpDataCopied;
|
||||
|
||||
private CheckBox _enabled => CEnableDevice;
|
||||
private CollapsibleHeading _addressLabel => CAddress;
|
||||
@@ -24,6 +25,7 @@ public sealed partial class PumpControl : BoxContainer
|
||||
private OptionButton _pressureCheck => CPressureCheck;
|
||||
private FloatSpinBox _externalBound => CExternalBound;
|
||||
private FloatSpinBox _internalBound => CInternalBound;
|
||||
private Button _copySettings => CCopySettings;
|
||||
|
||||
public PumpControl(GasVentPumpData data, string address)
|
||||
{
|
||||
@@ -84,6 +86,11 @@ public sealed partial class PumpControl : BoxContainer
|
||||
_data.PressureChecks = (VentPressureBound) args.Id;
|
||||
PumpDataChanged?.Invoke(_address, _data);
|
||||
};
|
||||
|
||||
_copySettings.OnPressed += _ =>
|
||||
{
|
||||
PumpDataCopied?.Invoke(_data);
|
||||
};
|
||||
}
|
||||
|
||||
public void ChangeData(GasVentPumpData data)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<BoxContainer Orientation="Horizontal" Margin="0 0 0 2">
|
||||
<CheckBox Name="CEnableDevice" Text="{Loc 'air-alarm-ui-widget-enable'}" />
|
||||
</BoxContainer>
|
||||
<!-- Upper row: toggle, direction, volume rate, widenet -->
|
||||
<!-- Upper row: toggle, direction, volume rate, widenet, copy settings -->
|
||||
<BoxContainer Orientation="Horizontal" Margin="0 0 0 2" HorizontalExpand="True">
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True">
|
||||
<Label Text="{Loc 'air-alarm-ui-scrubber-pump-direction-label'}" Margin="0 0 0 1"/>
|
||||
@@ -22,6 +22,9 @@
|
||||
<BoxContainer>
|
||||
<CheckBox Name="CWideNet" Text="{Loc 'air-alarm-ui-scrubber-wide-net-label'}" />
|
||||
</BoxContainer>
|
||||
<BoxContainer Orientation="Horizontal" Margin ="0 0 0 2">
|
||||
<Button Name="CCopySettings" Text="{Loc 'air-alarm-ui-widget-copy'}" ToolTip="{Loc 'air-alarm-ui-widget-copy-tooltip'}" />
|
||||
</BoxContainer>
|
||||
<!-- Lower row: every single gas -->
|
||||
<Collapsible Orientation="Vertical" Margin="2 2 2 2">
|
||||
<CollapsibleHeading Title="Gas filters" />
|
||||
|
||||
@@ -20,12 +20,14 @@ public sealed partial class ScrubberControl : BoxContainer
|
||||
private string _address;
|
||||
|
||||
public event Action<string, IAtmosDeviceData>? ScrubberDataChanged;
|
||||
public event Action<IAtmosDeviceData>? ScrubberDataCopied;
|
||||
|
||||
private CheckBox _enabled => CEnableDevice;
|
||||
private CollapsibleHeading _addressLabel => CAddress;
|
||||
private OptionButton _pumpDirection => CPumpDirection;
|
||||
private FloatSpinBox _volumeRate => CVolumeRate;
|
||||
private CheckBox _wideNet => CWideNet;
|
||||
private Button _copySettings => CCopySettings;
|
||||
|
||||
private GridContainer _gases => CGasContainer;
|
||||
private Dictionary<Gas, Button> _gasControls = new();
|
||||
@@ -76,6 +78,11 @@ public sealed partial class ScrubberControl : BoxContainer
|
||||
ScrubberDataChanged?.Invoke(_address, _data);
|
||||
};
|
||||
|
||||
_copySettings.OnPressed += _ =>
|
||||
{
|
||||
ScrubberDataCopied?.Invoke(_data);
|
||||
};
|
||||
|
||||
foreach (var value in Enum.GetValues<Gas>())
|
||||
{
|
||||
var gasButton = new Button
|
||||
|
||||
@@ -161,6 +161,7 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateAutoModeMessage>(OnUpdateAutoMode);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateAlarmThresholdMessage>(OnUpdateThreshold);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateDeviceDataMessage>(OnUpdateDeviceData);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmCopyDeviceDataMessage>(OnCopyDeviceData);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmTabSetMessage>(OnTabChange);
|
||||
SubscribeLocalEvent<AirAlarmComponent, DeviceListUpdateEvent>(OnDeviceListUpdate);
|
||||
SubscribeLocalEvent<AirAlarmComponent, BoundUIClosedEvent>(OnClose);
|
||||
@@ -302,6 +303,32 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCopyDeviceData(EntityUid uid, AirAlarmComponent component, AirAlarmCopyDeviceDataMessage args)
|
||||
{
|
||||
if (!AccessCheck(uid, args.Session.AttachedEntity, component))
|
||||
{
|
||||
UpdateUI(uid, component);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args.Data)
|
||||
{
|
||||
case GasVentPumpData ventData:
|
||||
foreach (string addr in component.VentData.Keys)
|
||||
{
|
||||
SetData(uid, addr, args.Data);
|
||||
}
|
||||
break;
|
||||
|
||||
case GasVentScrubberData scrubberData:
|
||||
foreach (string addr in component.ScrubberData.Keys)
|
||||
{
|
||||
SetData(uid, addr, args.Data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool AccessCheck(EntityUid uid, EntityUid? user, AirAlarmComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
|
||||
@@ -117,6 +117,17 @@ public sealed class AirAlarmUpdateDeviceDataMessage : BoundUserInterfaceMessage
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmCopyDeviceDataMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public IAtmosDeviceData Data { get; }
|
||||
|
||||
public AirAlarmCopyDeviceDataMessage(IAtmosDeviceData data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmUpdateAlarmThresholdMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
@@ -40,6 +40,8 @@ air-alarm-ui-mode-none = None
|
||||
### General
|
||||
|
||||
air-alarm-ui-widget-enable = Enabled
|
||||
air-alarm-ui-widget-copy = Copy settings to similar devices
|
||||
air-alarm-ui-widget-copy-tooltip = Copies the settings of this device to all devices in this air alarm tab.
|
||||
air-alarm-ui-widget-ignore = Ignore
|
||||
air-alarm-ui-atmos-net-device-label = Address: {$address}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user