mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
Uses the following Cherry-Picks: https://github.com/space-wizards/space-station-14/pull/26994 https://github.com/space-wizards/space-station-14/pull/26518 https://github.com/space-wizards/space-station-14/pull/26279 https://github.com/space-wizards/space-station-14/pull/24946 https://github.com/space-wizards/space-station-14/pull/27188 Requires: https://github.com/Simple-Station/Einstein-Engines/pull/535 https://github.com/Simple-Station/Einstein-Engines/pull/534 --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: Jake Huxell <JakeHuxell@pm.me> Co-authored-by: Tayrtahn <tayrtahn@gmail.com> Co-authored-by: 0x6273 <0x40@keemail.me> Co-authored-by: DEATHB4DEFEAT <zachcaffee@outlook.com>
99 lines
2.9 KiB
C#
99 lines
2.9 KiB
C#
using System.Linq;
|
|
using Content.Shared.Alert;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Alerts;
|
|
|
|
[UsedImplicitly]
|
|
public sealed class ClientAlertsSystem : AlertsSystem
|
|
{
|
|
public AlertOrderPrototype? AlertOrder { get; set; }
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
public event EventHandler? ClearAlerts;
|
|
public event EventHandler<IReadOnlyDictionary<AlertKey, AlertState>>? SyncAlerts;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<AlertsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<AlertsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
SubscribeLocalEvent<AlertsComponent, AfterAutoHandleStateEvent>(ClientAlertsHandleState);
|
|
}
|
|
protected override void LoadPrototypes()
|
|
{
|
|
base.LoadPrototypes();
|
|
|
|
AlertOrder = _prototypeManager.EnumeratePrototypes<AlertOrderPrototype>().FirstOrDefault();
|
|
if (AlertOrder == null)
|
|
Log.Error("No alertOrder prototype found, alerts will be in random order");
|
|
}
|
|
|
|
public IReadOnlyDictionary<AlertKey, AlertState>? ActiveAlerts
|
|
{
|
|
get
|
|
{
|
|
var ent = _playerManager.LocalEntity;
|
|
return ent is not null
|
|
? GetActiveAlerts(ent.Value)
|
|
: null;
|
|
}
|
|
}
|
|
|
|
protected override void AfterShowAlert(Entity<AlertsComponent> alerts)
|
|
{
|
|
UpdateHud(alerts);
|
|
}
|
|
|
|
protected override void AfterClearAlert(Entity<AlertsComponent> alerts)
|
|
{
|
|
UpdateHud(alerts);
|
|
}
|
|
|
|
private void ClientAlertsHandleState(Entity<AlertsComponent> alerts, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
UpdateHud(alerts);
|
|
}
|
|
|
|
private void UpdateHud(Entity<AlertsComponent> entity)
|
|
{
|
|
if (_playerManager.LocalEntity == entity.Owner)
|
|
SyncAlerts?.Invoke(this, entity.Comp.Alerts);
|
|
}
|
|
|
|
private void OnPlayerAttached(EntityUid uid, AlertsComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
if (_playerManager.LocalEntity != uid)
|
|
return;
|
|
|
|
SyncAlerts?.Invoke(this, component.Alerts);
|
|
}
|
|
|
|
protected override void HandleComponentShutdown(EntityUid uid, AlertsComponent component, ComponentShutdown args)
|
|
{
|
|
base.HandleComponentShutdown(uid, component, args);
|
|
|
|
if (_playerManager.LocalEntity != uid)
|
|
return;
|
|
|
|
ClearAlerts?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
private void OnPlayerDetached(EntityUid uid, AlertsComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
ClearAlerts?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
public void AlertClicked(AlertType alertType)
|
|
{
|
|
RaiseNetworkEvent(new ClickAlertEvent(alertType));
|
|
}
|
|
}
|