Changes to Module, Core, and throughout to support module filtering by game mode. Also tweaks to CareerStatus.formatDelta.
Changes to Module, Core, and throughout to support module filtering by game mode. Also tweaks to CareerStatus.formatDelta.

--- /dev/null
+++ b/API/Attributes/VOID_GameModesAttribute.cs
@@ -1,1 +1,48 @@
+// VOID
+//
+// VOID_ScenesAttribute.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+//    this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+//    to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
 
+namespace VOID
+{
+	[AttributeUsage(AttributeTargets.Class)]
+	public class VOID_ScenesAttribute : Attribute
+	{
+		public GameScenes[] ValidScenes
+		{
+			get;
+			private set;
+		}
+
+		public VOID_ScenesAttribute(params GameScenes[] validScenes)
+		{
+			this.ValidScenes = validScenes;
+		}
+	}
+}
+
+

--- a/API/Attributes/VOID_ScenesAttribute.cs
+++ b/API/Attributes/VOID_ScenesAttribute.cs
@@ -30,17 +30,17 @@
 namespace VOID
 {
 	[AttributeUsage(AttributeTargets.Class)]
-	public class VOID_ScenesAttribute : Attribute
+	public class VOID_GameModesAttribute : Attribute
 	{
-		public GameScenes[] ValidScenes
+		public Game.Modes[] ValidModes
 		{
 			get;
 			private set;
 		}
 
-		public VOID_ScenesAttribute(params GameScenes[] validScenes)
+		public VOID_GameModesAttribute(params Game.Modes[] validModes)
 		{
-			this.ValidScenes = validScenes;
+			this.ValidModes = validModes;
 		}
 	}
 }

--- a/API/IVOID_Module.cs
+++ b/API/IVOID_Module.cs
@@ -36,6 +36,7 @@
 		bool toggleActive { get; set; }
 		bool guiRunning { get; }
 		bool inValidScene { get; }
+		bool inValidGame { get; }
 
 		void DrawGUI();
 		void StartGUI();

--- a/API/VOIDCore.cs
+++ b/API/VOIDCore.cs
@@ -67,17 +67,10 @@
 		public abstract Stage LastStage { get; protected set; }
 		public abstract Stage[] Stages { get; protected set; }
 
-		public virtual event VOIDEventHandler onApplicationQuit;
+		public abstract event VOIDEventHandler onApplicationQuit;
+		public abstract event VOIDEventHandler onSkinChanged;
 
 		public virtual void OnGUI() {}
-
-		public virtual void OnApplicationQuit()
-		{
-			if (this.onApplicationQuit != null)
-			{
-				this.onApplicationQuit(this);
-			}
-		}
 
 		public override void LoadConfig()
 		{

--- a/API/VOID_Module.cs
+++ b/API/VOID_Module.cs
@@ -43,6 +43,7 @@
 		[AVOID_SaveValue("Active")]
 		protected VOID_SaveValue<bool> _Active = false;
 		private GameScenes[] validScenes;
+		private Game.Modes[] validModes;
 
 		protected float lastUpdate = 0;
 
@@ -57,15 +58,26 @@
 			}
 		}
 
+		protected virtual bool timeToUpdate
+		{
+			get
+			{
+				return (
+					(this.core.updateTimer - this.lastUpdate) > this.core.updatePeriod ||
+					this.lastUpdate > this.core.updateTimer
+				);
+			}
+		}
+
 		public virtual bool toggleActive
 		{
 			get
 			{
-				return this._Active;
+				return this._Active && this.inValidGame && this.inValidScene;
 			}
 			set
 			{
-				this._Active.value = value;
+				this._Active = value && this.inValidGame && this.inValidScene;
 			}
 		}
 
@@ -140,6 +152,63 @@
 				);
 
 				return this.ValidScenes.Contains(HighLogic.LoadedScene);
+			}
+		}
+
+		public virtual Game.Modes[] ValidModes
+		{
+			get
+			{
+				if (this.validModes == null)
+				{
+					Tools.PostDebugMessage(this, "validModes is null when checking inValidGame; fetching attribute.");
+					foreach (var attr in this.GetType().GetCustomAttributes(false))
+					{
+						if (attr is VOID_GameModesAttribute)
+						{
+							VOID_GameModesAttribute addonAttr = (VOID_GameModesAttribute)attr;
+
+							this.validModes = addonAttr.ValidModes;
+
+							Tools.PostDebugMessage("Found VOID_GameModesAttribute; validScenes set.");
+
+							break;
+						}
+					}
+
+					if (this.validModes == null)
+					{
+						this.validModes = new Game.Modes[]
+						{
+							Game.Modes.CAREER,
+							Game.Modes.SANDBOX,
+							Game.Modes.SCENARIO,
+							Game.Modes.SCENARIO_NON_RESUMABLE,
+							Game.Modes.SCIENCE_SANDBOX
+						};
+
+						Tools.PostDebugMessage("No VOID_GameModesAttribute found; validScenes defaulted to flight.");
+					}
+				}
+
+				return this.validModes;
+			}
+		}
+
+		public virtual bool inValidGame
+		{
+			get
+			{
+
+				Tools.PostDebugMessage(
+					this,
+					"Checking if mode is valid: CurrentGame.Mode={0}, ValidModes={1}, inValidGame={2}",
+					Enum.GetName(typeof(Game.Modes), HighLogic.CurrentGame.Mode),
+					string.Join(", ", this.ValidModes.Select(m => Enum.GetName(typeof(Game.Modes), m)).ToArray()),
+					this.ValidModes.Contains(HighLogic.CurrentGame.Mode)
+				);
+
+				return this.ValidModes.Contains(HighLogic.CurrentGame.Mode);
 			}
 		}
 
@@ -387,7 +456,9 @@
 				VOID_Tools.GetWindowHandler(this.ModuleWindow),
 				this.Name,
 				GUILayout.Width(this.defWidth),
-				GUILayout.Height(this.defHeight)
+				GUILayout.Height(this.defHeight),
+				GUILayout.ExpandWidth(true),
+				GUILayout.ExpandHeight(true)
 			);
 
 			bool cursorInWindow = _Pos.Contains(Mouse.screenPos);
@@ -422,7 +493,10 @@
 				case GameScenes.SPACECENTER:
 					if (cursorInWindow)
 					{
-						InputLockManager.SetControlLock(ControlTypes.KSC_FACILITIES, this.inputLockName);
+						InputLockManager.SetControlLock(
+							ControlTypes.KSC_FACILITIES | ControlTypes.CAMERACONTROLS,
+							this.inputLockName
+						);
 					}
 					else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)
 					{

--- a/Tools/VOID_Tools.cs
+++ b/Tools/VOID_Tools.cs
@@ -34,7 +34,7 @@
 
 namespace VOID
 {
-	public static partial class VOID_Tools
+	public static class VOID_Tools
 	{
 		#region CelestialBody Utilities
 		public static bool hasAncestor(this CelestialBody bodyA, CelestialBody bodyB)
@@ -516,9 +516,9 @@
 
 			public string FormatAsDate()
 			{
-				string format = "Y{0:D1}, D{1:D1} {2:D2}:{3:D2}:{4:00.0}s";
-
-				return string.Format(format, years, days, hours, minutes, seconds);
+				string format = "Y{0:#0}, D{1:#0} {2:00}:{3:00}:{4:00.0}s";
+
+				return string.Format(format, years + 1, days, hours, minutes, seconds);
 			}
 
 			public UnpackedTime(int years, int days, int hours, int minutes, double seconds)

--- a/VOID.csproj
+++ b/VOID.csproj
@@ -111,6 +111,7 @@
     <Compile Include="API\Attributes\VOID_ScenesAttribute.cs" />
     <Compile Include="API\Attributes\AVOID_SaveValue.cs" />
     <Compile Include="API\VOIDMaster.cs" />
+    <Compile Include="API\Attributes\VOID_GameModesAttribute.cs" />
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>

--- a/VOIDCore_Editor.cs
+++ b/VOIDCore_Editor.cs
@@ -36,6 +36,7 @@
 
 namespace VOID
 {
+	[VOID_Scenes(GameScenes.EDITOR)]
 	public class VOIDCore_Editor : VOIDCore_Generic<VOIDCore_Editor>
 	{
 		public VOIDCore_Editor() : base()

--- a/VOIDCore_Flight.cs
+++ b/VOIDCore_Flight.cs
@@ -32,6 +32,7 @@
 
 namespace VOID
 {
+	[VOID_Scenes(GameScenes.FLIGHT)]
 	public class VOIDCore_Flight : VOIDCore_Generic<VOIDCore_Flight>
 	{
 		public VOIDCore_Flight()

--- a/VOIDCore_Generic.cs
+++ b/VOIDCore_Generic.cs
@@ -324,6 +324,12 @@
 				return HighLogic.LoadedScene.ToAppScenes();
 			}
 		}
+
+		/*
+		 * Events
+		 * */
+		public override event VOIDEventHandler onApplicationQuit;
+		public override event VOIDEventHandler onSkinChanged;
 
 		/*
 		 * Methods
@@ -573,6 +579,16 @@
 			this.Dispose();
 		}
 
+		public virtual void OnApplicationQuit()
+		{
+			if (this.onApplicationQuit != null)
+			{
+				this.onApplicationQuit(this);
+			}
+
+			this.OnDestroy();
+		}
+
 		public void ResetGUI()
 		{
 			this.StopGUI();
@@ -941,6 +957,11 @@
 		protected void LoadGUIStyles()
 		{
 			VOID_Styles.OnSkinChanged();
+
+			if (this.onSkinChanged != null)
+			{
+				this.onSkinChanged(this);
+			}
 
 			this.GUIStylesLoaded = true;
 		}

--- a/VOIDCore_SpaceCentre.cs
+++ b/VOIDCore_SpaceCentre.cs
@@ -29,6 +29,7 @@
 
 namespace VOID
 {
+	[VOID_Scenes(GameScenes.SPACECENTER)]
 	public class VOIDCore_SpaceCentre : VOIDCore_Generic<VOIDCore_SpaceCentre>
 	{
 		public VOIDCore_SpaceCentre() : base()

--- a/VOID_CareerStatus.cs
+++ b/VOID_CareerStatus.cs
@@ -35,6 +35,7 @@
 namespace VOID
 {
 	[VOID_Scenes(GameScenes.FLIGHT, GameScenes.EDITOR, GameScenes.SPACECENTER)]
+	[VOID_GameModes(Game.Modes.CAREER, Game.Modes.SCIENCE_SANDBOX)]
 	public class VOID_CareerStatus : VOID_WindowModule
 	{
 		public static VOID_CareerStatus Instance
@@ -43,20 +44,25 @@
 			private set;
 		}
 
+		public static string formatDelta(double delta, string numberFormat)
+		{
+			if (delta > 0)
+			{
+				return string.Format("<color='lime'>{0}↑</color>", delta.ToString(numberFormat, Tools.mySIFormatter));
+			}
+			else if (delta < 0)
+			{
+				return string.Format("<color='red'>{0}↓</color>", delta.ToString(numberFormat, Tools.mySIFormatter));
+			}
+			else
+			{
+				return "0";
+			}
+		}
+
 		public static string formatDelta(double delta)
 		{
-			if (delta > 0)
-			{
-				return string.Format("<color='green'>{0:#,#.##}↑</color>", delta);
-			}
-			else if (delta < 0)
-			{
-				return string.Format("<color='red'>{0:#,#.##}↓</color>", delta);
-			}
-			else
-			{
-				return string.Intern("0");
-			}
+			return formatDelta(delta, "#,##0.##");
 		}
 
 		public static string formatDelta(float delta)
@@ -76,18 +82,6 @@
 		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;
@@ -122,21 +116,6 @@
 		{
 			get;
 			private set;
-		}
-
-		private bool inValidGame
-		{
-			get
-			{
-				switch (HighLogic.CurrentGame.Mode)
-				{
-					case Game.Modes.CAREER:
-					case Game.Modes.SCIENCE_SANDBOX:
-						return true;
-					default:
-						return false;
-				}
-			}
 		}
 
 		private bool currenciesInitialized
@@ -221,6 +200,11 @@
 			this.currentScience = newValue;
 		}
 
+		private void onGameStateLoad(ConfigNode node)
+		{
+			this.initCurrencies();
+		}
+
 		private void initCurrencies()
 		{
 			Tools.PostDebugMessage(
@@ -256,6 +240,7 @@
 			GameEvents.OnFundsChanged.Add(this.onFundsChange);
 			GameEvents.OnReputationChanged.Add(this.onRepChange);
 			GameEvents.OnScienceChanged.Add(this.onScienceChange);
+			GameEvents.onGameStateLoad.Add(this.onGameStateLoad);
 
 			bool texturesLoaded;
 
@@ -286,6 +271,7 @@
 			GameEvents.OnFundsChanged.Remove(this.onFundsChange);
 			GameEvents.OnReputationChanged.Remove(this.onRepChange);
 			GameEvents.OnScienceChanged.Remove(this.onScienceChange);
+			GameEvents.onGameStateLoad.Remove(this.onGameStateLoad);
 
 			VOID_CareerStatus.Instance = null;
 		}

--- a/VOID_Styles.cs
+++ b/VOID_Styles.cs
@@ -121,6 +121,8 @@
 
 		static VOID_Styles()
 		{
+			OnSkinChanged();
+
 			Ready = false;
 		}
 	}