2021-03-10 14:48:29 +01:00
|
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Communications;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-04-09 20:28:22 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.Timing;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
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 CommunicationsConsoleBoundUserInterface : BoundUserInterface
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2021-02-16 09:31:57 +01:00
|
|
|
|
[ViewVariables] private CommunicationsConsoleMenu? _menu;
|
|
|
|
|
|
|
2021-03-13 23:21:57 -06:00
|
|
|
|
public bool CanAnnounce { get; private set; }
|
2021-02-16 09:31:57 +01:00
|
|
|
|
public bool CanCall { get; private set; }
|
2020-04-09 20:28:22 +02:00
|
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
|
public bool CountdownStarted { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public int Countdown => _expectedCountdownTime == null
|
2020-04-09 20:28:22 +02:00
|
|
|
|
? 0 : Math.Max((int)_expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
|
|
|
|
|
|
private TimeSpan? _expectedCountdownTime;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
public CommunicationsConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
|
|
|
|
|
|
|
|
|
|
|
_menu = new CommunicationsConsoleMenu(this);
|
|
|
|
|
|
_menu.OnClose += Close;
|
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 01:43:28 +02:00
|
|
|
|
public void EmergencyShuttleButtonPressed()
|
|
|
|
|
|
{
|
2021-02-16 09:31:57 +01:00
|
|
|
|
if (CountdownStarted)
|
2020-04-09 01:43:28 +02:00
|
|
|
|
RecallShuttle();
|
|
|
|
|
|
else
|
|
|
|
|
|
CallShuttle();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-13 23:21:57 -06:00
|
|
|
|
public void AnnounceButtonPressed(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
var msg = message.Length <= 256 ? message.Trim() : $"{message.Trim().Substring(0, 256)}...";
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
|
public void CallShuttle()
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleCallEmergencyShuttleMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 01:43:28 +02:00
|
|
|
|
public void RecallShuttle()
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleRecallEmergencyShuttleMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
|
|
|
|
|
|
if (state is not CommunicationsConsoleInterfaceState commsState)
|
2020-04-09 00:28:56 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2021-03-13 23:21:57 -06:00
|
|
|
|
CanAnnounce = commsState.CanAnnounce;
|
2021-02-16 09:31:57 +01:00
|
|
|
|
CanCall = commsState.CanCall;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
|
|
|
|
|
|
CountdownStarted = commsState.CountdownStarted;
|
|
|
|
|
|
|
2021-02-16 09:31:57 +01:00
|
|
|
|
if (_menu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_menu.UpdateCountdown();
|
|
|
|
|
|
_menu.EmergencyShuttleButton.Disabled = !CanCall;
|
2021-03-13 23:21:57 -06:00
|
|
|
|
_menu.AnnounceButton.Disabled = !CanAnnounce;
|
2021-02-16 09:31:57 +01:00
|
|
|
|
}
|
2020-04-09 00:28:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
|
if (!disposing) return;
|
2020-10-06 10:16:42 +02:00
|
|
|
|
|
2020-04-09 00:28:56 +02:00
|
|
|
|
_menu?.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|