Added sane window start positions and states. 0.9.9
[VOID.git] / VOID_Rendezvous.cs
blob:a/VOID_Rendezvous.cs -> blob:b/VOID_Rendezvous.cs
--- a/VOID_Rendezvous.cs
+++ b/VOID_Rendezvous.cs
@@ -1,27 +1,36 @@
-//
-//  VOID_Orbital.cs
-//
-//  Author:
-//       toadicus <>
-//
-//  Copyright (c) 2013 toadicus
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// VOID
+//
+// VOID_Rendezvous.cs
+//
+// Copyright © 2014, 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 KSP;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using ToadicusTools;
 using UnityEngine;
 
 namespace VOID
@@ -49,7 +58,10 @@
 			Vessel rendezvessel = new Vessel();
 			CelestialBody rendezbody = new CelestialBody();
 
-			this.RegisterModule = VOID_Core.Instance.Modules.Where(m => typeof(VOID_VesselRegister).IsAssignableFrom(m.GetType())).FirstOrDefault() as VOID_VesselRegister;
+			if (this.RegisterModule == null)
+			{
+				this.RegisterModule = VOID_Core.Instance.Modules.Where(m => typeof(VOID_VesselRegister).IsAssignableFrom(m.GetType())).FirstOrDefault() as VOID_VesselRegister;
+			}
 
 			GUILayout.BeginVertical();
 
@@ -59,13 +71,13 @@
 			if (FlightGlobals.fetch.VesselTarget != null)
 			{
 				//a KSP Target (body or vessel) is selected
-				if (FlightGlobals.fetch.vesselTargetMode == FlightGlobals.VesselTargetModes.Direction)
+				if (FlightGlobals.fetch.vesselTargetMode == VesselTargetModes.Direction)
 				{
 					//a Body is selected
 					rendezbody = vessel.patchedConicSolver.targetBody;
 					display_rendezvous_info(null, rendezbody);
 				}
-				else if (FlightGlobals.fetch.vesselTargetMode == FlightGlobals.VesselTargetModes.DirectionAndVelocity)
+				else if (FlightGlobals.fetch.vesselTargetMode == VesselTargetModes.DirectionAndVelocity)
 				{
 					//a Vessel is selected
 					rendezvessel = FlightGlobals.fetch.VesselTarget.GetVessel();
@@ -114,7 +126,7 @@
 				}
 			}
 
-			untoggleRegisterInfo = GUILayout.Toggle(untoggleRegisterInfo, "Hide Vessel Register Info");
+			untoggleRegisterInfo.value = GUILayout.Toggle(untoggleRegisterInfo, "Hide Vessel Register Info");
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			GUILayout.Label(" ", GUILayout.ExpandWidth(true));
@@ -138,8 +150,8 @@
 				{
 					// Toadicus edit: added local sidereal longitude.
 					// Toadicus edit: added local sidereal longitude.
-					double LSL = vessel.longitude + vessel.orbit.referenceBody.rotationAngle;
-					LSL = Tools.FixDegreeDomain (LSL);
+					double LSL = v.longitude + v.orbit.referenceBody.rotationAngle;
+					LSL = VOID_Tools.FixDegreeDomain (LSL);
 
 					//display orbital info for orbiting/flying/suborbital/escaping vessels only
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -181,13 +193,19 @@
 					GUILayout.Label(Tools.MuMech_ToSI((vessel.findWorldCenterOfMass() - v.findWorldCenterOfMass()).magnitude) + "m", GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
-					//target_vessel_extended_orbital_info = GUILayout.Toggle(target_vessel_extended_orbital_info, "Extended info");
+					// Toadicus edit: added local sidereal longitude.
+					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+					GUILayout.Label("Local Sidereal Longitude:");
+					GUILayout.Label(LSL.ToString("F3") + "°", VOID_Core.Instance.LabelStyles["right"]);
+					GUILayout.EndHorizontal();
+
+					toggleExtendedOrbital.value = GUILayout.Toggle(toggleExtendedOrbital, "Extended info");
 
 					if (toggleExtendedOrbital)
 					{
 						GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 						GUILayout.Label("Period:");
-						GUILayout.Label(Tools.ConvertInterval(v.orbit.period), GUILayout.ExpandWidth(false));
+						GUILayout.Label(VOID_Tools.ConvertInterval(v.orbit.period), GUILayout.ExpandWidth(false));
 						GUILayout.EndHorizontal();
 
 						GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -226,24 +244,18 @@
 						GUILayout.Label("Arg. of periapsis:");
 						GUILayout.Label(v.orbit.argumentOfPeriapsis.ToString("F3") + "°", 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") + "°", VOID_Core.Instance.LabelStyles["txt_right"]);
-						GUILayout.EndHorizontal();
 					}
 				}
 				else
 				{
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 					GUILayout.Label("Latitude:");
-					GUILayout.Label(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(Tools.GetLongitudeString(vessel), GUILayout.ExpandWidth(false));
+					GUILayout.Label(VOID_Tools.GetLongitudeString(vessel), GUILayout.ExpandWidth(false));
 					GUILayout.EndHorizontal();
 
 					GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -288,28 +300,28 @@
 				//SUN2PLANET:
 				if (vessel.mainBody.bodyName == "Sun" && cb.referenceBody == vessel.mainBody)
 				{
-					Tools.display_transfer_angles_SUN2PLANET(cb, vessel);
+					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)
 				{
-					Tools.display_transfer_angles_PLANET2PLANET(cb, vessel);
+					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)
 				{
-					Tools.display_transfer_angles_PLANET2MOON(cb, vessel);
+					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)
 				{
-					Tools.display_transfer_angles_MOON2MOON(cb, vessel);
+					VOID_Tools.display_transfer_angles_MOON2MOON(cb, vessel);
 					//if (debugging) Debug.Log("[VOID] MOON2MOON OK");
 				}