VOID_HUDAdvanced: Fixed thrust offset to be in local coordinates, rather than world coordinates, to make it look more sane.
[VOID.git] / VOID_HUDAdvanced.cs
blob:a/VOID_HUDAdvanced.cs -> blob:b/VOID_HUDAdvanced.cs
--- a/VOID_HUDAdvanced.cs
+++ b/VOID_HUDAdvanced.cs
@@ -78,7 +78,7 @@
 		{
 			this._Name = "Advanced Heads-Up Display";
 
-			this._Active.value = true;
+			this.toggleActive = true;
 
 			this.leftHUDdefaultPos = new Rect(
 				Screen.width * .5f - (float)GameSettings.UI_SIZE * .25f - 300f,
@@ -105,9 +105,9 @@
 
 			leftHUD = new StringBuilder();
 
-			VOID_Core.Instance.LabelStyles["hud"].alignment = TextAnchor.UpperRight;
-
-			if (VOID_Core.Instance.powerAvailable)
+			this.core.LabelStyles["hud"].alignment = TextAnchor.UpperRight;
+
+			if (this.core.powerAvailable)
 			{
 				leftHUD.AppendFormat(
 					string.Intern("Mass: {0}\n"),
@@ -134,7 +134,7 @@
 					VOID_Data.vesselAngularVelocity.ToSIString(2)
 				);
 
-				if (VOID_Data.stageNominalThrust != 0)
+				if (VOID_Data.stageNominalThrust != 0d)
 				{
 					leftHUD.AppendFormat(
 						string.Intern("Thrust Offset: {0}\n"),
@@ -144,11 +144,11 @@
 			}
 			else
 			{
-				VOID_Core.Instance.LabelStyles["hud"].normal.textColor = Color.red;
+				this.core.LabelStyles["hud"].normal.textColor = Color.red;
 				leftHUD.Append(string.Intern("-- POWER LOST --"));
 			}
 
-			GUILayout.Label(leftHUD.ToString(), VOID_Core.Instance.LabelStyles["hud"], GUILayout.ExpandWidth(true));
+			GUILayout.Label(leftHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true));
 
 			if (!this.positionsLocked)
 			{
@@ -164,9 +164,9 @@
 
 			rightHUD = new StringBuilder();
 
-			VOID_Core.Instance.LabelStyles["hud"].alignment = TextAnchor.UpperLeft;
-
-			if (VOID_Core.Instance.powerAvailable)
+			this.core.LabelStyles["hud"].alignment = TextAnchor.UpperLeft;
+
+			if (this.core.powerAvailable)
 			{
 				rightHUD.AppendFormat(
 					"Burn Δv (Rem/Tot): {0} / {1}\n",
@@ -203,11 +203,11 @@
 			}
 			else
 			{
-				VOID_Core.Instance.LabelStyles["hud"].normal.textColor = Color.red;
+				this.core.LabelStyles["hud"].normal.textColor = Color.red;
 				rightHUD.Append(string.Intern("-- POWER LOST --"));
 			}
 
-			GUILayout.Label(rightHUD.ToString(), VOID_Core.Instance.LabelStyles["hud"], GUILayout.ExpandWidth(true));
+			GUILayout.Label(rightHUD.ToString(), this.core.LabelStyles["hud"], GUILayout.ExpandWidth(true));
 
 			if (!this.positionsLocked)
 			{
@@ -221,7 +221,7 @@
 		{
 			if (this.primaryHUD == null)
 			{
-				foreach (IVOID_Module module in VOID_Core.Instance.Modules)
+				foreach (IVOID_Module module in this.core.Modules)
 				{
 					if (module is VOID_HUD)
 					{
@@ -237,9 +237,9 @@
 				}
 
 				this.leftHUDPos.value = GUI.Window(
-					VOID_Core.Instance.windowID,
+					this.core.windowID,
 					this.leftHUDPos,
-					this.leftHUDWindow,
+					VOID_Tools.GetWindowHandler(this.leftHUDWindow),
 					GUIContent.none,
 					GUIStyle.none
 				);
@@ -247,9 +247,9 @@
 				if (VOID_Data.upcomingManeuverNodes > 0)
 				{
 					this.rightHUDPos.value = GUI.Window(
-						VOID_Core.Instance.windowID,
+						this.core.windowID,
 						this.rightHUDPos,
-						this.rightHUDWindow,
+						VOID_Tools.GetWindowHandler(this.rightHUDWindow),
 						GUIContent.none,
 						GUIStyle.none
 					);
@@ -378,7 +378,7 @@
 		public static readonly VOID_DoubleValue vesselAccel = new VOID_DoubleValue(
 			"Acceleration",
 			() => geeForce * KerbinGee,
-			"m/s"
+			"m/s²"
 		);
 
 		public static readonly VOID_IntValue vesselCrewCount = new VOID_IntValue(
@@ -433,18 +433,18 @@
 			"Nominal Stage Thrust",
 			delegate()
 		{
-			if (SimManager.LastStage == null)
+			if (core.LastStage == null)
 			{
 				return double.NaN;
 			}
 
-			if (SimManager.LastStage.actualThrust == 0d)
-			{
-				return SimManager.LastStage.thrust;
-			}
-			else
-			{
-				return SimManager.LastStage.actualThrust;
+			if (core.LastStage.actualThrust == 0d)
+			{
+				return core.LastStage.thrust;
+			}
+			else
+			{
+				return core.LastStage.actualThrust;
 			}
 		},
 			"kN"
@@ -454,12 +454,12 @@
 			"Stage Mass Flow",
 			delegate()
 			{
-				if (SimManager.LastStage == null)
+				if (core.LastStage == null)
 				{
 					return double.NaN;
 				}
 
-			double stageIsp = SimManager.LastStage.isp;
+			double stageIsp = core.LastStage.isp;
 			double stageThrust = stageNominalThrust;
 
 			Tools.PostDebugMessage(typeof(VOID_Data), "calculating stageMassFlow from:\n" +
@@ -528,7 +528,7 @@
 			"Total Burn Time",
 			delegate()
 			{
-				if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN)
+				if (core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
 				{
 					return double.NaN;
 				}
@@ -544,7 +544,7 @@
 			"Burn Time Remaining",
 			delegate()
 			{
-				if (SimManager.LastStage == null || currManeuverDVRemaining == double.NaN)
+				if (core.LastStage == null || currManeuverDVRemaining == double.NaN)
 				{
 					return double.NaN;
 				}
@@ -560,7 +560,7 @@
 			"Half Burn Time",
 			delegate()
 		{
-			if (SimManager.LastStage == null || currManeuverDeltaV.Value == double.NaN)
+			if (core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
 			{
 				return double.NaN;
 			}
@@ -576,7 +576,7 @@
 			"Full burn time to be half done at node",
 			delegate()
 		{
-			if (SimManager.LastStage == null && upcomingManeuverNodes < 1)
+			if (core.LastStage == null && upcomingManeuverNodes < 1)
 			{
 				return "N/A";
 			}
@@ -589,6 +589,11 @@
 			}
 
 			double interval = (node.UT - currentNodeBurnDuration) - Planetarium.GetUniversalTime();
+
+			if (double.IsNaN(interval))
+			{
+				return string.Intern("NaN");
+			}
 
 			int sign = Math.Sign(interval);
 			interval = Math.Abs(interval);
@@ -612,7 +617,7 @@
 			"Full burn time to be half done at node",
 			delegate()
 			{
-			if (SimManager.LastStage == null && upcomingManeuverNodes < 1)
+			if (core.LastStage == null && upcomingManeuverNodes < 1)
 			{
 				return "N/A";
 			}
@@ -625,6 +630,11 @@
 			}
 
 			double interval = (node.UT - currentNodeHalfBurnDuration) - Planetarium.GetUniversalTime();
+
+			if (double.IsNaN(interval))
+			{
+				return string.Intern("NaN");
+			}
 
 			int sign = Math.Sign(interval);
 			interval = Math.Abs(interval);