diff --git a/CrosshairMod/Button.cs b/CrosshairMod/Button.cs new file mode 100644 index 0000000..89d5696 --- /dev/null +++ b/CrosshairMod/Button.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using UnityEngine; + +namespace CrosshairMod +{ + // Button Wrapper class, utilizing GUI.Button() + public class Button + { + public Vector2 position = new Vector2(0, 0); + public Vector2 dimensions = new Vector2(0, 0); + public string label = ""; + public Action OnClick = new Action(() => { }); + + public Button(uint x, uint y, uint width, uint height, string label, Action e) + { + this.position = new Vector2(x, y); + this.dimensions = new Vector2(width, height); + this.label = label; + this.OnClick = e; + } + + public Button() { /*Empty*/ } + + public void Update() + { + bool buttonClicked = GUI.Button(new Rect(position, dimensions), label); + if (buttonClicked) + OnClick(); + } + } +} diff --git a/CrosshairMod/CrosshairMod.csproj b/CrosshairMod/CrosshairMod.csproj index d3c3b33..4598ca7 100644 --- a/CrosshairMod/CrosshairMod.csproj +++ b/CrosshairMod/CrosshairMod.csproj @@ -44,6 +44,8 @@ + + diff --git a/CrosshairMod/Logging.cs b/CrosshairMod/Logging.cs new file mode 100644 index 0000000..2a7864a --- /dev/null +++ b/CrosshairMod/Logging.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using UnityEngine; + +namespace CrosshairMod +{ + // CrosshairMod's Logging class + // Simply writes messages to the Unity Debug output + // However, I prefer this over Debug.Log() since it doesn't include a stacktrace (Except for Errors) + public static class Logging + { + public const string PREFIX = "[CROSSHAIRMOD]"; + + public static void Log(string message) + { + Console.WriteLine(PREFIX + "Info: " + message); + } + + public static void LogWarning(string message) + { + Console.WriteLine(PREFIX + "Warning: " + message); + } + + public static void LogError(string message) + { + Debug.Log(PREFIX + "Error: " + message); + } + } +} diff --git a/CrosshairMod/Main.cs b/CrosshairMod/Main.cs index aaf981d..323af46 100644 --- a/CrosshairMod/Main.cs +++ b/CrosshairMod/Main.cs @@ -13,17 +13,10 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace Mod -{ +namespace CrosshairMod +{ public class Main : MonoBehaviour { - // Logs a message made by this mod - // [CROSSHAIRMOD]Message - private void Log(string message) - { - System.Console.WriteLine("[CROSSHAIRMOD]" + message); - } - // Initialize Settings dictionary private Dictionary m_settings = new Dictionary(); @@ -37,7 +30,7 @@ namespace Mod // Reads settings file and sets all variables private bool readSettings(string filepath, ref Dictionary sett_dict) { - Log("Accessing Settings at " + filepath); + Logging.Log("Accessing Settings at " + filepath); // Try to read file contents into string string settings = ""; @@ -47,7 +40,7 @@ namespace Mod } catch(Exception e) { // Log error and return invalid state - Log(e.Message); + Logging.LogError(e.Message); return false; } @@ -66,7 +59,7 @@ namespace Mod sett_dict.Add(vals[0], Int32.Parse(vals[1])); // Store key and value in settings dictionary } - Log("Successfully loaded settings!"); + Logging.Log("Successfully loaded settings!"); return true; // Return valid state } @@ -81,37 +74,37 @@ namespace Mod // return an invalid state if (!m_settings.TryGetValue("crosshairLength", out m_crosshairLength)) { - Log("Missing Setting: crosshairLength"); + Logging.LogError("Missing Setting: crosshairLength"); return false; } if (!m_settings.TryGetValue("crosshairThickness", out m_crosshairThickness)) { - Log("Missing Setting: crosshairThickness"); + Logging.LogError("Missing Setting: crosshairThickness"); return false; } if (!m_settings.TryGetValue("crosshairColorRed", out m_crosshairColorRed)) { - Log("Missing Setting: crosshairColorRed"); + Logging.LogError("Missing Setting: crosshairColorRed"); return false; } if (!m_settings.TryGetValue("crosshairColorGreen", out m_crosshairColorGreen)) { - Log("Missing Setting: crosshairColorGreen"); + Logging.LogError("Missing Setting: crosshairColorGreen"); return false; } if (!m_settings.TryGetValue("crosshairColorBlue", out m_crosshairColorBlue)) { - Log("Missing Setting: crosshairColorBlue"); + Logging.LogError("Missing Setting: crosshairColorBlue"); return false; } if (!m_settings.TryGetValue("crosshairColorAlpha", out m_crosshairColorAlpha)) { - Log("Missing Setting: crosshairColorAlpha"); + Logging.LogError("Missing Setting: crosshairColorAlpha"); return false; } @@ -167,10 +160,15 @@ namespace Mod // Read settings, if this fails, the state will be invalid m_validState = readSettings(".\\Blackwake_Data\\Managed\\Mods\\chSettings.sett", ref m_settings); foreach (KeyValuePair setting in m_settings) - Log(setting.Key + ": " + setting.Value); + Logging.Log(setting.Key + ": " + setting.Value); } + + private Button testBtn = new Button(500, 500, 300, 200, "Test Button", () => { Logging.Log("Test Button pressed"); }); + void OnGUI() { + testBtn.Update(); + // If the mod is in an invalid state, the OnGUI function won't execute if (m_validState) { diff --git a/CrosshairMod/bin/Release/CrosshairMod.dll b/CrosshairMod/bin/Release/CrosshairMod.dll deleted file mode 100644 index aae6b3b..0000000 Binary files a/CrosshairMod/bin/Release/CrosshairMod.dll and /dev/null differ