Comms Console Announcements (#3629)
* Communications console announcements * title case for jobs * Helper * Prevent abuse * Cap message length * more abuse prevention * Validate clientside too to reduce bandwidth from unmodified clients
This commit is contained in:
@@ -14,6 +14,8 @@ namespace Content.Client.Command
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -25,13 +27,27 @@ namespace Content.Client.Command
|
||||
Title = Loc.GetString("Communications Console");
|
||||
Owner = owner;
|
||||
|
||||
_messageInput = new LineEdit
|
||||
{
|
||||
PlaceHolder = Loc.GetString("Announcement"),
|
||||
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);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Content.Client.GameObjects.Components.Command
|
||||
|
||||
[ViewVariables] private CommunicationsConsoleMenu? _menu;
|
||||
|
||||
public bool CanAnnounce { get; private set; }
|
||||
public bool CanCall { get; private set; }
|
||||
|
||||
public bool CountdownStarted { get; private set; }
|
||||
@@ -44,6 +45,12 @@ namespace Content.Client.GameObjects.Components.Command
|
||||
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());
|
||||
@@ -61,6 +68,7 @@ namespace Content.Client.GameObjects.Components.Command
|
||||
if (state is not CommunicationsConsoleInterfaceState commsState)
|
||||
return;
|
||||
|
||||
CanAnnounce = commsState.CanAnnounce;
|
||||
CanCall = commsState.CanCall;
|
||||
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
|
||||
CountdownStarted = commsState.CountdownStarted;
|
||||
@@ -69,6 +77,7 @@ namespace Content.Client.GameObjects.Components.Command
|
||||
{
|
||||
_menu.UpdateCountdown();
|
||||
_menu.EmergencyShuttleButton.Disabled = !CanCall;
|
||||
_menu.AnnounceButton.Disabled = !CanAnnounce;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user