Added stock toolbar support.
Added stock toolbar support.

 Binary files /dev/null and b/Assets/ToolbarIcon.psd differ
--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -1,4 +1,5 @@
-//     Kerbal Engineer Redux

+// 

+//     Kerbal Engineer Redux

 // 

 //     Copyright (C) 2014 CYBUTEK

 // 

@@ -18,6 +19,7 @@
 

 #region Using Directives

 

+using System;

 using System.Linq;

 

 using KerbalEngineer.Extensions;

@@ -70,7 +72,7 @@
         private bool showAllStages;

         private bool showReferenceBodies;

         private bool useAtmosphericDetails;

-        private bool visible;

+        private bool visible = true;

 

         /// <summary>

         ///     Gets and sets whether the display is enabled.

@@ -190,7 +192,7 @@
         {

             try

             {

-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.Count <= 0)

+                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)

                 {

                     return;

                 }

@@ -208,9 +210,10 @@
 

                 SimManager.TryStartSimulation();

             }

-            catch

-            {

-                /* A null reference exception is thrown when checking if EditorLogic.fetch != null??? */

+            catch (Exception ex)

+            {

+                Logger.Log("BuildAdvanced->Update");

+                Logger.Exception(ex);

             }

         }

 

@@ -218,7 +221,7 @@
         {

             try

             {

-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.Count <= 0)

+                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)

                 {

                     return;

                 }

@@ -226,18 +229,10 @@
                 SimManager.RequestSimulation();

 

                 // Change the window title based on whether in compact mode or not.

-                string title;

-                if (!this.compactMode)

-                {

-                    title = "KERBAL ENGINEER REDUX " + EngineerGlobals.PrettyVersion;

-                }

-                else

-                {

-                    title = "K.E.R. " + EngineerGlobals.PrettyVersion;

-                }

+                var title = !this.compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.PrettyVersion : "K.E.R. " + EngineerGlobals.PrettyVersion;

 

                 // Reset the window size when the staging or something else has changed.

-                int stageCount = SimManager.Stages.Count(stage => this.showAllStages || stage.deltaV > 0);

+                var stageCount = SimManager.Stages != null ? SimManager.Stages.Count(stage => this.showAllStages || stage.deltaV > 0) : 0;

                 if (this.hasChanged || stageCount != this.numberOfStages)

                 {

                     this.hasChanged = false;

@@ -252,9 +247,10 @@
                 // Check editor lock to manage click-through.

                 this.CheckEditorLock();

             }

-            catch

-            {

-                /* A null reference exception is thrown when checking if EditorLogic.fetch != null??? */

+            catch (Exception ex)

+            {

+                Logger.Log("BuildAdvanced->OnDraw");

+                Logger.Exception(ex);

             }

         }

 

@@ -541,9 +537,10 @@
                 handler.Set("selectedBodyName", CelestialBodies.Instance.SelectedBodyName);

                 handler.Save("BuildAdvanced.xml");

             }

-            catch

-            {

-                print("[KerbalEngineer]: Failed to save BuildAdvanced settings.");

+            catch (Exception ex)

+            {

+                Logger.Log("BuildAdvanced->OnDestroy");

+                Logger.Exception(ex);

             }

         }

 

@@ -563,9 +560,10 @@
                 handler.Get("useAtmosphericDetails", ref this.useAtmosphericDetails);

                 CelestialBodies.Instance.SelectedBodyName = handler.Get("selectedBodyName", CelestialBodies.Instance.SelectedBodyName);

             }

-            catch

-            {

-                print("[KerbalEngineer/BuildAdvanced]: Failed to load BuildAdvanced settings.");

+            catch (Exception ex)

+            {

+                Logger.Log("BuildAdvanced->Load");

+                Logger.Exception(ex);

             }

         }

 


--- a/KerbalEngineer/Editor/BuildButton.cs
+++ /dev/null
@@ -1,202 +1,1 @@
-//     Kerbal Engineer Redux

-// 

-//     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

-//     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

-//     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/>.

-// 

-

-#region Using Directives

-

-using System.IO;

-

-using UnityEngine;

-

-#endregion

-

-namespace KerbalEngineer.Editor

-{

-    [KSPAddon(KSPAddon.Startup.EditorAny, false)]

-    public class BuildButton : MonoBehaviour

-    {

-        #region Fields

-

-        private readonly Texture2D down = new Texture2D(50, 45, TextureFormat.RGBA32, false);

-        private readonly Texture2D hover = new Texture2D(50, 45, TextureFormat.RGBA32, false);

-        private readonly Texture2D locked = new Texture2D(50, 45, TextureFormat.RGBA32, false);

-        private readonly Texture2D normal = new Texture2D(50, 45, TextureFormat.RGBA32, false);

-

-        private bool clicked;

-        private Rect position = new Rect(Screen.width * 0.5f - 300.0f, 0, 50.0f, 45.0f);

-

-        #region Styles

-

-        private GUIStyle tooltipInfoStyle;

-        private GUIStyle tooltipTitleStyle;

-

-        #endregion

-

-        #endregion

-

-        #region Initialisation

-

-        private void Start()

-        {

-            // Load the button textures directly from the PNG files. (Would of used GameDatabase but it compresses them so it looks shit!)

-            this.normal.LoadImage(File.ReadAllBytes(EngineerGlobals.AssemblyPath + "PluginData/BuildButton/Normal.png"));

-            this.hover.LoadImage(File.ReadAllBytes(EngineerGlobals.AssemblyPath + "PluginData/BuildButton/Hover.png"));

-            this.down.LoadImage(File.ReadAllBytes(EngineerGlobals.AssemblyPath + "PluginData/BuildButton/Down.png"));

-            this.locked.LoadImage(File.ReadAllBytes(EngineerGlobals.AssemblyPath + "PluginData/BuildButton/Locked.png"));

-

-            this.InitialiseStyles();

-            RenderingManager.AddToPostDrawQueue(0, this.OnDraw);

-        }

-

-        /// <summary>

-        ///     Initialises all of the GUI styles that are required.

-        /// </summary>

-        private void InitialiseStyles()

-        {

-            this.tooltipTitleStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 13,

-                fontStyle = FontStyle.Bold

-            };

-

-            this.tooltipInfoStyle = new GUIStyle(HighLogic.Skin.label)

-            {

-                fontSize = 11,

-                fontStyle = FontStyle.Bold

-            };

-        }

-

-        #endregion

-

-        #region Update and Drawing

-

-        private void Update()

-        {

-            if (Input.GetKeyDown(KeyCode.Backslash))

-            {

-                LeftClick();

-            }

-        }

-

-        private void OnDraw()

-        {

-            if (EditorLogic.fetch.ship.Count > 0)

-            {

-                if (this.clicked) // Button has been clicked whilst being hovered.

-                {

-                    GUI.DrawTexture(this.position, this.down);

-

-                    if (this.position.Contains(Event.current.mousePosition)) // Mouse is hovering over the button.

-                    {

-                        this.DrawToolTip();

-

-                        if (Mouse.Left.GetButtonUp()) // The mouse up event has been triggered whilst over the button.

-                        {

-                            this.clicked = false;

-                            LeftClick();

-                        }

-                        else if (Mouse.Right.GetButtonUp())

-                        {

-                            this.clicked = false;

-                            RightClick();

-                        }

-                    }

-                }

-                else // The button is not registering as being clicked.

-                {

-                    if (this.position.Contains(Event.current.mousePosition)) // Mouse is hovering over the button.

-                    {

-                        // If the left mouse button has just been pressed, see the button as being clicked.

-                        if (!this.clicked && (Mouse.Left.GetButtonDown() || Mouse.Right.GetButtonDown()))

-                        {

-                            this.clicked = true;

-                        }

-

-                        if (this.clicked) // The button has just been clicked.

-                        {

-                            GUI.DrawTexture(this.position, this.down);

-                        }

-                        else if (!Mouse.Left.GetButton() && !Mouse.Right.GetButton()) // Mouse button is not down and is just hovering.

-                        {

-                            GUI.DrawTexture(this.position, this.hover);

-                            this.DrawToolTip();

-                        }

-                        else // Mouse button is down but no click was registered over the button.

-                        {

-                            GUI.DrawTexture(this.position, this.normal);

-                        }

-                    }

-                    else // The mouse is not being hovered.

-                    {

-                        GUI.DrawTexture(this.position, this.normal);

-                    }

-                }

-

-                // Check for an unclick event whilst the mouse is not hovering.

-                if (this.clicked && (Mouse.Left.GetButtonUp() || Mouse.Right.GetButtonUp()))

-                {

-                    this.clicked = false;

-                }

-            }

-            else // The editor is set as being locked.

-            {

-                GUI.DrawTexture(this.position, this.locked);

-            }

-        }

-

-        /// <summary>

-        ///     Draws the tooltop next to the mouse cursor.

-        /// </summary>

-        private void DrawToolTip()

-        {

-            GUI.Label(new Rect(Event.current.mousePosition.x + 16.0f, Event.current.mousePosition.y, 500.0f, 25.0f), "Kerbal Engineer Redux", this.tooltipTitleStyle);

-            GUI.Label(new Rect(Event.current.mousePosition.x + 16.0f, Event.current.mousePosition.y + 16.0f, 500.0f, 25.0f), "[Left Click / Backslash] Advanced - [Right Click] Overlay", this.tooltipInfoStyle);

-        }

-

-        #endregion

-

-        #region Static Methods

-

-        /// <summary>

-        ///     Runs when the button is clicked with the left mouse button.

-        /// </summary>

-        public static void LeftClick()

-        {

-            if (BuildAdvanced.Instance != null)

-            {

-                BuildAdvanced.Instance.Visible = !BuildAdvanced.Instance.Visible;

-            }

-        }

-

-        /// <summary>

-        ///     Runs when the button is clicked with the right mouse button.

-        /// </summary>

-        private static void RightClick()

-        {

-            if (BuildOverlay.Instance != null)

-            {

-                BuildOverlay.Instance.Visible = !BuildOverlay.Instance.Visible;

-            }

-        }

-

-        #endregion

-    }

-}
+

--- a/KerbalEngineer/Editor/BuildOverlay.cs
+++ b/KerbalEngineer/Editor/BuildOverlay.cs
@@ -1,4 +1,5 @@
-//     Kerbal Engineer Redux

+// 

+//     Kerbal Engineer Redux

 // 

 //     Copyright (C) 2014 CYBUTEK

 // 

@@ -18,6 +19,7 @@
 

 #region Using Directives

 

+using System;

 using System.Diagnostics;

 

 using KerbalEngineer.Extensions;

@@ -47,7 +49,7 @@
         private readonly Stopwatch tooltipInfoTimer = new Stopwatch();

         private readonly int windowId = EngineerGlobals.GetNextWindowId();

         private Part selectedPart;

-        private Rect windowPosition = new Rect(265.0f, 0, 0, 0);

+        private Rect windowPosition = new Rect(300.0f, 0, 0, 0);

 

         #endregion

 

@@ -154,7 +156,7 @@
         {

             try

             {

-                if (EditorLogic.fetch == null || EditorLogic.SortedShipList.Count <= 0)

+                if (EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)

                 {

                     return;

                 }

@@ -173,9 +175,10 @@
 

                 SimManager.TryStartSimulation();

             }

-            catch

-            {

-                /* A null reference exception is thrown when checking if EditorLogic.fetch != null??? */

+            catch (Exception ex)

+            {

+                Logger.Log("BuildOverlay->Update");

+                Logger.Exception(ex);

             }

         }

 

@@ -183,7 +186,7 @@
         {

             try

             {

-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.SortedShipList.Count <= 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)

+                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorLogic.EditorScreen.Parts)

                 {

                     return;

                 }

@@ -239,9 +242,10 @@
                     }

                 }

             }

-            catch

-            {

-                /* A null reference exception is thrown when checking if EditorLogic.fetch != null??? */

+            catch (Exception ex)

+            {

+                Logger.Log("BuildOverlay->OnDraw");

+                Logger.Exception(ex);

             }

         }

 

@@ -425,9 +429,10 @@
                 handler.Set("visible", this.visible);

                 handler.Save("BuildOverlay.xml");

             }

-            catch

-            {

-                print("[KerbalEngineer]: Failed to save BuildOverlay settings.");

+            catch (Exception ex)

+            {

+                Logger.Log("BuildOverlay->OnDestroy");

+                Logger.Exception(ex);

             }

         }

 

@@ -441,9 +446,10 @@
                 var handler = SettingHandler.Load("BuildOverlay.xml");

                 handler.Get("visible", ref this.visible);

             }

-            catch

-            {

-                print("[KerbalEngineer]: Failed to load BuildOverlay settings.");

+            catch (Exception ex)

+            {

+                Logger.Log("BuildOverlay->Load");

+                Logger.Exception(ex);

             }

         }

 


--- /dev/null
+++ b/KerbalEngineer/Editor/BuildToolbar.cs
@@ -1,1 +1,103 @@
-
+// 

+//     Kerbal Engineer Redux

+// 

+//     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

+//     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

+//     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/>.

+// 

+

+#region Using Directives

+

+using System;

+

+using UnityEngine;

+

+#endregion

+

+namespace KerbalEngineer.Editor

+{

+    [KSPAddon(KSPAddon.Startup.EditorAny, false)]

+    public class BuildToolbar : MonoBehaviour

+    {

+        private static Texture2D texture = new Texture2D(38, 38, TextureFormat.RGBA32, false);

+        private ApplicationLauncherButton button;

+

+        private void Awake()

+        {

+            texture = GameDatabase.Instance.GetTexture("KerbalEngineer/ToolbarIcon", false);

+            GameEvents.onGUIApplicationLauncherReady.Add(this.OnGuiAppLauncherReady);

+

+            Logger.Log("BuildToolbar->Awake");

+        }

+

+        private void OnGuiAppLauncherReady()

+        {

+            this.button = ApplicationLauncher.Instance.AddModApplication(

+                () => BuildAdvanced.Instance.Visible = true,

+                () => BuildAdvanced.Instance.Visible = false,

+                null,

+                null,

+                null,

+                null,

+                ApplicationLauncher.AppScenes.ALWAYS,

+                texture

+                );

+

+            Logger.Log("BuildToolbar->OnGuiAppLauncherReady");

+        }

+

+        private void Update()

+        {

+            try

+            {

+                if (this.button == null)

+                {

+                    return;

+                }

+

+                if (EditorLogic.fetch != null && EditorLogic.fetch.ship.parts.Count > 0)

+                {

+                    if (BuildAdvanced.Instance.Visible && this.button.State != RUIToggleButton.ButtonState.TRUE)

+                    {

+                        this.button.SetTrue();

+                    }

+                    else if (!BuildAdvanced.Instance.Visible && this.button.State != RUIToggleButton.ButtonState.FALSE)

+                    {

+                        this.button.SetFalse();

+                    }

+                }

+                else if (this.button.State != RUIToggleButton.ButtonState.DISABLED)

+                {

+                    this.button.Disable();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Log("BuildToolbar->Update");

+                Logger.Exception(ex);

+            }

+        }

+

+        private void OnDestroy()

+        {

+            GameEvents.onGUIApplicationLauncherReady.Remove(this.OnGuiAppLauncherReady);

+            if (this.button != null)

+            {

+                ApplicationLauncher.Instance.RemoveModApplication(this.button);

+            }

+

+            Logger.Log("BuildToolbar->OnDestroy");

+        }

+    }

+}

--- a/KerbalEngineer/KerbalEngineer.csproj
+++ b/KerbalEngineer/KerbalEngineer.csproj
@@ -35,7 +35,11 @@
   </PropertyGroup>

   <ItemGroup>

     <Reference Include="Assembly-CSharp">

-      <HintPath>..\Game\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>

+      <HintPath>..\Game\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>

+      <Private>False</Private>

+    </Reference>

+    <Reference Include="Assembly-CSharp-firstpass">

+      <HintPath>..\Game\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>

       <Private>False</Private>

     </Reference>

     <Reference Include="System">

@@ -47,15 +51,16 @@
       <Private>False</Private>

     </Reference>

     <Reference Include="UnityEngine">

-      <HintPath>..\Game\KSP_Data\Managed\UnityEngine.dll</HintPath>

+      <HintPath>..\Game\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>

       <Private>False</Private>

     </Reference>

   </ItemGroup>

   <ItemGroup>

     <Compile Include="Editor\BuildAdvanced.cs" />

-    <Compile Include="Editor\BuildButton.cs" />

     <Compile Include="Editor\BuildOverlay.cs" />

     <Compile Include="CelestialBodies.cs" />

+    <Compile Include="Editor\BuildToolbar.cs" />

+    <Compile Include="Logger.cs" />

     <Compile Include="EngineerGlobals.cs" />

     <Compile Include="Extensions\DoubleExtensions.cs" />

     <Compile Include="Extensions\FloatExtensions.cs" />


--- /dev/null
+++ b/KerbalEngineer/Logger.cs
@@ -1,1 +1,142 @@
-
+// 

+//     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

+//     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

+//     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/>.

+// 

+

+#region Using Directives

+

+using System;

+using System.Collections.Generic;

+using System.IO;

+using System.Reflection;

+

+using UnityEngine;

+

+#endregion

+

+namespace KerbalEngineer

+{

+    [KSPAddon(KSPAddon.Startup.Instantly, false)]

+    public class Logger : MonoBehaviour

+    {

+        #region Constants

+

+        private const string FileName = "KerbalEngineer.log";

+

+        #endregion

+

+        #region Fields

+

+        private static readonly List<string> messages = new List<string>();

+

+        #endregion

+

+        #region Initialisation

+

+        private void Awake()

+        {

+            DontDestroyOnLoad(this);

+            File.Delete(FileName);

+            using (var file = File.AppendText(FileName))

+            {

+                messages.Add("Version: " + Assembly.GetExecutingAssembly().GetName().Version);

+                Blank();

+            }

+        }

+

+        #endregion

+

+        #region Printing

+

+        public static void Blank()

+        {

+            lock (messages)

+            {

+                messages.Add(string.Empty);

+            }

+        }

+

+        public static void Log(object obj)

+        {

+            lock (messages)

+            {

+                messages.Add("[Log " + DateTime.Now.TimeOfDay + "]: " + obj);

+            }

+        }

+

+        public static void Log(string message)

+        {

+            lock (messages)

+            {

+                messages.Add("[Log " + DateTime.Now.TimeOfDay + "]: " + message);

+            }

+        }

+

+        public static void Warning(string message)

+        {

+            lock (messages)

+            {

+                messages.Add("[Warning " + DateTime.Now.TimeOfDay + "]: " + message);

+            }

+        }

+

+        public static void Error(string message)

+        {

+            lock (messages)

+            {

+                messages.Add("[Error " + DateTime.Now.TimeOfDay + "]: " + message);

+            }

+        }

+

+        public static void Exception(Exception ex)

+        {

+            lock (messages)

+            {

+                messages.Add("[Exception " + DateTime.Now.TimeOfDay + "]: " + ex.Message);

+                messages.Add(ex.StackTrace);

+                messages.Add(string.Empty);

+            }

+        }

+

+        #endregion

+

+        #region Flushing

+

+        public static void Flush()

+        {

+            lock (messages)

+            {

+                if (messages.Count > 0)

+                {

+                    using (var file = File.AppendText(FileName))

+                    {

+                        foreach (var message in messages)

+                        {

+                            file.WriteLine(message);

+                        }

+                    }

+                    messages.Clear();

+                }

+            }

+        }

+

+        private void LateUpdate()

+        {

+            Flush();

+        }

+

+        #endregion

+    }

+}

--- a/KerbalEngineer/Simulation/PartSim.cs
+++ b/KerbalEngineer/Simulation/PartSim.cs
@@ -71,7 +71,7 @@
             this.inverseStage = this.part.inverseStage;
             //MonoBehaviour.print("inverseStage = " + inverseStage);
 
-            this.cost = this.part.partInfo.cost;
+            //this.cost = this.part.partInfo.cost;
 
             // Work out if the part should have no physical significance
             this.isNoPhysics = this.part.HasModule<ModuleLandingGear>() ||

 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
 Binary files a/Output/KerbalEngineer/PluginData/BuildButton/Down.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/BuildButton/Hover.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/BuildButton/Locked.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/BuildButton/Normal.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/ClosedDown.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/ClosedHover.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/ClosedNormal.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/OpenDown.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/OpenHover.png and /dev/null differ
 Binary files a/Output/KerbalEngineer/PluginData/FlightButton/OpenNormal.png and /dev/null differ
 Binary files /dev/null and b/Output/KerbalEngineer/ToolbarIcon.png differ