Adds working communications console that ends the round

This commit is contained in:
zumorica
2020-04-09 00:28:56 +02:00
parent 45e9be43ef
commit 64eafde0c3
8 changed files with 353 additions and 18 deletions

View File

@@ -0,0 +1,78 @@
using System.Threading;
using Content.Client.GameObjects.Components.Command;
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.Timers.Timer;
namespace Content.Client.Command
{
public class CommunicationsConsoleMenu : SS14Window
{
#pragma warning disable 649
[Dependency] private readonly ILocalizationManager _localizationManager;
#pragma warning restore 649
protected override Vector2? CustomSize => new Vector2(600, 400);
private CommunicationsConsoleBoundUserInterface Owner { get; set; }
private readonly CancellationTokenSource _timerCancelTokenSource = new CancellationTokenSource();
private readonly RichTextLabel _countdownLabel;
public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
Title = _localizationManager.GetString("Communications Console");
Owner = owner;
_countdownLabel = new RichTextLabel(){CustomMinimumSize = new Vector2(0, 200)};
var emergencyShuttleButton = new Button() {Text = _localizationManager.GetString("Call emergency shuttle")};
emergencyShuttleButton.OnPressed += (e) => Owner.CallShuttle();
var vbox = new VBoxContainer() {SizeFlagsHorizontal = SizeFlags.FillExpand, SizeFlagsVertical = SizeFlags.FillExpand};
vbox.AddChild(_countdownLabel);
vbox.AddChild(emergencyShuttleButton);
var hbox = new HBoxContainer() {SizeFlagsHorizontal = SizeFlags.FillExpand, SizeFlagsVertical = SizeFlags.FillExpand};
hbox.AddChild(new Control(){CustomMinimumSize = new Vector2(100,0), SizeFlagsHorizontal = SizeFlags.FillExpand});
hbox.AddChild(vbox);
hbox.AddChild(new Control(){CustomMinimumSize = new Vector2(100,0), SizeFlagsHorizontal = SizeFlags.FillExpand});
Contents.AddChild(hbox);
UpdateCountdown();
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
}
private void UpdateCountdown()
{
if (!Owner.CountdownStarted)
{
_countdownLabel.SetMessage("");
return;
}
_countdownLabel.SetMessage($"Time remaining\n{Owner.Countdown.ToString()}s");
}
public override void Close()
{
base.Close();
_timerCancelTokenSource.Cancel();
}
protected override void Dispose(bool disposing)
{
if(disposing)
_timerCancelTokenSource.Cancel();
}
}
}

View File

@@ -0,0 +1,66 @@
using System;
using Content.Client.Command;
using Content.Shared.GameObjects.Components.Command;
using Robust.Client.GameObjects.Components.UserInterface;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Command
{
public class CommunicationsConsoleBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private CommunicationsConsoleMenu _menu;
public bool CountdownStarted { get; private set; }
public int Countdown => _expectedCountdownTime == null
? 0 : Math.Max((int)(_expectedCountdownTime.Value.Subtract(DateTime.Now)).TotalSeconds, 0);
private DateTime? _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 CallShuttle()
{
SendMessage(new CommunicationsConsoleCallEmergencyShuttleMessage());
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
switch (message)
{
}
}
protected override void UpdateState(BoundUserInterfaceState state)
{
if (!(state is CommunicationsConsoleInterfaceState commsState))
return;
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
CountdownStarted = commsState.CountdownStarted;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_menu?.Dispose();
}
}
}

View File

@@ -17,9 +17,9 @@ namespace Content.Client.GameObjects.Components.Research
private IPrototypeManager _prototypeManager;
#pragma warning restore
[ViewVariables]
private LatheMenu menu;
private LatheMenu _menu;
[ViewVariables]
private LatheQueueMenu queueMenu;
private LatheQueueMenu _queueMenu;
public MaterialStorageComponent Storage { get; private set; }
public SharedLatheComponent Lathe { get; private set; }
@@ -48,30 +48,30 @@ namespace Content.Client.GameObjects.Components.Research
Lathe = lathe;
Database = database;
menu = new LatheMenu(this);
queueMenu = new LatheQueueMenu { Owner = this };
_menu = new LatheMenu(this);
_queueMenu = new LatheQueueMenu { Owner = this };
menu.OnClose += Close;
_menu.OnClose += Close;
menu.Populate();
menu.PopulateMaterials();
_menu.Populate();
_menu.PopulateMaterials();
menu.QueueButton.OnPressed += (args) => { queueMenu.OpenCentered(); };
_menu.QueueButton.OnPressed += (args) => { _queueMenu.OpenCentered(); };
menu.ServerConnectButton.OnPressed += (args) =>
_menu.ServerConnectButton.OnPressed += (args) =>
{
SendMessage(new SharedLatheComponent.LatheServerSelectionMessage());
};
menu.ServerSyncButton.OnPressed += (args) =>
_menu.ServerSyncButton.OnPressed += (args) =>
{
SendMessage(new SharedLatheComponent.LatheServerSyncMessage());
};
storage.OnMaterialStorageChanged += menu.PopulateDisabled;
storage.OnMaterialStorageChanged += menu.PopulateMaterials;
storage.OnMaterialStorageChanged += _menu.PopulateDisabled;
storage.OnMaterialStorageChanged += _menu.PopulateMaterials;
menu.OpenCentered();
_menu.OpenCentered();
}
public void Queue(LatheRecipePrototype recipe, int quantity = 1)
@@ -85,10 +85,10 @@ namespace Content.Client.GameObjects.Components.Research
{
case SharedLatheComponent.LatheProducingRecipeMessage msg:
if (!_prototypeManager.TryIndex(msg.ID, out LatheRecipePrototype recipe)) break;
queueMenu?.SetInfo(recipe);
_queueMenu?.SetInfo(recipe);
break;
case SharedLatheComponent.LatheStoppedProducingRecipeMessage _:
queueMenu?.ClearInfo();
_queueMenu?.ClearInfo();
break;
case SharedLatheComponent.LatheFullQueueMessage msg:
_queuedRecipes.Clear();
@@ -97,7 +97,7 @@ namespace Content.Client.GameObjects.Components.Research
if (!_prototypeManager.TryIndex(id, out LatheRecipePrototype recipePrototype)) break;
_queuedRecipes.Enqueue(recipePrototype);
}
queueMenu?.PopulateList();
_queueMenu?.PopulateList();
break;
}
}
@@ -106,8 +106,8 @@ namespace Content.Client.GameObjects.Components.Research
{
base.Dispose(disposing);
if (!disposing) return;
menu?.Dispose();
queueMenu?.Dispose();
_menu?.Dispose();
_queueMenu?.Dispose();
}
}
}