diff --git a/CrosshairMod/Button.cs b/CrosshairMod/Button.cs
deleted file mode 100644
index 2b5a32a..0000000
--- a/CrosshairMod/Button.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-using UnityEngine;
-
-namespace CrosshairMod
-{
- /*
- * 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
- {
- // 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.
-
- // Position / Dimension of the Button.
- public Vector2 position = new Vector2(0, 0);
- public Vector2 dimensions = new Vector2(0, 0);
-
- // Visibilty variables
- private bool m_visible = true;
- private bool m_active = true;
-
- // Label of the Button
- public string label { get; set; } = "";
-
- // OnClick event
- public event EventHandler OnClick;
-
- // Initialize Button
- public GUIButton(uint x, uint y, uint width, uint height, string label, params EventHandler[] OnClickEvent)
- {
- Logging.Debug.Log("Button Constructor");
-
- // Assign position, dimension and label
- this.position = new Vector2(x, y);
- this.dimensions = new Vector2(width, height);
- this.label = label;
-
- // Push OnClickEvents
- foreach(EventHandler e in OnClickEvent)
- OnClick += e;
- }
-
- public GUIButton()
- {
- // Empty
- }
-
-
- // Changes visibilty of the Button
- public void Toggle()
- {
- m_visible = !m_visible;
- }
-
- // Changes Usabilty of the button
- public void Activate()
- {
- m_active = !m_active;
- }
-
- // Updates and Draws the Button.
- public void Update()
- {
- if (m_visible)
- {
- // Get if the Button was pressed and invoke OnClick event accordingly
- bool buttonPressed = GUI.Button(new Rect(position, dimensions), label);
- if (buttonPressed && m_active)
- OnClick?.Invoke(this, EventArgs.Empty);
- }
- }
- }
-}
diff --git a/CrosshairMod/Crosshair.cs b/CrosshairMod/Crosshair.cs
index 39906c6..d8727c9 100644
--- a/CrosshairMod/Crosshair.cs
+++ b/CrosshairMod/Crosshair.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+
using UnityEngine;
diff --git a/CrosshairMod/CrosshairMod.csproj b/CrosshairMod/CrosshairMod.csproj
index 0906b96..b48e39e 100644
--- a/CrosshairMod/CrosshairMod.csproj
+++ b/CrosshairMod/CrosshairMod.csproj
@@ -9,9 +9,10 @@
Properties
CrosshairMod
CrosshairMod
- v4.7.2
+ v3.5
512
true
+
true
@@ -44,9 +45,11 @@
-
+
+
+
diff --git a/CrosshairMod/Interface.cs b/CrosshairMod/Interface.cs
index b8bbe47..68465e8 100644
--- a/CrosshairMod/Interface.cs
+++ b/CrosshairMod/Interface.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+
using UnityEngine;
@@ -21,7 +21,7 @@ namespace CrosshairMod
private static bool m_visible = false;
// Stores all Buttons used in the interface.
- private static List m_buttons = new List();
+ private static List m_inputs = new List();
// Values of the RGBA Sliders
private static int rSliderValue, gSliderValue, bSliderValue, aSliderValue;
@@ -35,13 +35,19 @@ namespace CrosshairMod
private static Vector2 m_dimension;
- // Creates a new button object and adds it to the ButtonList
- // Returns the index of the button
- private static int AddButton(uint x, uint y, uint width, uint height, string label, params EventHandler[] onClickEvent)
+ // 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)
{
- GUIButton buttonObj = new GUIButton(x, y, width, height, label, onClickEvent);
- m_buttons.Add(buttonObj);
- return m_buttons.Count - 1;
+ GUIButton buttonObj = new GUIButton(x, y, width, height, label, ID, onClickEvent);
+ m_inputs.Add(buttonObj);
+ }
+
+ // 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)
+ {
+ GUISlider sliderObj = new GUISlider(x, y, width, height, min, max, init, ID);
+ m_inputs.Add(sliderObj);
}
// Initializes all Buttons, gives them their function etc
@@ -60,30 +66,33 @@ namespace CrosshairMod
// Apply Texture to Style
m_style.normal.background = m_background;
- AddButton(3, 3, 3, 3, "", (object sender, EventArgs e) => { });
-
// Create Crosshair Visibilty Button
- 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"; };
+ AddButton(m_position.x + 20, m_position.y + 20, 200, 30,
+ (Crosshair.Enabled() ? "Hide Crosshair" : "Show Crosshair"), "Toggle", (object sender, EventArgs e) => { Crosshair.Toggle(); },
+ (object sender, EventArgs e) => { GUIButton btn = (GUIButton)sender; btn.label = (Crosshair.Enabled() ? "Hide Crosshair" : "Show Crosshair"); });
// Create Crosshair Size +/- Buttons
- AddButton((uint)m_position.x + 20, (uint)m_position.y + 60, 30, 30,
- "-", (object sender, EventArgs e) => { Crosshair.ChangeSize(-1); });
- AddButton((uint)m_position.x + 190, (uint)m_position.y + 60, 30, 30,
- "+", (object sender, EventArgs e) => { Crosshair.ChangeSize(+1); });
+ AddButton(m_position.x + 20, m_position.y + 60, 30, 30,
+ "-", "sizedown", (object sender, EventArgs e) => { Crosshair.ChangeSize(-1); });
+ AddButton(m_position.x + 190, m_position.y + 60, 30, 30,
+ "+", "sizeup", (object sender, EventArgs e) => { Crosshair.ChangeSize(+1); });
// Create Crosshair Thickness +/- Buttons
- AddButton((uint)m_position.x + 20, (uint)m_position.y + 100, 30, 30,
- "-", (object sender, EventArgs e) => { Crosshair.ChangeThickness(-1); });
- AddButton((uint)m_position.x + 190, (uint)m_position.y + 100, 30, 30,
- "+", (object sender, EventArgs e) => { Crosshair.ChangeThickness(+1); });
+ AddButton(m_position.x + 20, m_position.y + 100, 30, 30,
+ "-", "thickdown", (object sender, EventArgs e) => { Crosshair.ChangeThickness(-1); });
+ AddButton(m_position.x + 190, m_position.y + 100, 30, 30,
+ "+", "thickup", (object sender, EventArgs e) => { Crosshair.ChangeThickness(+1); });
- // Assign setting values to sliders
rSliderValue = Settings.GetValue("crosshairColorRed");
gSliderValue = Settings.GetValue("crosshairColorGreen");
bSliderValue = Settings.GetValue("crosshairColorBlue");
aSliderValue = Settings.GetValue("crosshairColorAlpha");
+
+ // Create RGBA Sliders
+ AddSlider(m_position.x + m_dimension.x / 2 + 60, m_position.y + 20, 200, 30, 0, 255, rSliderValue, "red");
+ AddSlider(m_position.x + m_dimension.x / 2 + 60, m_position.y + 60, 200, 30, 0, 255, gSliderValue, "green");
+ AddSlider(m_position.x + m_dimension.x / 2 + 60, m_position.y + 100, 200, 30, 0, 255, bSliderValue, "blue");
+ AddSlider(m_position.x + m_dimension.x / 2 + 60, m_position.y + 140, 200, 30, 0, 255, aSliderValue, "alpha");
}
// Displays / Hides the menu
@@ -107,18 +116,17 @@ namespace CrosshairMod
// Draw the RGBA Labels and Sliders
// TODO: Find better way to handle Sliders. Maybe make some InputInterface class that handles Buttons/Sliders etc
GUI.Label(new Rect(m_position.x + m_dimension.x / 2 + 20, m_position.y + 30, 200, 30), "R: " + rSliderValue);
- rSliderValue = (int)GUI.HorizontalSlider(new Rect(m_position.x + m_dimension.x / 2 + 60, m_position.y + 20, 200, 30), (int)rSliderValue, 0f, 255f);
-
GUI.Label(new Rect(m_position.x + m_dimension.x / 2 + 20, m_position.y + 70, 200, 30), "G: " + gSliderValue);
- gSliderValue = (int)GUI.HorizontalSlider(new Rect(m_position.x + m_dimension.x / 2 + 60, m_position.y + 60, 200, 30), (int)gSliderValue, 0f, 255f);
-
GUI.Label(new Rect(m_position.x + m_dimension.x / 2 + 20, m_position.y + 110, 200, 30), "B: " + bSliderValue);
- bSliderValue = (int)GUI.HorizontalSlider(new Rect(m_position.x + m_dimension.x / 2 + 60, m_position.y + 100, 200, 30), (int)bSliderValue, 0f, 255f);
-
GUI.Label(new Rect(m_position.x + m_dimension.x / 2 + 20, m_position.y + 150, 200, 30), "A: " + aSliderValue);
- aSliderValue = (int)GUI.HorizontalSlider(new Rect(m_position.x + m_dimension.x / 2 + 60, m_position.y + 140, 200, 30), (int)aSliderValue, 0f, 255f);
// Set crosshair Colour after getting slider values
+ 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
@@ -129,9 +137,9 @@ namespace CrosshairMod
// Calls the Update function on all Buttons to check if they were pressed, and execute their Action
private static void HandleButtons()
{
- foreach(GUIButton button in m_buttons)
+ foreach(InputObject obj in m_inputs)
{
- button.Update();
+ obj.Update();
}
}
}
diff --git a/CrosshairMod/Interface/Button.cs b/CrosshairMod/Interface/Button.cs
new file mode 100644
index 0000000..895da89
--- /dev/null
+++ b/CrosshairMod/Interface/Button.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+
+using UnityEngine;
+
+namespace CrosshairMod
+{
+ /*
+ * 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
+ {
+ // 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;
+
+ // Label of the Button
+ public string label { get; set; } = "";
+
+ // 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");
+
+ // Assign position, dimension and label
+ this.label = label;
+
+ // Push OnClickEvents
+ foreach(EventHandler e in OnClickEvent)
+ OnClick += e;
+ }
+
+ public GUIButton(string ID)
+ : base(0, 0, 0, 0, ID)
+ {
+ // Empty
+ }
+
+ // 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);
+ if (buttonPressed)
+ OnClick?.Invoke(this, EventArgs.Empty);
+
+ return (buttonPressed ? 1.0f : 0.0f);
+ }
+ }
+}
diff --git a/CrosshairMod/Interface/InputObject.cs b/CrosshairMod/Interface/InputObject.cs
new file mode 100644
index 0000000..7e14d2a
--- /dev/null
+++ b/CrosshairMod/Interface/InputObject.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+
+using UnityEngine;
+
+namespace CrosshairMod
+{
+ /*
+ * 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;
+
+ // 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 (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
new file mode 100644
index 0000000..47dbf80
--- /dev/null
+++ b/CrosshairMod/Interface/Slider.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+
+using UnityEngine;
+
+namespace CrosshairMod
+{
+ class GUISlider : InputObject
+ {
+ // Min/Max values for the slider
+ public float Min { get; set; } = 0;
+ public float Max { get; set; } = 0;
+
+ // Current slider value
+ public float Value { get; set; } = 0;
+
+ 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;
+ }
+
+ public GUISlider(string ID)
+ :base (0, 0, 0, 0, ID)
+ {
+
+ }
+
+ public override float Update()
+ {
+ Value = GUI.HorizontalSlider(new Rect(position, dimensions), Value, Min, Max);
+ return Value;
+ }
+ }
+}
diff --git a/CrosshairMod/Logging.cs b/CrosshairMod/Logging.cs
index c39db3f..db9fd39 100644
--- a/CrosshairMod/Logging.cs
+++ b/CrosshairMod/Logging.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+
using UnityEngine;
diff --git a/CrosshairMod/Main.cs b/CrosshairMod/Main.cs
index c3b1a78..d0a81da 100644
--- a/CrosshairMod/Main.cs
+++ b/CrosshairMod/Main.cs
@@ -11,7 +11,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+
using UnityEngine;
namespace CrosshairMod
@@ -31,6 +31,7 @@ namespace CrosshairMod
// This will be executed first
void Start()
{
+
// Update the settings
Settings.LoadSettings(".\\Blackwake_Data\\Managed\\Mods\\chSettings.sett");
// Create Crosshair
diff --git a/CrosshairMod/Settings.cs b/CrosshairMod/Settings.cs
index 36d16d7..795ad70 100644
--- a/CrosshairMod/Settings.cs
+++ b/CrosshairMod/Settings.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+
namespace CrosshairMod
{