diff --git a/CrosshairMod/Crosshair.cs b/CrosshairMod/Crosshair.cs
index aa42e23..d8727c9 100644
--- a/CrosshairMod/Crosshair.cs
+++ b/CrosshairMod/Crosshair.cs
@@ -8,31 +8,34 @@ using UnityEngine;
namespace CrosshairMod
{
- ///
- /// Contains Crosshair information and draws/creates it
- ///
+ /* The class responsible for drawing/creating/administrating the crosshair.
+ *
+ * This is where settings are applied to the crosshair.
+ */
static class Crosshair
{
- ///
- /// Graphics information for the crosshair
- ///
+ // Crosshair Texture / Style
private static Texture2D m_texture = new Texture2D(0, 0);
private static GUIStyle m_style;
+ // If crosshair is visible or hidden
private static bool m_enabled = true;
private static bool m_validState = true;
+ // Toggles visibilty of the crosshair
public static void Toggle()
{
m_enabled = !m_enabled;
Settings.SetSetting("crosshairVisible", 1, true);
}
+ // Returns wether the crosshair is enabled
public static bool Enabled()
{
return m_enabled;
}
+ // Change Color
public static void SetColor(int r, int g, int b, int a)
{
Settings.SetSetting("crosshairColorRed", r);
@@ -43,6 +46,7 @@ namespace CrosshairMod
Create();
}
+ // Change Size
public static void ChangeSize(int difference)
{
int currentLength = Settings.GetValue("crosshairLength");
@@ -52,6 +56,7 @@ namespace CrosshairMod
Create();
}
+ // Change Thickness
public static void ChangeThickness(int difference)
{
int currentThickness = Settings.GetValue("crosshairThickness");
@@ -61,9 +66,7 @@ namespace CrosshairMod
Create();
}
- ///
- /// Creates a new crosshair texture with the current settings
- ///
+ // This must be called, or else no crosshair will be rendered
public static void Create()
{
// Creates a crosshair texture
@@ -122,6 +125,7 @@ namespace CrosshairMod
m_style.normal.background = m_texture;
}
+ // Render the Crosshair
public static void Render()
{
// If the crosshair is faulty, then don't execute this code
diff --git a/CrosshairMod/Interface.cs b/CrosshairMod/Interface.cs
index 1d77afe..53b71c7 100644
--- a/CrosshairMod/Interface.cs
+++ b/CrosshairMod/Interface.cs
@@ -8,64 +8,45 @@ using UnityEngine;
namespace CrosshairMod
{
- ///
- /// Handles and contains every Object needed for the interface
- ///
+
+ /* A class that handles the Crosshair GUI.
+ *
+ * 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
private static bool m_visible = false;
- ///
- /// A list of all Objects (That includes buttons, sliders etc) inside the GUI Window
- /// This makes it easy to add more components if it is needed.
- ///
- private static Dictionary m_inputs = new Dictionary();
+ // Stores all Buttons used in the interface.
+ private static List m_inputs = new List();
- ///
- /// RGBA Slider values
- ///
+ // Values of the RGBA Sliders
private static int rSliderValue, gSliderValue, bSliderValue, aSliderValue;
+ // Position ind dimension of the GUI background
private static Vector2 m_position;
private static Vector2 m_dimension;
- ///
- /// Creates a new Button and adds it to the content list
- ///
- /// X-Position
- /// Y-position
- /// Width
- /// Height
- /// Text to be displayed on the button
- /// Key of the Button
- /// Action to be executed when the button is pressed
+ // Creates a new button object and adds it to the List
private static void AddButton(float x, float y, float width, float height, string label, string ID, params EventHandler[] onClickEvent)
{
- Input.Button buttonObj = new Input.Button(x, y, width, height, label, onClickEvent);
- m_inputs.Add(ID, buttonObj);
+ GUIButton buttonObj = new GUIButton(x, y, width, height, label, ID, onClickEvent);
+ m_inputs.Add(buttonObj);
}
- ///
- /// Creates a new Slider and adds ot to the content list
- ///
- /// X-Position
- /// Y-Position/param>
- /// Width
- /// Height
- /// Minimum value of the slider
- /// Maximum value of the slider
- /// Starting value of the slider
- /// Key of the slider
+ // Creates a new slider object and adds it to the List
+ // Returns the index of the button
private static void AddSlider(float x, float y, float width, float height, float min, float max, float init, string ID)
{
- Input.Slider sliderObj = new Input.Slider(x, y, width, height, min, max, init);
- m_inputs.Add(ID, sliderObj);
+ GUISlider sliderObj = new GUISlider(x, y, width, height, min, max, init, ID);
+ m_inputs.Add(sliderObj);
}
- ///
- /// Creates all needed input objects and initializes window
- ///
+ // Initializes all Buttons, gives them their function etc
public static void Init()
{
// Set dimension to 0.25 of the screen width/height
@@ -77,7 +58,7 @@ namespace CrosshairMod
// Create Crosshair Visibilty Button
AddButton(20, 20, 200, 30,
(Crosshair.Enabled() ? "Hide Crosshair" : "Show Crosshair"), "Toggle", (object sender, EventArgs e) => { Crosshair.Toggle(); },
- (object sender, EventArgs e) => { Input.Button btn = (Input.Button)sender; btn.Label = (Crosshair.Enabled() ? "Hide Crosshair" : "Show Crosshair"); });
+ (object sender, EventArgs e) => { GUIButton btn = (GUIButton)sender; btn.label = (Crosshair.Enabled() ? "Hide Crosshair" : "Show Crosshair"); });
// Create Crosshair Size +/- Buttons
AddButton(20, 60, 30, 30,
@@ -103,25 +84,23 @@ namespace CrosshairMod
AddSlider(m_dimension.x / 2 + 60, 150, 200, 30, 0, 255, aSliderValue, "alpha");
}
+ // Displays / Hides the menu
public static void Toggle()
{
m_visible = !m_visible;
}
+ // Renders the window
public static void Render()
{
if (m_visible)
GUI.Window(420, new Rect(m_position, m_dimension), RenderFunc, "Crosshair Settings");
}
- ///
- /// Where actual rendering happens. Draws all objects and updated them
- ///
+ // Renders the Panel, but also handles Updating the buttons
private static void RenderFunc(int windowID)
{
- // Make Window draggable
- GUI.DragWindow(new Rect(0, 0, 10000, 20));
-
+
// Draw the Length and Thickness Labels
GUI.Label(new Rect(60, 70, 120, 30), "Length: " + Settings.GetValue("crosshairLength"));
GUI.Label(new Rect(60, 110, 120, 30), "Thickness: " + Settings.GetValue("crosshairThickness"));
@@ -133,27 +112,25 @@ namespace CrosshairMod
GUI.Label(new Rect(m_dimension.x / 2 + 20, 150, 200, 30), "A: " + aSliderValue);
// Set crosshair Colour after getting slider values
- IEnumerable it = m_inputs.OfType();
- rSliderValue = (int)((Input.Slider)m_inputs["red"]).Value;
- gSliderValue = (int)((Input.Slider)m_inputs["green"]).Value;
- bSliderValue = (int)((Input.Slider)m_inputs["blue"]).Value;
- aSliderValue = (int)((Input.Slider)m_inputs["alpha"]).Value;
+ IEnumerable it = m_inputs.OfType();
+ rSliderValue = (int)it.First(slider => slider.ID == "red").Value;
+ gSliderValue = (int)it.First(slider => slider.ID == "green").Value;
+ bSliderValue = (int)it.First(slider => slider.ID == "blue").Value;
+ aSliderValue = (int)it.First(slider => slider.ID == "alpha").Value;
Crosshair.SetColor(rSliderValue, gSliderValue, bSliderValue, aSliderValue);
// Update Buttons
- HandleInputObjects();
+ HandleButtons();
}
- ///
- /// Calls the Update function of each input object
- ///
- private static void HandleInputObjects()
+ // Calls the Update function on all Buttons to check if they were pressed, and execute their Action
+ private static void HandleButtons()
{
- foreach(KeyValuePair obj in m_inputs)
+ foreach(InputObject obj in m_inputs)
{
- obj.Value.Update();
+ obj.Update();
}
}
}
diff --git a/CrosshairMod/Interface/Button.cs b/CrosshairMod/Interface/Button.cs
index 17e42db..895da89 100644
--- a/CrosshairMod/Interface/Button.cs
+++ b/CrosshairMod/Interface/Button.cs
@@ -6,60 +6,51 @@ using System.Text;
using UnityEngine;
-namespace CrosshairMod.Input
+namespace CrosshairMod
{
- ///
- /// Button wrapper for Unitys GUI.Button() function. I made this in order
- /// to store buttons and render them in Lists
- ///
- class Button : InputObject
+ /*
+ * A button wrapper class that is used right now as I don't have access to
+ * the games buttons. Since UnityEngine.GUI only has a function to draw Buttons,
+ * I made this class for easy handling.
+ *
+ */
+ class GUIButton : InputObject
{
- ///
- /// Event Handler that contains the actions to execute when the Button was clicked
- ///
+ // da_google thinks this Button Wrapper is stupid, so let's see what ths Button Wrapper thinks about him
+ private const bool IS_DA_GOOGLE_STUPID = true;
+ // Interesting.
+
+ // OnClick event
public event EventHandler OnClick;
- public string Label = "";
+ // Label of the Button
+ public string label { get; set; } = "";
- ///
- /// Create new Button
- ///
- /// X-Position
- /// Y-Position
- /// Width
- /// Height
- /// Text inside the button
- /// Action to execute when button is pressed
- public Button(float x, float y, float width, float height, string label, params EventHandler[] OnClickEvent)
- : base(x, y, width, height)
+ // Initialize Button
+ public GUIButton(float x, float y, float width, float height, string label, string ID, params EventHandler[] OnClickEvent)
+ : base(x, y, width, height, ID)
{
- Logging.Debug.Log("Button Constructor: " + label);
+ Logging.Debug.Log("Button Constructor");
// Assign position, dimension and label
- this.Label = label;
+ this.label = label;
// Push OnClickEvents
foreach(EventHandler e in OnClickEvent)
OnClick += e;
}
- ///
- /// Sad, pathetic default constructor
- ///
- public Button()
- : base(0, 0, 0, 0)
+ public GUIButton(string ID)
+ : base(0, 0, 0, 0, ID)
{
// Empty
}
- ///
- /// Draws button and returns button state / executes button action
- ///
- /// 1f if the button is pressed, 0f else
+ // Updates and Draws the Button.
public override float Update()
{
// Get if the Button was pressed and invoke OnClick event accordingly
- bool buttonPressed = GUI.Button(new Rect(position, dimensions), Label);
+ bool buttonPressed = GUI.Button(new Rect(position, dimensions), label);
if (buttonPressed)
OnClick?.Invoke(this, EventArgs.Empty);
diff --git a/CrosshairMod/Interface/InputObject.cs b/CrosshairMod/Interface/InputObject.cs
index cd039f0..7e14d2a 100644
--- a/CrosshairMod/Interface/InputObject.cs
+++ b/CrosshairMod/Interface/InputObject.cs
@@ -6,34 +6,31 @@ using System.Text;
using UnityEngine;
-namespace CrosshairMod.Input
+namespace CrosshairMod
{
- ///
- /// Base class for all InputObjects. Defines basic attributes that
- /// every input object needs
- ///
+ /*
+ * Base of all Input Objects.
+ *
+ * Any Input Object that wants to be displayed in the Interface must
+ * inherit from this class.
+ */
abstract class InputObject
{
+ // position and dimension of the object
public Vector2 position, dimensions;
- ///
- /// Create new InputObject
- ///
- /// X-Position
- /// Y-Position
- /// Width
- /// Height
- public InputObject(float x, float y, float width, float height)
+ // ID of the Object
+ public readonly string ID;
+
+ // constructor to set position and size
+ public InputObject(float x, float y, float width, float height, string ID)
{
this.position = new Vector2(x, y);
this.dimensions = new Vector2(width, height);
+ this.ID = ID;
}
- ///
- /// The Update method every Input Object needs.
- /// This is needed to store all kinds of input objects in one List for example
- ///
- /// Value of the Object
+ // the update method (that works as renderer) must be overriden by each object
public abstract float Update();
}
}
diff --git a/CrosshairMod/Interface/Slider.cs b/CrosshairMod/Interface/Slider.cs
index bab072e..47dbf80 100644
--- a/CrosshairMod/Interface/Slider.cs
+++ b/CrosshairMod/Interface/Slider.cs
@@ -6,52 +6,31 @@ using System.Text;
using UnityEngine;
-namespace CrosshairMod.Input
+namespace CrosshairMod
{
- class Slider : InputObject
+ class GUISlider : InputObject
{
- ///
- /// Min/Max Slider values
- ///
- public float Min = 0;
- public float Max = 0;
+ // Min/Max values for the slider
+ public float Min { get; set; } = 0;
+ public float Max { get; set; } = 0;
- ///
- /// Current slider value
- ///
- public float Value = 0;
+ // Current slider value
+ public float Value { get; set; } = 0;
- ///
- /// Creates a new Slider
- ///
- /// X-Position
- /// Y-Position
- /// Width
- /// Height
- /// Minimum Slider value
- /// Maximum Slider value
- /// Initial Slider value
- public Slider(float x, float y, float width, float height, float min, float max, float init)
- : base(x, y, width, height)
+ public GUISlider(float x, float y, float width, float height, float min, float max, float init, string ID)
+ : base(x, y, width, height, ID)
{
Min = min;
Max = max;
Value = init;
}
- ///
- /// Sad, pathetic default constructor
- ///
- public Slider()
- :base (0, 0, 0, 0)
+ public GUISlider(string ID)
+ :base (0, 0, 0, 0, ID)
{
}
- ///
- /// Draws and Updates the slider
- ///
- /// Value of the Slider
public override float Update()
{
Value = GUI.HorizontalSlider(new Rect(position, dimensions), Value, Min, Max);
diff --git a/CrosshairMod/Logging.cs b/CrosshairMod/Logging.cs
index 3f1c199..db9fd39 100644
--- a/CrosshairMod/Logging.cs
+++ b/CrosshairMod/Logging.cs
@@ -8,17 +8,17 @@ using UnityEngine;
namespace CrosshairMod
{
- ///
- /// Handles Logging in the Crosshair mod
- ///
+ // 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
{
+ // The Prefix that gets put in front of every Log
public const string PREFIX = "[CROSSHAIRMOD]";
- ///
- /// Logging's subclass for Debug Logging.
- /// This only logs messages in the debug build of the mod.
- ///
+ // A kind of sub-class that is used to Log messages that will only appear
+ // when the User installs a Debug build of the Mod. Release versions will
+ // not log Debug messages this way.
public static class Debug
{
public static void Log(string message)
@@ -44,17 +44,19 @@ namespace CrosshairMod
}
+ // Logs information
public static void Log(string message)
{
Console.WriteLine(PREFIX + "Info: " + message);
}
+ // Logs warnings
public static void LogWarning(string message)
{
Console.WriteLine(PREFIX + "Warning: " + message);
}
-
+ // Logs errors
public static void LogError(string message)
{
UnityEngine.Debug.Log(PREFIX + "Error: " + message);
diff --git a/CrosshairMod/Main.cs b/CrosshairMod/Main.cs
index 910981d..d0a81da 100644
--- a/CrosshairMod/Main.cs
+++ b/CrosshairMod/Main.cs
@@ -1,11 +1,12 @@
/*
- * Source code of a mod that adds a crosshair into
+ * Source code of a mode that adds a crosshair into
* the game Blackwake.
*
* @author Lauchmelder
- * @version v0.3.1
+ * @version v0.3
*/
+
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,22 +16,24 @@ using UnityEngine;
namespace CrosshairMod
{
- ///
- /// Class that gets loaded by the ModLoader. Calls every component of the Mod
- ///
- public class CrosshairMod : MonoBehaviour
+
+ /*
+ * This is the Main class that is responsible for
+ * handling initializing and updating the components
+ * of the crosshair mod.
+ */
+ public class Main : MonoBehaviour
{
- ///
- /// Default Hotkey Definitions
- ///
+ // Define Hotkeys for Menu and Crosshair Toggle
private char MENU_OPEN_KEY = 'H';
private char CH_TOGGLE_KEY = 'J';
+ // This will be executed first
void Start()
{
// Update the settings
- Settings.LoadSettings(".\\Blackwake_Data\\Managed\\Mods\\Assets\\chSettings.sett");
+ Settings.LoadSettings(".\\Blackwake_Data\\Managed\\Mods\\chSettings.sett");
// Create Crosshair
Crosshair.Create();
// Create Panel
@@ -41,6 +44,7 @@ namespace CrosshairMod
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
@@ -62,10 +66,11 @@ namespace CrosshairMod
Crosshair.Render();
}
+ // Will be called when the application is closed
void OnApplicationQuit()
{
// Save settings
- Settings.SaveSettings(".\\Blackwake_Data\\Managed\\Mods\\Assets\\chSettings.sett");
+ Settings.SaveSettings(".\\Blackwake_Data\\Managed\\Mods\\chSettings.sett");
Logging.Debug.Log("Saved Settings");
}
}
diff --git a/CrosshairMod/Settings.cs b/CrosshairMod/Settings.cs
index a48bedc..795ad70 100644
--- a/CrosshairMod/Settings.cs
+++ b/CrosshairMod/Settings.cs
@@ -6,17 +6,16 @@ using System.Text;
namespace CrosshairMod
{
- ///
- /// Loads, contains and handles settings
- ///
+ /*
+ * The class that is responsible for loading and storing all the
+ * necessary settings. There is much room for improvement.
+ */
static class Settings
{
+ // Initialize Settings dictionary
private static Dictionary m_settings = new Dictionary();
- ///
- /// Load settings from file
- ///
- ///
+ // Load settings from file
public static void LoadSettings(string filepath)
{
Logging.Debug.Log("Accessing Settings at " + filepath);
@@ -76,10 +75,7 @@ namespace CrosshairMod
Logging.Log("Settings loaded.");
}
- ///
- /// Converts dictionary to a string to be stored in the settings file
- ///
- /// Save location
+ // Converts the dictionary to a sett file
public static void SaveSettings(string filepath)
{
string filecontent = "";
@@ -91,11 +87,7 @@ namespace CrosshairMod
System.IO.File.WriteAllText(filepath, filecontent);
}
- ///
- /// Create new setting and add it to the dictionary
- ///
- /// Setting name
- /// Setting value
+ // Adds a setting to the settings
public static void AddSetting(string key, int value)
{
if (m_settings.ContainsKey(key))
@@ -104,12 +96,7 @@ namespace CrosshairMod
m_settings.Add(key, value);
}
- ///
- /// Change a settings value
- ///
- /// Setting name
- /// New setting value
- /// If the setting doesn't exist, create it
+ // Changes a settings value, and adds it if specified
public static void SetSetting(string key, int newVal, bool addIfDoesntExist = false)
{
// If the setting doesn't exist, either add and set it, or print a Debug.Warning
@@ -130,13 +117,9 @@ namespace CrosshairMod
m_settings[key] = newVal;
}
- ///
- /// Returns the value of a setting
- ///
- /// Setting name
- /// Add the setting if it doesn't exist
- /// Initial value of the setting in case it doesn't exist
- ///
+ // Tries to return the value belonging to a certain key
+ // If the specified key doesn't exist, it returns 0 and logs an error
+ // One can also specify that the setting should be created with some initial value
public static int GetValue(string key, bool addIfDoesntExist = false, int initialValue = 0)
{
int value = 0;
diff --git a/CrosshairMod/bin/Release/CrosshairMod.dll b/CrosshairMod/bin/Release/CrosshairMod.dll
index db70273..7175232 100644
Binary files a/CrosshairMod/bin/Release/CrosshairMod.dll and b/CrosshairMod/bin/Release/CrosshairMod.dll differ