diff --git a/CrosshairMod/CrosshairMod.csproj b/CrosshairMod/CrosshairMod.csproj index 1f918ef..0906b96 100644 --- a/CrosshairMod/CrosshairMod.csproj +++ b/CrosshairMod/CrosshairMod.csproj @@ -52,8 +52,5 @@ - - - \ No newline at end of file diff --git a/CrosshairMod/Interface.cs b/CrosshairMod/Interface.cs index d287ba5..4423629 100644 --- a/CrosshairMod/Interface.cs +++ b/CrosshairMod/Interface.cs @@ -13,6 +13,8 @@ namespace CrosshairMod * * Contains all Buttons, Sliders etc. that are able to modify the crosshair. */ + + // TODO: Create GUILayout.Window to make a less crappy version of the settings window static class Interface { // Saves wether the interface is visible or not @@ -66,7 +68,6 @@ namespace CrosshairMod AddButton(3, 3, 3, 3, "", (object sender, EventArgs e) => { }); // Create Crosshair Visibilty Button - // TODO: Make Button change label depending on Crosshait State (e.g. if it's hidden the label should be "Show", and vice versa) int index = AddButton((uint)m_position.x + 20, (uint)m_position.y + 20, 200, 30, "Hide Crosshair", (object sender, EventArgs e) => { Crosshair.Toggle(); }); m_buttons[index].OnClick += (object sender, EventArgs args) => { m_buttons[index].label = (Crosshair.Enabled()) ? "Show Crosshair" : "Hide Crosshair"; }; diff --git a/CrosshairMod/Logging.cs b/CrosshairMod/Logging.cs index eef8696..c39db3f 100644 --- a/CrosshairMod/Logging.cs +++ b/CrosshairMod/Logging.cs @@ -31,14 +31,14 @@ namespace CrosshairMod public static void LogWarning(string message) { #if DEBUG - Logging.LogError(message); + Logging.LogWarning(message); #endif // DEBUG } public static void LogError(string message) { #if DEBUG - Debug.Log(PREFIX + "Error: " + message); + Logging.LogError(PREFIX + "Error: " + message); #endif // DEBUG } } @@ -59,7 +59,7 @@ namespace CrosshairMod // Logs errors public static void LogError(string message) { - Debug.Log(PREFIX + "Error: " + message); + UnityEngine.Debug.Log(PREFIX + "Error: " + message); } } } diff --git a/CrosshairMod/Main.cs b/CrosshairMod/Main.cs index d3ff673..c3b1a78 100644 --- a/CrosshairMod/Main.cs +++ b/CrosshairMod/Main.cs @@ -25,9 +25,8 @@ namespace CrosshairMod public class Main : MonoBehaviour { // Define Hotkeys for Menu and Crosshair Toggle - // TODO: Make Hotkeys editable for the User - private const string MENU_OPEN_KEY = "H"; - private const string CH_TOGGLE_KEY = "J"; + private char MENU_OPEN_KEY = 'H'; + private char CH_TOGGLE_KEY = 'J'; // This will be executed first void Start() @@ -38,19 +37,23 @@ namespace CrosshairMod Crosshair.Create(); // Create Panel Interface.Init(); + + // Load Hotkeys + MENU_OPEN_KEY = (char)Settings.GetValue("hotkeyCrosshairToggle", true, MENU_OPEN_KEY); + CH_TOGGLE_KEY = (char)Settings.GetValue("hotkeyGUIToggle", true, CH_TOGGLE_KEY); } // This gets called on every GUI Update (Can be multiple tiems per Frame) void OnGUI() { // Check for Key presses - if(Event.current.Equals(Event.KeyboardEvent(MENU_OPEN_KEY))) + if (Event.current.Equals(Event.KeyboardEvent(MENU_OPEN_KEY.ToString()))) { // Toggle Crosshair GUI Interface.Toggle(); } - if (Event.current.Equals(Event.KeyboardEvent(CH_TOGGLE_KEY))) + if (Event.current.Equals(Event.KeyboardEvent(CH_TOGGLE_KEY.ToString()))) { // Toggle Crosshair Crosshair.Toggle(); diff --git a/CrosshairMod/Settings.cs b/CrosshairMod/Settings.cs index f274f7c..36d16d7 100644 --- a/CrosshairMod/Settings.cs +++ b/CrosshairMod/Settings.cs @@ -21,15 +21,39 @@ namespace CrosshairMod Logging.Debug.Log("Accessing Settings at " + filepath); // Try to read file contents into string + // If no file exists, create one string settings = ""; + if(!System.IO.File.Exists(filepath)) + { + // No settings file found, create one + Logging.Debug.LogWarning("Settings file not found, creating one..."); + try + { + System.IO.File.Create(filepath); + } + // If that fails then shit just hit the fan. React accordingly + catch(Exception e) + { + Logging.LogError("Something went wrong while creating a settings file... :("); + Logging.LogError(e.Message); + Logging.LogError(e.StackTrace); + + return; + } + } + + // Read file to string try { settings = System.IO.File.ReadAllText(filepath); } + // Something incredibly weird just happened catch (Exception e) { - // Log error and return invalid state + Logging.LogError("Something went wrong while reading a settings file... :("); Logging.LogError(e.Message); + Logging.LogError(e.StackTrace); + return; } @@ -48,7 +72,7 @@ namespace CrosshairMod m_settings.Add(vals[0], Int32.Parse(vals[1])); // Store key and value in settings dictionary } - Logging.Debug.Log("Successfully loaded settings!"); + Logging.Log("Settings loaded."); } // Converts the dictionary to a sett file @@ -80,7 +104,7 @@ namespace CrosshairMod { if (!addIfDoesntExist) { - Logging.LogError("Tried to change a setting with key \"" + key + "\" that doesn't exist."); + Logging.Debug.LogError("Tried to change a setting with key \"" + key + "\" that doesn't exist."); return; } else @@ -105,7 +129,7 @@ namespace CrosshairMod { if (!addIfDoesntExist) { - Logging.LogError("Tried to access unknown setting: \"" + key + "\". Check your chSettings.sett for errors."); + Logging.Debug.LogError("Tried to access unknown setting: \"" + key + "\". Check your chSettings.sett for errors."); } else { diff --git a/CrosshairMod/chSettings.sett b/CrosshairMod/chSettings.sett deleted file mode 100644 index 55e84e0..0000000 --- a/CrosshairMod/chSettings.sett +++ /dev/null @@ -1,6 +0,0 @@ -crosshairLength=15 -crosshairThickness=3 -crosshairColorRed=255 -crosshairColorGreen=94 -crosshairColorBlue=244 -crosshairColorAlpha=100 \ No newline at end of file