Updated for KSP 0.90.0 and KerbalEngineer 1.0.
[VOID.git] / VOID_StageInfo.cs
blob:a/VOID_StageInfo.cs -> blob:b/VOID_StageInfo.cs
--- a/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -13,6 +13,7 @@
 
 namespace VOID
 {
+	[VOID_Scenes(GameScenes.EDITOR, GameScenes.FLIGHT)]
 	public class VOID_StageInfo : VOID_WindowModule
 	{
 		private Table stageTable;
@@ -25,60 +26,95 @@
 		private Table.Column<double> stageTotalMassCol;
 		private Table.Column<double> stageThrustCol;
 		private Table.Column<double> stageTWRCol;
+		private Table.Column<string> stageTimeCol;
 
 		private bool stylesApplied;
+
 		private bool showBodyList;
-
 		private Rect bodyListPos;
 
-		private CelestialBody selectedBody;
+		private bool showColumnSelection;
+
+		private CelestialBody _selectedBody;
 		[AVOID_SaveValue("bodyIdx")]
 		private VOID_SaveValue<int> bodyIdx;
 		private int lastIdx;
 
+		private bool showAdvanced;
+
+		[AVOID_SaveValue("UseSealLevel")]
+		private VOID_SaveValue<bool> useSeaLevel;
+		private GUIContent seaLevelToggle;
+
+		private CelestialBody selectedBody
+		{
+			get
+			{
+				return this._selectedBody;
+			}
+			set
+			{
+				this._selectedBody = value;
+				KerbalEngineer.Helpers.CelestialBodies.SelectedBody = value;
+			}
+		}
+
 		public VOID_StageInfo() : base()
 		{
-			this._Name = "Stage Information";
-			this.defWidth = 200f;
-			this.bodyIdx = 4;
+			this.Name = "Stage Information";
+			this.defWidth = 20f;
+			this.bodyIdx = (VOID_SaveValue<int>)4;
 
 			this.stylesApplied = false;
 			this.showBodyList = false;
+			this.showColumnSelection = false;
 
 			this.bodyListPos = new Rect();
 
 			this.stageTable = new Table();
 
-			this.stageNumberCol = new Table.Column<int>("Stage", 40f);
+			this.stageNumberCol = new Table.Column<int>("Stage", 20f);
 			this.stageTable.Add(this.stageNumberCol);
 
-			this.stageDeltaVCol = new Table.Column<double>("DeltaV [m/s]", 60f);
+			this.stageDeltaVCol = new Table.Column<double>("DeltaV [m/s]", 20f);
 			this.stageDeltaVCol.Format = "S2";
 			this.stageTable.Add(this.stageDeltaVCol);
 
-			this.stageTotalDVCol = new Table.Column<double>("Total ΔV [m/s]", 60f);
+			this.stageTotalDVCol = new Table.Column<double>("Total ΔV [m/s]", 20f);
 			this.stageTotalDVCol.Format = "S2";
 			this.stageTable.Add(this.stageTotalDVCol);
 
-			this.stageInvertDVCol = new Table.Column<double>("Invert ΔV [m/s]", 60f);
+			this.stageInvertDVCol = new Table.Column<double>("Invert ΔV [m/s]", 20f);
 			this.stageInvertDVCol.Format = "S2";
 			this.stageTable.Add(this.stageInvertDVCol);
 
-			this.stageMassCol = new Table.Column<double>("Mass [Mg]", 60f);
+			this.stageMassCol = new Table.Column<double>("Mass [Mg]", 20f);
 			this.stageMassCol.Format = "#.#";
 			this.stageTable.Add(this.stageMassCol);
 
-			this.stageTotalMassCol = new Table.Column<double>("Total [Mg]", 60f);
+			this.stageTotalMassCol = new Table.Column<double>("Total [Mg]", 20f);
 			this.stageTotalMassCol.Format = "#.#";
 			this.stageTable.Add(this.stageTotalMassCol);
 
-			this.stageThrustCol = new Table.Column<double>("Thrust [N]", 60f);
+			this.stageThrustCol = new Table.Column<double>("Thrust [N]", 20f);
 			this.stageThrustCol.Format = "S2";
 			this.stageTable.Add(this.stageThrustCol);
 
-			this.stageTWRCol = new Table.Column<double>("T/W Ratio", 60f);
+			this.stageTWRCol = new Table.Column<double>("T/W Ratio", 20f);
 			this.stageTWRCol.Format = "#.#";
 			this.stageTable.Add(this.stageTWRCol);
+
+			this.stageTimeCol = new Table.Column<string>("Burn Time", 20f);
+			this.stageTable.Add(this.stageTimeCol);
+
+			this.showAdvanced = false;
+
+			this.useSeaLevel = (VOID_SaveValue<bool>)false;
+
+			seaLevelToggle = new GUIContent(
+				"Use Sea Level",
+				"Use 'sea' level atmospheric conditions on bodies with atmospheres."
+			);
 		}
 
 		public override void DrawGUI()
@@ -87,14 +123,19 @@
 
 			if (this.showBodyList)
 			{
-				GUILayout.Window(core.windowID, this.bodyListPos, this.BodyPickerWindow, string.Empty);
-			}
-		}
-
-		public override void ModuleWindow(int _)
-		{
+				GUILayout.Window(core.WindowID, this.bodyListPos, this.BodyPickerWindow, string.Empty);
+			}
+		}
+
+		public override void ModuleWindow(int id)
+		{
+			if (this.selectedBody == null)
+			{
+				this.selectedBody = core.HomeBody;
+			}
+
 			if (
-				HighLogic.LoadedSceneIsEditor ||
+				!HighLogic.LoadedSceneIsFlight ||
 				(TimeWarp.WarpMode == TimeWarp.Modes.LOW) ||
 				(TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)
 			)
@@ -121,6 +162,15 @@
 				return;
 			}
 
+			if (HighLogic.LoadedSceneIsEditor && this.selectedBody.atmosphere && this.useSeaLevel)
+			{
+				SimManager.Atmosphere = this.selectedBody.GetPressure(0) * PhysicsGlobals.KpaToAtmospheres;
+			}
+			else
+			{
+				SimManager.Atmosphere = 0d;
+			}
+
 			foreach (Stage stage in core.Stages)
 			{
 				if (stage.deltaV == 0 && stage.mass == 0)
@@ -139,20 +189,27 @@
 
 				this.stageThrustCol.Add(stage.thrust * 1000f);
 				this.stageTWRCol.Add(stage.thrustToWeight / (this.selectedBody ?? core.HomeBody).GeeASL);
+
+				this.stageTimeCol.Add(VOID_Tools.FormatInterval(stage.time));
 			}
 
 			this.stageTable.Render();
 
-			if (core.sortedBodyList != null)
+			if (core.SortedBodyList != null)
 			{
 				GUILayout.BeginHorizontal();
 
 				if (GUILayout.Button("◄"))
 				{
-					this.bodyIdx--;
-				}
-
-				this.showBodyList = GUILayout.Toggle(this.showBodyList, (this.selectedBody ?? core.HomeBody).bodyName, GUI.skin.button);
+					this.bodyIdx.value--;
+				}
+
+				this.showBodyList = GUILayout.Toggle(
+					this.showBodyList,
+					(this.selectedBody ?? core.HomeBody).bodyName,
+					GUI.skin.button
+				);
+
 				Rect bodyButtonPos = GUILayoutUtility.GetLastRect();
 
 				if (Event.current.type == EventType.Repaint)
@@ -164,21 +221,43 @@
 
 				if (GUILayout.Button("►"))
 				{
-					this.bodyIdx++;
-				}
-
-				this.bodyIdx %= core.sortedBodyList.Count;
+					this.bodyIdx.value++;
+				}
+
+				this.bodyIdx.value %= core.SortedBodyList.Count;
 
 				if (this.bodyIdx < 0)
 				{
-					this.bodyIdx += core.sortedBodyList.Count;
+					this.bodyIdx.value += core.SortedBodyList.Count;
 				}
 
 				if (this.lastIdx != this.bodyIdx)
 				{
 					this.lastIdx = this.bodyIdx;
-					this.selectedBody = core.sortedBodyList[this.bodyIdx];
-				}
+					this.selectedBody = core.SortedBodyList[this.bodyIdx];
+				}
+
+				if (HighLogic.LoadedSceneIsEditor)
+				{
+					if (
+						GUILayout.Button(
+							this.showAdvanced ? "▲" : "▼",
+							GUILayout.ExpandWidth(false)
+						)
+					)
+					{
+						this.showAdvanced = !this.showAdvanced;
+					}
+				}
+
+				GUILayout.EndHorizontal();
+			}
+
+			if (this.showAdvanced && HighLogic.LoadedSceneIsEditor)
+			{
+				GUILayout.BeginHorizontal();
+
+				this.useSeaLevel.value = GUITools.Toggle(this.useSeaLevel, this.seaLevelToggle, false);
 
 				GUILayout.EndHorizontal();
 			}
@@ -195,24 +274,31 @@
 
 			GUILayout.EndHorizontal();
 
-			GUI.DragWindow();
+			base.ModuleWindow(id);
+		}
+
+		public override void DrawConfigurables()
+		{
+			this.showColumnSelection = GUILayout.Toggle(
+				this.showColumnSelection,
+				"Select StageInfo Columns",
+				GUI.skin.button
+			);
 		}
 
 		private void BodyPickerWindow(int _)
 		{
-			foreach (CelestialBody body in core.sortedBodyList)
+			foreach (CelestialBody body in core.SortedBodyList)
 			{
 				if (GUILayout.Button(body.bodyName, VOID_Styles.labelDefault))
 				{
 					Debug.Log("Picked new body focus: " + body.bodyName);
-					this.bodyIdx = core.sortedBodyList.IndexOf(body);
+					this.bodyIdx.value = core.SortedBodyList.IndexOf(body);
 					this.showBodyList = false;
 				}
 			}
 		}
 	}
-
-	public class VOID_StageInfoEditor : VOID_StageInfo, IVOID_EditorModule {}
 }