From b57cc9146253c6a41e8be4b1cea043403dbc8c52 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 4 Aug 2019 15:07:31 +0200 Subject: [PATCH] Updated GUI Window to have checkboxes --- src/ModGUI.cs | 53 ++++++++++++++++++++++++++++++++++++++---------- src/ModLogger.cs | 9 ++++++++ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/ModGUI.cs b/src/ModGUI.cs index 51d6387..c8c8cff 100644 --- a/src/ModGUI.cs +++ b/src/ModGUI.cs @@ -6,6 +6,15 @@ using System.Linq; using UnityEngine; namespace BWModLoader.ModGUI { + public enum ScreenType + { + MOD, + LOG + } + + /// + /// Manages contents and behaviour of the Debug Window + /// public class ModGUI : MonoBehaviour { static bool debugEnabled; @@ -13,9 +22,10 @@ namespace BWModLoader.ModGUI static Vector2 scrollPosition; static Vector2 size; static Vector2 position; + void Start() { - currentScreen = 0; + currentScreen = (int)ScreenType.MOD; scrollPosition = Vector2.zero; debugEnabled = false; size = new Vector2(1000, 1000); @@ -23,6 +33,9 @@ namespace BWModLoader.ModGUI (Screen.height / 2) - (size.x / 2)); } + /// + /// Toggles the Window when the Hotkey is pressed + /// void Update() { if (Input.GetKeyUp("insert")) @@ -32,6 +45,9 @@ namespace BWModLoader.ModGUI } + /// + /// Code that executes if the window was opened + /// void OnGUI() { if (debugEnabled) @@ -40,12 +56,16 @@ namespace BWModLoader.ModGUI } } + /// + /// Manages contents of the window + /// + /// ID of the Debug Window void DebugWindow(int windowID) { GUI.DragWindow(new Rect(0, 0, 10000, 20)); - currentScreen = GUI.SelectionGrid(new Rect(25, 25, size.x-50, 75), currentScreen, - new string[] { "Mods", "Logs"}, 2); - if(currentScreen == 0) + currentScreen = GUI.SelectionGrid(new Rect(25, 25, size.x - 50, 75), currentScreen, + new string[] { "Mods", "Logs" }, 2); + if (currentScreen == (int)ScreenType.MOD) { ModWindow(); } @@ -55,6 +75,9 @@ namespace BWModLoader.ModGUI } } + /// + /// Logging window content + /// void LogWindow() { GUI.Label(new Rect(0, 100, 100, 25), "LogWindow"); @@ -70,13 +93,18 @@ namespace BWModLoader.ModGUI GUI.EndScrollView(); } } + + /// + /// Mod window content + /// void ModWindow() { if (GUI.Button(new Rect(0, 100, 100, 25), "Reload all mods")) { ModLoader.Instance.RefreshModFiles(); } - scrollPosition = GUI.BeginScrollView(new Rect(0, 100, size.x, size.y-100), scrollPosition, new Rect(0, 0, size.x, 50)); + + scrollPosition = GUI.BeginScrollView(new Rect(0, 100, size.x, size.y - 100), scrollPosition, new Rect(0, 0, size.x, 50)); int modNum = 0; var allmods = ModLoader.Instance.GetAllMods(); foreach (FileInfo file in allmods.Keys) @@ -84,24 +112,27 @@ namespace BWModLoader.ModGUI foreach (Type mod in allmods[file]) { modNum++; - GUI.Label(new Rect(0, modNum * 25, 100, 25), mod.Name); - if (!ModLoader.Instance.IsLoaded(mod)) + //GUI.Label(new Rect(0, modNum * 25, 100, 25), mod.Name); + //GUI.Toggle(new Rect(0, modNum * 25, 100, 25), ModLoader.Instance.IsLoaded(mod), mod.Name); + bool newCheckboxStatus = GUI.Toggle(new Rect(20, modNum * 25, 100, 25), ModLoader.Instance.IsLoaded(mod), mod.Name); + if (newCheckboxStatus) { - if (GUI.Button(new Rect(100, modNum * 25, 100, 25), "Enable")) + if (!ModLoader.Instance.IsLoaded(mod)) { ModLoader.Instance.Load(file); } } else { - if (GUI.Button(new Rect(100, modNum * 25, 100, 25), "Disable")) + if (ModLoader.Instance.IsLoaded(mod)) { ModLoader.Instance.Unload(file); } - } + } + + // Reload the respective Mod if (GUI.Button(new Rect(200, modNum * 25, 100, 25), "Reload")) { - ModLoader.Instance.Unload(file); ModLoader.Instance.RefreshModFiles(); } } diff --git a/src/ModLogger.cs b/src/ModLogger.cs index 06b52b8..927d7f2 100644 --- a/src/ModLogger.cs +++ b/src/ModLogger.cs @@ -6,6 +6,9 @@ using System.Text; namespace BWModLoader { + /// + /// Handles logging + /// public class ModLogger { string prefix; @@ -27,6 +30,9 @@ namespace BWModLoader } } + /// + /// Clears ingame log and log files + /// public void ClearLog() { Logs.Clear(); @@ -49,6 +55,9 @@ namespace BWModLoader } } + /// + /// Only logs messages in Debug builds of the modloader + /// public void DebugLog(string output) { #if DEBUG