Stock toolbar support.
Stock toolbar support.

--- a/KerbalEngineer/Editor/BuildToolbar.cs
+++ b/KerbalEngineer/Editor/BuildToolbar.cs
@@ -30,31 +30,34 @@
     [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");

+            try

+            {

+                this.button = ApplicationLauncher.Instance.AddModApplication(

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

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

+                    null,

+                    null,

+                    null,

+                    null,

+                    ApplicationLauncher.AppScenes.ALWAYS,

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

+                    );

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

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildToolbar->OnGuiAppLauncherReady");

+            }

         }

 

         private void Update()

@@ -84,8 +87,7 @@
             }

             catch (Exception ex)

             {

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

-                Logger.Exception(ex);

+                Logger.Exception(ex, "BuildToolbar->Update");

             }

         }

 

@@ -96,7 +98,6 @@
             {

                 ApplicationLauncher.Instance.RemoveModApplication(this.button);

             }

-

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

         }

     }


--- a/KerbalEngineer/Flight/ActionMenu.cs
+++ b/KerbalEngineer/Flight/ActionMenu.cs
@@ -19,6 +19,7 @@
 

 #region Using Directives

 

+using System;

 using System.Collections.Generic;

 

 using KerbalEngineer.Flight.Sections;

@@ -43,15 +44,22 @@
 

         #region Fields

 

-        private bool isOpen = true;

+        private bool isOpen;

         private int numberOfSections;

         private float scrollPercent;

         private int windowId;

-        private Rect windowPosition = new Rect((Screen.width * 0.25f) - 100.0f, 0, 200.0f, 0);

+        private Rect windowPosition = new Rect(Screen.width - 250.0f, 40.0f, 250.0f, 0);

+        private ApplicationLauncherButton button; 

 

         #endregion

 

         #region Constructors

+

+        private void Awake()

+        {

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

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

+        }

 

         /// <summary>

         ///     Initialises object's state on creation.

@@ -62,6 +70,29 @@
             this.InitialiseStyles();

             this.Load();

             RenderingManager.AddToPostDrawQueue(0, this.Draw);

+            Logger.Log("ActionMenu->Start");

+        }

+

+        private void OnGuiAppLauncherReady()

+        {

+            try

+            {

+                this.button = ApplicationLauncher.Instance.AddModApplication(

+                    () => this.isOpen = true,

+                    () => this.isOpen = false,

+                    null,

+                    null,

+                    null,

+                    null,

+                    ApplicationLauncher.AppScenes.ALWAYS,

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

+                    );

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

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->OnGuiAppLauncherReady");

+            }

         }

 

         #endregion

@@ -77,27 +108,69 @@
         /// </summary>

         private void InitialiseStyles()

         {

-            this.windowStyle = new GUIStyle();

-

-            this.boxStyle = new GUIStyle(HighLogic.Skin.window)

-            {

-                margin = new RectOffset(),

-                padding = new RectOffset(3, 3, 3, 3)

-            };

-

-            this.buttonStyle = new GUIStyle(HighLogic.Skin.button)

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                margin = new RectOffset(),

-                padding = new RectOffset(),

-                alignment = TextAnchor.MiddleCenter,

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                fixedHeight = 20.0f,

-            };

+            try

+            {

+                this.windowStyle = new GUIStyle();

+

+                this.boxStyle = new GUIStyle(HighLogic.Skin.window)

+                {

+                    margin = new RectOffset(),

+                    padding = new RectOffset(3, 3, 3, 3)

+                };

+

+                this.buttonStyle = new GUIStyle(HighLogic.Skin.button)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    margin = new RectOffset(),

+                    padding = new RectOffset(),

+                    alignment = TextAnchor.MiddleCenter,

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    fixedHeight = 20.0f,

+                };

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->InitialiseStyles");

+            }

+        }

+

+        #endregion

+

+        #region Updating

+

+        private void Update()

+        {

+            try

+            {

+                if (this.button == null)

+                {

+                    return;

+                }

+

+                if (FlightEngineerCore.Instance != null)

+                {

+                    if (this.isOpen && this.button.State != RUIToggleButton.ButtonState.TRUE)

+                    {

+                        this.button.SetTrue();

+                    }

+                    else if (!this.isOpen && this.button.State != RUIToggleButton.ButtonState.FALSE)

+                    {

+                        this.button.SetFalse();

+                    }

+                }

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

+                {

+                    this.button.Disable();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->Update");

+            }

         }

 

         #endregion

@@ -109,13 +182,26 @@
         /// </summary>

         private void Draw()

         {

-            if (this.numberOfSections != SectionLibrary.Instance.NumberOfSections)

-            {

-                this.numberOfSections = SectionLibrary.Instance.NumberOfSections;

-                this.windowPosition.height = 0;

-            }

-            this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, string.Empty, this.windowStyle);

-            this.ScrollMechanism();

+            try

+            {

+                if (!this.isOpen)

+                {

+                    return;

+                }

+

+                if (this.numberOfSections != SectionLibrary.Instance.NumberOfSections)

+                {

+                    this.numberOfSections = SectionLibrary.Instance.NumberOfSections;

+                    this.windowPosition.height = 0;

+                }

+

+                this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, string.Empty, this.windowStyle);

+                //this.ScrollMechanism();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->Draw");

+            }

         }

 

         /// <summary>

@@ -123,18 +209,22 @@
         /// </summary>

         private void Window(int windowId)

         {

-            GUILayout.BeginVertical(this.boxStyle);

-

-            this.DrawControlBarButton();

-            this.DrawSections(SectionLibrary.Instance.StockSections);

-            this.DrawSections(SectionLibrary.Instance.CustomSections);

-            this.DrawNewButton();

-

-            GUILayout.EndVertical();

-

-            if (GUILayout.Button("FLIGHT ENGINEER", this.buttonStyle))

-            {

-                this.isOpen = !this.isOpen;

+            try

+            {

+                GUILayout.BeginVertical(this.boxStyle);

+

+                this.DrawControlBarButton();

+                GUILayout.Space(5.0f);

+                this.DrawSections(SectionLibrary.Instance.StockSections);

+                this.DrawSections(SectionLibrary.Instance.CustomSections);

+                GUILayout.Space(5.0f);

+                this.DrawNewButton();

+

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->Window");

             }

         }

 

@@ -143,10 +233,17 @@
         /// </summary>

         private void DrawControlBarButton()

         {

-            if (GUILayout.Toggle(DisplayStack.Instance.ShowControlBar, "CONTROL BAR", this.buttonStyle) != DisplayStack.Instance.ShowControlBar)

-            {

-                DisplayStack.Instance.ShowControlBar = !DisplayStack.Instance.ShowControlBar;

-                DisplayStack.Instance.RequestResize();

+            try

+            {

+                if (GUILayout.Toggle(DisplayStack.Instance.ShowControlBar, "CONTROL BAR", this.buttonStyle) != DisplayStack.Instance.ShowControlBar)

+                {

+                    DisplayStack.Instance.ShowControlBar = !DisplayStack.Instance.ShowControlBar;

+                    DisplayStack.Instance.RequestResize();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->DrawControlBarButton");

             }

         }

 

@@ -155,34 +252,48 @@
         /// </summary>

         private void DrawSections(IEnumerable<SectionModule> sections)

         {

-            foreach (var section in sections)

+            try

+            {

+                foreach (var section in sections)

+                {

+                    GUILayout.BeginHorizontal();

+                    section.IsVisible = GUILayout.Toggle(section.IsVisible, section.Name.ToUpper(), this.buttonStyle);

+                    section.IsEditorVisible = GUILayout.Toggle(section.IsEditorVisible, "EDIT", this.buttonStyle, GUILayout.Width(50.0f));

+                    GUILayout.EndHorizontal();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->DrawSections");

+            }

+        }

+

+        /// <summary>

+        ///     Draws and performs the new section button action.

+        /// </summary>

+        private void DrawNewButton()

+        {

+            try

             {

                 GUILayout.BeginHorizontal();

-                section.IsVisible = GUILayout.Toggle(section.IsVisible, section.Name.ToUpper(), this.buttonStyle);

-                section.IsEditorVisible = GUILayout.Toggle(section.IsEditorVisible, "EDIT", this.buttonStyle, GUILayout.Width(50.0f));

+

+                if (GUILayout.Button("NEW CUSTOM SECTION", this.buttonStyle))

+                {

+                    SectionLibrary.Instance.CustomSections.Add(new SectionModule

+                    {

+                        Name = "Custom " + (SectionLibrary.Instance.CustomSections.Count + 1),

+                        Abbreviation = "CUST " + (SectionLibrary.Instance.CustomSections.Count + 1),

+                        IsVisible = true,

+                        IsCustom = true,

+                        IsEditorVisible = true

+                    });

+                }

                 GUILayout.EndHorizontal();

             }

-        }

-

-        /// <summary>

-        ///     Draws and performs the new section button action.

-        /// </summary>

-        private void DrawNewButton()

-        {

-            GUILayout.BeginHorizontal();

-

-            if (GUILayout.Button("NEW CUSTOM SECTION", this.buttonStyle))

-            {

-                SectionLibrary.Instance.CustomSections.Add(new SectionModule

-                {

-                    Name = "Custom " + (SectionLibrary.Instance.CustomSections.Count + 1),

-                    Abbreviation = "CUST " + (SectionLibrary.Instance.CustomSections.Count + 1),

-                    IsVisible = true,

-                    IsCustom = true,

-                    IsEditorVisible = true

-                });

-            }

-            GUILayout.EndHorizontal();

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->DrawNewButton");

+            }

         }

 

         /// <summary>

@@ -190,19 +301,26 @@
         /// </summary>

         private void ScrollMechanism()

         {

-            if (this.isOpen && this.windowPosition.y != 0)

-            {

-                this.scrollPercent += Time.deltaTime * ScrollSpeed;

-                this.windowPosition.y = Mathf.Lerp(this.windowPosition.y, 0, this.scrollPercent);

-            }

-            else if (!this.isOpen && this.windowPosition.y != 20.0f - this.windowPosition.height)

-            {

-                this.scrollPercent += Time.deltaTime * ScrollSpeed;

-                this.windowPosition.y = Mathf.Lerp(this.windowPosition.y, 20.0f - this.windowPosition.height, this.scrollPercent);

-            }

-            else

-            {

-                this.scrollPercent = 0;

+            try

+            {

+                if (this.isOpen && this.windowPosition.y != 0)

+                {

+                    this.scrollPercent += Time.deltaTime * ScrollSpeed;

+                    this.windowPosition.y = Mathf.Lerp(this.windowPosition.y, 0, this.scrollPercent);

+                }

+                else if (!this.isOpen && this.windowPosition.y != 20.0f - this.windowPosition.height)

+                {

+                    this.scrollPercent += Time.deltaTime * ScrollSpeed;

+                    this.windowPosition.y = Mathf.Lerp(this.windowPosition.y, 20.0f - this.windowPosition.height, this.scrollPercent);

+                }

+                else

+                {

+                    this.scrollPercent = 0;

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->ScrollMechanism");

             }

         }

 

@@ -215,9 +333,21 @@
         /// </summary>

         private void OnDestroy()

         {

-            this.Save();

-

-            RenderingManager.RemoveFromPostDrawQueue(0, this.Draw);

+            try

+            {

+                this.Save();

+                RenderingManager.RemoveFromPostDrawQueue(0, this.Draw);

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

+                if (this.button != null)

+                {

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

+                }

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

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->OnDestroy");

+            }

         }

 

         #endregion

@@ -229,11 +359,19 @@
         /// </summary>

         private void Save()

         {

-            var handler = new SettingHandler();

-            handler.Set("isOpen", this.isOpen);

-            handler.Set("windowPositionY", this.windowPosition.y);

-            handler.Set("windowPositionHeight", this.windowPosition.height);

-            handler.Save("ActionMenu.xml");

+            try

+            {

+                var handler = new SettingHandler();

+                handler.Set("isOpen", this.isOpen);

+                handler.Set("windowPositionY", this.windowPosition.y);

+                handler.Set("windowPositionHeight", this.windowPosition.height);

+                handler.Save("ActionMenu.xml");

+                Logger.Log("ActionMenu->Save");

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->Save");

+            }

         }

 

         /// <summary>

@@ -241,10 +379,18 @@
         /// </summary>

         private void Load()

         {

-            var handler = SettingHandler.Load("ActionMenu.xml");

-            handler.Get("isOpen", ref this.isOpen);

-            this.windowPosition.y = handler.Get("windowPositionY", this.windowPosition.y);

-            this.windowPosition.height = handler.Get("windowPositionHeight", this.windowPosition.height);

+            try

+            {

+                var handler = SettingHandler.Load("ActionMenu.xml");

+                handler.Get("isOpen", ref this.isOpen);

+                this.windowPosition.y = handler.Get("windowPositionY", this.windowPosition.y);

+                this.windowPosition.height = handler.Get("windowPositionHeight", this.windowPosition.height);

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

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "ActionMenu->Load");

+            }

         }

 

         #endregion


--- a/KerbalEngineer/Flight/DisplayStack.cs
+++ b/KerbalEngineer/Flight/DisplayStack.cs
@@ -17,7 +17,7 @@
 //     along with this program.  If not, see <http://www.gnu.org/licenses/>.

 // 

 

-#region

+#region Using Directives

 

 using System.Collections.Generic;

 


 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
--- a/Output/ReadMe.htm
+++ b/Output/ReadMe.htm
@@ -155,6 +155,13 @@
 			<h3>Change Log</h3>

 			<ul id='changelog'>

 				<li>

+					1.0.0.1

+					<ul>

+						<li>Changed: Orbital Period has higher precision.</li>

+						<li>Fixed: Various NullRefs in editor window and overlay.</li>

+					</ul>

+				</li>

+				<li>

 					1.0.0.0

 					<ul>

 						<li>Initial release for public testing.</li>