Optimised the BuildAdvanced class.
[VesselSimulator.git] / KerbalEngineer / Editor / BuildAdvanced.cs
blob:a/KerbalEngineer/Editor/BuildAdvanced.cs -> blob:b/KerbalEngineer/Editor/BuildAdvanced.cs
--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -1,7 +1,5 @@
 // 
-//     Kerbal Engineer Redux
-// 
-//     Copyright (C) 2014 CYBUTEK
+//     Copyright (C) 2015 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
@@ -19,23 +17,27 @@
 
 namespace KerbalEngineer.Editor
 {
-    #region Using Directives
     using System;
     using Extensions;
     using Flight;
     using Helpers;
+    using KeyBinding;
     using Settings;
     using UIControls;
+    using Unity;
     using UnityEngine;
     using VesselSimulator;
-
-    #endregion
 
     [KSPAddon(KSPAddon.Startup.EditorAny, false)]
     public class BuildAdvanced : MonoBehaviour
     {
-        #region Fields
-        public static float Altitude = 0.0f;
+        public static float Altitude;
+
+        private static Rect compactModeRect = new Rect(0.0f, 5.0f, 0.0f, 20.0f);
+        private static Stage stage;
+        private static int stagesCount;
+        private static int stagesLength;
+        private static string title;
 
         private GUIStyle areaSettingStyle;
         private GUIStyle areaStyle;
@@ -64,9 +66,7 @@
         private GUIStyle titleStyle;
         private bool visible = true;
         private GUIStyle windowStyle;
-        #endregion
-
-        #region Properties
+
         /// <summary>
         ///     Gets the current instance if started or returns null.
         /// </summary>
@@ -146,14 +146,6 @@
                 visible = value;
             }
         }
-        #endregion
-
-        #region Methods
-        private static Rect compactModeRect = new Rect(0.0f, 5.0f, 0.0f, 20.0f);
-        private static Stage stage;
-        private static int stagesCount;
-        private static int stagesLength;
-        private static string title;
 
         protected void Awake()
         {
@@ -179,6 +171,8 @@
         /// </summary>
         protected void OnDestroy()
         {
+            Logger.Log("BuildAdvanced->OnDestroy");
+
             try
             {
                 SettingHandler handler = new SettingHandler();
@@ -198,6 +192,8 @@
             {
                 Logger.Exception(ex, "BuildAdvanced.OnDestroy()");
             }
+
+            EditorLock(false);
         }
 
         protected void OnGUI()
@@ -215,7 +211,7 @@
                 }
 
                 // Change the window title based on whether in compact mode or not.
-                title = !compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion + (showAtmosphericDetails ? " (ATMOS.)" : String.Empty);
+                title = !compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.ASSEMBLY_VERSION : "K.E.R. " + EngineerGlobals.ASSEMBLY_VERSION;
 
                 // Reset the window size when the staging or something else has changed.
                 stagesLength = stages.Length;
@@ -354,7 +350,7 @@
                 GUILayout.Space(5.0f);
 
                 GUILayout.BeginVertical();
-                GUILayout.Label("Mach: " + atmosphericMach.ToString("F1"), settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
+                GUILayout.Label("Mach: " + atmosphericMach.ToString("F2"), settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
                 GUI.skin = HighLogic.Skin;
                 atmosphericMach = GUILayout.HorizontalSlider(Mathf.Clamp(atmosphericMach, 0.0f, maxMach), 0.0f, maxMach);
                 GUI.skin = null;
@@ -523,8 +519,13 @@
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
-            GUILayout.Label("Simulate using vectored thrust values:");
+            GUILayout.Label("Simulate using vectored thrust values:", settingStyle);
             SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            GUILayout.EndHorizontal();
+
+            GUILayout.BeginHorizontal();
+            GUILayout.Label("Verbose Simulation Log:", settingStyle);
+            SimManager.logOutput = GUILayout.Toggle(SimManager.logOutput, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
@@ -547,6 +548,14 @@
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
+            GUILayout.Label("Key Bindings:", settingStyle);
+            if (GUILayout.Button("EDIT KEY BINDINGS", buttonStyle, GUILayout.Width(200.0f * GuiDisplaySize.Offset)))
+            {
+                KeyBinder.Show();
+            }
+            GUILayout.EndHorizontal();
+
+            GUILayout.BeginHorizontal();
             GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, settingStyle);
             if (GUILayout.Button("<", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
             {
@@ -558,9 +567,10 @@
             }
             GUILayout.EndHorizontal();
 
-            GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.Milliseconds + "ms", settingStyle);
+            GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.TotalMilliseconds + "ms", settingStyle);
             GUI.skin = HighLogic.Skin;
-            SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)GUILayout.HorizontalSlider(SimManager.minSimTime.Milliseconds, 0, 2000.0f));
+            SimManager.minSimTime = TimeSpan.FromMilliseconds(GUILayout.HorizontalSlider((float)SimManager.minSimTime.TotalMilliseconds, 0, 2000.0f));
+
             GUI.skin = null;
         }
 
@@ -640,13 +650,13 @@
         {
             if (state)
             {
-                EditorLogic.fetch.Lock(true, true, true, "KER_BuildAdvanced");
+                InputLockManager.SetControlLock(ControlTypes.All, "KER_BuildAdvanced");
                 BuildOverlayPartInfo.Hidden = true;
                 isEditorLocked = true;
             }
             else
             {
-                EditorLogic.fetch.Unlock("KER_BuildAdvanced");
+                InputLockManager.SetControlLock(ControlTypes.None, "KER_BuildAdvanced");
                 BuildOverlayPartInfo.Hidden = false;
                 isEditorLocked = false;
             }
@@ -701,7 +711,7 @@
                 fontSize = (int)(11 * GuiDisplaySize.Offset),
                 fontStyle = FontStyle.Bold,
                 alignment = TextAnchor.MiddleCenter,
-                stretchWidth = true,
+                stretchWidth = true
             };
 
             infoStyle = new GUIStyle(HighLogic.Skin.label)
@@ -802,11 +812,15 @@
                 // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.
                 if (!compactMode)
                 {
-                    if (GUI.Toggle(new Rect(position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), showSettings, "SETTINGS", buttonStyle) != showSettings)
+                    if (GUI.Button(new Rect(position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), "SETTINGS", buttonStyle))
                     {
-                        hasChanged = true;
-                        showSettings = !showSettings;
+                        SettingsWindow.Open();
                     }
+                    //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;
+                    //    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)
                     {
@@ -823,6 +837,14 @@
                     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.
@@ -841,7 +863,7 @@
                     DrawBurnTime();
                     GUILayout.EndHorizontal();
 
-                    if (showAtmosphericDetails)
+                    if (showAtmosphericDetails && !compactMode)
                     {
                         GUILayout.BeginVertical(areaSettingStyle);
                         DrawAtmosphericDetails();
@@ -871,6 +893,5 @@
                 Logger.Exception(ex, "BuildAdvanced.Window()");
             }
         }
-        #endregion
     }
 }