Major changes to the way VOID_Core was implemented to allow a more-extensible core framework for use in multiple scenes.
[VOID.git] / VOID_CareerStatus.cs
blob:a/VOID_CareerStatus.cs -> blob:b/VOID_CareerStatus.cs
--- a/VOID_CareerStatus.cs
+++ b/VOID_CareerStatus.cs
@@ -34,6 +34,7 @@
 
 namespace VOID
 {
+	[VOID_Scenes(GameScenes.FLIGHT, GameScenes.EDITOR, GameScenes.SPACECENTER)]
 	public class VOID_CareerStatus : VOID_WindowModule
 	{
 		public static VOID_CareerStatus Instance
@@ -67,13 +68,63 @@
 		private GUIContent repContent;
 		private GUIContent scienceContent;
 
+		#pragma warning disable 0414
 		private Texture2D fundsIconGreen;
 		private Texture2D fundsIconRed;
 		private Texture2D reputationIconGreen;
 		private Texture2D reputationIconRed;
 		private Texture2D scienceIcon;
+		#pragma warning restore 0414
 
 		public override bool toggleActive
+		{
+			get
+			{
+				return base.toggleActive && this.inValidGame;
+			}
+			set
+			{
+				base.toggleActive = this.inValidGame && value;
+			}
+		}
+
+		public double lastFundsChange
+		{
+			get;
+			private set;
+		}
+
+		public float lastRepChange
+		{
+			get;
+			private set;
+		}
+
+		public float lastScienceChange
+		{
+			get;
+			private set;
+		}
+
+		public double currentFunds
+		{
+			get;
+			private set;
+		}
+
+		public float currentReputation
+		{
+			get;
+			private set;
+		}
+
+		public float currentScience
+		{
+			get;
+			private set;
+		}
+
+		private bool inValidGame
 		{
 			get
 			{
@@ -81,63 +132,32 @@
 				{
 					case Game.Modes.CAREER:
 					case Game.Modes.SCIENCE_SANDBOX:
-						return base.toggleActive;
+						return true;
 					default:
 						return false;
 				}
 			}
-			set
-			{
-				switch (HighLogic.CurrentGame.Mode)
-				{
-					case Game.Modes.CAREER:
-					case Game.Modes.SCIENCE_SANDBOX:
-						base.toggleActive = value;
-						break;
-					default:
-						return;
-				}
-			}
-		}
-
-		public double lastFundsChange
-		{
-			get;
-			private set;
-		}
-
-		public float lastRepChange
-		{
-			get;
-			private set;
-		}
-
-		public float lastScienceChange
-		{
-			get;
-			private set;
-		}
-
-		public double currentFunds
-		{
-			get;
-			private set;
-		}
-
-		public float currentReputation
-		{
-			get;
-			private set;
-		}
-
-		public float currentScience
-		{
-			get;
-			private set;
+		}
+
+		private bool currenciesInitialized
+		{
+			get
+			{
+				return (
+					this.currentFunds == double.NaN ||
+					this.currentScience == float.NaN ||
+					this.currentReputation == float.NaN
+				);
+			}
 		}
 
 		public override void ModuleWindow(int _)
 		{
+			if (!this.currenciesInitialized)
+			{
+				this.initCurrencies();
+			}
+
 			GUILayout.BeginVertical();
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -183,6 +203,14 @@
 		{
 			this.lastScienceChange = newValue - this.currentScience;
 			this.currentScience = newValue;
+		}
+
+		private void initCurrencies()
+		{
+			this.currentFunds = Funding.Instance != null ? Funding.Instance.Funds : double.NaN;
+			this.currentReputation = Reputation.Instance != null ? Reputation.Instance.reputation : float.NaN;
+			this.currentScience = ResearchAndDevelopment.Instance != null ?
+				ResearchAndDevelopment.Instance.Science : float.NaN;
 		}
 
 		/*
@@ -221,10 +249,7 @@
 				this.scienceContent.image = this.scienceIcon;
 			}
 
-			this.currentFunds = Funding.Instance != null ? Funding.Instance.Funds : double.NaN;
-			this.currentReputation = Reputation.Instance != null ? Reputation.Instance.reputation : float.NaN;
-			this.currentScience = ResearchAndDevelopment.Instance != null ?
-				ResearchAndDevelopment.Instance.Science : float.NaN;
+			this.initCurrencies();
 		}
 
 		~VOID_CareerStatus()