diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml index 266856d691..9e6ef34cad 100644 --- a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml @@ -10,6 +10,7 @@ + + diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/LoadBlueprintsWindow.xaml.cs b/Content.Client/Administration/UI/Tabs/AdminbusTab/LoadBlueprintsWindow.xaml.cs new file mode 100644 index 0000000000..833624d756 --- /dev/null +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/LoadBlueprintsWindow.xaml.cs @@ -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 _pathIndices = new(); + + public LoadBlueprintsWindow() + { + RobustXamlLoader.Load(this); + } + + protected override void EnteredTree() + { + var mapManager = IoCManager.Resolve(); + var provider = IoCManager.Resolve(); + + 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(); + var playerManager = IoCManager.Resolve(); + var player = playerManager.LocalPlayer?.ControlledEntity; + + var currentMap = MapId.Nullspace; + var position = Vector2.Zero; + var rotation = Angle.Zero; + + if (entManager.TryGetComponent(player, out var xform)) + { + currentMap = xform.MapID; + position = xform.WorldPosition; + + if (entManager.TryGetComponent(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().ExecuteCommand( + $"tp {XCoordinate.Value} {YCoordinate.Value} {MapOptions.SelectedId}"); + } + + private void OnSubmitButtonPressed(BaseButton.ButtonEventArgs obj) + { + IoCManager.Resolve().ExecuteCommand( + $"loadbp {MapOptions.SelectedId} \"{_pathIndices[MapPath.SelectedId]}\" {XCoordinate.Value} {YCoordinate.Value} {RotationSpin.Value}"); + } + } +} diff --git a/Content.Client/Sandbox/SandboxSystem.cs b/Content.Client/Sandbox/SandboxSystem.cs index 700278f3a4..fc57fab744 100644 --- a/Content.Client/Sandbox/SandboxSystem.cs +++ b/Content.Client/Sandbox/SandboxSystem.cs @@ -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() { diff --git a/Resources/Locale/en-US/administration/ui/tabs/adminbus-tab/adminbus-tab.ftl b/Resources/Locale/en-US/administration/ui/tabs/adminbus-tab/adminbus-tab.ftl index a8dc75e3ab..8713d98228 100644 --- a/Resources/Locale/en-US/administration/ui/tabs/adminbus-tab/adminbus-tab.ftl +++ b/Resources/Locale/en-US/administration/ui/tabs/adminbus-tab/adminbus-tab.ftl @@ -1,3 +1,4 @@ delete-singularities = Delete Singularities open-station-events = Station Events load-game-prototype = Load Prototype +load-blueprints = Load Blueprints