New bql_select command. (#17007)

Shows BQL results in a client window. Allows TP and VV to the entities.
This commit is contained in:
Pieter-Jan Briers
2023-06-01 00:29:31 +02:00
committed by GitHub
parent 543baa158a
commit 9931a6b2f2
6 changed files with 187 additions and 0 deletions

View 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();
}
}

View 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>

View 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 }
});
}
}
}