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