VOID_Styles: Removed 'Ready' property because we weren't using it.
VOID_Styles: Removed 'Ready' property because we weren't using it.

--- a/API/IVOID_Module.cs
+++ b/API/IVOID_Module.cs
@@ -38,7 +38,7 @@
 		bool InValidScene { get; }
 		bool InValidGame { get; }
 
-		void DrawGUI();
+		void DrawGUI(object sender);
 		void StartGUI();
 		void StopGUI();
 

--- a/API/VOIDCore.cs
+++ b/API/VOIDCore.cs
@@ -29,6 +29,7 @@
 using KerbalEngineer.VesselSimulator;
 using KSP;
 using System;
+using System.Linq;
 using System.Collections.Generic;
 using UnityEngine;
 
@@ -72,8 +73,82 @@
 		public abstract event VOIDEventHandler onApplicationQuit;
 		public abstract event VOIDEventHandler onSkinChanged;
 		public abstract event VOIDEventHandler onUpdate;
+		public virtual event VOIDEventHandler onPreRender;
+		public virtual event VOIDEventHandler onPostRender;
 
-		public virtual void OnGUI() {}
+		public virtual bool MethodInPreRenderQueue(VOIDEventHandler method)
+		{
+			if (this.onPreRender != null)
+			{
+				ToadicusTools.Logging.PostDebugMessage(this, "Looking in onPreRender for method {0} in onGui", method);
+
+				foreach (Delegate invoker in this.onPreRender.GetInvocationList())
+				{
+					ToadicusTools.Logging.PostDebugMessage(this, "Checking invoker {0}", invoker);
+
+					if (invoker == method)
+					{
+						ToadicusTools.Logging.PostDebugMessage(this, "Found match.");
+						return true;
+					}
+				}
+			}
+			#if DEBUG
+			else
+			{
+			ToadicusTools.Logging.PostDebugMessage(this, "this.onPreRender == null");
+			}
+			#endif
+
+
+			return false;
+		}
+
+		public virtual bool MethodInPostRenderQueue(VOIDEventHandler method)
+		{
+			if (this.onPostRender != null)
+			{
+				ToadicusTools.Logging.PostDebugMessage(this, "Looking in onPostRender for method {0} in onGui", method);
+
+				foreach (Delegate invoker in this.onPostRender.GetInvocationList())
+				{
+					ToadicusTools.Logging.PostDebugMessage(this, "Checking invoker {0}", invoker);
+
+					if (invoker == method)
+					{
+						ToadicusTools.Logging.PostDebugMessage(this, "Found match.");
+						return true;
+					}
+				}
+			}
+			#if DEBUG
+			else
+			{
+				ToadicusTools.Logging.PostDebugMessage(this, "this.onPostRender == null");
+			}
+			#endif
+
+
+			return false;
+		}
+
+		public void OnGUI()
+		{
+			if (Event.current.type == EventType.Repaint || Event.current.isMouse)
+			{
+				if (this.onPreRender != null)
+				{
+					ToadicusTools.Logging.PostDebugMessage(this, "In OnGUI; doing 'pre draw' stuff");
+					this.onPreRender(this);
+				}
+			}
+
+			if (this.onPostRender != null)
+			{
+				ToadicusTools.Logging.PostDebugMessage(this, "In OnGUI; doing 'post draw' stuff");
+				this.onPostRender(this);
+			}
+		}
 
 		public abstract void SaveConfig();
 

--- a/API/VOID_HUDModule.cs
+++ b/API/VOID_HUDModule.cs
@@ -91,8 +91,13 @@
 			this.Windows = new List<HUDWindow>();
 		}
 
-		public override void DrawGUI()
-		{
+		public override void DrawGUI(object sender)
+		{
+			if (this.core == null)
+			{
+				return;
+			}
+
 			VOID_Styles.labelHud.normal.textColor = textColors [ColorIndex];
 
 			GUI.skin = this.core.Skin;

--- a/API/VOID_Module.cs
+++ b/API/VOID_Module.cs
@@ -70,24 +70,22 @@
 		{
 			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)
+				using (var log = ToadicusTools.DebugTools.PooledDebugLogger.New(this))
+				{
+					log.AppendFormat("this.core: {0}\n", this.core != null ? this.core.ToString() : "null");
+					if (this.core != null)
 					{
-						return false;
+						log.AppendFormat("this.core.MethodInPostRenderQueue(this.DrawGUI): {0}\n",
+							this.core.MethodInPostRenderQueue(this.DrawGUI));
 					}
 
-					return callback.GetInvocationList().Contains((Callback)this.DrawGUI);
-				}
+					log.AppendFormat("this.GUIRunning: {0}\n",
+						this.core != null && this.core.MethodInPostRenderQueue(this.DrawGUI));
+
+					log.Print(false);
+				}
+
+				return this.core != null && this.core.MethodInPostRenderQueue(this.DrawGUI);
 			}
 		}
 
@@ -232,7 +230,7 @@
 			}
 
 			ToadicusTools.Logging.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
-			RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
+			this.core.onPostRender += this.DrawGUI;
 		}
 
 		public virtual void StopGUI()
@@ -242,10 +240,10 @@
 				return;
 			}
 			ToadicusTools.Logging.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name));
-			RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI);
-		}
-
-		public abstract void DrawGUI();
+			this.core.onPostRender -= this.DrawGUI;
+		}
+
+		public abstract void DrawGUI(object sender);
 
 		public virtual void DrawConfigurables() {}
 
@@ -509,8 +507,13 @@
 			GUI.DragWindow();
 		}
 
-		public override void DrawGUI()
-		{
+		public override void DrawGUI(object sender)
+		{
+			if (this.core == null)
+			{
+				return;
+			}
+
 			GUI.skin = this.core.Skin;
 
 			Rect _Pos = this.WindowPos;

--- a/API/VOID_SingletonCore.cs
+++ b/API/VOID_SingletonCore.cs
@@ -25,7 +25,9 @@
 // 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;
+using UnityEngine;
 
 namespace VOID
 {

--- a/Tools/VOID_DataValue.cs
+++ b/Tools/VOID_DataValue.cs
@@ -109,8 +109,26 @@
 			return (T)this.cache;
 		}
 
-		public virtual string ValueUnitString() {
-			return this.Value.ToString() + this.Units;
+		public virtual string ValueUnitString()
+		{
+			if (this.Value == null || this.Units == null)
+			{
+				using (PooledStringBuilder sb = PooledStringBuilder.Get())
+				{
+					if (this.Value == null)
+					{
+						sb.AppendFormat("{0}: Value is null during ValueUnitString\n", this.Label);
+					}
+					if (this.Units == null)
+					{
+						sb.AppendFormat("{0}: Units is null during ValueUnitString\n", this.Label);
+					}
+
+					ToadicusTools.Logging.PostErrorMessage(sb.ToString());
+				}
+			}
+
+			return string.Format("{0}{1}", this.Value == null ? "NULL" : this.Value.ToString(), this.Units);
 		}
 
 		public virtual void DoGUIHorizontal()
@@ -335,9 +353,9 @@
 		public VOID_StrValue(string Label, Func<string> ValueFunc) : base(Label, ValueFunc, "") {}
 	}
 
-	public class VOID_Vector3dValue : VOID_DataValue<Vector3d>
-	{
-		public VOID_Vector3dValue(string Label, Func<Vector3d> ValueFunc, string Units)
+	public class VOID_Vector3Value : VOID_DataValue<Vector3>
+	{
+		public VOID_Vector3Value(string Label, Func<Vector3> ValueFunc, string Units)
 			: base(Label, ValueFunc, Units)
 		{}
 

--- a/Tools/VOID_SaveValue.cs
+++ b/Tools/VOID_SaveValue.cs
@@ -68,11 +68,9 @@
 				{
 					ToadicusTools.Logging.PostDebugMessage (string.Format (
 						"VOID: Dirtying config for type {0}." +
-						"\n\t Old Value: {2}, New Value: {3}" +
-						"\n\t Object.Equals(New, Old): {4}\n" +
-						"{1}",
+						"\n\t Old Value: {1}, New Value: {2}" +
+						"\n\t Object.Equals(New, Old): {3}\n" +
 						this._type,
-						new System.Diagnostics.StackTrace().ToString(),
 						this._value,
 						value,
 						System.Object.Equals(this._value, value)

--- a/Tools/VOID_Tools.cs
+++ b/Tools/VOID_Tools.cs
@@ -704,8 +704,8 @@
 
 		public static double mrenigma03_calcphase(Vessel vessel, CelestialBody target)   //calculates phase angle between the current body and target body
 		{
-			Vector3d vecthis = new Vector3d();
-			Vector3d vectarget = new Vector3d();
+			Vector3 vecthis = new Vector3();
+			Vector3 vectarget = new Vector3();
 			vectarget = target.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
 
 			if ((vessel.mainBody.name == "Sun") || (vessel.mainBody.referenceBody.referenceBody.name == "Sun"))
@@ -717,15 +717,15 @@
 				vecthis = vessel.mainBody.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
 			}
 
-			vecthis = Vector3d.Project(new Vector3d(vecthis.x, 0, vecthis.z), vecthis);
-			vectarget = Vector3d.Project(new Vector3d(vectarget.x, 0, vectarget.z), vectarget);
-
-			Vector3d prograde = new Vector3d();
-			prograde = Quaternion.AngleAxis(90, Vector3d.forward) * vecthis;
-
-			double phase = Vector3d.Angle(vecthis, vectarget);
-
-			if (Vector3d.Angle(prograde, vectarget) > 90)
+			vecthis = Vector3.Project(new Vector3(vecthis.x, 0, vecthis.z), vecthis);
+			vectarget = Vector3.Project(new Vector3(vectarget.x, 0, vectarget.z), vectarget);
+
+			Vector3 prograde = new Vector3();
+			prograde = Quaternion.AngleAxis(90, Vector3.forward) * vecthis;
+
+			double phase = Vector3.Angle(vecthis, vectarget);
+
+			if (Vector3.Angle(prograde, vectarget) > 90)
 				phase = 360 - phase;
 
 			return (phase + 360) % 360;

--- a/VOID.csproj
+++ b/VOID.csproj
@@ -136,6 +136,15 @@
     <Reference Include="UnityEngine">
       <HintPath>..\_KSPAssemblies\UnityEngine.dll</HintPath>
     </Reference>
+    <Reference Include="KSPUtil">
+      <HintPath>..\_KSPAssemblies\KSPUtil.dll</HintPath>
+    </Reference>
+    <Reference Include="UnityEngine.UI">
+      <HintPath>..\_KSPAssemblies\UnityEngine.UI.dll</HintPath>
+    </Reference>
+    <Reference Include="Assembly-CSharp-firstpass">
+      <HintPath>..\_KSPAssemblies\Assembly-CSharp-firstpass.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\ToadicusTools\ToadicusTools.csproj">

--- a/VOIDCore_Generic.cs
+++ b/VOIDCore_Generic.cs
@@ -30,6 +30,7 @@
 using KerbalEngineer.Helpers;
 using KerbalEngineer.VesselSimulator;
 using KSP;
+using KSP.UI.Screens;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -323,7 +324,7 @@
 		/*
 		 * Methods
 		 * */
-		public override void DrawGUI()
+		public override void DrawGUI(object sender)
 		{
 			this.windowID = this.windowBaseID;
 
@@ -362,7 +363,7 @@
 
 			if (this.Active)
 			{
-				base.DrawGUI();
+				base.DrawGUI(sender);
 			}
 		}
 
@@ -555,7 +556,8 @@
 		{
 			if (!this.GUIRunning)
 			{
-				RenderingManager.AddToPostDrawQueue(3, this.DrawGUI);
+				Logging.PostDebugMessage(this, "Adding DrawGUI to onGui");
+				this.onPostRender += this.DrawGUI;
 			}
 		}
 

--- a/VOID_CareerStatus.cs
+++ b/VOID_CareerStatus.cs
@@ -136,14 +136,14 @@
 			}
 		}
 
-		public override void DrawGUI()
+		public override void DrawGUI(object sender)
 		{
 			if (Event.current.type != EventType.Layout && !this.currenciesInitialized)
 			{
 				this.initCurrencies();
 			}
 
-			base.DrawGUI();
+			base.DrawGUI(sender);
 		}
 
 		public override void ModuleWindow(int id)

--- a/VOID_Data.cs
+++ b/VOID_Data.cs
@@ -486,20 +486,20 @@
 				""
 			);
 
-		public static readonly VOID_Vector3dValue vesselThrustOffset =
-			new VOID_Vector3dValue(
+		public static readonly VOID_Vector3Value vesselThrustOffset =
+			new VOID_Vector3Value(
 				"Thrust Offset",
 				delegate()
 				{
 					if (Core.Vessel == null)
 					{
-						return Vector3d.zero;
+						return Vector3.zero;
 					}
 
 					IList<PartModule> engineModules = Core.Vessel.getModulesOfType<PartModule>();
 
-					Vector3d thrustPos = Vector3d.zero;
-					Vector3d thrustDir = Vector3d.zero;
+					Vector3 thrustPos = Vector3.zero;
+					Vector3 thrustDir = Vector3.zero;
 					float thrust = 0;
 
 					PartModule engine;
@@ -562,7 +562,7 @@
 					thrustPos = vesselTransform.InverseTransformPoint(thrustPos);
 					thrustDir = vesselTransform.InverseTransformDirection(thrustDir);
 
-					Vector3d thrustOffset = VectorTools.PointDistanceToLine(
+					Vector3 thrustOffset = VectorTools.PointDistanceToLine(
 						                        thrustPos, thrustDir.normalized, Core.Vessel.findLocalCenterOfMass());
 
 					Logging.PostDebugMessage(typeof(VOID_Data), "vesselThrustOffset:\n" +

--- 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);
 
@@ -196,38 +197,24 @@
 			}
 		}
 
-		public override void DrawGUI()
+		public override void DrawGUI(object sender)
 		{
 			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
-			{
-				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();
+			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;
+			}
+
+			base.DrawGUI(this);
 
 			Rect hudPos = this.ehudWindow.WindowPos;
 

--- a/VOID_HUD.cs
+++ b/VOID_HUD.cs
@@ -58,10 +58,10 @@
 
 			this.Active = true;
 
-			this.leftHUD = new HUDWindow("leftHUD", this.leftHUDWindow, new Rect(Screen.width * .375f - 300f, 0f, 300f, 90f));
+			this.leftHUD = new HUDWindow("leftHUD", this.leftHUDWindow, new Rect((float)Screen.width * .375f - 300f, 0f, 300f, 90f));
 			this.Windows.Add(this.leftHUD);
 
-			this.rightHUD = new HUDWindow("rightHUD", this.rightHUDWindow, new Rect(Screen.width * .625f, 0f, 300f, 90f));
+			this.rightHUD = new HUDWindow("rightHUD", this.rightHUDWindow, new Rect((float)Screen.width * .625f, 0f, 300f, 90f));
 			this.Windows.Add(this.rightHUD);
 
 			Logging.PostDebugMessage ("VOID_HUD: Constructed.");

--- 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_SIZE * .25f - 300f,
+					Screen.width * .5f - (float)GameSettings.UI_SCALE * .25f - 300f,
 					Screen.height - 200f,
 					300f, 90f)
 			);
@@ -90,7 +90,7 @@
 				"rightHUD",
 				this.rightHUDWindow,
 				new Rect(
-					Screen.width * .5f + (float)GameSettings.UI_SIZE * .25f,
+					Screen.width * .5f + (float)GameSettings.UI_SCALE * .25f,
 					Screen.height - 200f,
 					300f, 90f)
 			);
@@ -227,7 +227,7 @@
 			}
 		}
 
-		public override void DrawGUI()
+		public override void DrawGUI(object sender)
 		{
 			if (this.primaryHUD == null)
 			{
@@ -252,7 +252,7 @@
 				this.Windows.Add(this.rightHUD);
 			}
 
-			base.DrawGUI();
+			base.DrawGUI(sender);
 		}
 
 		public override void DrawConfigurables()

--- a/VOID_Rendezvous.cs
+++ b/VOID_Rendezvous.cs
@@ -185,7 +185,7 @@
 					{
 						GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 						GUILayout.Label("Relative inclination:");
-						GUILayout.Label(Vector3d.Angle(Vessel.orbit.GetOrbitNormal(), v.orbit.GetOrbitNormal()).ToString("F3") + "°", GUILayout.ExpandWidth(false));
+						GUILayout.Label(Vector3.Angle(Vessel.orbit.GetOrbitNormal(), v.orbit.GetOrbitNormal()).ToString("F3") + "°", GUILayout.ExpandWidth(false));
 						GUILayout.EndHorizontal();
 					}
 					//if (debugging) Debug.Log("[CHATR] v -> v relative incl OK");
@@ -297,7 +297,7 @@
 				{
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Relative inclination:");
-					GUILayout.Label(Vector3d.Angle(Vessel.orbit.GetOrbitNormal(), cb.orbit.GetOrbitNormal()).ToString("F3") + "°", GUILayout.ExpandWidth(false));
+					GUILayout.Label(Vector3.Angle(Vessel.orbit.GetOrbitNormal(), cb.orbit.GetOrbitNormal()).ToString("F3") + "°", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 					//if (debugging) Debug.Log("[VOID] cb Relative inclination OK");
 				}

--- a/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -116,9 +116,9 @@
 			);
 		}
 
-		public override void DrawGUI()
-		{
-			base.DrawGUI();
+		public override void DrawGUI(object sender)
+		{
+			base.DrawGUI(sender);
 
 			if (this.showBodyList)
 			{

--- 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;
 		}
 	}
 }
 
-