diff --git a/SpaceWarp/API/SpaceWarpManager.cs b/SpaceWarp/API/SpaceWarpManager.cs index 10475acf..94665db2 100644 --- a/SpaceWarp/API/SpaceWarpManager.cs +++ b/SpaceWarp/API/SpaceWarpManager.cs @@ -26,7 +26,7 @@ public class SpaceWarpManager : Manager private BaseModLogger _modLogger; private const string MODS_FOLDER_NAME = "Mods"; - public static string MODS_FULL_PATH = Application.dataPath + "/" + MODS_FOLDER_NAME; + public static string MODS_FULL_PATH = Directory.GetCurrentDirectory() + "/SpaceWarp/" + MODS_FOLDER_NAME; private const string SPACE_WARP_CONFIG_FILE_NAME = "space_warp_config.json"; private static string SPACEWARP_CONFIG_FULL_PATH = MODS_FULL_PATH + "/" + SPACE_WARP_CONFIG_FILE_NAME; @@ -480,13 +480,18 @@ internal void InvokePostInitializeModsAfterAllModsLoaded() /// private void InitModUI() { - GameObject modUIObject = new GameObject(); + GameObject modUIObject = new GameObject("Space Warp Mod UI"); DontDestroyOnLoad(modUIObject); modUIObject.transform.SetParent(transform.parent); ModListUI UI = modUIObject.AddComponent(); - UI.manager = this; modUIObject.SetActive(true); + + GameObject consoleUIObject = new GameObject("Space Warp Console"); + DontDestroyOnLoad(consoleUIObject); + consoleUIObject.transform.SetParent(transform.parent); + SpaceWarpConsole con = consoleUIObject.AddComponent(); + consoleUIObject.SetActive(true); } } } \ No newline at end of file diff --git a/SpaceWarp/SpaceWarp.csproj b/SpaceWarp/SpaceWarp.csproj index c95c79a4..542e7380 100644 --- a/SpaceWarp/SpaceWarp.csproj +++ b/SpaceWarp/SpaceWarp.csproj @@ -93,6 +93,7 @@ + diff --git a/SpaceWarp/UI/ModListUI.cs b/SpaceWarp/UI/ModListUI.cs index 3778c9da..ec4c67be 100644 --- a/SpaceWarp/UI/ModListUI.cs +++ b/SpaceWarp/UI/ModListUI.cs @@ -15,7 +15,6 @@ public class ModListUI : KerbalMonoBehaviour private Rect windowRect; private int windowWidth = 350; private int windowHeight = 700; - public SpaceWarpManager manager; public void Start() { if (loaded) @@ -69,14 +68,19 @@ private void FillWindow(int windowID) GUILayout.BeginVertical(); scrollPositionMods = GUILayout.BeginScrollView(scrollPositionMods, false, true, GUILayout.Height((float)(windowHeight * 0.8)), GUILayout.Width(300)); - foreach ((string modID, ModInfo modInfo) in manager.LoadedMods) + SpaceWarpManager manager; + if (ManagerLocator.TryGet(out manager)) { - if (GUILayout.Button(modID)) + foreach ((string modID, ModInfo modInfo) in manager.LoadedMods) { - selectedMod = modID; - selectedModInfo = modInfo; + if (GUILayout.Button(modID)) + { + selectedMod = modID; + selectedModInfo = modInfo; + } } } + GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginVertical(); diff --git a/SpaceWarp/UI/SpaceWarpConsole.cs b/SpaceWarp/UI/SpaceWarpConsole.cs new file mode 100644 index 00000000..852daa9c --- /dev/null +++ b/SpaceWarp/UI/SpaceWarpConsole.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using KSP.Game; +using KSP.Sim.impl; +using SpaceWarp.API; +using SpaceWarp.API.Configuration; +using SpaceWarp.API.Managers; +using UnityEngine; + +using KSP.Logging; +namespace SpaceWarp.UI +{ + public class SpaceWarpConsole : KerbalBehavior + { + static bool loaded = false; + private bool drawUI = false; + private Rect windowRect; + private int windowWidth = 350; + private int windowHeight = 700; + + + public void Start() + { + if (loaded) + { + Destroy(this); + } + + loaded = true; + } + + void Awake() + { + KspLogManager.AddLogCallback(LogCallback); + windowWidth = (int)(Screen.width * 0.5f); + windowHeight = (int)(Screen.height * 0.5f); + windowRect = new Rect((Screen.width * 0.15f), (Screen.height * 0.15f), + 0, 0); + } + private void OnGUI() + { + if (drawUI) + { + windowRect = GUILayout.Window( + GUIUtility.GetControlID(FocusType.Passive), + windowRect, + DrawConsole, + "Space Warp Console", + GUILayout.Width((float)(windowWidth * 0.8)), + GUILayout.Height((float)(windowHeight * 0.8)) + ); + } + } + + private static GUIStyle boxStyle; + private static Vector2 scrollPosition; + + private List debugMessages = new List(); + + private void LogCallback(string condition, string stackTrace, LogType type) + { + switch (type) + { + case LogType.Error: + debugMessages.Add($"[ERR] {condition}"); + break; + case LogType.Assert: + debugMessages.Add($"[AST] {condition}"); + break; + case LogType.Warning: + debugMessages.Add($"[WRN] {condition}"); + break; + case LogType.Log: + debugMessages.Add($"[LOG] {condition}"); + break; + case LogType.Exception: + debugMessages.Add($"[EXC] {condition}"); + break; + default: + throw new ArgumentOutOfRangeException(nameof(type), type, null); + } + } + private void Update() + { + if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.C)) + { + drawUI = !drawUI; + } + } + + private void DrawConsole(int windowID) + { + boxStyle = GUI.skin.GetStyle("Box"); + GUILayout.BeginVertical(); + scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true); + foreach (var debugMessage in debugMessages) + { + GUILayout.Label(debugMessage); + } + + GUILayout.EndScrollView(); + GUILayout.BeginHorizontal(); + if (GUILayout.Button("Close")) + { + drawUI = false; + } + + if (GUILayout.Button("Clear")) + { + debugMessages.Clear(); + } + + if (GUILayout.Button("Clear Control Locks")) + { + KSP.Game.GameManager.Instance.Game.ViewController.inputLockManager.ClearControlLocks(); + } + GUILayout.EndHorizontal(); + GUILayout.EndVertical(); + GUI.DragWindow(new Rect(0, 0, 10000, 500)); + } + } +} \ No newline at end of file