diff --git a/Content.Client/Communications/UI/CommunicationsConsoleMenu.cs b/Content.Client/Communications/UI/CommunicationsConsoleMenu.cs index 66de4561f0..bee292b026 100644 --- a/Content.Client/Communications/UI/CommunicationsConsoleMenu.cs +++ b/Content.Client/Communications/UI/CommunicationsConsoleMenu.cs @@ -95,20 +95,29 @@ namespace Content.Client.Communications.UI 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); } else { foreach (var alert in alerts) { - AlertLevelButton.AddItem(Loc.GetString($"alert-level-{alert}")); - AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, alert); - - if (alert == currentAlert) - { - AlertLevelButton.Select(AlertLevelButton.ItemCount - 1); - } + var name = alert; + if (Loc.TryGetString($"alert-level-{alert}", out var locName)) + { + name = locName; + } + AlertLevelButton.AddItem(name); + AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, alert); + if (alert == currentAlert) + { + AlertLevelButton.Select(AlertLevelButton.ItemCount - 1); + } } } } diff --git a/Content.Server/AlertLevel/AlertLevelSystem.cs b/Content.Server/AlertLevel/AlertLevelSystem.cs index 026c5de86d..e3a03250ba 100644 --- a/Content.Server/AlertLevel/AlertLevelSystem.cs +++ b/Content.Server/AlertLevel/AlertLevelSystem.cs @@ -22,6 +22,15 @@ public sealed class AlertLevelSystem : EntitySystem public override void Initialize() { SubscribeLocalEvent(OnStationInitialize); + + _prototypeManager.PrototypesReloaded += OnPrototypeReload; + } + + public override void Shutdown() + { + base.Shutdown(); + + _prototypeManager.PrototypesReloaded -= OnPrototypeReload; } public override void Update(float time) @@ -67,6 +76,34 @@ public sealed class AlertLevelSystem : EntitySystem 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()) + { + 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) { if (!Resolve(station, ref alert)) @@ -115,10 +152,20 @@ public sealed class AlertLevelSystem : EntitySystem 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. - 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. 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 AlertLevelPrototypeReloadedEvent : EntityEventArgs +{} + public sealed class AlertLevelChangedEvent : EntityEventArgs { public string AlertLevel { get; } diff --git a/Resources/Prototypes/AlertLevels/alert_levels.yml b/Resources/Prototypes/AlertLevels/alert_levels.yml index 4b6e3a7780..ab84b09feb 100644 --- a/Resources/Prototypes/AlertLevels/alert_levels.yml +++ b/Resources/Prototypes/AlertLevels/alert_levels.yml @@ -9,10 +9,6 @@ announcement: alert-level-blue-announcement sound: /Audio/Misc/notice1.ogg color: DodgerBlue - red: - announcement: alert-level-red-announcement - sound: /Audio/Misc/notice1.ogg - color: Red violet: announcement: alert-level-violet-announcement sound: /Audio/Misc/notice1.ogg @@ -21,6 +17,10 @@ announcement: alert-level-yellow-announcement sound: /Audio/Misc/notice1.ogg color: Yellow + red: + announcement: alert-level-red-announcement + sound: /Audio/Misc/notice1.ogg + color: Red gamma: announcement: alert-level-gamma-announcement selectable: false