Close bodies menu if mouse click off menu.
[VesselSimulator.git] / KerbalEngineer / Editor / BuildAdvanced.cs
blob:a/KerbalEngineer/Editor/BuildAdvanced.cs -> blob:b/KerbalEngineer/Editor/BuildAdvanced.cs
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives  
   
using System;  
using System.Linq;  
   
using KerbalEngineer.Extensions;  
using KerbalEngineer.Flight;  
using KerbalEngineer.Settings;  
using KerbalEngineer.VesselSimulator;  
   
using UnityEngine;  
   
#endregion  
   
namespace KerbalEngineer.Editor namespace KerbalEngineer.Editor
{ {
  #region Using Directives
  using System;
  using Extensions;
  using Flight;
  using Helpers;
  using Settings;
  using UIControls;
  using UnityEngine;
  using VesselSimulator;
   
  #endregion
   
[KSPAddon(KSPAddon.Startup.EditorAny, false)] [KSPAddon(KSPAddon.Startup.EditorAny, false)]
public class BuildAdvanced : MonoBehaviour public class BuildAdvanced : MonoBehaviour
{ {
#region Instance  
   
/// <summary>  
/// Gets the current instance if started or returns null.  
/// </summary>  
public static BuildAdvanced Instance { get; private set; }  
   
#endregion  
   
#region Fields #region Fields
  public static float Altitude = 0.0f;
private float atmosphericPercentage = 1.0f;  
private float atmosphericVelocity; private GUIStyle areaSettingStyle;
private BuildBodiesList bodiesList; private GUIStyle areaStyle;
  private float atmosphericMach;
  private GUIStyle bodiesButtonActiveStyle;
  private GUIStyle bodiesButtonStyle;
  private DropDown bodiesList;
  private Rect bodiesListPosition;
  private GUIStyle buttonStyle;
private int compactCheck; private int compactCheck;
private bool compactCollapseRight; private bool compactCollapseRight;
  private bool compactMode;
private float compactRight; private float compactRight;
private bool hasChanged; private bool hasChanged;
  private GUIStyle infoStyle;
private bool isEditorLocked; private bool isEditorLocked;
  private float maxMach;
private int numberOfStages; private int numberOfStages;
private Rect referenceBodiesButtonRect; private Rect position = new Rect(265.0f, 45.0f, 0, 0);
private Stage[] stages;  
private int windowId;  
private Rect windowPosition = new Rect(265.0f, 45.0f, 0, 0);  
   
#region Styles  
   
private GUIStyle areaSettingStyle;  
private GUIStyle areaStyle;  
private GUIStyle buttonStyle;  
private GUIStyle infoStyle;  
private GUIStyle settingAtmoStyle; private GUIStyle settingAtmoStyle;
private GUIStyle settingStyle; private GUIStyle settingStyle;
private GUIStyle titleStyle;  
private GUIStyle windowStyle;  
   
#endregion  
   
#endregion  
   
#region Properties  
   
private bool compactMode;  
private bool showAllStages; private bool showAllStages;
private bool showAtmosphericDetails; private bool showAtmosphericDetails;
private bool showReferenceBodies;  
private bool showSettings; private bool showSettings;
  private Stage[] stages;
  private GUIStyle titleStyle;
private bool visible = true; private bool visible = true;
  private GUIStyle windowStyle;
  #endregion
   
  #region Properties
  /// <summary>
  /// Gets the current instance if started or returns null.
  /// </summary>
  public static BuildAdvanced Instance { get; private set; }
   
  /// <summary>
  /// Gets and sets whether to show in compact mode.
  /// </summary>
  public bool CompactMode
  {
  get
  {
  return compactMode;
  }
  set
  {
  compactMode = value;
  }
  }
   
  /// <summary>
  /// Gets and sets whether to show all stages.
  /// </summary>
  public bool ShowAllStages
  {
  get
  {
  return showAllStages;
  }
  set
  {
  showAllStages = value;
  }
  }
   
  /// <summary>
  /// Gets and sets whether to use atmospheric details.
  /// </summary>
  public bool ShowAtmosphericDetails
  {
  get
  {
  return showAtmosphericDetails;
  }
  set
  {
  showAtmosphericDetails = value;
  }
  }
   
  /// <summary>
  /// Gets and sets whether to show the settings display.
  /// </summary>
  public bool ShowSettings
  {
  get
  {
  return showSettings;
  }
  set
  {
  showSettings = value;
  }
  }
   
/// <summary> /// <summary>
/// Gets and sets whether the display is enabled. /// Gets and sets whether the display is enabled.
/// </summary> /// </summary>
public bool Visible public bool Visible
{ {
get { return this.visible; } get
  {
  return visible;
  }
set set
{ {
this.visible = value; visible = value;
Logger.Log("BuildAdvanced->Visible = " + value); }
} }
}  
   
/// <summary>  
/// Gets and sets whether to show in compact mode.  
/// </summary>  
public bool CompactMode  
{  
get { return this.compactMode; }  
set  
{  
this.compactMode = value;  
Logger.Log("BuildAdvanced->CompactMode = " + value);  
}  
}  
   
/// <summary>  
/// Gets and sets whether to show all stages.  
/// </summary>  
public bool ShowAllStages  
{  
get { return this.showAllStages; }  
set  
{  
this.showAllStages = value;  
Logger.Log("BuildAdvanced->ShowAllStages = " + value);  
}  
}  
   
/// <summary>  
/// Gets and sets whether to use atmospheric details.  
/// </summary>  
public bool ShowAtmosphericDetails  
{  
get { return this.showAtmosphericDetails; }  
set  
{  
this.showAtmosphericDetails = value;  
Logger.Log("BuildAdvanced->ShowAtmosphericDetails = " + value);  
}  
}  
   
/// <summary>  
/// Gets and sets whether to show the settings display.  
/// </summary>  
public bool ShowSettings  
{  
get { return this.showSettings; }  
set  
{  
this.showSettings = value;  
Logger.Log("BuildAdvanced->ShowSettings = " + value);  
}  
}  
   
#endregion #endregion
   
#region Initialisation #region Methods
  private static Rect compactModeRect = new Rect(0.0f, 5.0f, 0.0f, 20.0f);
private void Awake() private static Stage stage;
{ private static int stagesCount;
Instance = this; private static int stagesLength;
this.bodiesList = this.gameObject.AddComponent<BuildBodiesList>(); private static string title;
this.Load();  
} protected void Awake()
   
private void Start()  
{  
this.windowId = this.GetHashCode();  
this.InitialiseStyles();  
GuiDisplaySize.OnSizeChanged += this.OnSizeChanged;  
}  
   
/// <summary>  
/// Initialises all the styles that are required.  
/// </summary>  
private void InitialiseStyles()  
{ {
try try
{ {
this.windowStyle = new GUIStyle(HighLogic.Skin.window) Instance = this;
{ bodiesList = gameObject.AddComponent<DropDown>();
alignment = TextAnchor.UpperLeft bodiesList.DrawCallback = DrawBodiesList;
}; Load();
   
this.areaStyle = new GUIStyle(HighLogic.Skin.box) SimManager.UpdateModSettings();
{ SimManager.OnReady -= GetStageInfo;
padding = new RectOffset(0, 0, 9, 0) SimManager.OnReady += GetStageInfo;
}; }
  catch (Exception ex)
this.areaSettingStyle = new GUIStyle(HighLogic.Skin.box) {
{ Logger.Exception(ex, "BuildAdvanced.Awake()");
padding = new RectOffset(10, 10, 10, 10) }
}; }
   
this.buttonStyle = new GUIStyle(HighLogic.Skin.button) /// <summary>
{ /// Saves the settings when this object is destroyed.
normal = /// </summary>
  protected void OnDestroy()
  {
  try
  {
  SettingHandler handler = new SettingHandler();
  handler.Set("visible", visible);
  handler.Set("windowPositionX", position.x);
  handler.Set("windowPositionY", position.y);
  handler.Set("compactMode", compactMode);
  handler.Set("compactCollapseRight", compactCollapseRight);
  handler.Set("showAllStages", showAllStages);
  handler.Set("showAtmosphericDetails", showAtmosphericDetails);
  handler.Set("showSettings", showSettings);
  handler.Set("selectedBodyName", CelestialBodies.SelectedBody.Name);
  handler.Save("BuildAdvanced.xml");
  GuiDisplaySize.OnSizeChanged -= OnSizeChanged;
  }
  catch (Exception ex)
  {
  Logger.Exception(ex, "BuildAdvanced.OnDestroy()");
  }
  }
   
  protected void OnGUI()
  {
  try
  {
  if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
  {
  return;
  }
   
  if (stages == null)
  {
  return;
  }
   
  // Change the window title based on whether in compact mode or not.
  title = !compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion;
   
  // Reset the window size when the staging or something else has changed.
  stagesLength = stages.Length;
  if (showAllStages)
  {
  stagesCount = stagesLength;
  }
  if (showAllStages == false)
  {
  stagesCount = 0;
  for (int i = 0; i < stagesLength; ++i)
{ {
textColor = Color.white if (stages[i].deltaV > 0.0f)
}, {
fontSize = (int)(11 * GuiDisplaySize.Offset), stagesCount = stagesCount + 1;
fontStyle = FontStyle.Bold, }
alignment = TextAnchor.MiddleCenter }
}; }
   
this.titleStyle = new GUIStyle(HighLogic.Skin.label) if (hasChanged || stagesCount != numberOfStages)
{ {
normal = hasChanged = false;
  numberOfStages = stagesCount;
   
  position.width = 0;
  position.height = 0;
  }
   
  GUI.skin = null;
  position = GUILayout.Window(GetInstanceID(), position, Window, title, windowStyle).ClampToScreen();
   
  if (compactCheck > 0 && compactCollapseRight)
  {
  position.x = compactRight - position.width;
  compactCheck--;
  }
  else if (compactCheck > 0)
  {
  compactCheck = 0;
  }
   
  // Check editor lock to manage click-through.
  CheckEditorLock();
  }
  catch (Exception ex)
  {
  Logger.Exception(ex, "BuildAdvanced.OnGUI()");
  }
  }
   
  protected void Start()
  {
  try
  {
  InitialiseStyles();
  GuiDisplaySize.OnSizeChanged += OnSizeChanged;
  }
  catch (Exception ex)
  {
  Logger.Exception(ex, "BuildAdvanced.Start()");
  }
  }
   
  protected void Update()
  {
  try
  {
  if (Input.GetKeyDown(KeyBinder.EditorShowHide))
  {
  visible = !visible;
  if (!visible)
{ {
textColor = Color.white EditorLock(false);
}, }
fontSize = (int)(11 * GuiDisplaySize.Offset), }
fontStyle = FontStyle.Bold,  
alignment = TextAnchor.MiddleCenter, if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)
stretchWidth = true, {
}; bodiesList.enabled = false;
   
this.infoStyle = new GUIStyle(HighLogic.Skin.label)  
{  
fontSize = (int)(11 * GuiDisplaySize.Offset),  
fontStyle = FontStyle.Bold,  
alignment = TextAnchor.MiddleCenter,  
stretchWidth = true  
};  
   
this.settingStyle = new GUIStyle(this.titleStyle)  
{  
alignment = TextAnchor.MiddleLeft,  
stretchWidth = true,  
stretchHeight = true  
};  
   
this.settingAtmoStyle = new GUIStyle(this.titleStyle)  
{  
margin = new RectOffset(),  
padding = new RectOffset(),  
alignment = TextAnchor.UpperLeft  
};  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->InitialiseStyles");  
}  
}  
   
private void OnSizeChanged()  
{  
this.InitialiseStyles();  
this.hasChanged = true;  
}  
   
#endregion  
   
#region Update and Drawing  
   
private void Update()  
{  
try  
{  
if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)  
{  
this.bodiesList.enabled = false;  
return; return;
} }
   
this.bodiesList.SetPosition(this.referenceBodiesButtonRect.x + this.windowPosition.x, this.referenceBodiesButtonRect.y + this.referenceBodiesButtonRect.height + this.windowPosition.y, this.referenceBodiesButtonRect.width);  
   
// Configure the simulation parameters based on the selected reference body. // Configure the simulation parameters based on the selected reference body.
SimManager.Gravity = CelestialBodies.SelectedBody.Gravity; SimManager.Gravity = CelestialBodies.SelectedBody.Gravity;
   
if (this.showAtmosphericDetails) if (showAtmosphericDetails)
{ {
SimManager.Atmosphere = CelestialBodies.SelectedBody.Atmosphere * 0.01d * this.atmosphericPercentage; SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude);
} }
else else
{ {
SimManager.Atmosphere = 0; SimManager.Atmosphere = 0;
} }
   
SimManager.Velocity = this.atmosphericVelocity; SimManager.Mach = atmosphericMach;
   
  SimManager.RequestSimulation();
SimManager.TryStartSimulation(); SimManager.TryStartSimulation();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex, "BuildAdvanced->Update"); Logger.Exception(ex, "BuildAdvanced.Update()");
} }
} }
   
private void OnGUI() /// <summary>
  /// Checks whether the editor should be locked to stop click-through.
  /// </summary>
  private void CheckEditorLock()
  {
  if ((position.MouseIsOver() || bodiesList.Position.MouseIsOver()) && !isEditorLocked)
  {
  EditorLock(true);
  }
  else if (!position.MouseIsOver() && !bodiesList.Position.MouseIsOver() && isEditorLocked)
  {
  EditorLock(false);
  }
  }
   
  /// <summary>
  /// Draws the atmospheric settings.
  /// </summary>
  private void DrawAtmosphericDetails()
{ {
try try
{ {
if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0) GUILayout.BeginHorizontal();
{ GUILayout.BeginVertical();
return; GUILayout.Label("Altitude: " + (Altitude * 0.001f).ToString("F1") + "km", settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
} GUI.skin = HighLogic.Skin;
  Altitude = GUILayout.HorizontalSlider(Altitude, 0.0f, (float)(CelestialBodies.SelectedBody.CelestialBody.atmosphereDepth));
if (SimManager.ResultsReady())  
{  
this.stages = SimManager.Stages;  
}  
   
SimManager.RequestSimulation();  
   
if (this.stages == null)  
{  
return;  
}  
   
// Change the window title based on whether in compact mode or not.  
var title = !this.compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion;  
   
// Reset the window size when the staging or something else has changed.  
var stageCount = this.stages.Count(stage => this.showAllStages || stage.deltaV > 0);  
if (this.hasChanged || stageCount != this.numberOfStages)  
{  
this.hasChanged = false;  
this.numberOfStages = stageCount;  
   
this.windowPosition.width = 0;  
this.windowPosition.height = 0;  
}  
   
GUI.skin = null; GUI.skin = null;
this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, title, this.windowStyle).ClampToScreen(); GUILayout.EndVertical();
   
if (this.compactCheck > 0 && this.compactCollapseRight) GUILayout.Space(5.0f);
{  
this.windowPosition.x = this.compactRight - this.windowPosition.width; GUILayout.BeginVertical();
this.compactCheck--; GUILayout.Label("Mach: " + atmosphericMach.ToString("F2"), settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
} GUI.skin = HighLogic.Skin;
else if (this.compactCheck > 0) atmosphericMach = GUILayout.HorizontalSlider(Mathf.Clamp(atmosphericMach, 0.0f, maxMach), 0.0f, maxMach);
{ GUI.skin = null;
this.compactCheck = 0; GUILayout.EndVertical();
} GUILayout.EndHorizontal();
   
// Check editor lock to manage click-through.  
this.CheckEditorLock();  
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex, "BuildAdvanced->OnDraw"); Logger.Exception(ex, "BuildAdvanced.DrawAtmosphericDetails()");
} }
} }
   
/// <summary> private void DrawBodiesList()
/// Checks whether the editor should be locked to stop click-through. {
/// </summary> if (CelestialBodies.SystemBody == CelestialBodies.SelectedBody)
private void CheckEditorLock() {
  DrawBody(CelestialBodies.SystemBody);
  }
  else
  {
  foreach (CelestialBodies.BodyInfo body in CelestialBodies.SystemBody.Children)
  {
  DrawBody(body);
  }
  }
  }
   
  private void DrawBody(CelestialBodies.BodyInfo bodyInfo, int depth = 0)
  {
  GUILayout.BeginHorizontal();
  GUILayout.Space(20.0f * depth);
  if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? bodiesButtonActiveStyle : bodiesButtonStyle))
  {
  CelestialBodies.SetSelectedBody(bodyInfo.Name);
  Altitude = 0.0f;
  bodiesList.Resize = true;
  }
  GUILayout.EndHorizontal();
   
  if (bodyInfo.Selected)
  {
  for (int i = 0; i < bodyInfo.Children.Count; ++i)
  {
  DrawBody(bodyInfo.Children[i], depth + 1);
  }
  }
  }
   
  /// <summary>
  /// Draws the burn time column.
  /// </summary>
  private void DrawBurnTime()
  {
  GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
  GUILayout.Label("BURN", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(TimeFormatter.ConvertToString(stage.time), infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the cost column.
  /// </summary>
  private void DrawCost()
  {
  GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));
  GUILayout.Label("COST", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(Units.Cost(stage.cost, stage.totalCost), infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the deltaV column.
  /// </summary>
  private void DrawDeltaV()
  {
  GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.Label("DELTA-V", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the specific impluse column.
  /// </summary>
  private void DrawIsp()
  {
  GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
  GUILayout.Label("ISP", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.isp.ToString("F1") + "s", infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the mass column.
  /// </summary>
  private void DrawMass()
  {
  GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));
  GUILayout.Label("MASS", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(Units.ToMass(stage.mass, stage.totalMass), infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the part count column.
  /// </summary>
  private void DrawPartCount()
  {
  GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset));
  GUILayout.Label("PARTS", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.partCount + " / " + stage.totalPartCount, infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the settings panel.
  /// </summary>
  private void DrawSettings()
  {
  GUILayout.BeginHorizontal();
  GUILayout.Label("Compact mode collapses to the:", settingStyle);
  compactCollapseRight = !GUILayout.Toggle(!compactCollapseRight, "LEFT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  compactCollapseRight = GUILayout.Toggle(compactCollapseRight, "RIGHT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("Simulate using vectored thrust values:");
  SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("Verbose Simulation Log:");
  SimManager.logOutput = GUILayout.Toggle(SimManager.logOutput, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("Build Engineer Overlay:", settingStyle);
  BuildOverlay.Visible = GUILayout.Toggle(BuildOverlay.Visible, "VISIBLE", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  BuildOverlayPartInfo.NamesOnly = GUILayout.Toggle(BuildOverlayPartInfo.NamesOnly, "NAMES ONLY", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  BuildOverlayPartInfo.ClickToOpen = GUILayout.Toggle(BuildOverlayPartInfo.ClickToOpen, "CLICK TO OPEN", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("Flight Engineer activation mode:", settingStyle);
  FlightEngineerCore.IsCareerMode = GUILayout.Toggle(FlightEngineerCore.IsCareerMode, "CAREER", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  FlightEngineerCore.IsCareerMode = !GUILayout.Toggle(!FlightEngineerCore.IsCareerMode, "PARTLESS", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("Flight Engineer Career Limitations:", settingStyle);
  FlightEngineerCore.IsKerbalLimited = GUILayout.Toggle(FlightEngineerCore.IsKerbalLimited, "KERBAL", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  FlightEngineerCore.IsTrackingStationLimited = GUILayout.Toggle(FlightEngineerCore.IsTrackingStationLimited, "TRACKING", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.EndHorizontal();
   
  GUILayout.BeginHorizontal();
  GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, settingStyle);
  if (GUILayout.Button("<", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
  {
  GuiDisplaySize.Increment--;
  }
  if (GUILayout.Button(">", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
  {
  GuiDisplaySize.Increment++;
  }
  GUILayout.EndHorizontal();
   
  GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.Milliseconds + "ms", settingStyle);
  GUI.skin = HighLogic.Skin;
  SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)GUILayout.HorizontalSlider(SimManager.minSimTime.Milliseconds, 0, 2000.0f));
  GUI.skin = null;
  }
   
  /// <summary>
  /// Draws the stage number column.
  /// </summary>
  private void DrawStageNumbers()
  {
  GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset));
  GUILayout.Label(string.Empty, titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label("S" + stage.number, titleStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the thrust column.
  /// </summary>
  private void DrawThrust()
  {
  GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
  GUILayout.Label("THRUST", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.thrust.ToForce(), infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Draws the torque column.
  /// </summary>
  private void DrawTorque()
  {
  GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
  GUILayout.Label("TORQUE", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.maxThrustTorque.ToTorque(), infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  /// <summary>
  /// Drwas the thrust to weight ratio column.
  /// </summary>
  private void DrawTwr()
  {
  GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));
  GUILayout.Label("TWR (MAX)", titleStyle);
  for (int i = 0; i < stagesLength; ++i)
  {
  stage = stages[i];
  if (showAllStages || stage.deltaV > 0.0)
  {
  GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", infoStyle);
  }
  }
  GUILayout.EndVertical();
  }
   
  private void EditorLock(bool state)
  {
  if (state)
  {
  InputLockManager.SetControlLock(ControlTypes.All, "KER_BuildAdvanced");
  BuildOverlayPartInfo.Hidden = true;
  isEditorLocked = true;
  }
  else
  {
  InputLockManager.SetControlLock(ControlTypes.None, "KER_BuildAdvanced");
  BuildOverlayPartInfo.Hidden = false;
  isEditorLocked = false;
  }
  }
   
  private void GetStageInfo()
  {
  stages = SimManager.Stages;
  if (stages != null && stages.Length > 0)
  {
  maxMach = stages[stages.Length - 1].maxMach;
  }
  }
   
  /// <summary>
  /// Initialises all the styles that are required.
  /// </summary>
  private void InitialiseStyles()
  {
  windowStyle = new GUIStyle(HighLogic.Skin.window)
  {
  alignment = TextAnchor.UpperLeft
  };
   
  areaStyle = new GUIStyle(HighLogic.Skin.box)
  {
  padding = new RectOffset(0, 0, 9, 0)
  };
   
  areaSettingStyle = new GUIStyle(HighLogic.Skin.box)
  {
  padding = new RectOffset(10, 10, 10, 10)
  };
   
  buttonStyle = new GUIStyle(HighLogic.Skin.button)
  {
  normal =
  {
  textColor = Color.white
  },
  fontSize = (int)(11 * GuiDisplaySize.Offset),
  fontStyle = FontStyle.Bold,
  alignment = TextAnchor.MiddleCenter
  };
   
  titleStyle = new GUIStyle(HighLogic.Skin.label)
  {
  normal =
  {
  textColor = Color.white
  },
  fontSize = (int)(11 * GuiDisplaySize.Offset),
  fontStyle = FontStyle.Bold,
  alignment = TextAnchor.MiddleCenter,
  stretchWidth = true,
  };
   
  infoStyle = new GUIStyle(HighLogic.Skin.label)
  {
  fontSize = (int)(11 * GuiDisplaySize.Offset),
  fontStyle = FontStyle.Bold,
  alignment = TextAnchor.MiddleCenter,
  stretchWidth = true
  };
   
  settingStyle = new GUIStyle(titleStyle)
  {
  alignment = TextAnchor.MiddleLeft,
  stretchWidth = true,
  stretchHeight = true
  };
   
  settingAtmoStyle = new GUIStyle(titleStyle)
  {
  margin = new RectOffset(),
  padding = new RectOffset(),
  alignment = TextAnchor.UpperLeft
  };
   
  bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button)
  {
  margin = new RectOffset(0, 0, 2, 0),
  padding = new RectOffset(5, 5, 5, 5),
  normal =
  {
  textColor = Color.white
  },
  active =
  {
  textColor = Color.white
  },
  fontSize = (int)(11 * GuiDisplaySize.Offset),
  fontStyle = FontStyle.Bold,
  alignment = TextAnchor.MiddleCenter,
  fixedHeight = 20.0f
  };
   
  bodiesButtonActiveStyle = new GUIStyle(bodiesButtonStyle)
  {
  normal = bodiesButtonStyle.onNormal,
  hover = bodiesButtonStyle.onHover
  };
  }
   
  /// <summary>
  /// Loads the settings when this object is created.
  /// </summary>
  private void Load()
{ {
try try
{ {
if ((this.windowPosition.MouseIsOver() || this.bodiesList.Position.MouseIsOver()) && this.isEditorLocked == false) SettingHandler handler = SettingHandler.Load("BuildAdvanced.xml");
{ handler.Get("visible", ref visible);
EditorLogic.fetch.State = EditorLogic.EditorState.GUI_SELECTED; position.x = handler.Get("windowPositionX", position.x);
this.isEditorLocked = true; position.y = handler.Get("windowPositionY", position.y);
} handler.Get("compactMode", ref compactMode);
else if (!this.windowPosition.MouseIsOver() && !this.bodiesList.Position.MouseIsOver() && this.isEditorLocked) handler.Get("compactCollapseRight", ref compactCollapseRight);
{ handler.Get("showAllStages", ref showAllStages);
EditorLogic.fetch.State = EditorLogic.EditorState.PAD_UNSELECTED; handler.Get("showAtmosphericDetails", ref showAtmosphericDetails);
this.isEditorLocked = false; handler.Get("showSettings", ref showSettings);
} CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name));
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex, "BuildAdvanced->CheckEditorLock"); Logger.Exception(ex, "BuildAdvanced.Load()");
} }
  }
   
  private void OnSizeChanged()
  {
  InitialiseStyles();
  hasChanged = true;
} }
   
/// <summary> /// <summary>
/// Draws the OnGUI window. /// Draws the OnGUI window.
/// </summary> /// </summary>
private void Window(int windowId) private void Window(int windowId)
{ {
try try
{ {
  compactModeRect = new Rect(position.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f);
   
// Draw the compact mode toggle. // Draw the compact mode toggle.
if (GUI.Toggle(new Rect(this.windowPosition.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode) if (GUI.Toggle(compactModeRect, compactMode, "COMPACT", buttonStyle) != compactMode)
{ {
this.hasChanged = true; hasChanged = true;
this.compactCheck = 2; compactCheck = 2;
this.compactRight = this.windowPosition.xMax; compactRight = position.xMax;
this.compactMode = !this.compactMode; compactMode = !compactMode;
} }
   
// When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles. // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.
if (!this.compactMode) if (!compactMode)
{ {
if (GUI.Toggle(new Rect(this.windowPosition.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), this.showSettings, "SETTINGS", this.buttonStyle) != this.showSettings) if (GUI.Toggle(new Rect(position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), showSettings, "SETTINGS", buttonStyle) != showSettings)
{ {
this.hasChanged = true; hasChanged = true;
this.showSettings = !this.showSettings; showSettings = !showSettings;
} }
   
if (GUI.Toggle(new Rect(this.windowPosition.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages) if (GUI.Toggle(new Rect(position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), showAllStages, "ALL STAGES", buttonStyle) != showAllStages)
{ {
this.hasChanged = true; hasChanged = true;
this.showAllStages = !this.showAllStages; showAllStages = !showAllStages;
} }
   
if (GUI.Toggle(new Rect(this.windowPosition.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails) if (GUI.Toggle(new Rect(position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMOSPHERIC", buttonStyle) != showAtmosphericDetails)
{ {
this.hasChanged = true; hasChanged = true;
this.showAtmosphericDetails = !this.showAtmosphericDetails; showAtmosphericDetails = !showAtmosphericDetails;
} }
   
this.referenceBodiesButtonRect = new Rect(this.windowPosition.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f); bodiesListPosition = new Rect(position.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f);
this.bodiesList.enabled = GUI.Toggle(this.referenceBodiesButtonRect, this.bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), this.buttonStyle); bodiesList.enabled = GUI.Toggle(bodiesListPosition, bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), buttonStyle);
  bodiesList.SetPosition(bodiesListPosition.Translate(position));
  }
  else
  {
  if (GUI.Toggle(new Rect(position.width - 133.0f * GuiDisplaySize.Offset, 5.0f, 60.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMO", buttonStyle) != showAtmosphericDetails)
  {
  hasChanged = true;
  showAtmosphericDetails = !showAtmosphericDetails;
  }
} }
   
// Draw the main informational display box. // Draw the main informational display box.
if (!this.compactMode) if (!compactMode)
{ {
GUILayout.BeginHorizontal(this.areaStyle); GUILayout.BeginHorizontal(areaStyle);
this.DrawStageNumbers(); DrawStageNumbers();
//this.DrawPartCount(); DrawPartCount();
this.DrawCost(); DrawCost();
this.DrawMass(); DrawMass();
this.DrawIsp(); DrawIsp();
this.DrawThrust(); DrawThrust();
this.DrawTwr(); DrawTorque();
this.DrawDeltaV(); DrawTwr();
this.DrawBurnTime(); DrawDeltaV();
  DrawBurnTime();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
if (this.showAtmosphericDetails) if (showAtmosphericDetails && !compactMode)
{ {
GUILayout.BeginVertical(this.areaSettingStyle); GUILayout.BeginVertical(areaSettingStyle);
this.DrawAtmosphericDetails(); DrawAtmosphericDetails();
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
   
if (this.showSettings) if (showSettings)
{ {
GUILayout.BeginVertical(this.areaSettingStyle); GUILayout.BeginVertical(areaSettingStyle);
this.DrawSettings(); DrawSettings();
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
} }
else // Draw only a few details when in compact mode. else // Draw only a few details when in compact mode.
{ {
GUILayout.BeginHorizontal(this.areaStyle); GUILayout.BeginHorizontal(areaStyle);
this.DrawStageNumbers(); DrawStageNumbers();
this.DrawTwr(); DrawTwr();
this.DrawDeltaV(); DrawDeltaV();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
   
GUI.DragWindow(); GUI.DragWindow();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex, "BuildAdvanced->Window"); Logger.Exception(ex, "BuildAdvanced.Window()");
} }
} }
   
/// <summary>  
/// Draws the atmospheric settings.  
/// </summary>  
private void DrawAtmosphericDetails()  
{  
try  
{  
GUILayout.BeginHorizontal();  
GUILayout.Label("Pressure: " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));  
GUI.skin = HighLogic.Skin;  
GUILayout.BeginVertical();  
GUILayout.FlexibleSpace();  
this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);  
GUILayout.FlexibleSpace();  
GUILayout.EndVertical();  
GUI.skin = null;  
GUILayout.EndHorizontal();  
   
GUILayout.Space(5.0f);  
   
GUILayout.BeginHorizontal();  
GUILayout.Label("Velocity: " + this.atmosphericVelocity.ToString("F1") + "m/s", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));  
GUI.skin = HighLogic.Skin;  
GUILayout.BeginVertical();  
GUILayout.FlexibleSpace();  
this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f);  
GUILayout.FlexibleSpace();  
GUILayout.EndVertical();  
GUI.skin = null;  
GUILayout.EndHorizontal();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawAtmosphericDetails");  
}  
}  
   
/// <summary>  
/// Draws the settings panel.  
/// </summary>  
private void DrawSettings()  
{  
try  
{  
GUILayout.BeginHorizontal();  
GUILayout.Label("Compact mode collapses to the:", this.settingStyle);  
this.compactCollapseRight = !GUILayout.Toggle(!this.compactCollapseRight, "LEFT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
this.compactCollapseRight = GUILayout.Toggle(this.compactCollapseRight, "RIGHT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
GUILayout.EndHorizontal();  
   
GUILayout.BeginHorizontal();  
GUILayout.Label("Build Engineer Overlay:", this.settingStyle);  
BuildOverlay.Instance.Visible = GUILayout.Toggle(BuildOverlay.Instance.Visible, "ENABLED", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
BuildOverlay.Instance.Visible = !GUILayout.Toggle(!BuildOverlay.Instance.Visible, "DISABLED", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
GUILayout.EndHorizontal();  
   
GUILayout.BeginHorizontal();  
GUILayout.Label("Flight Engineer activation mode:", this.settingStyle);  
FlightEngineerPartless.IsPartless = GUILayout.Toggle(FlightEngineerPartless.IsPartless, "PARTLESS", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
FlightEngineerPartless.IsPartless = !GUILayout.Toggle(!FlightEngineerPartless.IsPartless, "MODULE", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
GUILayout.EndHorizontal();  
   
GUILayout.BeginHorizontal();  
GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, this.settingStyle);  
if (GUILayout.Button("<", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))  
{  
GuiDisplaySize.Increment--;  
}  
if (GUILayout.Button(">", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))  
{  
GuiDisplaySize.Increment++;  
}  
GUILayout.EndHorizontal();  
   
GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime + "ms", this.settingStyle);  
GUI.skin = HighLogic.Skin;  
SimManager.minSimTime = (long)GUILayout.HorizontalSlider(SimManager.minSimTime, 0, 2000.0f);  
GUI.skin = null;  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawSettings");  
}  
}  
   
/// <summary>  
/// Draws the stage number column.  
/// </summary>  
private void DrawStageNumbers()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset));  
GUILayout.Label(string.Empty, this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label("S" + stage.number, this.titleStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawStageNumbers");  
}  
}  
   
/// <summary>  
/// Draws the part count column.  
/// </summary>  
private void DrawPartCount()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset));  
GUILayout.Label("PARTS", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
//GUILayout.Label(stage.PartCount.ToString("N0"), this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawPartCount");  
}  
}  
   
/// <summary>  
/// Draws the cost column.  
/// </summary>  
private void DrawCost()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));  
GUILayout.Label("COST", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawCost");  
}  
}  
   
/// <summary>  
/// Draws the mass column.  
/// </summary>  
private void DrawMass()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));  
GUILayout.Label("MASS", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.mass.ToMass(false) + " / " + stage.totalMass.ToMass(), this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawMass");  
}  
}  
   
/// <summary>  
/// Draws the specific impluse column.  
/// </summary>  
private void DrawIsp()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));  
GUILayout.Label("ISP", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawIsp");  
}  
}  
   
/// <summary>  
/// Draws the thrust column.  
/// </summary>  
private void DrawThrust()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));  
GUILayout.Label("THRUST", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawThrust");  
}  
}  
   
/// <summary>  
/// Drwas the thrust to weight ratio column.  
/// </summary>  
private void DrawTwr()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
GUILayout.Label("TWR (MAX)", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawTwr");  
}  
}  
   
/// <summary>  
/// Draws the deltaV column.  
/// </summary>  
private void DrawDeltaV()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));  
GUILayout.Label("DELTA-V", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawDeltaV");  
}  
}  
   
/// <summary>  
/// Draws the burn time column.  
/// </summary>  
private void DrawBurnTime()  
{  
try  
{  
GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));  
GUILayout.Label("BURN", this.titleStyle);  
foreach (var stage in this.stages)  
{  
if (this.showAllStages || stage.deltaV > 0)  
{  
GUILayout.Label(stage.time.ToTime(), this.infoStyle);  
}  
}  
GUILayout.EndVertical();  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->DrawBurnTime");  
}  
}  
   
#endregion  
   
#region Save and Load  
   
/// <summary>  
/// Saves the settings when this object is destroyed.  
/// </summary>  
private void OnDestroy()  
{  
try  
{  
var handler = new SettingHandler();  
handler.Set("visible", this.visible);  
handler.Set("windowPositionX", this.windowPosition.x);  
handler.Set("windowPositionY", this.windowPosition.y);  
handler.Set("compactMode", this.compactMode);  
handler.Set("compactCollapseRight", this.compactCollapseRight);  
handler.Set("showAllStages", this.showAllStages);  
handler.Set("showAtmosphericDetails", this.showAtmosphericDetails);  
handler.Set("showReferenceBodies", this.showReferenceBodies);  
handler.Set("showSettings", this.showSettings);  
handler.Set("selectedBodyName", CelestialBodies.SelectedBody.Name);  
handler.Save("BuildAdvanced.xml");  
GuiDisplaySize.OnSizeChanged -= this.OnSizeChanged;  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->OnDestroy");  
}  
}  
   
/// <summary>  
/// Loads the settings when this object is created.  
/// </summary>  
private void Load()  
{  
try  
{  
var handler = SettingHandler.Load("BuildAdvanced.xml");  
handler.Get("visible", ref this.visible);  
this.windowPosition.x = handler.Get("windowPositionX", this.windowPosition.x);  
this.windowPosition.y = handler.Get("windowPositionY", this.windowPosition.y);  
handler.Get("compactMode", ref this.compactMode);  
handler.Get("compactCollapseRight", ref this.compactCollapseRight);  
handler.Get("showAllStages", ref this.showAllStages);  
handler.Get("showAtmosphericDetails", ref this.showAtmosphericDetails);  
handler.Get("showSettings", ref this.showSettings);  
CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name));  
}  
catch (Exception ex)  
{  
Logger.Exception(ex, "BuildAdvanced->Load");  
}  
}  
   
#endregion #endregion
} }
} }