2022-01-01 20:56:24 -08:00
|
|
|
using Content.Shared.Atmos;
|
|
|
|
|
using Content.Shared.Atmos.Monitor;
|
|
|
|
|
using Content.Shared.Atmos.Monitor.Components;
|
|
|
|
|
using Robust.Client.GameObjects;
|
2024-07-21 14:48:13 +10:00
|
|
|
using Robust.Client.UserInterface;
|
2022-01-01 20:56:24 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
namespace Content.Client.Atmos.Monitor.UI;
|
|
|
|
|
|
|
|
|
|
public sealed class AirAlarmBoundUserInterface : BoundUserInterface
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
private AirAlarmWindow? _window;
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
public AirAlarmBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2022-08-29 07:37:26 -07:00
|
|
|
{
|
|
|
|
|
}
|
2022-08-23 10:55:46 -07:00
|
|
|
|
|
|
|
|
protected override void Open()
|
2022-01-01 20:56:24 -08:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
base.Open();
|
2022-08-23 13:24:39 -07:00
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
_window = this.CreateWindow<AirAlarmWindow>();
|
|
|
|
|
_window.SetEntity(Owner);
|
2022-08-23 13:24:39 -07:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
_window.AtmosDeviceDataChanged += OnDeviceDataChanged;
|
2023-08-09 22:20:19 +04:00
|
|
|
_window.AtmosDeviceDataCopied += OnDeviceDataCopied;
|
2022-08-23 10:55:46 -07:00
|
|
|
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
|
|
|
|
|
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
|
2023-07-09 22:22:41 +03:00
|
|
|
_window.AutoModeChanged += OnAutoModeChanged;
|
2022-08-23 10:55:46 -07:00
|
|
|
_window.ResyncAllRequested += ResyncAllDevices;
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void ResyncAllDevices()
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmResyncAllDevicesMessage());
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnDeviceDataChanged(string address, IAtmosDeviceData data)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
|
2023-08-09 22:20:19 +04:00
|
|
|
}
|
2023-09-11 21:20:46 +10:00
|
|
|
|
2023-08-09 22:20:19 +04:00
|
|
|
private void OnDeviceDataCopied(IAtmosDeviceData data)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmCopyDeviceDataMessage(data));
|
2022-08-23 10:55:46 -07:00
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnAirAlarmModeChanged(AirAlarmMode mode)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmUpdateAlarmModeMessage(mode));
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2023-07-09 22:22:41 +03:00
|
|
|
private void OnAutoModeChanged(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmUpdateAutoModeMessage(enabled));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
private void OnThresholdChanged(string address, AtmosMonitorThresholdType type, AtmosAlarmThreshold threshold, Gas? gas = null)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new AirAlarmUpdateAlarmThresholdMessage(address, type, threshold, gas));
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
if (state is not AirAlarmUIState cast || _window == null)
|
2022-08-18 08:14:18 -07:00
|
|
|
{
|
2022-08-23 10:55:46 -07:00
|
|
|
return;
|
2022-08-18 08:14:18 -07:00
|
|
|
}
|
|
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
_window.UpdateState(cast);
|
|
|
|
|
}
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2022-01-01 20:56:24 -08:00
|
|
|
|
2022-08-23 10:55:46 -07:00
|
|
|
if (disposing) _window?.Dispose();
|
2022-01-01 20:56:24 -08:00
|
|
|
}
|
|
|
|
|
}
|