Add UI window for loadbp (#9441)

* Add UI window for loadbp

* Perms disabled

* Also teleport button

* wraparound fix

* Review
This commit is contained in:
metalgearsloth
2022-07-06 14:17:19 +10:00
committed by GitHub
parent 0079014691
commit 7e0b49c7bd
6 changed files with 183 additions and 7 deletions

View File

@@ -10,6 +10,7 @@
<Button Name="SpawnTilesButton" Text="{Loc 'sandbox-window-spawn-tiles-button'}" />
<Button Name="SpawnDecalsButton" Text="{Loc 'sandbox-window-spawn-decals-button'}" />
<Button Name="LoadGamePrototypeButton" Text="{Loc 'load-game-prototype'}"/>
<cc:UICommandButton Name="LoadBlueprintsButton" Command="loadbp" Text="{Loc 'load-blueprints'}" WindowType="{x:Type abt:LoadBlueprintsWindow}"/>
<cc:CommandButton Command="deleteewc Singularity" Name="DeleteSingulos" Text="{Loc 'delete-singularities'}"/>
<cc:UICommandButton Command="events" Text="{Loc 'open-station-events'}" WindowType="{x:Type abt:StationEventsWindow}" />
</GridContainer>

View File

@@ -1,13 +1,11 @@
using System.IO;
using Content.Client.Administration.Managers;
using Content.Client.Decals.UI;
using Content.Client.Sandbox;
using Content.Shared.Administration;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{
@@ -18,16 +16,20 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
var adminManager = IoCManager.Resolve<IClientAdminManager>();
// For the SpawnEntitiesButton and SpawnTilesButton we need to do the press manually
// TODO: This will probably need some command check at some point
SpawnEntitiesButton.OnPressed += SpawnEntitiesButtonOnOnPressed;
SpawnEntitiesButton.OnPressed += SpawnEntitiesButtonOnPressed;
SpawnTilesButton.OnPressed += SpawnTilesButtonOnOnPressed;
SpawnDecalsButton.OnPressed += SpawnDecalsButtonOnPressed;
LoadGamePrototypeButton.OnPressed += LoadGamePrototypeButtonOnOnPressed;
LoadGamePrototypeButton.Visible = IoCManager.Resolve<IClientAdminManager>().HasFlag(AdminFlags.Query);
LoadGamePrototypeButton.OnPressed += LoadGamePrototypeButtonOnPressed;
LoadGamePrototypeButton.Disabled = !adminManager.HasFlag(AdminFlags.Query);
LoadBlueprintsButton.Disabled = !adminManager.HasFlag(AdminFlags.Mapping);
}
private async void LoadGamePrototypeButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
private async void LoadGamePrototypeButtonOnPressed(BaseButton.ButtonEventArgs obj)
{
var dialogManager = IoCManager.Resolve<IFileDialogManager>();
var loadManager = IoCManager.Resolve<IGamePrototypeLoadManager>();
@@ -42,7 +44,7 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
loadManager.SendGamePrototype(proto);
}
private void SpawnEntitiesButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
private void SpawnEntitiesButtonOnPressed(BaseButton.ButtonEventArgs obj)
{
EntitySystem.Get<SandboxSystem>().ToggleEntitySpawnWindow();
}

View File

@@ -0,0 +1,33 @@
<DefaultWindow
xmlns="https://spacestation14.io" Title="{Loc Load Blueprint}">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc Map}" MinSize="100 0" />
<Control MinSize="50 0" />
<OptionButton Name="MapOptions" MinSize="100 0" HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc Path}" MinSize="100 0" />
<Control MinSize="50 0" />
<OptionButton Name="MapPath" MinSize="200 0" HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc X}" MinSize="100 0" />
<Control MinSize="50 0" />
<SpinBox Name="XCoordinate" MinSize="100 0" HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc Y}" MinSize="100 0" />
<Control MinSize="50 0" />
<SpinBox Name="YCoordinate" MinSize="100 0" HorizontalExpand="True" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc Rotation}" MinSize="100 0" />
<Control MinSize="50 0" />
<SpinBox Name="RotationSpin" MinSize="100 0" HorizontalExpand="True" />
</BoxContainer>
<Button Name="SubmitButton" Text="{Loc Load Blueprint}" />
<Button Name="TeleportButton" Text="{Loc Teleport to}" />
<Button Name="ResetButton" Text="{Loc Reset to default}"></Button>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,138 @@
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.ContentPack;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Content.Client.Administration.UI.Tabs.AdminbusTab
{
[GenerateTypedNameReferences]
[UsedImplicitly]
public sealed partial class LoadBlueprintsWindow : DefaultWindow
{
private Dictionary<int, string> _pathIndices = new();
public LoadBlueprintsWindow()
{
RobustXamlLoader.Load(this);
}
protected override void EnteredTree()
{
var mapManager = IoCManager.Resolve<IMapManager>();
var provider = IoCManager.Resolve<IResourceManager>();
foreach (var mapId in mapManager.GetAllMapIds())
{
MapOptions.AddItem(mapId.ToString(), (int) mapId);
}
var pathIndex = 0;
foreach (var path in provider.ContentFindFiles(new ResourcePath("/Maps/")))
{
var strPath = path.ToString();
if (strPath.StartsWith("/Maps/Salvage/") || strPath.StartsWith("/Maps/Test/")) continue;
MapPath.AddItem(strPath[6..], pathIndex);
_pathIndices[pathIndex] = strPath;
pathIndex++;
}
Reset();
MapOptions.OnItemSelected += OnOptionSelect;
MapPath.OnItemSelected += OnPathSelect;
RotationSpin.ValueChanged += OnRotate;
SubmitButton.OnPressed += OnSubmitButtonPressed;
TeleportButton.OnPressed += OnTeleportButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
}
private void Reset()
{
var entManager = IoCManager.Resolve<IEntityManager>();
var playerManager = IoCManager.Resolve<IPlayerManager>();
var player = playerManager.LocalPlayer?.ControlledEntity;
var currentMap = MapId.Nullspace;
var position = Vector2.Zero;
var rotation = Angle.Zero;
if (entManager.TryGetComponent<TransformComponent>(player, out var xform))
{
currentMap = xform.MapID;
position = xform.WorldPosition;
if (entManager.TryGetComponent<TransformComponent>(xform.GridUid, out var gridXform))
{
rotation = gridXform.WorldRotation;
}
else
{
// MapId moment
rotation = xform.WorldRotation - xform.LocalRotation;
}
}
if (currentMap != MapId.Nullspace)
MapOptions.Select((int) currentMap);
XCoordinate.Value = (int) position.X;
YCoordinate.Value = (int) position.Y;
RotationSpin.OverrideValue(Wraparound((int) rotation.Degrees));
}
private void OnResetButtonPressed(BaseButton.ButtonEventArgs obj)
{
Reset();
}
private void OnRotate(object? sender, ValueChangedEventArgs e)
{
var newValue = Wraparound(e.Value);
if (e.Value == newValue) return;
RotationSpin.OverrideValue(newValue);
}
private int Wraparound(int value)
{
var newValue = (value % 360);
if (newValue < 0)
newValue += 360;
return newValue;
}
private void OnPathSelect(OptionButton.ItemSelectedEventArgs obj)
{
MapPath.SelectId(obj.Id);
}
private void OnOptionSelect(OptionButton.ItemSelectedEventArgs obj)
{
MapOptions.SelectId(obj.Id);
}
private void OnTeleportButtonPressed(BaseButton.ButtonEventArgs obj)
{
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"tp {XCoordinate.Value} {YCoordinate.Value} {MapOptions.SelectedId}");
}
private void OnSubmitButtonPressed(BaseButton.ButtonEventArgs obj)
{
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"loadbp {MapOptions.SelectedId} \"{_pathIndices[MapPath.SelectedId]}\" {XCoordinate.Value} {YCoordinate.Value} {RotationSpin.Value}");
}
}
}

View File

@@ -390,6 +390,7 @@ namespace Content.Client.Sandbox
RaiseNetworkEvent(new MsgSandboxSuicide());
}
// TODO: These should check for command perms + be reset if the round is over.
public void ToggleEntitySpawnWindow()
{

View File

@@ -1,3 +1,4 @@
delete-singularities = Delete Singularities
open-station-events = Station Events
load-game-prototype = Load Prototype
load-blueprints = Load Blueprints