2024-07-21 14:48:13 +10:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using Content.Client.UserInterface.Controls;
|
2024-04-19 20:07:10 -05:00
|
|
|
|
using Content.Shared.CCVar;
|
2023-03-25 07:51:16 -07:00
|
|
|
|
using Robust.Client.AutoGenerated;
|
|
|
|
|
|
using Robust.Client.UserInterface.XAML;
|
2024-04-19 20:07:10 -05:00
|
|
|
|
using Robust.Shared.Configuration;
|
2024-07-21 14:48:13 +10:00
|
|
|
|
using Robust.Shared.Timing;
|
2023-04-14 12:57:47 -07:00
|
|
|
|
using Robust.Shared.Utility;
|
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
|
|
|
|
{
|
2024-04-19 20:07:10 -05:00
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
2024-07-21 14:48:13 +10:00
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
|
[Dependency] private readonly ILocalizationManager _loc = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public bool CanAnnounce;
|
|
|
|
|
|
public bool CanBroadcast;
|
|
|
|
|
|
public bool CanCall;
|
|
|
|
|
|
public bool AlertLevelSelectable;
|
|
|
|
|
|
public bool CountdownStarted;
|
|
|
|
|
|
public string CurrentLevel = string.Empty;
|
|
|
|
|
|
public TimeSpan? CountdownEnd;
|
|
|
|
|
|
|
|
|
|
|
|
public event Action? OnEmergencyLevel;
|
|
|
|
|
|
public event Action<string>? OnAlertLevel;
|
|
|
|
|
|
public event Action<string>? OnAnnounce;
|
|
|
|
|
|
public event Action<string>? OnBroadcast;
|
|
|
|
|
|
|
|
|
|
|
|
public CommunicationsConsoleMenu()
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
2023-03-25 07:51:16 -07:00
|
|
|
|
RobustXamlLoader.Load(this);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
MessageInput.Placeholder = new Rope.Leaf(_loc.GetString("comms-console-menu-announcement-placeholder"));
|
2023-04-14 12:57:47 -07:00
|
|
|
|
|
2024-04-19 20:07:10 -05:00
|
|
|
|
var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
|
|
|
|
|
|
MessageInput.OnTextChanged += (args) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Control.TextLength > maxAnnounceLength)
|
|
|
|
|
|
{
|
|
|
|
|
|
AnnounceButton.Disabled = true;
|
|
|
|
|
|
AnnounceButton.ToolTip = Loc.GetString("comms-console-message-too-long");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
AnnounceButton.Disabled = !CanAnnounce;
|
2024-04-19 20:07:10 -05:00
|
|
|
|
AnnounceButton.ToolTip = null;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
AnnounceButton.OnPressed += _ => OnAnnounce?.Invoke(Rope.Collapse(MessageInput.TextRope));
|
|
|
|
|
|
AnnounceButton.Disabled = !CanAnnounce;
|
2021-03-13 23:21:57 -06:00
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
BroadcastButton.OnPressed += _ => OnBroadcast?.Invoke(Rope.Collapse(MessageInput.TextRope));
|
|
|
|
|
|
BroadcastButton.Disabled = !CanBroadcast;
|
2024-01-27 05:51:24 -08:00
|
|
|
|
|
2022-05-17 21:05:31 -07:00
|
|
|
|
AlertLevelButton.OnItemSelected += args =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
|
|
|
|
|
|
if (metadata != null && metadata is string cast)
|
|
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
OnAlertLevel?.Invoke(cast);
|
2022-05-17 21:05:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
AlertLevelButton.Disabled = !AlertLevelSelectable;
|
|
|
|
|
|
|
|
|
|
|
|
EmergencyShuttleButton.OnPressed += _ => OnEmergencyLevel?.Invoke();
|
|
|
|
|
|
EmergencyShuttleButton.Disabled = !CanCall;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.FrameUpdate(args);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
UpdateCountdown();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
if (!CountdownStarted)
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
CountdownLabel.SetMessage(string.Empty);
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
var diff = MathHelper.Max((CountdownEnd - _timing.CurTime) ?? TimeSpan.Zero, TimeSpan.Zero);
|
|
|
|
|
|
|
2022-06-03 21:37:35 +10:00
|
|
|
|
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-recall-shuttle");
|
2024-07-09 16:36:33 +03:00
|
|
|
|
var infoText = Loc.GetString($"comms-console-menu-time-remaining",
|
2024-08-05 05:16:19 +02:00
|
|
|
|
("time", diff.ToString(@"hh\:mm\:ss", CultureInfo.CurrentCulture)));
|
2024-07-09 16:36:33 +03:00
|
|
|
|
CountdownLabel.SetMessage(infoText);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|