* add Guard Bell * revert vanila changes, add same functionality * revert more vanila changes, replace .ogg, fix locale and locale usage * Update GuardBell.yml * Update base.yml * add attributions.yml for alerts * try changing to proper license --------- Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com>
87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using System.Globalization;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.CCVar;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._CP14.UserInterface
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class GuardBellMenu : FancyWindow
|
|
{
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly ILocalizationManager _loc = default!;
|
|
|
|
public bool AlertLevelSelectable;
|
|
public string CurrentLevel = string.Empty;
|
|
|
|
|
|
public event Action<string>? OnAlertLevel;
|
|
|
|
public GuardBellMenu()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
AlertLevelButton.OnItemSelected += args =>
|
|
{
|
|
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
|
|
if (metadata != null && metadata is string cast)
|
|
{
|
|
OnAlertLevel?.Invoke(cast);
|
|
}
|
|
};
|
|
|
|
|
|
AlertLevelButton.Disabled = !AlertLevelSelectable;
|
|
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
}
|
|
|
|
// The current alert could make levels unselectable, so we need to ensure that the UI reacts properly.
|
|
// If the current alert is unselectable, the only item in the alerts list will be
|
|
// the current alert. Otherwise, it will be the list of alerts, with the current alert
|
|
// selected.
|
|
public void UpdateAlertLevels(List<string>? alerts, string currentAlert)
|
|
{
|
|
AlertLevelButton.Clear();
|
|
|
|
if (alerts == null)
|
|
{
|
|
var name = currentAlert;
|
|
if (_loc.TryGetString($"cp14-alert-level-{currentAlert}", out var locName))
|
|
{
|
|
name = locName;
|
|
}
|
|
AlertLevelButton.AddItem(name);
|
|
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, currentAlert);
|
|
}
|
|
else
|
|
{
|
|
foreach (var alert in alerts)
|
|
{
|
|
var name = alert;
|
|
if (_loc.TryGetString($"cp14-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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|