2020-10-06 10:16:42 +02:00
|
|
|
|
using System.Threading;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
2021-07-18 18:39:31 +02:00
|
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
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
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class CommunicationsConsoleMenu : DefaultWindow
|
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();
|
2021-03-13 23:21:57 -06:00
|
|
|
|
private LineEdit _messageInput { get; set; }
|
|
|
|
|
|
public readonly Button AnnounceButton;
|
2021-02-16 09:31:57 +01:00
|
|
|
|
public readonly Button EmergencyShuttleButton;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
private readonly RichTextLabel _countdownLabel;
|
|
|
|
|
|
|
|
|
|
|
|
public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
|
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
|
SetSize = MinSize = (600, 400);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
|
2021-05-21 15:39:33 +02:00
|
|
|
|
Title = Loc.GetString("communicationsconsole-menu-title");
|
2020-04-09 00:28:56 +02:00
|
|
|
|
Owner = owner;
|
|
|
|
|
|
|
2021-03-13 23:21:57 -06:00
|
|
|
|
_messageInput = new LineEdit
|
|
|
|
|
|
{
|
2021-05-21 15:39:33 +02:00
|
|
|
|
PlaceHolder = Loc.GetString("communicationsconsole-menu-announcement-placeholder"),
|
2021-03-13 23:21:57 -06:00
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
SizeFlagsStretchRatio = 1
|
|
|
|
|
|
};
|
|
|
|
|
|
AnnounceButton = new Button();
|
|
|
|
|
|
AnnounceButton.Text = "Announce";
|
|
|
|
|
|
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(_messageInput.Text.Trim());
|
|
|
|
|
|
AnnounceButton.Disabled = !owner.CanAnnounce;
|
|
|
|
|
|
|
2021-02-21 12:38:56 +01:00
|
|
|
|
_countdownLabel = new RichTextLabel(){MinSize = new Vector2(0, 200)};
|
2021-02-16 09:31:57 +01:00
|
|
|
|
EmergencyShuttleButton = new Button();
|
|
|
|
|
|
EmergencyShuttleButton.OnPressed += (_) => Owner.EmergencyShuttleButtonPressed();
|
|
|
|
|
|
EmergencyShuttleButton.Disabled = !owner.CanCall;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
|
var vbox = new BoxContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
Orientation = LayoutOrientation.Vertical,
|
|
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
VerticalExpand = true
|
|
|
|
|
|
};
|
2021-03-13 23:21:57 -06:00
|
|
|
|
vbox.AddChild(_messageInput);
|
|
|
|
|
|
vbox.AddChild(new Control(){MinSize = new Vector2(0,10), HorizontalExpand = true});
|
|
|
|
|
|
vbox.AddChild(AnnounceButton);
|
|
|
|
|
|
vbox.AddChild(new Control(){MinSize = new Vector2(0,10), HorizontalExpand = true});
|
2020-04-09 00:28:56 +02:00
|
|
|
|
vbox.AddChild(_countdownLabel);
|
2021-02-16 09:31:57 +01:00
|
|
|
|
vbox.AddChild(EmergencyShuttleButton);
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
|
var hbox = new BoxContainer
|
|
|
|
|
|
{
|
|
|
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
|
|
|
|
HorizontalExpand = true,
|
|
|
|
|
|
VerticalExpand = true
|
|
|
|
|
|
};
|
2021-02-21 12:38:56 +01:00
|
|
|
|
hbox.AddChild(new Control(){MinSize = new Vector2(100,0), HorizontalExpand = true});
|
2020-04-09 00:28:56 +02:00
|
|
|
|
hbox.AddChild(vbox);
|
2021-02-21 12:38:56 +01:00
|
|
|
|
hbox.AddChild(new Control(){MinSize = new Vector2(100,0), HorizontalExpand = true});
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
Contents.AddChild(hbox);
|
|
|
|
|
|
|
|
|
|
|
|
UpdateCountdown();
|
|
|
|
|
|
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-10 13:36:30 +02:00
|
|
|
|
public void UpdateCountdown()
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!Owner.CountdownStarted)
|
|
|
|
|
|
{
|
|
|
|
|
|
_countdownLabel.SetMessage("");
|
2021-05-21 15:39:33 +02:00
|
|
|
|
EmergencyShuttleButton.Text = Loc.GetString("communicationsconsole-menu-call-shuttle");
|
2020-04-09 00:28:56 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-21 15:39:33 +02:00
|
|
|
|
EmergencyShuttleButton.Text = Loc.GetString("communicationsconsole-menu-recall-shuttle");
|
2020-04-09 00:28:56 +02:00
|
|
|
|
_countdownLabel.SetMessage($"Time remaining\n{Owner.Countdown.ToString()}s");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|