From 74d122a9a646bf941ded26627cc38e4912846c13 Mon Sep 17 00:00:00 2001 From: Robert Altner Date: Thu, 1 Aug 2019 17:48:05 +0200 Subject: [PATCH] Added Button, doesn't work with BWML --- CrosshairMod/Button.cs | 36 ++++++++++++++++++++++ CrosshairMod/CrosshairMod.csproj | 2 ++ CrosshairMod/Logging.cs | 33 ++++++++++++++++++++ CrosshairMod/Main.cs | 36 ++++++++++------------ CrosshairMod/bin/Release/CrosshairMod.dll | Bin 7168 -> 0 bytes 5 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 CrosshairMod/Button.cs create mode 100644 CrosshairMod/Logging.cs delete mode 100644 CrosshairMod/bin/Release/CrosshairMod.dll 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 aae6b3ba77f546fa8d7d7c54e897553f05bbe9f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7168 zcmeHLYit}>6+ZLWhsVy6*-h4I9?c|f=q8RA$4;B14{FDD61Q>edYxCD;LPrh?Wt#X zwllLyOq(LF9`vqrsIp>~x=H5Fqa@#|s5Rr=C8*dOjfu38RfNu@XL7Z6s-2{EB<*5x% zNc*4KFfnWUM#XbyJhNmJ%yQWcjJ#!d)v{rijlt2JQF4n`cG)uRs+#GsA)@_~Lf`s} z{!HE5^R&@umAZ*mfD;Y57kbef`1RpOv|QkF7&kL&YDD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