Major reworking of the HUD underpinnings to be more modular and require less code duplication. Also made the Editor HUD movable, but for now it's stuck along the left edge.
[VOID.git] / VOID_HUDAdvanced.cs
blob:a/VOID_HUDAdvanced.cs -> blob:b/VOID_HUDAdvanced.cs
--- a/VOID_HUDAdvanced.cs
+++ b/VOID_HUDAdvanced.cs
@@ -47,11 +47,6 @@
 		protected HUDWindow leftHUD;
 		protected HUDWindow rightHUD;
 
-		[AVOID_SaveValue("leftHUDPos")]
-		protected VOID_SaveValue<Rect> leftHUDPos;
-		[AVOID_SaveValue("rightHUDPos")]
-		protected VOID_SaveValue<Rect> rightHUDPos;
-
 		/*
 		 * Properties
 		 * */
@@ -77,29 +72,30 @@
 		 * */
 		public VOID_HUDAdvanced() : base()
 		{
-			this._Name = "Advanced Heads-Up Display";
-
-			this.toggleActive = true;
-
-			this.leftHUD = new HUDWindow(this.leftHUDWindow, new Rect(
-				Screen.width * .5f - (float)GameSettings.UI_SIZE * .25f - 300f,
-				Screen.height - 200f,
-				300f, 90f)
+			this.Name = "Advanced Heads-Up Display";
+
+			this.Active = true;
+
+			this.leftHUD = new HUDWindow("leftHUD",
+				this.leftHUDWindow,
+				new Rect(
+					Screen.width * .5f - (float)GameSettings.UI_SIZE * .25f - 300f,
+					Screen.height - 200f,
+					300f, 90f)
 			);
 			this.Windows.Add(this.leftHUD);
 
-			this.leftHUDPos = this.leftHUD.WindowPos;
-
-			this.rightHUD = new HUDWindow(this.rightHUDWindow, new Rect(
-				Screen.width * .5f + (float)GameSettings.UI_SIZE * .25f,
-				Screen.height - 200f,
-				300f, 90f)
+			this.rightHUD = new HUDWindow(
+				"rightHUD",
+				this.rightHUDWindow,
+				new Rect(
+					Screen.width * .5f + (float)GameSettings.UI_SIZE * .25f,
+					Screen.height - 200f,
+					300f, 90f)
 			);
 			this.Windows.Add(this.rightHUD);
 
-			this.rightHUDPos = this.rightHUD.WindowPos;
-
-			this.positionsLocked = true;
+			this.positionsLocked.value = true;
 
 			Tools.PostDebugMessage (this, "Constructed.");
 		}
@@ -153,7 +149,12 @@
 				leftHUD.Append(string.Intern("-- POWER LOST --"));
 			}
 
-			GUILayout.Label(leftHUD.ToString(), VOID_Styles.labelHud, GUILayout.ExpandWidth(true));
+			GUILayout.Label(
+				leftHUD.ToString(),
+				VOID_Styles.labelHud,
+				GUILayout.ExpandWidth(true),
+				GUILayout.ExpandHeight(true)
+			);
 
 			if (!this.positionsLocked)
 			{
@@ -212,7 +213,12 @@
 				rightHUD.Append(string.Intern("-- POWER LOST --"));
 			}
 
-			GUILayout.Label(rightHUD.ToString(), VOID_Styles.labelHud, GUILayout.ExpandWidth(true));
+			GUILayout.Label(
+				rightHUD.ToString(),
+				VOID_Styles.labelHud,
+				GUILayout.ExpandWidth(true),
+				GUILayout.ExpandHeight(true)
+			);
 
 			if (!this.positionsLocked)
 			{
@@ -235,17 +241,31 @@
 				}
 			}
 
+			if (VOID_Data.upcomingManeuverNodes < 1 && this.Windows.Contains(this.rightHUD))
+			{
+				this.Windows.Remove(this.rightHUD);
+			}
+			else if (VOID_Data.upcomingManeuverNodes > 0 && !this.Windows.Contains(this.rightHUD))
+			{
+				this.Windows.Add(this.rightHUD);
+			}
+
 			base.DrawGUI();
-
-			this.leftHUDPos.value = this.leftHUD.WindowPos;
-			this.rightHUDPos.value = this.rightHUD.WindowPos;
 		}
 
 		public override void DrawConfigurables()
 		{
-			this.positionsLocked = GUILayout.Toggle(this.positionsLocked,
-				string.Intern("Lock Advanced HUD Positions"),
-				GUILayout.ExpandWidth(false));
+			base.DrawConfigurables();
+
+			if (GUILayout.Button(string.Intern("Reset Advanced HUD Positions"), GUILayout.ExpandWidth(false)))
+			{
+				foreach (HUDWindow window in this.Windows)
+				{
+					window.WindowPos = new Rect(window.defaultWindowPos);
+				}
+			}
+
+			this.positionsLocked.value = GUITools.Toggle(this.positionsLocked, string.Intern("Lock Advanced HUD Positions"));
 		}
 	}
 }