Alert level reloads (#8530)
* adds prototype reload for AlertLevelSystem, reorganizes selectable alerts a bit * makes alert levels not necessarily require localization * oops * sus * does the same for announcements as well * oh, that's not how that works at all * ok, NOW it works * fixes localization, adds event for when alerts are reloaded * addresses review
This commit is contained in:
@@ -95,20 +95,29 @@ namespace Content.Client.Communications.UI
|
|||||||
|
|
||||||
if (alerts == null)
|
if (alerts == null)
|
||||||
{
|
{
|
||||||
AlertLevelButton.AddItem(Loc.GetString($"alert-level-{currentAlert}"));
|
var name = currentAlert;
|
||||||
|
if (Loc.TryGetString($"alert-level-{currentAlert}", out var locName))
|
||||||
|
{
|
||||||
|
name = locName;
|
||||||
|
}
|
||||||
|
AlertLevelButton.AddItem(name);
|
||||||
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, currentAlert);
|
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, currentAlert);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var alert in alerts)
|
foreach (var alert in alerts)
|
||||||
{
|
{
|
||||||
AlertLevelButton.AddItem(Loc.GetString($"alert-level-{alert}"));
|
var name = alert;
|
||||||
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, alert);
|
if (Loc.TryGetString($"alert-level-{alert}", out var locName))
|
||||||
|
{
|
||||||
if (alert == currentAlert)
|
name = locName;
|
||||||
{
|
}
|
||||||
AlertLevelButton.Select(AlertLevelButton.ItemCount - 1);
|
AlertLevelButton.AddItem(name);
|
||||||
}
|
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, alert);
|
||||||
|
if (alert == currentAlert)
|
||||||
|
{
|
||||||
|
AlertLevelButton.Select(AlertLevelButton.ItemCount - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,15 @@ public sealed class AlertLevelSystem : EntitySystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialize);
|
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialize);
|
||||||
|
|
||||||
|
_prototypeManager.PrototypesReloaded += OnPrototypeReload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
|
||||||
|
_prototypeManager.PrototypesReloaded -= OnPrototypeReload;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float time)
|
public override void Update(float time)
|
||||||
@@ -67,6 +76,34 @@ public sealed class AlertLevelSystem : EntitySystem
|
|||||||
SetLevel(args.Station, defaultLevel, false, false, true);
|
SetLevel(args.Station, defaultLevel, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnPrototypeReload(PrototypesReloadedEventArgs args)
|
||||||
|
{
|
||||||
|
if (!args.ByType.TryGetValue(typeof(AlertLevelPrototype), out var alertPrototypes)
|
||||||
|
|| !alertPrototypes.Modified.TryGetValue(DefaultAlertLevelSet, out var alertObject)
|
||||||
|
|| alertObject is not AlertLevelPrototype alerts)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var comp in EntityQuery<AlertLevelComponent>())
|
||||||
|
{
|
||||||
|
comp.AlertLevels = alerts;
|
||||||
|
|
||||||
|
if (!comp.AlertLevels.Levels.ContainsKey(comp.CurrentLevel))
|
||||||
|
{
|
||||||
|
var defaultLevel = comp.AlertLevels.DefaultLevel;
|
||||||
|
if (string.IsNullOrEmpty(defaultLevel))
|
||||||
|
{
|
||||||
|
defaultLevel = comp.AlertLevels.Levels.Keys.First();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetLevel(comp.Owner, defaultLevel, true, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RaiseLocalEvent(new AlertLevelPrototypeReloadedEvent());
|
||||||
|
}
|
||||||
|
|
||||||
public float GetAlertLevelDelay(EntityUid station, AlertLevelComponent? alert = null)
|
public float GetAlertLevelDelay(EntityUid station, AlertLevelComponent? alert = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(station, ref alert))
|
if (!Resolve(station, ref alert))
|
||||||
@@ -115,10 +152,20 @@ public sealed class AlertLevelSystem : EntitySystem
|
|||||||
|
|
||||||
var stationName = dataComponent.EntityName;
|
var stationName = dataComponent.EntityName;
|
||||||
|
|
||||||
var name = Loc.GetString($"alert-level-{level}").ToLower();
|
var name = level.ToLower();
|
||||||
|
|
||||||
|
if (Loc.TryGetString($"alert-level-{level}", out var locName))
|
||||||
|
{
|
||||||
|
name = locName.ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
// Announcement text. Is passed into announcementFull.
|
// Announcement text. Is passed into announcementFull.
|
||||||
var announcement = Loc.GetString(detail.Announcement);
|
var announcement = detail.Announcement;
|
||||||
|
|
||||||
|
if (Loc.TryGetString(detail.Announcement, out var locAnnouncement))
|
||||||
|
{
|
||||||
|
announcement = locAnnouncement;
|
||||||
|
}
|
||||||
|
|
||||||
// The full announcement to be spat out into chat.
|
// The full announcement to be spat out into chat.
|
||||||
var announcementFull = Loc.GetString("alert-level-announcement", ("name", name), ("announcement", announcement));
|
var announcementFull = Loc.GetString("alert-level-announcement", ("name", name), ("announcement", announcement));
|
||||||
@@ -150,6 +197,9 @@ public sealed class AlertLevelSystem : EntitySystem
|
|||||||
public sealed class AlertLevelDelayFinishedEvent : EntityEventArgs
|
public sealed class AlertLevelDelayFinishedEvent : EntityEventArgs
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
public sealed class AlertLevelPrototypeReloadedEvent : EntityEventArgs
|
||||||
|
{}
|
||||||
|
|
||||||
public sealed class AlertLevelChangedEvent : EntityEventArgs
|
public sealed class AlertLevelChangedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public string AlertLevel { get; }
|
public string AlertLevel { get; }
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
announcement: alert-level-blue-announcement
|
announcement: alert-level-blue-announcement
|
||||||
sound: /Audio/Misc/notice1.ogg
|
sound: /Audio/Misc/notice1.ogg
|
||||||
color: DodgerBlue
|
color: DodgerBlue
|
||||||
red:
|
|
||||||
announcement: alert-level-red-announcement
|
|
||||||
sound: /Audio/Misc/notice1.ogg
|
|
||||||
color: Red
|
|
||||||
violet:
|
violet:
|
||||||
announcement: alert-level-violet-announcement
|
announcement: alert-level-violet-announcement
|
||||||
sound: /Audio/Misc/notice1.ogg
|
sound: /Audio/Misc/notice1.ogg
|
||||||
@@ -21,6 +17,10 @@
|
|||||||
announcement: alert-level-yellow-announcement
|
announcement: alert-level-yellow-announcement
|
||||||
sound: /Audio/Misc/notice1.ogg
|
sound: /Audio/Misc/notice1.ogg
|
||||||
color: Yellow
|
color: Yellow
|
||||||
|
red:
|
||||||
|
announcement: alert-level-red-announcement
|
||||||
|
sound: /Audio/Misc/notice1.ogg
|
||||||
|
color: Red
|
||||||
gamma:
|
gamma:
|
||||||
announcement: alert-level-gamma-announcement
|
announcement: alert-level-gamma-announcement
|
||||||
selectable: false
|
selectable: false
|
||||||
|
|||||||
Reference in New Issue
Block a user