Got the close button working; now converting from a cached anonymous method to an inherited method. TODO: VOID_ConfigModule.
[VOID.git] / VOID_VesselRegister.cs
blob:a/VOID_VesselRegister.cs -> blob:b/VOID_VesselRegister.cs
--- a/VOID_VesselRegister.cs
+++ b/VOID_VesselRegister.cs
@@ -28,8 +28,6 @@
 
 using KSP;
 using System;
-using System.Linq;
-using ToadicusTools;
 using UnityEngine;
 
 namespace VOID
@@ -37,16 +35,16 @@
 	public class VOID_VesselRegister : VOID_WindowModule
 	{
 		[AVOID_SaveValue("selectedBodyIdx")]
-		protected VOID_SaveValue<int> selectedBodyIdx = 0;
+		protected VOID_SaveValue<int> selectedBodyIdx;
 		protected CelestialBody seletedBody;
 
 		[AVOID_SaveValue("selectedVesselTypeIdx")]
-		protected VOID_SaveValue<int> selectedVesselTypeIdx = 0;
+		protected VOID_SaveValue<int> selectedVesselTypeIdx;
 		protected VesselType selectedVesselType;
 
-		protected string vesselSituation = "Orbiting";
+		protected string vesselSituation;
 
-		protected Vector2 selectorScrollPos = new Vector2();
+		protected Vector2 selectorScrollPos;
 
 		protected Vessel _selectedVessel;
 
@@ -65,13 +63,30 @@
 			this.WindowPos.x = 845;
 			this.WindowPos.y = 275;
 			this.defHeight = 375;
+
+			this.selectedBodyIdx = (VOID_SaveValue<int>)0;
+			this.selectedVesselTypeIdx = (VOID_SaveValue<int>)0;
+
+			this.vesselSituation = "Orbiting";
+
+			this.selectorScrollPos = new Vector2();
 		}
 
 		public override void ModuleWindow(int id)
 		{
-			if (!this.core.allVesselTypes.Any())
+			if (this.core.AllVesselTypes.Length < 1)
 			{
 				return;
+			}
+
+			if (selectedBodyIdx >= this.core.SortedBodyList.Count)
+			{
+				selectedBodyIdx.value %= this.core.SortedBodyList.Count;
+			}
+
+			if (selectedBodyIdx < 0)
+			{
+				selectedBodyIdx.value += this.core.SortedBodyList.Count;
 			}
 
 			GUILayout.BeginVertical();
@@ -79,34 +94,46 @@
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("<"))
 			{
-				selectedBodyIdx--;
-				if (selectedBodyIdx < 0) selectedBodyIdx = this.core.allBodies.Count - 1;
+				selectedBodyIdx.value--;
+				if (selectedBodyIdx < 0)
+				{
+					selectedBodyIdx.value = this.core.SortedBodyList.Count - 1;
+				}
 			}
-			GUILayout.Label(this.core.allBodies[selectedBodyIdx].bodyName, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
+			GUILayout.Label(this.core.SortedBodyList[selectedBodyIdx].bodyName, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
 			if (GUILayout.Button(">"))
 			{
-				selectedBodyIdx++;
-				if (selectedBodyIdx > this.core.allBodies.Count - 1) selectedBodyIdx = 0;
+				selectedBodyIdx.value++;
+				if (selectedBodyIdx > this.core.SortedBodyList.Count - 1)
+				{
+					selectedBodyIdx.value = 0;
+				}
 			}
 			GUILayout.EndHorizontal();
 
-			seletedBody = this.core.allBodies[selectedBodyIdx];
+			seletedBody = this.core.SortedBodyList[selectedBodyIdx];
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("<"))
 			{
-				selectedVesselTypeIdx--;
-				if (selectedVesselTypeIdx < 0) selectedVesselTypeIdx = this.core.allVesselTypes.Count - 1;
+				selectedVesselTypeIdx.value--;
+				if (selectedVesselTypeIdx < 0)
+				{
+					selectedVesselTypeIdx.value = this.core.AllVesselTypes.Length - 1;
+				}
 			}
-			GUILayout.Label(this.core.allVesselTypes[selectedVesselTypeIdx].ToString(), VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
+			GUILayout.Label(this.core.AllVesselTypes[selectedVesselTypeIdx].ToString(), VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
 			if (GUILayout.Button(">"))
 			{
-				selectedVesselTypeIdx++;
-				if (selectedVesselTypeIdx > this.core.allVesselTypes.Count - 1) selectedVesselTypeIdx = 0;
+				selectedVesselTypeIdx.value++;
+				if (selectedVesselTypeIdx > this.core.AllVesselTypes.Length - 1)
+				{
+					selectedVesselTypeIdx.value = 0;
+				}
 			}
 			GUILayout.EndHorizontal();
 
-			selectedVesselType = this.core.allVesselTypes[selectedVesselTypeIdx];
+			selectedVesselType = this.core.AllVesselTypes[selectedVesselTypeIdx];
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("Landed", GUILayout.ExpandWidth(true))) vesselSituation = "Landed";
@@ -122,9 +149,12 @@
 
 			selectorScrollPos = GUILayout.BeginScrollView(selectorScrollPos, false, false);
 
-			foreach (Vessel v in FlightGlobals.Vessels)
+			Vessel v;
+			for (int idx = 0; idx < FlightGlobals.Vessels.Count; idx++)
 			{
-				if (v != vessel && v.vesselType == selectedVesselType && v.mainBody == seletedBody)
+				v = FlightGlobals.Vessels[idx];
+
+				if (v != Vessel && v.vesselType == selectedVesselType && v.mainBody == seletedBody)
 				{
 					if ((vesselSituation == "Landed" &&
 					     (v.situation == Vessel.Situations.LANDED ||
@@ -142,7 +172,7 @@
 							if (_selectedVessel != v)
 							{
 								_selectedVessel = v; //set clicked vessel as selected_vessel
-								this.toggleActive = true;    //turn bool on to open the window if closed
+								this.Active = true;    //turn bool on to open the window if closed
 							}
 							else
 							{