Station alert levels (#8226)

This commit is contained in:
Flipp Syder
2022-05-17 21:05:31 -07:00
committed by GitHub
parent 2697bbf8c7
commit dcdda39048
21 changed files with 566 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ namespace Content.Client.Communications.UI
public readonly Button AnnounceButton;
public readonly Button EmergencyShuttleButton;
private readonly RichTextLabel _countdownLabel;
public readonly OptionButton AlertLevelButton;
public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
{
@@ -38,6 +39,17 @@ namespace Content.Client.Communications.UI
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(_messageInput.Text.Trim());
AnnounceButton.Disabled = !owner.CanAnnounce;
AlertLevelButton = new OptionButton();
AlertLevelButton.OnItemSelected += args =>
{
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
if (metadata != null && metadata is string cast)
{
Owner.AlertLevelSelected(cast);
}
};
AlertLevelButton.Disabled = !owner.AlertLevelSelectable;
_countdownLabel = new RichTextLabel(){MinSize = new Vector2(0, 200)};
EmergencyShuttleButton = new Button();
EmergencyShuttleButton.OnPressed += (_) => Owner.EmergencyShuttleButtonPressed();
@@ -52,6 +64,7 @@ namespace Content.Client.Communications.UI
vbox.AddChild(_messageInput);
vbox.AddChild(new Control(){MinSize = new Vector2(0,10), HorizontalExpand = true});
vbox.AddChild(AnnounceButton);
vbox.AddChild(AlertLevelButton);
vbox.AddChild(new Control(){MinSize = new Vector2(0,10), HorizontalExpand = true});
vbox.AddChild(_countdownLabel);
vbox.AddChild(EmergencyShuttleButton);
@@ -72,6 +85,34 @@ namespace Content.Client.Communications.UI
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
}
// 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)
{
AlertLevelButton.AddItem(Loc.GetString($"alert-level-{currentAlert}"));
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);
}
}
}
}
public void UpdateCountdown()
{
if (!Owner.CountdownStarted)