Add 'auto mode' button to the air alarm ui (#17874)
Signed-off-by: c4llv07e <kseandi@gmail.com>
This commit is contained in:
@@ -33,6 +33,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
_window.AtmosDeviceDataChanged += OnDeviceDataChanged;
|
||||
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
|
||||
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
|
||||
_window.AutoModeChanged += OnAutoModeChanged;
|
||||
_window.ResyncAllRequested += ResyncAllDevices;
|
||||
_window.AirAlarmTabChange += OnTabChanged;
|
||||
}
|
||||
@@ -52,6 +53,11 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
||||
SendMessage(new AirAlarmUpdateAlarmModeMessage(mode));
|
||||
}
|
||||
|
||||
private void OnAutoModeChanged(bool enabled)
|
||||
{
|
||||
SendMessage(new AirAlarmUpdateAutoModeMessage(enabled));
|
||||
}
|
||||
|
||||
private void OnThresholdChanged(string address, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null)
|
||||
{
|
||||
SendMessage(new AirAlarmUpdateAlarmThresholdMessage(address, type, threshold, gas));
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Label Text="{Loc 'air-alarm-ui-window-mode-label'}" Margin="0 0 2 0" />
|
||||
<OptionButton Name="CModeButton" HorizontalExpand="True" />
|
||||
<CheckBox Name="AutoModeCheckBox" Text="{Loc 'air-alarm-ui-window-auto-mode-label'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</ui:FancyWindow>
|
||||
|
||||
@@ -20,6 +20,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
public event Action<string, IAtmosDeviceData>? AtmosDeviceDataChanged;
|
||||
public event Action<string, AtmosMonitorThresholdType, AtmosAlarmThreshold, Gas?>? AtmosAlarmThresholdChanged;
|
||||
public event Action<AirAlarmMode>? AirAlarmModeChanged;
|
||||
public event Action<bool>? AutoModeChanged;
|
||||
public event Action<string>? ResyncDeviceRequested;
|
||||
public event Action? ResyncAllRequested;
|
||||
public event Action<AirAlarmTab>? AirAlarmTabChange;
|
||||
@@ -44,6 +45,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
|
||||
private OptionButton _modes => CModeButton;
|
||||
|
||||
private CheckBox _autoMode => AutoModeCheckBox;
|
||||
|
||||
public AirAlarmWindow(BoundUserInterface owner)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
@@ -68,6 +71,11 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
AirAlarmModeChanged!.Invoke((AirAlarmMode) args.Id);
|
||||
};
|
||||
|
||||
_autoMode.OnToggled += args =>
|
||||
{
|
||||
AutoModeChanged!.Invoke(_autoMode.Pressed);
|
||||
};
|
||||
|
||||
_tabContainer.SetTabTitle(0, Loc.GetString("air-alarm-ui-window-tab-vents"));
|
||||
_tabContainer.SetTabTitle(1, Loc.GetString("air-alarm-ui-window-tab-scrubbers"));
|
||||
_tabContainer.SetTabTitle(2, Loc.GetString("air-alarm-ui-window-tab-sensors"));
|
||||
@@ -101,6 +109,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
("color", ColorForAlarm(state.AlarmType)),
|
||||
("state", $"{state.AlarmType}")));
|
||||
UpdateModeSelector(state.Mode);
|
||||
UpdateAutoMode(state.AutoMode);
|
||||
foreach (var (addr, dev) in state.DeviceData)
|
||||
{
|
||||
UpdateDeviceData(addr, dev);
|
||||
@@ -114,6 +123,11 @@ public sealed partial class AirAlarmWindow : FancyWindow
|
||||
_modes.SelectId((int) mode);
|
||||
}
|
||||
|
||||
public void UpdateAutoMode(bool enabled)
|
||||
{
|
||||
_autoMode.Pressed = enabled;
|
||||
}
|
||||
|
||||
public void UpdateDeviceData(string addr, IAtmosDeviceData device)
|
||||
{
|
||||
switch (device)
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Content.Server.Atmos.Monitor.Components;
|
||||
public sealed class AirAlarmComponent : Component
|
||||
{
|
||||
[ViewVariables] public AirAlarmMode CurrentMode { get; set; } = AirAlarmMode.Filtering;
|
||||
[ViewVariables] public bool AutoMode { get; set; } = true;
|
||||
|
||||
// Remember to null this afterwards.
|
||||
[ViewVariables] public IAirAlarmModeUpdate? CurrentModeUpdater { get; set; }
|
||||
|
||||
@@ -157,6 +157,7 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
SubscribeLocalEvent<AirAlarmComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmResyncAllDevicesMessage>(OnResyncAll);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateAlarmModeMessage>(OnUpdateAlarmMode);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateAutoModeMessage>(OnUpdateAutoMode);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateAlarmThresholdMessage>(OnUpdateThreshold);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmUpdateDeviceDataMessage>(OnUpdateDeviceData);
|
||||
SubscribeLocalEvent<AirAlarmComponent, AirAlarmTabSetMessage>(OnTabChange);
|
||||
@@ -273,6 +274,12 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
UpdateUI(uid, component);
|
||||
}
|
||||
|
||||
private void OnUpdateAutoMode(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAutoModeMessage args)
|
||||
{
|
||||
component.AutoMode = args.Enabled;
|
||||
UpdateUI(uid, component);
|
||||
}
|
||||
|
||||
private void OnUpdateThreshold(EntityUid uid, AirAlarmComponent component, AirAlarmUpdateAlarmThresholdMessage args)
|
||||
{
|
||||
if (AccessCheck(uid, args.Session.AttachedEntity, component))
|
||||
@@ -317,6 +324,8 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
if (EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn))
|
||||
addr = netConn.Address;
|
||||
|
||||
if (component.AutoMode)
|
||||
{
|
||||
if (args.AlarmType == AtmosAlarmType.Danger)
|
||||
{
|
||||
SetMode(uid, addr, AirAlarmMode.WideFiltering, false);
|
||||
@@ -325,6 +334,7 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
{
|
||||
SetMode(uid, addr, AirAlarmMode.Filtering, false);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateUI(uid, component);
|
||||
}
|
||||
@@ -545,7 +555,7 @@ public sealed class AirAlarmSystem : EntitySystem
|
||||
_uiSystem.TrySetUiState(
|
||||
uid,
|
||||
SharedAirAlarmInterfaceKey.Key,
|
||||
new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, highestAlarm.Value));
|
||||
new AirAlarmUIState(devNet.Address, deviceCount, pressure, temperature, dataToSend, alarm.CurrentMode, alarm.CurrentTab, highestAlarm.Value, alarm.AutoMode));
|
||||
}
|
||||
|
||||
private const float Delay = 8f;
|
||||
|
||||
@@ -37,7 +37,7 @@ public interface IAtmosDeviceData
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
{
|
||||
public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosAlarmType alarmType)
|
||||
public AirAlarmUIState(string address, int deviceCount, float pressureAverage, float temperatureAverage, Dictionary<string, IAtmosDeviceData> deviceData, AirAlarmMode mode, AirAlarmTab tab, AtmosAlarmType alarmType, bool autoMode)
|
||||
{
|
||||
Address = address;
|
||||
DeviceCount = deviceCount;
|
||||
@@ -47,6 +47,7 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
Mode = mode;
|
||||
Tab = tab;
|
||||
AlarmType = alarmType;
|
||||
AutoMode = autoMode;
|
||||
}
|
||||
|
||||
public string Address { get; }
|
||||
@@ -63,6 +64,7 @@ public sealed class AirAlarmUIState : BoundUserInterfaceState
|
||||
public AirAlarmMode Mode { get; }
|
||||
public AirAlarmTab Tab { get; }
|
||||
public AtmosAlarmType AlarmType { get; }
|
||||
public bool AutoMode { get; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
@@ -91,6 +93,17 @@ public sealed class AirAlarmUpdateAlarmModeMessage : BoundUserInterfaceMessage
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmUpdateAutoModeMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public bool Enabled { get; }
|
||||
|
||||
public AirAlarmUpdateAutoModeMessage(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AirAlarmUpdateDeviceDataMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ air-alarm-ui-window-device-count-label = Total Devices
|
||||
air-alarm-ui-window-resync-devices-label = Resync
|
||||
|
||||
air-alarm-ui-window-mode-label = Mode
|
||||
air-alarm-ui-window-auto-mode-label = Auto mode
|
||||
|
||||
air-alarm-ui-window-pressure = {$pressure} kPa
|
||||
air-alarm-ui-window-pressure-indicator = Pressure: [color={$color}]{$pressure} kPa[/color]
|
||||
|
||||
Reference in New Issue
Block a user