First pass implementation of an Editor side. It works, but the styles are HEINOUS.
[VOID.git] / VOID_EditorCore.cs
blob:a/VOID_EditorCore.cs -> blob:b/VOID_EditorCore.cs
--- a/VOID_EditorCore.cs
+++ b/VOID_EditorCore.cs
@@ -18,6 +18,7 @@
 //
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using Engineer.VesselSimulator;
 using KSP;
 using System;
 using System.Collections.Generic;
@@ -56,9 +57,12 @@
 
 		public new static void Reset()
 		{
-			_instance.StopGUI();
-			_instance = null;
-			_initialized = false;
+			if (_initialized)
+			{
+				_instance.StopGUI();
+				_instance = null;
+				_initialized = false;
+			}
 		}
 
 		public VOID_EditorCore() : base()
@@ -66,27 +70,63 @@
 			this._Name = "VOID Editor Core";
 		}
 
+		public new void OnGUI() {}
+
 		public override void DrawGUI()
 		{
 			if (!this._modulesLoaded)
 			{
 				this.LoadModulesOfType<IVOID_EditorModule>();
 			}
+
+			Rect _iconPos = Tools.DockToWindow (this.VOIDIconPos, this.mainWindowPos);
+
+			_iconPos = Tools.ClampRectToScreen (_iconPos, (int)_iconPos.width, (int)_iconPos.height);
+
+			if (_iconPos != this.VOIDIconPos)
+			{
+				this.VOIDIconPos = _iconPos;
+			}
+
+			base.DrawGUI();
 		}
 
 		public new void Update()
 		{
 			foreach (IVOID_EditorModule module in this.Modules)
 			{
-				if (HighLogic.LoadedSceneIsEditor && module.toggleActive)
+				if (EditorLogic.startPod == null)
+				{
+					module.StopGUI();
+					continue;
+				}
+				if (HighLogic.LoadedSceneIsEditor && module.toggleActive && EditorLogic.SortedShipList.Any())
 				{
 					module.StartGUI();
 				}
-				if (!HighLogic.LoadedSceneIsEditor || !module.toggleActive)
+				if (!HighLogic.LoadedSceneIsEditor || !module.toggleActive || !EditorLogic.SortedShipList.Any())
 				{
 					module.StopGUI();
 				}
 			}
+
+			if (EditorLogic.startPod == null || !HighLogic.LoadedSceneIsEditor)
+			{
+				this.StopGUI();
+				return;
+			}
+			else if (!this.guiRunning && HighLogic.LoadedSceneIsEditor)
+			{
+				this.StartGUI();
+			}
+
+			if (EditorLogic.SortedShipList.Count > 0)
+			{
+				SimManager.Instance.Gravity = VOID_Data.KerbinGee;
+				SimManager.Instance.TryStartSimulation();
+			}
+
+			this.CheckAndSave ();
 		}
 
 		public new void FixedUpdate() {}