2023-01-16 21:42:22 +13:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
using Content.Client.Guidebook.Richtext;
|
|
|
|
|
using Robust.Client.Console;
|
|
|
|
|
using Robust.Client.UserInterface;
|
2021-02-17 09:39:31 -03:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Administration.UI.CustomControls
|
2021-02-17 09:39:31 -03:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
[Virtual]
|
2023-01-16 21:42:22 +13:00
|
|
|
public class CommandButton : Button, IDocumentTag
|
2021-02-17 09:39:31 -03:00
|
|
|
{
|
|
|
|
|
public string? Command { get; set; }
|
|
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public CommandButton()
|
2021-02-17 09:39:31 -03:00
|
|
|
{
|
|
|
|
|
OnPressed += Execute;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual bool CanPress()
|
|
|
|
|
{
|
|
|
|
|
return string.IsNullOrEmpty(Command) ||
|
2021-10-10 05:47:15 -05:00
|
|
|
IoCManager.Resolve<IClientConGroupController>().CanCommand(Command.Split(' ')[0]);
|
2021-02-17 09:39:31 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void EnteredTree()
|
|
|
|
|
{
|
|
|
|
|
if (!CanPress())
|
|
|
|
|
{
|
|
|
|
|
Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Execute(ButtonEventArgs obj)
|
|
|
|
|
{
|
|
|
|
|
// Default is to execute command
|
|
|
|
|
if (!string.IsNullOrEmpty(Command))
|
|
|
|
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(Command);
|
|
|
|
|
}
|
2023-01-16 21:42:22 +13:00
|
|
|
|
|
|
|
|
public bool TryParseTag(Dictionary<string, string> args, [NotNullWhen(true)] out Control? control)
|
|
|
|
|
{
|
|
|
|
|
if (args.Count != 2 || !args.TryGetValue("Text", out var text) || !args.TryGetValue("Command", out var command))
|
|
|
|
|
{
|
|
|
|
|
Logger.Error($"Invalid arguments passed to {nameof(CommandButton)}");
|
|
|
|
|
control = null;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Command = command;
|
|
|
|
|
Text = Loc.GetString(text);
|
|
|
|
|
control = this;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-02-17 09:39:31 -03:00
|
|
|
}
|
|
|
|
|
}
|