| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<IClientConGroupController>().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<IClientConsoleHost>().ExecuteCommand(Command);
- }
- 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;
- }
- }
- }
|