Admin shuttle call button (#4859)

* shuttle call ui

* shuttle call ui

* Localize shuttle commands better.

* localization fix
This commit is contained in:
moonheart08
2021-10-13 12:15:28 -05:00
committed by GitHub
parent dfe500a8bb
commit 9250bd62cb
9 changed files with 128 additions and 11 deletions

View File

@@ -0,0 +1,14 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc 'admin-shuttle-title'}"
MinWidth="300">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True">
<LineEdit Name="_callShuttleTime" Text="4:00" PlaceHolder="m:ss" HorizontalExpand="True" SizeFlagsStretchRatio="2"/>
<Control HorizontalExpand="True" SizeFlagsStretchRatio="1"/>
<cc:CommandButton Command="callshuttle 4:00" Name="_callShuttleButton" Text="{Loc 'communicationsconsole-menu-call-shuttle'}" HorizontalExpand="True" SizeFlagsStretchRatio="2" />
</BoxContainer>
<cc:CommandButton Command="recallshuttle" Name="_recallShuttleButton" Text="{Loc 'communicationsconsole-menu-recall-shuttle'}" HorizontalAlignment="Center"/>
</BoxContainer>
</SS14Window>

View File

@@ -0,0 +1,31 @@
using System;
using Content.Shared.Localizations;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Client.Administration.UI.Tabs.AdminTab
{
[GenerateTypedNameReferences]
public partial class AdminShuttleWindow : SS14Window
{
public AdminShuttleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_callShuttleTime.OnTextChanged += CallShuttleTimeOnOnTextChanged;
}
private void CallShuttleTimeOnOnTextChanged(LineEdit.LineEditEventArgs obj)
{
var loc = IoCManager.Resolve<ILocalizationManager>();
_callShuttleButton.Disabled = !TimeSpan.TryParseExact(obj.Text, Localization.TimeSpanMinutesFormats, loc.DefaultCulture, out _);
_callShuttleButton.Command = $"callshuttle {obj.Text}";
}
}
}

View File

@@ -6,13 +6,14 @@
Margin="4"
MinSize="50 50">
<BoxContainer Orientation="Vertical">
<GridContainer Columns="4">
<GridContainer Columns="3">
<cc:UICommandButton Command="kick" Text="{Loc admin-player-actions-window-title}" WindowType="{x:Type at:PlayerActionsWindow}" />
<cc:UICommandButton Command="ban" Text="{Loc Ban}" WindowType="{x:Type at:BanWindow}" />
<cc:CommandButton Command="aghost" Text="{Loc Admin Ghost}" />
<cc:UICommandButton Command="tpto" Text="{Loc Teleport}" WindowType="{x:Type at:TeleportWindow}" />
<cc:CommandButton Command="permissions" Text="{Loc Permissions Panel}" />
<cc:CommandButton Command="announceui" Text="{Loc Announce}"/>
<cc:UICommandButton Command="callshuttle" Text="{Loc (Re)call Shuttle}" WindowType="{x:Type at:AdminShuttleWindow}"/>
</GridContainer>
</BoxContainer>
</Control>

View File

@@ -0,0 +1,51 @@
using System;
using Content.Server.RoundEnd;
using Content.Shared.Administration;
using Content.Shared.Localizations;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Server)]
public class CallShuttleCommand : IConsoleCommand
{
public string Command => "callshuttle";
public string Description => Loc.GetString("call-shuttle-command-description");
public string Help => Loc.GetString("call-shuttle-command-help-text", ("command",Command));
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var loc = IoCManager.Resolve<ILocalizationManager>();
// ReSharper disable once ConvertIfStatementToSwitchStatement
if (args.Length == 1 && TimeSpan.TryParseExact(args[0], Localization.TimeSpanMinutesFormats, loc.DefaultCulture, out var timeSpan))
{
EntitySystem.Get<RoundEndSystem>().RequestRoundEnd(timeSpan, false);
}
else if (args.Length == 1)
{
shell.WriteLine(Loc.GetString("shell-timespan-minutes-must-be-correct"));
}
else
{
EntitySystem.Get<RoundEndSystem>().RequestRoundEnd(false);
}
}
}
[AdminCommand(AdminFlags.Server)]
public class RecallShuttleCommand : IConsoleCommand
{
public string Command => "recallshuttle";
public string Description => Loc.GetString("recall-shuttle-command-description");
public string Help => Loc.GetString("recall-shuttle-command-help-text", ("command",Command));
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
EntitySystem.Get<RoundEndSystem>().CancelRoundEndCountdown(false);
}
}
}

View File

@@ -74,36 +74,41 @@ namespace Content.Server.RoundEnd
Timer.Spawn(CallCooldown, () => OnCallCooldownEnded?.Invoke(), _callCooldownEndedTokenSource.Token);
}
public void RequestRoundEnd()
public void RequestRoundEnd(bool checkCooldown = true)
{
RequestRoundEnd(RoundEndCountdownTime, checkCooldown);
}
public void RequestRoundEnd(TimeSpan countdownTime, bool checkCooldown = true)
{
if (IsRoundEndCountdownStarted)
return;
if (!CanCall())
if (checkCooldown && !CanCall())
{
return;
}
IsRoundEndCountdownStarted = true;
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement",("minutes", RoundEndCountdownTime.Minutes)), Loc.GetString("Station"));
_chatManager.DispatchStationAnnouncement(Loc.GetString("round-end-system-shuttle-called-announcement",("minutes", countdownTime.Minutes)), Loc.GetString("Station"));
SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlecalled.ogg");
ExpectedCountdownEnd = _gameTiming.CurTime + RoundEndCountdownTime;
Timer.Spawn(RoundEndCountdownTime, EndRound, _roundEndCancellationTokenSource.Token);
ExpectedCountdownEnd = _gameTiming.CurTime + countdownTime;
Timer.Spawn(countdownTime, EndRound, _roundEndCancellationTokenSource.Token);
ActivateCooldown();
OnRoundEndCountdownStarted?.Invoke();
}
public void CancelRoundEndCountdown()
public void CancelRoundEndCountdown( bool checkCooldown = true)
{
if (!IsRoundEndCountdownStarted)
return;
if (!CanCall())
if (checkCooldown && !CanCall())
{
return;
}

View File

@@ -11,6 +11,17 @@ namespace Content.Shared.Localizations
// If you want to change your codebase's language, do it here.
private const string Culture = "en-US";
/// <summary>
/// Custom format strings used for parsing and displaying minutes:seconds timespans.
/// </summary>
public static readonly string[] TimeSpanMinutesFormats = new[]
{
@"m\:ss",
@"mm\:ss",
@"%m",
@"mm"
};
public static void Init()
{
var loc = IoCManager.Resolve<ILocalizationManager>();

View File

@@ -0,0 +1,4 @@
call-shuttle-command-description = Calls the emergency shuttle with an optionally provided arrival time.
call-shuttle-command-help-text = Usage: {$command} [m:ss]
recall-shuttle-command-description = Recalls the emergency shuttle.
recall-shuttle-command-help-text = Usage: {$command}

View File

@@ -0,0 +1 @@
admin-shuttle-title = (Re)call shuttle

View File

@@ -29,5 +29,4 @@ shell-entity-with-uid-lacks-component = Entity with uid {$uid} doesn't have a {$
shell-invalid-color-hex = Invalid color hex!
shell-target-player-does-not-exist = Target player does not exist!
shell-target-entity-does-not-have-message = Target entity does not have a(n) {$missing}!
shell-timespan-minutes-must-be-correct = {$span} is not a valid minutes timespan.