Added sane window start positions and states. 0.9.9
[VOID.git] / VOID_VesselRegister.cs
blob:a/VOID_VesselRegister.cs -> blob:b/VOID_VesselRegister.cs
--- a/VOID_VesselRegister.cs
+++ b/VOID_VesselRegister.cs
@@ -1,26 +1,35 @@
+// VOID
 //
-//  VOID_Orbital.cs
+// VOID_VesselRegister.cs
 //
-//  Author:
-//       toadicus <>
+// Copyright © 2014, toadicus
+// All rights reserved.
 //
-//  Copyright (c) 2013 toadicus
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
 //
-//  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.
+// 1. Redistributions of source code must retain the above copyright notice,
+//    this list of conditions and the following disclaimer.
 //
-//  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.
+// 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.
 //
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 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.Linq;
+using ToadicusTools;
 using UnityEngine;
 
 namespace VOID
@@ -28,16 +37,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;
 
@@ -49,18 +58,25 @@
 			}
 		}
 
-		public VOID_VesselRegister()
+		public VOID_VesselRegister() : base()
 		{
-			this._Name = "Vessel Register";
+			this.Name = "Vessel Register";
 
 			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 _)
+		public override void ModuleWindow(int id)
 		{
-			if (!VOID_Core.Instance.allVesselTypes.Any())
+			if (!this.core.AllVesselTypes.Any())
 			{
 				return;
 			}
@@ -70,34 +86,46 @@
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("<"))
 			{
-				selectedBodyIdx--;
-				if (selectedBodyIdx < 0) selectedBodyIdx = VOID_Core.Instance.allBodies.Count - 1;
+				selectedBodyIdx.value--;
+				if (selectedBodyIdx < 0)
+				{
+					selectedBodyIdx.value = this.core.AllBodies.Count - 1;
+				}
 			}
-			GUILayout.Label(VOID_Core.Instance.allBodies[selectedBodyIdx].bodyName, VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true));
+			GUILayout.Label(this.core.AllBodies[selectedBodyIdx].bodyName, VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
 			if (GUILayout.Button(">"))
 			{
-				selectedBodyIdx++;
-				if (selectedBodyIdx > VOID_Core.Instance.allBodies.Count - 1) selectedBodyIdx = 0;
+				selectedBodyIdx.value++;
+				if (selectedBodyIdx > this.core.AllBodies.Count - 1)
+				{
+					selectedBodyIdx.value = 0;
+				}
 			}
 			GUILayout.EndHorizontal();
 
-			seletedBody = VOID_Core.Instance.allBodies[selectedBodyIdx];
+			seletedBody = this.core.AllBodies[selectedBodyIdx];
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("<"))
 			{
-				selectedVesselTypeIdx--;
-				if (selectedVesselTypeIdx < 0) selectedVesselTypeIdx = VOID_Core.Instance.allVesselTypes.Count - 1;
+				selectedVesselTypeIdx.value--;
+				if (selectedVesselTypeIdx < 0)
+				{
+					selectedVesselTypeIdx.value = this.core.AllVesselTypes.Length - 1;
+				}
 			}
-			GUILayout.Label(VOID_Core.Instance.allVesselTypes[selectedVesselTypeIdx].ToString(), VOID_Core.Instance.LabelStyles["center_bold"], GUILayout.ExpandWidth(true));
+			GUILayout.Label(this.core.AllVesselTypes[selectedVesselTypeIdx].ToString(), VOID_Styles.labelCenterBold, GUILayout.ExpandWidth(true));
 			if (GUILayout.Button(">"))
 			{
-				selectedVesselTypeIdx++;
-				if (selectedVesselTypeIdx > VOID_Core.Instance.allVesselTypes.Count - 1) selectedVesselTypeIdx = 0;
+				selectedVesselTypeIdx.value++;
+				if (selectedVesselTypeIdx > this.core.AllVesselTypes.Length - 1)
+				{
+					selectedVesselTypeIdx.value = 0;
+				}
 			}
 			GUILayout.EndHorizontal();
 
-			selectedVesselType = VOID_Core.Instance.allVesselTypes[selectedVesselTypeIdx];
+			selectedVesselType = this.core.AllVesselTypes[selectedVesselTypeIdx];
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			if (GUILayout.Button("Landed", GUILayout.ExpandWidth(true))) vesselSituation = "Landed";
@@ -106,8 +134,8 @@
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 			GUILayout.Label(
-				Tools.UppercaseFirst(vesselSituation) + " " + selectedVesselType.ToString() + "s  @ " + seletedBody.bodyName,
-				VOID_Core.Instance.LabelStyles["center"],
+				VOID_Tools.UppercaseFirst(vesselSituation) + " " + selectedVesselType.ToString() + "s  @ " + seletedBody.bodyName,
+				VOID_Styles.labelCenter,
 				GUILayout.ExpandWidth(true));
 			GUILayout.EndHorizontal();
 
@@ -115,7 +143,7 @@
 
 			foreach (Vessel v in FlightGlobals.Vessels)
 			{
-				if (v != vessel && v.vesselType == selectedVesselType && v.mainBody == seletedBody)
+				if (v != Vessel && v.vesselType == selectedVesselType && v.mainBody == seletedBody)
 				{
 					if ((vesselSituation == "Landed" &&
 					     (v.situation == Vessel.Situations.LANDED ||
@@ -133,7 +161,7 @@
 							if (_selectedVessel != v)
 							{
 								_selectedVessel = v; //set clicked vessel as selected_vessel
-								this._Active = true;    //turn bool on to open the window if closed
+								this.Active = true;    //turn bool on to open the window if closed
 							}
 							else
 							{
@@ -148,7 +176,7 @@
 
 			GUILayout.EndVertical();
 
-			GUI.DragWindow();
+			base.ModuleWindow(id);
 		}
 	}
 }