Files
crystall-punk-14/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs

84 lines
2.3 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
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-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-23 10:55:46 -07:00
protected override void Open()
{
2022-08-23 10:55:46 -07:00
base.Open();
2022-08-23 13:24:39 -07: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;
_window.AtmosDeviceDataCopied += OnDeviceDataCopied;
2022-08-23 10:55:46 -07:00
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
_window.AirAlarmModeChanged += OnAirAlarmModeChanged;
_window.AutoModeChanged += OnAutoModeChanged;
2022-08-23 10:55:46 -07:00
_window.ResyncAllRequested += ResyncAllDevices;
}
2022-08-23 10:55:46 -07:00
private void ResyncAllDevices()
{
SendMessage(new AirAlarmResyncAllDevicesMessage());
}
2022-08-23 10:55:46 -07:00
private void OnDeviceDataChanged(string address, IAtmosDeviceData data)
{
SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
}
2023-09-11 21:20:46 +10:00
private void OnDeviceDataCopied(IAtmosDeviceData data)
{
SendMessage(new AirAlarmCopyDeviceDataMessage(data));
2022-08-23 10:55:46 -07:00
}
2022-08-23 10:55:46 -07:00
private void OnAirAlarmModeChanged(AirAlarmMode mode)
{
SendMessage(new AirAlarmUpdateAlarmModeMessage(mode));
}
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-08-23 10:55:46 -07:00
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
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-08-23 10:55:46 -07:00
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
2022-08-23 10:55:46 -07:00
if (disposing) _window?.Dispose();
}
}