LoadBlueprintsWindow.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System.Numerics;
  2. using JetBrains.Annotations;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.Console;
  5. using Robust.Client.Player;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Client.UserInterface.CustomControls;
  8. using Robust.Client.UserInterface.XAML;
  9. using Robust.Shared.Map;
  10. namespace Content.Client.Administration.UI.Tabs.AdminbusTab
  11. {
  12. [GenerateTypedNameReferences]
  13. [UsedImplicitly]
  14. public sealed partial class LoadBlueprintsWindow : DefaultWindow
  15. {
  16. public LoadBlueprintsWindow()
  17. {
  18. RobustXamlLoader.Load(this);
  19. }
  20. protected override void EnteredTree()
  21. {
  22. var mapManager = IoCManager.Resolve<IMapManager>();
  23. foreach (var mapId in mapManager.GetAllMapIds())
  24. {
  25. MapOptions.AddItem(mapId.ToString(), (int) mapId);
  26. }
  27. Reset();
  28. MapOptions.OnItemSelected += OnOptionSelect;
  29. RotationSpin.ValueChanged += OnRotate;
  30. SubmitButton.OnPressed += OnSubmitButtonPressed;
  31. TeleportButton.OnPressed += OnTeleportButtonPressed;
  32. ResetButton.OnPressed += OnResetButtonPressed;
  33. }
  34. private void Reset()
  35. {
  36. var entManager = IoCManager.Resolve<IEntityManager>();
  37. var xformSystem = entManager.System<SharedTransformSystem>();
  38. var playerManager = IoCManager.Resolve<IPlayerManager>();
  39. var player = playerManager.LocalEntity;
  40. var currentMap = MapId.Nullspace;
  41. var position = Vector2.Zero;
  42. var rotation = Angle.Zero;
  43. if (entManager.TryGetComponent<TransformComponent>(player, out var xform))
  44. {
  45. currentMap = xform.MapID;
  46. position = xformSystem.GetWorldPosition(xform);
  47. if (entManager.TryGetComponent<TransformComponent>(xform.GridUid, out var gridXform))
  48. {
  49. rotation = xformSystem.GetWorldRotation(gridXform);
  50. }
  51. else
  52. {
  53. // MapId moment
  54. rotation = xformSystem.GetWorldRotation(xform) - xform.LocalRotation;
  55. }
  56. }
  57. if (currentMap != MapId.Nullspace)
  58. MapOptions.Select((int) currentMap);
  59. XCoordinate.Value = (int) position.X;
  60. YCoordinate.Value = (int) position.Y;
  61. RotationSpin.OverrideValue(Wraparound((int) rotation.Degrees));
  62. }
  63. private void OnResetButtonPressed(BaseButton.ButtonEventArgs obj)
  64. {
  65. Reset();
  66. }
  67. private void OnRotate(ValueChangedEventArgs e)
  68. {
  69. var newValue = Wraparound(e.Value);
  70. if (e.Value == newValue) return;
  71. RotationSpin.OverrideValue(newValue);
  72. }
  73. private int Wraparound(int value)
  74. {
  75. var newValue = (value % 360);
  76. if (newValue < 0)
  77. newValue += 360;
  78. return newValue;
  79. }
  80. private void OnOptionSelect(OptionButton.ItemSelectedEventArgs obj)
  81. {
  82. MapOptions.SelectId(obj.Id);
  83. }
  84. private void OnTeleportButtonPressed(BaseButton.ButtonEventArgs obj)
  85. {
  86. IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
  87. $"tp {XCoordinate.Value} {YCoordinate.Value} {new MapId(MapOptions.SelectedId)}");
  88. }
  89. private void OnSubmitButtonPressed(BaseButton.ButtonEventArgs obj)
  90. {
  91. if (MapPath.Text.Length == 0) return;
  92. IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
  93. $"loadbp {new MapId(MapOptions.SelectedId)} \"{MapPath.Text}\" {XCoordinate.Value} {YCoordinate.Value} {RotationSpin.Value}");
  94. }
  95. }
  96. }