Console completions (content side) (#8211)
This commit is contained in:
committed by
GitHub
parent
d09ea18de5
commit
ddb4c00816
@@ -0,0 +1,48 @@
|
||||
using System.Linq;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.ContentPack;
|
||||
|
||||
namespace Content.Client.Administration.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Proxy to server-side <c>playglobalsound</c> command. Implements completions.
|
||||
/// </summary>
|
||||
public sealed class PlayGlobalSoundCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "playglobalsound";
|
||||
public string Description => Loc.GetString("play-global-sound-command-description");
|
||||
public string Help => Loc.GetString("play-global-sound-command-help");
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
shell.RemoteExecuteCommand(argStr);
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var hint = Loc.GetString("play-global-sound-command-arg-path");
|
||||
var res = IoCManager.Resolve<IResourceManager>();
|
||||
|
||||
var options = CompletionHelper.ContentFilePath(args[0], res);
|
||||
|
||||
return CompletionResult.FromHintOptions(options, hint);
|
||||
}
|
||||
|
||||
if (args.Length == 2)
|
||||
return CompletionResult.FromHint(Loc.GetString("play-global-sound-command-arg-volume"));
|
||||
|
||||
if (args.Length > 2)
|
||||
{
|
||||
var plyMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
var options = plyMgr.Sessions.Select(c => c.Name);
|
||||
return CompletionResult.FromHintOptions(
|
||||
options,
|
||||
Loc.GetString("play-global-sound-command-arg-usern", ("user", args.Length - 2)));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -110,5 +111,32 @@ namespace Content.Server.Administration.Commands
|
||||
targetPlayer.ConnectedClient.Disconnect(banDef.DisconnectMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
var options = playerMgr.ServerSessions.Select(c => c.Name).OrderBy(c => c).ToArray();
|
||||
return CompletionResult.FromHintOptions(options, "<name/user ID>");
|
||||
}
|
||||
|
||||
if (args.Length == 2)
|
||||
return CompletionResult.FromHint("<reason>");
|
||||
|
||||
if (args.Length == 3)
|
||||
{
|
||||
var durations = new CompletionOption[]
|
||||
{
|
||||
new("0", "Permanent"),
|
||||
new("1440", "1 day"),
|
||||
new("10080", "1 week"),
|
||||
};
|
||||
|
||||
return CompletionResult.FromHintOptions(durations, "[duration]");
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,6 @@ play-global-sound-command-description = Plays a global sound for a specific play
|
||||
play-global-sound-command-help = playglobalsound <path> [volume] [user 1] ... [user n]
|
||||
play-global-sound-command-player-not-found = Player "{$username}" not found.
|
||||
play-global-sound-command-volume-parse = Invalid volume of {$volume} specified.
|
||||
play-global-sound-command-arg-path = <path>
|
||||
play-global-sound-command-arg-volume = [volume]
|
||||
play-global-sound-command-arg-usern = [user {$user}]
|
||||
|
||||
@@ -288,6 +288,16 @@ binds:
|
||||
- function: TextHistoryNext
|
||||
type: State
|
||||
key: Down
|
||||
- function: TextCompleteNext
|
||||
type: State
|
||||
key: Down
|
||||
priority: 1
|
||||
canRepeat: true
|
||||
- function: TextCompletePrev
|
||||
type: State
|
||||
key: Up
|
||||
priority: 1
|
||||
canRepeat: true
|
||||
- function: TextReleaseFocus
|
||||
type: State
|
||||
key: Escape
|
||||
|
||||
Reference in New Issue
Block a user