using System.Diagnostics.CodeAnalysis; using Content.Client.Guidebook.Richtext; using Robust.Client.Console; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; namespace Content.Client.Administration.UI.CustomControls { [Virtual] public class CommandButton : Button, IDocumentTag { public string? Command { get; set; } public CommandButton() { OnPressed += Execute; } protected virtual bool CanPress() { return string.IsNullOrEmpty(Command) || IoCManager.Resolve().CanCommand(Command.Split(' ')[0]); } 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().ExecuteCommand(Command); } public bool TryParseTag(Dictionary 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; } } }