Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Content.Shared.Communications;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.Communications.UI
|
||||
{
|
||||
public class CommunicationsConsoleBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[ViewVariables] private CommunicationsConsoleMenu? _menu;
|
||||
|
||||
public bool CanAnnounce { get; private set; }
|
||||
public bool CanCall { get; private set; }
|
||||
|
||||
public bool CountdownStarted { get; private set; }
|
||||
|
||||
public int Countdown => _expectedCountdownTime == null
|
||||
? 0 : Math.Max((int)_expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
|
||||
private TimeSpan? _expectedCountdownTime;
|
||||
|
||||
public CommunicationsConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_menu = new CommunicationsConsoleMenu(this);
|
||||
_menu.OnClose += Close;
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
public void EmergencyShuttleButtonPressed()
|
||||
{
|
||||
if (CountdownStarted)
|
||||
RecallShuttle();
|
||||
else
|
||||
CallShuttle();
|
||||
}
|
||||
|
||||
public void AnnounceButtonPressed(string message)
|
||||
{
|
||||
var msg = message.Length <= 256 ? message.Trim() : $"{message.Trim().Substring(0, 256)}...";
|
||||
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
|
||||
}
|
||||
|
||||
public void CallShuttle()
|
||||
{
|
||||
SendMessage(new CommunicationsConsoleCallEmergencyShuttleMessage());
|
||||
}
|
||||
|
||||
public void RecallShuttle()
|
||||
{
|
||||
SendMessage(new CommunicationsConsoleRecallEmergencyShuttleMessage());
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (state is not CommunicationsConsoleInterfaceState commsState)
|
||||
return;
|
||||
|
||||
CanAnnounce = commsState.CanAnnounce;
|
||||
CanCall = commsState.CanCall;
|
||||
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
|
||||
CountdownStarted = commsState.CountdownStarted;
|
||||
|
||||
if (_menu != null)
|
||||
{
|
||||
_menu.UpdateCountdown();
|
||||
_menu.EmergencyShuttleButton.Disabled = !CanCall;
|
||||
_menu.AnnounceButton.Disabled = !CanAnnounce;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
|
||||
_menu?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Threading;
|
||||
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;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Content.Client.Communications.UI
|
||||
{
|
||||
public class CommunicationsConsoleMenu : SS14Window
|
||||
{
|
||||
private CommunicationsConsoleBoundUserInterface Owner { get; set; }
|
||||
private readonly CancellationTokenSource _timerCancelTokenSource = new();
|
||||
private LineEdit _messageInput { get; set; }
|
||||
public readonly Button AnnounceButton;
|
||||
public readonly Button EmergencyShuttleButton;
|
||||
private readonly RichTextLabel _countdownLabel;
|
||||
|
||||
public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
|
||||
{
|
||||
SetSize = MinSize = (600, 400);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Title = Loc.GetString("communicationsconsole-menu-title");
|
||||
Owner = owner;
|
||||
|
||||
_messageInput = new LineEdit
|
||||
{
|
||||
PlaceHolder = Loc.GetString("communicationsconsole-menu-announcement-placeholder"),
|
||||
HorizontalExpand = true,
|
||||
SizeFlagsStretchRatio = 1
|
||||
};
|
||||
AnnounceButton = new Button();
|
||||
AnnounceButton.Text = "Announce";
|
||||
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(_messageInput.Text.Trim());
|
||||
AnnounceButton.Disabled = !owner.CanAnnounce;
|
||||
|
||||
_countdownLabel = new RichTextLabel(){MinSize = new Vector2(0, 200)};
|
||||
EmergencyShuttleButton = new Button();
|
||||
EmergencyShuttleButton.OnPressed += (_) => Owner.EmergencyShuttleButtonPressed();
|
||||
EmergencyShuttleButton.Disabled = !owner.CanCall;
|
||||
|
||||
var vbox = new VBoxContainer() {HorizontalExpand = true, VerticalExpand = true};
|
||||
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});
|
||||
vbox.AddChild(_countdownLabel);
|
||||
vbox.AddChild(EmergencyShuttleButton);
|
||||
|
||||
var hbox = new HBoxContainer() {HorizontalExpand = true, VerticalExpand = true};
|
||||
hbox.AddChild(new Control(){MinSize = new Vector2(100,0), HorizontalExpand = true});
|
||||
hbox.AddChild(vbox);
|
||||
hbox.AddChild(new Control(){MinSize = new Vector2(100,0), HorizontalExpand = true});
|
||||
|
||||
Contents.AddChild(hbox);
|
||||
|
||||
UpdateCountdown();
|
||||
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
|
||||
}
|
||||
|
||||
public void UpdateCountdown()
|
||||
{
|
||||
if (!Owner.CountdownStarted)
|
||||
{
|
||||
_countdownLabel.SetMessage("");
|
||||
EmergencyShuttleButton.Text = Loc.GetString("communicationsconsole-menu-call-shuttle");
|
||||
return;
|
||||
}
|
||||
|
||||
EmergencyShuttleButton.Text = Loc.GetString("communicationsconsole-menu-recall-shuttle");
|
||||
_countdownLabel.SetMessage($"Time remaining\n{Owner.Countdown.ToString()}s");
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
base.Close();
|
||||
|
||||
_timerCancelTokenSource.Cancel();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
_timerCancelTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user