* hallway screen refactor pending comms console support * comms console broadcasts * screen and timer localization
126 lines
4.0 KiB
C#
126 lines
4.0 KiB
C#
using Content.Shared.CCVar;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Communications;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Communications.UI
|
|
{
|
|
public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
[ViewVariables]
|
|
private CommunicationsConsoleMenu? _menu;
|
|
|
|
[ViewVariables]
|
|
public bool CanAnnounce { get; private set; }
|
|
[ViewVariables]
|
|
public bool CanBroadcast { get; private set; }
|
|
|
|
[ViewVariables]
|
|
public bool CanCall { get; private set; }
|
|
|
|
[ViewVariables]
|
|
public bool CountdownStarted { get; private set; }
|
|
|
|
[ViewVariables]
|
|
public bool AlertLevelSelectable { get; private set; }
|
|
|
|
[ViewVariables]
|
|
public string CurrentLevel { get; private set; } = default!;
|
|
|
|
[ViewVariables]
|
|
private TimeSpan? _expectedCountdownTime;
|
|
|
|
public int Countdown => _expectedCountdownTime == null ? 0 : Math.Max((int) _expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
|
|
|
|
public CommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
{
|
|
}
|
|
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
_menu = new CommunicationsConsoleMenu(this);
|
|
_menu.OnClose += Close;
|
|
_menu.OpenCentered();
|
|
}
|
|
|
|
public void AlertLevelSelected(string level)
|
|
{
|
|
if (AlertLevelSelectable)
|
|
{
|
|
CurrentLevel = level;
|
|
SendMessage(new CommunicationsConsoleSelectAlertLevelMessage(level));
|
|
}
|
|
}
|
|
|
|
public void EmergencyShuttleButtonPressed()
|
|
{
|
|
if (CountdownStarted)
|
|
RecallShuttle();
|
|
else
|
|
CallShuttle();
|
|
}
|
|
|
|
public void AnnounceButtonPressed(string message)
|
|
{
|
|
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
|
|
var msg = SharedChatSystem.SanitizeAnnouncement(message, maxLength);
|
|
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
|
|
}
|
|
|
|
public void BroadcastButtonPressed(string message)
|
|
{
|
|
SendMessage(new CommunicationsConsoleBroadcastMessage(message));
|
|
}
|
|
|
|
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;
|
|
CanBroadcast = commsState.CanBroadcast;
|
|
CanCall = commsState.CanCall;
|
|
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
|
|
CountdownStarted = commsState.CountdownStarted;
|
|
AlertLevelSelectable = commsState.AlertLevels != null && !float.IsNaN(commsState.CurrentAlertDelay) && commsState.CurrentAlertDelay <= 0;
|
|
CurrentLevel = commsState.CurrentAlert;
|
|
|
|
if (_menu != null)
|
|
{
|
|
_menu.UpdateCountdown();
|
|
_menu.UpdateAlertLevels(commsState.AlertLevels, CurrentLevel);
|
|
_menu.AlertLevelButton.Disabled = !AlertLevelSelectable;
|
|
_menu.EmergencyShuttleButton.Disabled = !CanCall;
|
|
_menu.AnnounceButton.Disabled = !CanAnnounce;
|
|
_menu.BroadcastButton.Disabled = !CanBroadcast;
|
|
}
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
if (!disposing) return;
|
|
|
|
_menu?.Dispose();
|
|
}
|
|
}
|
|
}
|