From 81d0cc6754872b0fd54d9a8ba3639b3a494f9cfa Mon Sep 17 00:00:00 2001
From: Robert <Robert-Altner@t-online.de>
Date: Fri, 2 Aug 2019 20:01:49 +0200
Subject: [PATCH] Made the Toggle Button's label change on Click

It now shows "Hide Crosshair" when the crosshair is enabled and vice versa
---
 CrosshairMod/Crosshair.cs | 6 ++++++
 CrosshairMod/Interface.cs | 9 ++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/CrosshairMod/Crosshair.cs b/CrosshairMod/Crosshair.cs
index a649372..39906c6 100644
--- a/CrosshairMod/Crosshair.cs
+++ b/CrosshairMod/Crosshair.cs
@@ -29,6 +29,12 @@ namespace CrosshairMod
             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)
         {
diff --git a/CrosshairMod/Interface.cs b/CrosshairMod/Interface.cs
index 35206af..d287ba5 100644
--- a/CrosshairMod/Interface.cs
+++ b/CrosshairMod/Interface.cs
@@ -34,7 +34,8 @@ namespace CrosshairMod
 
 
         // Creates a new button object and adds it to the ButtonList
-        private static void AddButton(uint x, uint y, uint width, uint height, string label, params EventHandler[] onClickEvent)
+        // Returns the index of the button
+        private static int AddButton(uint x, uint y, uint width, uint height, string label, params EventHandler[] onClickEvent)
         {
             GUIButton buttonObj = new GUIButton(x, y, width, height, label);
             foreach(EventHandler e in onClickEvent)
@@ -43,6 +44,7 @@ namespace CrosshairMod
             }
 
             m_buttons.Add(buttonObj);
+            return m_buttons.Count - 1;
         }
 
         // Initializes all Buttons, gives them their function etc
@@ -65,8 +67,9 @@ namespace CrosshairMod
 
             // 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)
-            AddButton((uint)m_position.x + 20, (uint)m_position.y + 20, 200, 30, 
-                "Toggle Crosshair", (object sender, EventArgs e) => { Crosshair.Toggle(); });
+            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"; };
 
             // Create Crosshair Size +/- Buttons
             AddButton((uint)m_position.x + 20, (uint)m_position.y + 60, 30, 30,