Files
tbd-station-14/Content.Client/UserInterface/Systems/Alerts/AlertsUIController.cs
Jezithyr 571dd4e6d5 Hud refactor (#7202)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: Jezithyr <jmaster9999@gmail.com>
Co-authored-by: Jezithyr <Jezithyr@gmail.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: wrexbe <wrexbe@protonmail.com>
Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
2022-10-12 10:16:23 +02:00

59 lines
1.7 KiB
C#

using Content.Client.Alerts;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Systems.Alerts.Widgets;
using Content.Shared.Alert;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
namespace Content.Client.UserInterface.Systems.Alerts;
public sealed class AlertsUIController : UIController, IOnStateEntered<GameplayState>, IOnSystemChanged<ClientAlertsSystem>
{
[UISystemDependency] private readonly ClientAlertsSystem? _alertsSystem = default;
private AlertsUI? UI => UIManager.GetActiveUIWidgetOrNull<AlertsUI>();
private void OnAlertPressed(object? sender, AlertType e)
{
_alertsSystem?.AlertClicked(e);
}
private void SystemOnClearAlerts(object? sender, EventArgs e)
{
UI?.ClearAllControls();
}
private void SystemOnSyncAlerts(object? sender, IReadOnlyDictionary<AlertKey, AlertState> e)
{
if (sender is ClientAlertsSystem system)
UI?.SyncControls(system, system.AlertOrder, e);
}
public void OnSystemLoaded(ClientAlertsSystem system)
{
system.SyncAlerts += SystemOnSyncAlerts;
system.ClearAlerts += SystemOnClearAlerts;
}
public void OnSystemUnloaded(ClientAlertsSystem system)
{
system.SyncAlerts -= SystemOnSyncAlerts;
system.ClearAlerts -= SystemOnClearAlerts;
}
public void OnStateEntered(GameplayState state)
{
if (UI != null)
{
UI.AlertPressed += OnAlertPressed;
}
// initially populate the frame if system is available
var alerts = _alertsSystem?.ActiveAlerts;
if (alerts != null)
{
SystemOnSyncAlerts(_alertsSystem, alerts);
}
}
}