Merge branch 'exp' of ssh://toad.homelinux.net:22222/VOID into exp exp
Merge branch 'exp' of ssh://toad.homelinux.net:22222/VOID into exp

--- a/API/VOID_Module.cs
+++ b/API/VOID_Module.cs
@@ -70,25 +70,6 @@
 		{
 			get
 			{
-				/*if (
-					RenderingManager.fetch == null ||
-					RenderingManager.fetch.postDrawQueue == null ||
-					RenderingManager.fetch.postDrawQueue.Length < 4
-				)
-				{
-					return false;
-				}
-				else
-				{
-					Delegate callback = RenderingManager.fetch.postDrawQueue[3];
-					if (callback == null)
-					{
-						return false;
-					}
-
-					return callback.GetInvocationList().Contains((Callback)this.DrawGUI);
-				}*/
-
 				using (var log = ToadicusTools.DebugTools.PooledDebugLogger.New(this))
 				{
 					log.AppendFormat("this.core: {0}\n", this.core != null ? this.core.ToString() : "null");
@@ -249,7 +230,6 @@
 			}
 
 			ToadicusTools.Logging.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
-			// RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
 			this.core.onPostRender += this.DrawGUI;
 		}
 

--- a/VOIDCore_Generic.cs
+++ b/VOIDCore_Generic.cs
@@ -432,32 +432,59 @@
 				}
 			}
 
-			if (this.useToolbarManager)
-			{
+			if (ToolbarManager.ToolbarAvailable && this.useToolbarManager)
+			{
+				if (this.ToolbarButton == null)
+				{
+					this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
+					this.ToolbarButton.Text = this.VoidName;
+					this.SetIconTexture(this.powerState | this.activeState);
+
+					this.ToolbarButton.Visible = true;
+
+					this.ToolbarButton.OnClick += 
+						(e) =>
+						{
+							this.ToggleMainWindow();
+						};
+
+					Logging.PostDebugMessage(string.Format("{0}: Toolbar Button initialized.", this.GetType().Name));
+				}
+
 				if (this.AppLauncherButton != null)
 				{
 					ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
 					this.AppLauncherButton = null;
 				}
-
-				if (this.ToolbarButton == null)
-				{
-					this.InitializeToolbarButton();
-				}
 			}
 			else
 			{
+				if (this.AppLauncherButton == null)
+				{
+					if (ApplicationLauncher.Instance != null)
+					{
+						this.AppLauncherButton = ApplicationLauncher.Instance.AddModApplication(
+							this.ToggleMainWindow, this.ToggleMainWindow,
+							this.appIconVisibleScenes,
+							this.VOIDIconTexture
+						);
+
+						Logging.PostDebugMessage(
+							this,
+							"AppLauncherButton initialized in {0}",
+							Enum.GetName(
+								typeof(GameScenes),
+								HighLogic.LoadedScene
+							)
+						);
+					}
+				}
+
 				if (this.ToolbarButton != null)
 				{
 					this.ToolbarButton.Destroy();
 					this.ToolbarButton = null;
 				}
-
-				if (this.AppLauncherButton == null)
-				{
-					this.InitializeAppLauncherButton();
-				}
-
 			}
 
 			this.saveTimer += Time.deltaTime;
@@ -556,7 +583,6 @@
 		{
 			if (!this.GUIRunning)
 			{
-				// RenderingManager.AddToPostDrawQueue(3, this.DrawGUI);
 				Logging.PostDebugMessage(this, "Adding DrawGUI to onGui");
 				this.onPostRender += this.DrawGUI;
 			}
@@ -1012,51 +1038,6 @@
 				SimManager.OnReady += this.GetSimManagerResults;
 
 				this.simManagerLoaded = true;
-			}
-		}
-
-		protected void InitializeToolbarButton()
-		{
-			// Do nothing if (the Toolbar is not available.
-			if (!ToolbarManager.ToolbarAvailable)
-			{
-				Logging.PostDebugMessage(this, "Refusing to make a ToolbarButton: ToolbarAvailable = false");
-				return;
-			}
-
-			this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
-			this.ToolbarButton.Text = this.VoidName;
-			this.SetIconTexture(this.powerState | this.activeState);
-
-			this.ToolbarButton.Visible = true;
-
-			this.ToolbarButton.OnClick += 
-				(e) =>
-			{
-				this.ToggleMainWindow();
-			};
-
-			Logging.PostDebugMessage(string.Format("{0}: Toolbar Button initialized.", this.GetType().Name));
-		}
-
-		protected void InitializeAppLauncherButton()
-		{
-			if (ApplicationLauncher.Ready)
-			{
-				this.AppLauncherButton = ApplicationLauncher.Instance.AddModApplication(
-					this.ToggleMainWindow, this.ToggleMainWindow,
-					this.appIconVisibleScenes,
-					this.VOIDIconTexture
-				);
-
-				Logging.PostDebugMessage(
-					this,
-					"AppLauncherButton initialized in {0}",
-					Enum.GetName(
-						typeof(GameScenes),
-						HighLogic.LoadedScene
-					)
-				);
 			}
 		}
 

--- a/VOID_Data.cs
+++ b/VOID_Data.cs
@@ -502,55 +502,66 @@
 					Vector3 thrustDir = Vector3.zero;
 					float thrust = 0;
 
-					PartModule engine;
-					for (int idx = 0; idx < engineModules.Count; idx++)
-					{
-						engine = engineModules[idx];
-						float moduleThrust = 0;
-
-						switch (engine.moduleName)
-						{
-							case "ModuleEngines":
-							case "ModuleEnginesFX":
-								break;
-							default:
-								continue;
-						}
-
-						if (!engine.isEnabled)
+					Part part;
+					for (int partIdx = 0; partIdx < Core.Vessel.parts.Count; partIdx++)
+					{
+						part = Core.Vessel.parts[partIdx];
+
+						if (part == null || part.Modules == null)
 						{
 							continue;
 						}
 
-						CenterOfThrustQuery cotQuery = new CenterOfThrustQuery();
-
-						if (engine is ModuleEngines)
+						PartModule module;
+						for (int idx = 0; idx < part.Modules.Count; idx++)
 						{
-							ModuleEngines engineModule = engine as ModuleEngines;
-
-							moduleThrust = engineModule.finalThrust;
-
-							engineModule.OnCenterOfThrustQuery(cotQuery);
+							module = part.Modules[idx];
+
+							float moduleThrust = 0;
+
+							switch (module.moduleName)
+							{
+								case "ModuleEngines":
+								case "ModuleEnginesFX":
+									break;
+								default:
+									continue;
+							}
+
+							if (!module.isEnabled)
+							{
+								continue;
+							}
+
+							CenterOfThrustQuery cotQuery = new CenterOfThrustQuery();
+
+							if (module is ModuleEngines)
+							{
+								ModuleEngines engineModule = module as ModuleEngines;
+
+								moduleThrust = engineModule.finalThrust;
+
+								engineModule.OnCenterOfThrustQuery(cotQuery);
+							}
+							else // engine is ModuleEnginesFX
+							{
+								ModuleEnginesFX engineFXModule = module as ModuleEnginesFX;
+
+								moduleThrust = engineFXModule.finalThrust;
+
+								engineFXModule.OnCenterOfThrustQuery(cotQuery);
+							}
+
+							if (moduleThrust != 0d)
+							{
+								cotQuery.thrust = moduleThrust;
+							}
+
+							thrustPos += cotQuery.pos * cotQuery.thrust;
+							thrustDir += cotQuery.dir * cotQuery.thrust;
+							thrust += cotQuery.thrust;
 						}
-						else // engine is ModuleEnginesFX
-						{
-							ModuleEnginesFX engineFXModule = engine as ModuleEnginesFX;
-
-							moduleThrust = engineFXModule.finalThrust;
-
-							engineFXModule.OnCenterOfThrustQuery(cotQuery);
-						}
-
-						if (moduleThrust != 0d)
-						{
-							cotQuery.thrust = moduleThrust;
-						}
-
-						thrustPos += cotQuery.pos * cotQuery.thrust;
-						thrustDir += cotQuery.dir * cotQuery.thrust;
-						thrust += cotQuery.thrust;
-					}
-
+					}
 					if (thrust != 0)
 					{
 						thrustPos /= thrust;

--- a/VOID_EditorHUD.cs
+++ b/VOID_EditorHUD.cs
@@ -28,6 +28,7 @@
 
 using KerbalEngineer.VesselSimulator;
 using KSP;
+using KSP.UI.Screens;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -110,7 +111,7 @@
 			this.ehudWindow = new HUDWindow(
 				"editorHUD",
 				this.ehudWindowFunc,
-				new Rect(/*EditorPanels.Instance.partsPanelWidth + */10f, 125f, 300f, 64f)
+				new Rect(10f, 125f, 300f, 64f)
 			);
 			this.Windows.Add(this.ehudWindow);
 
@@ -200,32 +201,30 @@
 		{
 			float hudLeft;
 
-			if (EditorLogic.fetch.editorScreen == EditorScreen.Parts)
-			{
-				hudLeft = /*EditorPanels.Instance.partsPanelWidth + */10f;
-				hudLeft += /*EditorPartList.Instance.transformTopLeft.position.x -*/
-					/*EditorPartList.Instance.transformTopLeft.parent.parent.position.x -*/
-					72f;
-			}
-			else if (EditorLogic.fetch.editorScreen == EditorScreen.Actions)
-			{
-				hudLeft = /*EditorPanels.Instance.actionsPanelWidth +*/ 10f;
-			}
-			else
-			{
+			try
+			{
+				switch (EditorLogic.fetch.editorScreen)
+				{
+					case EditorScreen.Parts:
+						hudLeft = 16f + EditorPanels.Instance.partsEditor.panelTransform.rect.width +
+							EditorPanels.Instance.partcategorizerModes.transform.localPosition.x;
+						break;
+					case EditorScreen.Actions:
+						hudLeft = EditorPanels.Instance.actions.transform.localPosition.x + 464f;
+						break;
+					default:
+						return;
+				}
+			}
+			catch (NullReferenceException)
+			{
+				Logging.PostErrorMessage(
+					"[{0}]: Something was null when fetching panel geometry; skipping frame.",
+					this.GetType().FullName
+				);
+
 				return;
 			}
-
-			/*Logging.PostDebugMessage(this,
-				"EditorPartList topLeft.parent.parent.position: {0}\n" +
-				"EditorPartList topLeft.parent.position: {1}\n" +
-				"EditorPartList topLeft.position: {2}\n" +
-				"snapToEdge: {3} (pos.Xmin: {4}; hudLeft: {5})",
-				EditorPartList.Instance.transformTopLeft.parent.parent.position,
-				EditorPartList.Instance.transformTopLeft.parent.position,
-				EditorPartList.Instance.transformTopLeft.position,
-				this.snapToLeft, this.ehudWindow.WindowPos.xMin, hudLeft
-			);*/
 
 			base.DrawGUI(this);
 

--- a/VOID_HUDAdvanced.cs
+++ b/VOID_HUDAdvanced.cs
@@ -80,7 +80,7 @@
 			this.leftHUD = new HUDWindow("leftHUD",
 				this.leftHUDWindow,
 				new Rect(
-					Screen.width * .5f - (float)GameSettings.UI_SCALE * .25f - 300f,
+					Screen.width * .5f - 300f - 220f * GameSettings.UI_SCALE,
 					Screen.height - 200f,
 					300f, 90f)
 			);
@@ -90,7 +90,7 @@
 				"rightHUD",
 				this.rightHUDWindow,
 				new Rect(
-					Screen.width * .5f + (float)GameSettings.UI_SCALE * .25f,
+					Screen.width * .5f + 180f * GameSettings.UI_SCALE,
 					Screen.height - 200f,
 					300f, 90f)
 			);
@@ -257,8 +257,6 @@
 
 		public override void DrawConfigurables()
 		{
-			base.DrawConfigurables();
-
 			if (GUILayout.Button(string.Intern("Reset Advanced HUD Positions"), GUILayout.ExpandWidth(false)))
 			{
 				HUDWindow window;

--- a/VOID_Orbital.cs
+++ b/VOID_Orbital.cs
@@ -113,7 +113,7 @@
             }
 
             GUILayout.EndVertical();
-            
+
 			base.ModuleWindow(id);
 		}
 
@@ -133,4 +133,3 @@
 	}
 }
 
-

--- a/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -281,11 +281,11 @@
 
 		public override void DrawConfigurables()
 		{
-			this.showColumnSelection = GUILayout.Toggle(
+			/*this.showColumnSelection = GUILayout.Toggle(
 				this.showColumnSelection,
 				"Select StageInfo Columns",
 				GUI.skin.button
-			);
+			);*/
 		}
 
 		private void BodyPickerWindow(int _)

--- a/VOID_Styles.cs
+++ b/VOID_Styles.cs
@@ -33,12 +33,6 @@
 {
 	public static class VOID_Styles
 	{
-		public static bool Ready
-		{
-			get;
-			private set;
-		}
-
 		public static GUIStyle labelDefault
 		{
 			get;
@@ -115,17 +109,12 @@
 
 			labelGreen = new GUIStyle(GUI.skin.label);
 			labelGreen.normal.textColor = Color.green;
-
-			Ready = true;
 		}
 
 		static VOID_Styles()
 		{
 			OnSkinChanged();
-
-			Ready = false;
 		}
 	}
 }
 
-