New bql_select command. (#17007)
Shows BQL results in a client window. Allows TP and VV to the entities.
This commit is contained in:
committed by
GitHub
parent
543baa158a
commit
9931a6b2f2
45
Content.Client/Bql/BqlResultsEui.cs
Normal file
45
Content.Client/Bql/BqlResultsEui.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Content.Client.Eui;
|
||||||
|
using Content.Shared.Bql;
|
||||||
|
using Content.Shared.Eui;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Client.Console;
|
||||||
|
|
||||||
|
namespace Content.Client.Bql;
|
||||||
|
|
||||||
|
[UsedImplicitly]
|
||||||
|
public sealed class BqlResultsEui : BaseEui
|
||||||
|
{
|
||||||
|
private readonly BqlResultsWindow _window;
|
||||||
|
|
||||||
|
public BqlResultsEui()
|
||||||
|
{
|
||||||
|
_window = new BqlResultsWindow(
|
||||||
|
IoCManager.Resolve<IClientConsoleHost>(),
|
||||||
|
IoCManager.Resolve<ILocalizationManager>()
|
||||||
|
);
|
||||||
|
|
||||||
|
_window.OnClose += () => SendMessage(new CloseEuiMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleState(EuiStateBase state)
|
||||||
|
{
|
||||||
|
if (state is not BqlResultsEuiState castState)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_window.Update(castState.Entities);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Closed()
|
||||||
|
{
|
||||||
|
base.Closed();
|
||||||
|
|
||||||
|
_window.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Opened()
|
||||||
|
{
|
||||||
|
base.Opened();
|
||||||
|
|
||||||
|
_window.OpenCentered();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Content.Client/Bql/BqlResultsWindow.xaml
Normal file
10
Content.Client/Bql/BqlResultsWindow.xaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<DefaultWindow
|
||||||
|
xmlns="https://spacestation14.io"
|
||||||
|
Title="{Loc 'ui-bql-results-title'}">
|
||||||
|
<BoxContainer Orientation="Vertical">
|
||||||
|
<Label Name="StatusLabel" />
|
||||||
|
<ScrollContainer VerticalExpand="True">
|
||||||
|
<BoxContainer Orientation="Vertical" Name="ItemList" VerticalExpand="True" />
|
||||||
|
</ScrollContainer>
|
||||||
|
</BoxContainer>
|
||||||
|
</DefaultWindow>
|
||||||
48
Content.Client/Bql/BqlResultsWindow.xaml.cs
Normal file
48
Content.Client/Bql/BqlResultsWindow.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using Robust.Client.AutoGenerated;
|
||||||
|
using Robust.Client.Console;
|
||||||
|
using Robust.Client.UserInterface.Controls;
|
||||||
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
|
using Robust.Client.UserInterface.XAML;
|
||||||
|
|
||||||
|
namespace Content.Client.Bql;
|
||||||
|
|
||||||
|
[GenerateTypedNameReferences]
|
||||||
|
internal sealed partial class BqlResultsWindow : DefaultWindow
|
||||||
|
{
|
||||||
|
private readonly IClientConsoleHost _console;
|
||||||
|
private readonly ILocalizationManager _loc;
|
||||||
|
|
||||||
|
public BqlResultsWindow(IClientConsoleHost console, ILocalizationManager loc)
|
||||||
|
{
|
||||||
|
_console = console;
|
||||||
|
_loc = loc;
|
||||||
|
|
||||||
|
RobustXamlLoader.Load(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Vector2 ContentsMinimumSize => (500, 700);
|
||||||
|
|
||||||
|
public void Update((string name, EntityUid entity)[] entities)
|
||||||
|
{
|
||||||
|
StatusLabel.Text = _loc.GetString("ui-bql-results-status", ("count", entities.Length));
|
||||||
|
ItemList.RemoveAllChildren();
|
||||||
|
|
||||||
|
foreach (var (name, entity) in entities)
|
||||||
|
{
|
||||||
|
var nameLabel = new Label { Text = name, HorizontalExpand = true };
|
||||||
|
var tpButton = new Button { Text = _loc.GetString("ui-bql-results-tp") };
|
||||||
|
tpButton.OnPressed += _ => _console.ExecuteCommand($"tpto {entity}");
|
||||||
|
tpButton.ToolTip = _loc.GetString("ui-bql-results-tp-tooltip");
|
||||||
|
|
||||||
|
var vvButton = new Button { Text = _loc.GetString("ui-bql-results-vv") };
|
||||||
|
vvButton.ToolTip = _loc.GetString("ui-bql-results-vv-tooltip");
|
||||||
|
vvButton.OnPressed += _ => _console.ExecuteCommand($"vv {entity}");
|
||||||
|
|
||||||
|
ItemList.AddChild(new BoxContainer
|
||||||
|
{
|
||||||
|
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||||
|
Children = { nameLabel, tpButton, vvButton }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Content.Server/Bql/BqlSelectCommand.cs
Normal file
56
Content.Server/Bql/BqlSelectCommand.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Content.Server.Administration;
|
||||||
|
using Content.Server.EUI;
|
||||||
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.Bql;
|
||||||
|
using Content.Shared.Eui;
|
||||||
|
using Robust.Server.Bql;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Console;
|
||||||
|
|
||||||
|
namespace Content.Server.Bql;
|
||||||
|
|
||||||
|
[AdminCommand(AdminFlags.Query)]
|
||||||
|
public sealed class BqlSelectCommand : LocalizedCommands
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IBqlQueryManager _bql = default!;
|
||||||
|
[Dependency] private readonly EuiManager _euiManager = default!;
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
|
||||||
|
public override string Command => "bql_select";
|
||||||
|
|
||||||
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
if (shell.Player == null)
|
||||||
|
{
|
||||||
|
shell.WriteError(LocalizationManager.GetString("cmd-bql_select-err-server-shell"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var (entities, rest) = _bql.SimpleParseAndExecute(argStr["bql_select".Length..]);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(rest))
|
||||||
|
shell.WriteLine(LocalizationManager.GetString("cmd-bql_select-err-rest", ("rest", rest)));
|
||||||
|
|
||||||
|
var ui = new BqlResultsEui(
|
||||||
|
entities.Select(e => (_entityManager.GetComponent<MetaDataComponent>(e).EntityName, e)).ToArray()
|
||||||
|
);
|
||||||
|
_euiManager.OpenEui(ui, (IPlayerSession) shell.Player);
|
||||||
|
_euiManager.QueueStateUpdate(ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class BqlResultsEui : BaseEui
|
||||||
|
{
|
||||||
|
private readonly (string name, EntityUid entity)[] _entities;
|
||||||
|
|
||||||
|
public BqlResultsEui((string name, EntityUid entity)[] entities)
|
||||||
|
{
|
||||||
|
_entities = entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override EuiStateBase GetNewState()
|
||||||
|
{
|
||||||
|
return new BqlResultsEuiState(_entities);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Content.Shared/Bql/BqlResultsEuiState.cs
Normal file
15
Content.Shared/Bql/BqlResultsEuiState.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Content.Shared.Eui;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.Bql;
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class BqlResultsEuiState : EuiStateBase
|
||||||
|
{
|
||||||
|
public readonly (string name, EntityUid entity)[] Entities;
|
||||||
|
|
||||||
|
public BqlResultsEuiState((string name, EntityUid entity)[] entities)
|
||||||
|
{
|
||||||
|
Entities = entities;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Resources/Locale/en-US/bql/bql-select.ftl
Normal file
13
Resources/Locale/en-US/bql/bql-select.ftl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
cmd-bql_select-desc = Show results of a BQL query in a client-side window
|
||||||
|
cmd-bql_select-help = Usage: bql_select <bql query>
|
||||||
|
The opened window allows you to teleport to or view variables the resulting entities.
|
||||||
|
|
||||||
|
cmd-bql_select-err-server-shell = Cannot be executed from server shell
|
||||||
|
cmd-bql_select-err-rest = Warning: unused part after BQL query: "{ $rest }"
|
||||||
|
|
||||||
|
ui-bql-results-title = BQL results
|
||||||
|
ui-bql-results-vv = VV
|
||||||
|
ui-bql-results-tp = TP
|
||||||
|
ui-bql-results-vv-tooltip = View entity variables
|
||||||
|
ui-bql-results-tp-tooltip = Teleport to entity
|
||||||
|
ui-bql-results-status = { $count } entities
|
||||||
Reference in New Issue
Block a user