Throughout: Change in-module "_Active" references to "toggleActive" property.
[VOID.git] / VOID_Rendezvous.cs
blob:a/VOID_Rendezvous.cs -> blob:b/VOID_Rendezvous.cs
--- a/VOID_Rendezvous.cs
+++ b/VOID_Rendezvous.cs
@@ -29,8 +29,9 @@
 using KSP;
 using System;
 using System.Collections.Generic;
-using System.Linq;
 using ToadicusTools;
+using ToadicusTools.GUIUtils;
+using ToadicusTools.Text;
 using UnityEngine;
 
 namespace VOID
@@ -38,43 +39,53 @@
 	public class VOID_Rendezvous : VOID_WindowModule
 	{
 		[AVOID_SaveValue("untoggleRegisterInfo")]
-		protected VOID_SaveValue<bool> untoggleRegisterInfo = false;
+		protected VOID_SaveValue<bool> untoggleRegisterInfo;
 
 		[AVOID_SaveValue("toggleExtendedOrbital")]
-		protected VOID_SaveValue<bool> toggleExtendedOrbital = false;
+		protected VOID_SaveValue<bool> toggleExtendedOrbital;
 
 		protected VOID_VesselRegister RegisterModule;
 
 		public VOID_Rendezvous()
 		{
-			this._Name = "Rendezvous Information";
+			this.Name = "Rendezvous Information";
 
 			this.WindowPos.x = 845;
 			this.WindowPos.y = 85;
+
+			this.untoggleRegisterInfo = (VOID_SaveValue<bool>)false;
+			this.toggleExtendedOrbital = (VOID_SaveValue<bool>)false;
 		}
 
-		public override void ModuleWindow(int _)
+		public override void ModuleWindow(int id)
 		{
-			Vessel rendezvessel = new Vessel();
-			CelestialBody rendezbody = new CelestialBody();
+			Vessel rendezvessel;
+			CelestialBody rendezbody;
 
 			if (this.RegisterModule == null)
 			{
-				this.RegisterModule = this.core.Modules.Where(m => typeof(VOID_VesselRegister).IsAssignableFrom(m.GetType())).FirstOrDefault() as VOID_VesselRegister;
+				for (int idx = 0; idx < this.core.Modules.Count; idx++)
+				{
+					if (this.core.Modules[idx] is VOID_VesselRegister)
+					{
+						this.RegisterModule = this.core.Modules[idx] as VOID_VesselRegister;
+						break;
+					}
+				}
 			}
 
 			GUILayout.BeginVertical();
 
 			//display both
 			//Show Target Info
-			GUILayout.Label("Target:", this.core.LabelStyles["center_bold"]);
+			GUILayout.Label("Target:", VOID_Styles.labelCenterBold);
 			if (FlightGlobals.fetch.VesselTarget != null)
 			{
 				//a KSP Target (body or vessel) is selected
 				if (FlightGlobals.fetch.vesselTargetMode == VesselTargetModes.Direction)
 				{
 					//a Body is selected
-					rendezbody = vessel.patchedConicSolver.targetBody;
+					rendezbody = Vessel.patchedConicSolver.targetBody;
 					display_rendezvous_info(null, rendezbody);
 				}
 				else if (FlightGlobals.fetch.vesselTargetMode == VesselTargetModes.DirectionAndVelocity)
@@ -87,20 +98,20 @@
 				if (GUILayout.Button("Unset Target", GUILayout.ExpandWidth(false)))
 				{
 					FlightGlobals.fetch.SetVesselTarget(null);
-					Tools.PostDebugMessage("VOID_Rendezvous: KSP Target set to null");
+					Logging.PostDebugMessage("VOID_Rendezvous: KSP Target set to null");
 				}
 
 			}
 			else
 			{
 				//no KSP Target selected
-				GUILayout.Label("No Target Selected", this.core.LabelStyles["center_bold"]);
+				GUILayout.Label("No Target Selected", VOID_Styles.labelCenterBold);
 			}
 
 			//Show Vessel Register vessel info
 			if (untoggleRegisterInfo == false && this.RegisterModule != default(IVOID_Module))
 			{
-				GUILayout.Label("Vessel Register:", this.core.LabelStyles["center_bold"]);
+				GUILayout.Label("Vessel Register:", VOID_Styles.labelCenterBold);
 				if (this.RegisterModule.selectedVessel != null)
 				{
 					rendezvessel = this.RegisterModule.selectedVessel;
@@ -114,7 +125,7 @@
 						if (GUILayout.Button("Set Target", GUILayout.ExpandWidth(false)))
 						{
 							FlightGlobals.fetch.SetVesselTarget(rendezvessel);
-							Tools.PostDebugMessage("[VOID] KSP Target set to " + rendezvessel.vesselName);
+							Logging.PostDebugMessage("[VOID] KSP Target set to " + rendezvessel.vesselName);
 						}
 					}
 				}
@@ -122,19 +133,20 @@
 				{
 					//vesreg Vessel is null
 					//targ = null;
-					GUILayout.Label("No Vessel Selected", this.core.LabelStyles["center_bold"]);
-				}
-			}
-
-			untoggleRegisterInfo.value = GUILayout.Toggle(untoggleRegisterInfo, "Hide Vessel Register Info");
+					GUILayout.Label("No Vessel Selected", VOID_Styles.labelCenterBold);
+				}
+			}
+
+			untoggleRegisterInfo.value = Layout.Toggle(untoggleRegisterInfo, "Hide Vessel Register Info");
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			GUILayout.Label(" ", GUILayout.ExpandWidth(true));
-			if (GUILayout.Button("Close", GUILayout.ExpandWidth(false))) this.toggleActive = false;
+			if (GUILayout.Button("Close", GUILayout.ExpandWidth(false))) this.Active = false;
 			GUILayout.EndHorizontal();
 
 			GUILayout.EndVertical();
-			GUI.DragWindow();
+
+			base.ModuleWindow(id);
 		}
 
 		private void display_rendezvous_info(Vessel v, CelestialBody cb)
@@ -143,7 +155,7 @@
 			{
 				//Display vessel rendezvous info
 				GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
-				GUILayout.Label(v.vesselName, this.core.LabelStyles["center_bold"], GUILayout.ExpandWidth(true));
+				GUILayout.Label(v.vesselName, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
 				GUILayout.EndHorizontal();
 
 				if (v.situation == Vessel.Situations.ESCAPING || v.situation == Vessel.Situations.FLYING || v.situation == Vessel.Situations.ORBITING || v.situation == Vessel.Situations.SUB_ORBITAL)
@@ -156,12 +168,12 @@
 					//display orbital info for orbiting/flying/suborbital/escaping vessels only
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Ap/Pe:");
-					GUILayout.Label(Tools.MuMech_ToSI(v.orbit.ApA) + "m / " + Tools.MuMech_ToSI(v.orbit.PeA) + "m", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI(v.orbit.ApA, 3) + "m / " + SIFormatProvider.ToSI(v.orbit.PeA, 3) + "m", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Altitude:");
-					GUILayout.Label(Tools.MuMech_ToSI(v.orbit.altitude) + "m", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI(v.orbit.altitude, 3) + "m", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -169,43 +181,43 @@
 					GUILayout.Label(v.orbit.inclination.ToString("F3") + "°", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
-					if (vessel.mainBody == v.mainBody)
+					if (Vessel.mainBody == v.mainBody)
 					{
 						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");
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Velocity:");
-					GUILayout.Label(Tools.MuMech_ToSI(v.orbit.vel.magnitude) + "m/s", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI(v.orbit.vel.magnitude, 3) + "m/s", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Relative velocity:");
-					GUILayout.Label(Tools.MuMech_ToSI(v.orbit.vel.magnitude - vessel.orbit.vel.magnitude) + "m/s", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI(v.orbit.vel.magnitude - Vessel.orbit.vel.magnitude, 3) + "m/s", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Distance:");
-					GUILayout.Label(Tools.MuMech_ToSI((vessel.findWorldCenterOfMass() - v.findWorldCenterOfMass()).magnitude) + "m", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI((Vessel.findWorldCenterOfMass() - v.findWorldCenterOfMass()).magnitude, 3) + "m", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					// Toadicus edit: added local sidereal longitude.
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Local Sidereal Longitude:");
-					GUILayout.Label(LSL.ToString("F3") + "°", this.core.LabelStyles["right"]);
-					GUILayout.EndHorizontal();
-
-					toggleExtendedOrbital.value = GUILayout.Toggle(toggleExtendedOrbital, "Extended info");
+					GUILayout.Label(LSL.ToString("F3") + "°", VOID_Styles.labelRight);
+					GUILayout.EndHorizontal();
+
+					toggleExtendedOrbital.value = Layout.Toggle(toggleExtendedOrbital, "Extended info");
 
 					if (toggleExtendedOrbital)
 					{
 						GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 						GUILayout.Label("Period:");
-						GUILayout.Label(VOID_Tools.ConvertInterval(v.orbit.period), GUILayout.ExpandWidth(false));
+						GUILayout.Label(VOID_Tools.FormatInterval(v.orbit.period), GUILayout.ExpandWidth(false));
 						GUILayout.EndHorizontal();
 
 						GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -250,28 +262,28 @@
 				{
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Latitude:");
-					GUILayout.Label(VOID_Tools.GetLatitudeString(vessel), GUILayout.ExpandWidth(false));
+					GUILayout.Label(VOID_Tools.GetLatitudeString(Vessel), GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Longitude:");
-					GUILayout.Label(VOID_Tools.GetLongitudeString(vessel), GUILayout.ExpandWidth(false));
+					GUILayout.Label(VOID_Tools.GetLongitudeString(Vessel), GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Distance:");
-					GUILayout.Label(Tools.MuMech_ToSI((vessel.findWorldCenterOfMass() - v.findWorldCenterOfMass()).magnitude) + "m", GUILayout.ExpandWidth(false));
+					GUILayout.Label(SIFormatProvider.ToSI((Vessel.findWorldCenterOfMass() - v.findWorldCenterOfMass()).magnitude, 3) + "m", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 				}
 			}
 			else if (cb != null && v == null)
 			{
 				//Display CelstialBody rendezvous info
-				GUILayout.Label(cb.bodyName, this.core.LabelStyles["center_bold"]);
+				GUILayout.Label(cb.bodyName, VOID_Styles.labelCenterBold);
 
 				GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 				GUILayout.Label("Ap/Pe:");
-				GUILayout.Label(Tools.MuMech_ToSI(cb.orbit.ApA) + "m / " + Tools.MuMech_ToSI(cb.orbit.PeA) + "m", GUILayout.ExpandWidth(false));
+				GUILayout.Label(SIFormatProvider.ToSI(cb.orbit.ApA, 3) + "m / " + SIFormatProvider.ToSI(cb.orbit.PeA, 3) + "m", GUILayout.ExpandWidth(false));
 				GUILayout.EndHorizontal();
 				//if (debugging) Debug.Log("[VOID] Ap/Pe OK");
 
@@ -281,47 +293,47 @@
 				GUILayout.EndHorizontal();
 				//if (debugging) Debug.Log("[VOID] Inclination OK");
 
-				if (cb.referenceBody == vessel.mainBody)
+				if (cb.referenceBody == Vessel.mainBody)
 				{
 					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");
 				}
 
 				GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 				GUILayout.Label("Distance:");
-				GUILayout.Label(Tools.MuMech_ToSI((vessel.mainBody.position - cb.position).magnitude) + "m", GUILayout.ExpandWidth(false));
+				GUILayout.Label(SIFormatProvider.ToSI((Vessel.mainBody.position - cb.position).magnitude, 3) + "m", GUILayout.ExpandWidth(false));
 				GUILayout.EndHorizontal();
 
 				//if (debugging) Debug.Log("[VOID] Distance OK");
 
 				//SUN2PLANET:
-				if (vessel.mainBody.bodyName == "Sun" && cb.referenceBody == vessel.mainBody)
-				{
-					VOID_Tools.display_transfer_angles_SUN2PLANET(cb, vessel);
+				if (Vessel.mainBody.bodyName == "Sun" && cb.referenceBody == Vessel.mainBody)
+				{
+					VOID_Tools.display_transfer_angles_SUN2PLANET(cb, Vessel);
 					//if (debugging) Debug.Log("[VOID] SUN2PLANET OK");
 				}
 
 				//PLANET2PLANET
-				else if (vessel.mainBody.referenceBody.bodyName == "Sun" && cb.referenceBody == vessel.mainBody.referenceBody)
-				{
-					VOID_Tools.display_transfer_angles_PLANET2PLANET(cb, vessel);
+				else if (Vessel.mainBody.referenceBody.bodyName == "Sun" && cb.referenceBody == Vessel.mainBody.referenceBody)
+				{
+					VOID_Tools.display_transfer_angles_PLANET2PLANET(cb, Vessel);
 					//if (debugging) Debug.Log("[VOID] PLANET2PLANET OK");
 				}
 
 				//PLANET2MOON
-				else if (vessel.mainBody.referenceBody.bodyName == "Sun" && cb.referenceBody == vessel.mainBody)
-				{
-					VOID_Tools.display_transfer_angles_PLANET2MOON(cb, vessel);
+				else if (Vessel.mainBody.referenceBody.bodyName == "Sun" && cb.referenceBody == Vessel.mainBody)
+				{
+					VOID_Tools.display_transfer_angles_PLANET2MOON(cb, Vessel);
 					//if (debugging) Debug.Log("[VOID] PLANET2MOON OK");
 				}
 
 				//MOON2MOON
-				else if (vessel.mainBody.referenceBody.referenceBody.bodyName == "Sun" && cb.referenceBody == vessel.mainBody.referenceBody)
-				{
-					VOID_Tools.display_transfer_angles_MOON2MOON(cb, vessel);
+				else if (Vessel.mainBody.referenceBody.referenceBody.bodyName == "Sun" && cb.referenceBody == Vessel.mainBody.referenceBody)
+				{
+					VOID_Tools.display_transfer_angles_MOON2MOON(cb, Vessel);
 					//if (debugging) Debug.Log("[VOID] MOON2MOON OK");
 				}