* Add UI window for loadbp * Perms disabled * Also teleport button * wraparound fix * Review
139 lines
4.4 KiB
C#
139 lines
4.4 KiB
C#
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}");
|
|
}
|
|
}
|
|
}
|