2023-03-25 07:51:16 -07:00
|
|
|
|
using Content.Client.UserInterface.Controls;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using Robust.Client.AutoGenerated;
|
|
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
2023-04-14 12:57:47 -07:00
|
|
|
|
using Robust.Shared.Utility;
|
2021-02-18 20:45:45 -08:00
|
|
|
|
using Timer = Robust.Shared.Timing.Timer;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Communications.UI
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
2023-03-25 07:51:16 -07:00
|
|
|
|
[GenerateTypedNameReferences]
|
|
|
|
|
|
public sealed partial class CommunicationsConsoleMenu : FancyWindow
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
private CommunicationsConsoleBoundUserInterface Owner { get; set; }
|
2020-11-27 11:00:49 +01:00
|
|
|
|
private readonly CancellationTokenSource _timerCancelTokenSource = new();
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
|
|
|
|
|
|
{
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
2023-03-25 07:51:16 -07:00
|
|
|
|
RobustXamlLoader.Load(this);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
Owner = owner;
|
|
|
|
|
|
|
2023-04-14 12:57:47 -07:00
|
|
|
|
var loc = IoCManager.Resolve<ILocalizationManager>();
|
|
|
|
|
|
MessageInput.Placeholder = new Rope.Leaf(loc.GetString("comms-console-menu-announcement-placeholder"));
|
|
|
|
|
|
|
2024-01-21 13:14:01 +04:00
|
|
|
|
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope));
|
2021-03-13 23:21:57 -06:00
|
|
|
|
AnnounceButton.Disabled = !owner.CanAnnounce;
|
|
|
|
|
|
|
2024-01-27 05:51:24 -08:00
|
|
|
|
BroadcastButton.OnPressed += (_) => Owner.BroadcastButtonPressed(Rope.Collapse(MessageInput.TextRope));
|
|
|
|
|
|
BroadcastButton.Disabled = !owner.CanBroadcast;
|
|
|
|
|
|
|
2022-05-17 21:05:31 -07:00
|
|
|
|
AlertLevelButton.OnItemSelected += args =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
|
|
|
|
|
|
if (metadata != null && metadata is string cast)
|
|
|
|
|
|
{
|
|
|
|
|
|
Owner.AlertLevelSelected(cast);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
AlertLevelButton.Disabled = !owner.AlertLevelSelectable;
|
|
|
|
|
|
|
2021-02-16 09:31:57 +01:00
|
|
|
|
EmergencyShuttleButton.OnPressed += (_) => Owner.EmergencyShuttleButtonPressed();
|
|
|
|
|
|
EmergencyShuttleButton.Disabled = !owner.CanCall;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
UpdateCountdown();
|
|
|
|
|
|
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-17 21:05:31 -07:00
|
|
|
|
// 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)
|
|
|
|
|
|
{
|
2022-06-01 00:40:11 -07:00
|
|
|
|
var name = currentAlert;
|
|
|
|
|
|
if (Loc.TryGetString($"alert-level-{currentAlert}", out var locName))
|
|
|
|
|
|
{
|
|
|
|
|
|
name = locName;
|
|
|
|
|
|
}
|
|
|
|
|
|
AlertLevelButton.AddItem(name);
|
2022-05-17 21:05:31 -07:00
|
|
|
|
AlertLevelButton.SetItemMetadata(AlertLevelButton.ItemCount - 1, currentAlert);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var alert in alerts)
|
|
|
|
|
|
{
|
2022-06-01 00:40:11 -07:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2022-05-17 21:05:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-10 13:36:30 +02:00
|
|
|
|
public void UpdateCountdown()
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!Owner.CountdownStarted)
|
|
|
|
|
|
{
|
2023-03-25 07:51:16 -07:00
|
|
|
|
CountdownLabel.SetMessage("");
|
2022-06-03 21:37:35 +10:00
|
|
|
|
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-call-shuttle");
|
2020-04-09 00:28:56 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-03 21:37:35 +10:00
|
|
|
|
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-recall-shuttle");
|
2023-03-25 07:51:16 -07:00
|
|
|
|
CountdownLabel.SetMessage($"Time remaining\n{Owner.Countdown.ToString()}s");
|
2020-04-09 00:28:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Close();
|
|
|
|
|
|
|
|
|
|
|
|
_timerCancelTokenSource.Cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
|
{
|
2020-10-06 10:16:42 +02:00
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
|
|
|
|
|
|
|
if (disposing)
|
2020-04-09 00:28:56 +02:00
|
|
|
|
_timerCancelTokenSource.Cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|