2024-01-21 13:14:01 +04:00
|
|
|
|
using Content.Shared.CCVar;
|
|
|
|
|
|
using Content.Shared.Chat;
|
|
|
|
|
|
using Content.Shared.Communications;
|
|
|
|
|
|
using Robust.Shared.Configuration;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.Timing;
|
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 CommunicationsConsoleBoundUserInterface : BoundUserInterface
|
2020-04-09 00:28:56 +02:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2024-01-21 13:14:01 +04:00
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
private CommunicationsConsoleMenu? _menu;
|
2021-02-16 09:31:57 +01:00
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
2021-03-13 23:21:57 -06:00
|
|
|
|
public bool CanAnnounce { get; private set; }
|
2024-01-27 05:51:24 -08:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public bool CanBroadcast { get; private set; }
|
2023-07-08 09:02:17 -07:00
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-02-16 09:31:57 +01:00
|
|
|
|
public bool CanCall { get; private set; }
|
2020-04-09 20:28:22 +02:00
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
2020-04-09 00:28:56 +02:00
|
|
|
|
public bool CountdownStarted { get; private set; }
|
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
2022-05-17 21:05:31 -07:00
|
|
|
|
public bool AlertLevelSelectable { get; private set; }
|
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
2022-05-17 21:05:31 -07:00
|
|
|
|
public string CurrentLevel { get; private set; } = default!;
|
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
2020-04-09 20:28:22 +02:00
|
|
|
|
private TimeSpan? _expectedCountdownTime;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
public int Countdown => _expectedCountdownTime == null ? 0 : Math.Max((int) _expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
|
2023-03-25 07:51:16 -07:00
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
public CommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
|
|
|
|
{
|
2020-04-09 00:28:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
|
|
|
|
|
|
|
|
|
|
|
_menu = new CommunicationsConsoleMenu(this);
|
|
|
|
|
|
_menu.OnClose += Close;
|
|
|
|
|
|
_menu.OpenCentered();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-17 21:05:31 -07:00
|
|
|
|
public void AlertLevelSelected(string level)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AlertLevelSelectable)
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentLevel = level;
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleSelectAlertLevelMessage(level));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2024-01-21 13:14:01 +04:00
|
|
|
|
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
|
|
|
|
|
|
var msg = SharedChatSystem.SanitizeAnnouncement(message, maxLength);
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
|
2021-03-13 23:21:57 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-27 05:51:24 -08:00
|
|
|
|
public void BroadcastButtonPressed(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new CommunicationsConsoleBroadcastMessage(message));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
2024-01-27 05:51:24 -08:00
|
|
|
|
CanBroadcast = commsState.CanBroadcast;
|
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;
|
2022-05-17 21:05:31 -07:00
|
|
|
|
AlertLevelSelectable = commsState.AlertLevels != null && !float.IsNaN(commsState.CurrentAlertDelay) && commsState.CurrentAlertDelay <= 0;
|
|
|
|
|
|
CurrentLevel = commsState.CurrentAlert;
|
2020-04-09 00:28:56 +02:00
|
|
|
|
|
2021-02-16 09:31:57 +01:00
|
|
|
|
if (_menu != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_menu.UpdateCountdown();
|
2022-05-17 21:05:31 -07:00
|
|
|
|
_menu.UpdateAlertLevels(commsState.AlertLevels, CurrentLevel);
|
|
|
|
|
|
_menu.AlertLevelButton.Disabled = !AlertLevelSelectable;
|
2021-02-16 09:31:57 +01:00
|
|
|
|
_menu.EmergencyShuttleButton.Disabled = !CanCall;
|
2021-03-13 23:21:57 -06:00
|
|
|
|
_menu.AnnounceButton.Disabled = !CanAnnounce;
|
2024-01-27 05:51:24 -08:00
|
|
|
|
_menu.BroadcastButton.Disabled = !CanBroadcast;
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|