Increased Orbital Period precision + fixes various NullRefs.
[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
@@ -60,7 +60,6 @@
         private GUIStyle areaStyle;

         private GUIStyle buttonStyle;

         private GUIStyle infoStyle;

-        private GUIStyle settingStyle;

         private GUIStyle titleStyle;

         private GUIStyle windowStyle;

 

@@ -95,7 +94,11 @@
         public bool CompactMode

         {

             get { return this.compactMode; }

-            set { this.compactMode = value; }

+            set

+            {

+                this.compactMode = value; 

+                Logger.Log("BuildAdvanced->CompactMode = " + value);

+            }

         }

 

         /// <summary>

@@ -104,7 +107,11 @@
         public bool ShowAllStages

         {

             get { return this.showAllStages; }

-            set { this.showAllStages = value; }

+            set

+            {

+                this.showAllStages = value; 

+                Logger.Log("BuildAdvanced->ShowAllStages = " + value);

+            }

         }

 

         /// <summary>

@@ -113,7 +120,11 @@
         public bool ShowAtmosphericDetails

         {

             get { return this.showAtmosphericDetails; }

-            set { this.showAtmosphericDetails = value; }

+            set

+            {

+                this.showAtmosphericDetails = value; 

+                Logger.Log("BuildAdvanced->ShowAtmosphericDetails = " + value);

+            }

         }

 

         /// <summary>

@@ -122,7 +133,11 @@
         public bool ShowReferenceBodies

         {

             get { return this.showReferenceBodies; }

-            set { this.showReferenceBodies = value; }

+            set

+            {

+                this.showReferenceBodies = value; 

+                Logger.Log("BuildAdvanced->ShowReferenceBodies = " + value);

+            }

         }

 

         #endregion

@@ -147,60 +162,55 @@
         /// </summary>

         private void InitialiseStyles()

         {

-            this.areaBodiesStyle = new GUIStyle(HighLogic.Skin.box);

-

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

-            {

-                alignment = TextAnchor.UpperLeft

-            };

-

-            this.areaStyle = new GUIStyle(HighLogic.Skin.box)

-            {

-                padding = new RectOffset(0, 0, 9, 0)

-            };

-

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

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter

-            };

-

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

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter,

-                stretchWidth = true

-            };

-

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

-            {

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleCenter,

-                stretchWidth = true

-            };

-

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

-            {

-                normal =

-                {

-                    textColor = Color.white

-                },

-                fontSize = 11,

-                fontStyle = FontStyle.Bold,

-                alignment = TextAnchor.MiddleLeft,

-                stretchWidth = true

-            };

+            try

+            {

+                this.areaBodiesStyle = new GUIStyle(HighLogic.Skin.box);

+

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

+                {

+                    alignment = TextAnchor.UpperLeft

+                };

+

+                this.areaStyle = new GUIStyle(HighLogic.Skin.box)

+                {

+                    padding = new RectOffset(0, 0, 9, 0)

+                };

+

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

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter

+                };

+

+                this.titleStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    normal =

+                    {

+                        textColor = Color.white

+                    },

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter,

+                    stretchWidth = true

+                };

+

+                this.infoStyle = new GUIStyle(HighLogic.Skin.label)

+                {

+                    fontSize = 11,

+                    fontStyle = FontStyle.Bold,

+                    alignment = TextAnchor.MiddleCenter,

+                    stretchWidth = true

+                };

+            }

+            catch (Exception ex)

+            {

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

+            }

         }

 

         #endregion

@@ -233,8 +243,7 @@
             }

             catch (Exception ex)

             {

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

-                Logger.Exception(ex);

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

             }

         }

 

@@ -252,26 +261,28 @@
                 // Change the window title based on whether in compact mode or not.

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

 

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

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

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

-                {

-                    this.hasChanged = false;

-                    this.numberOfStages = stageCount;

-

-                    this.windowPosition.width = 0;

-                    this.windowPosition.height = 0;

-                }

-

-                this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, title, this.windowStyle).ClampToScreen();

-

-                // Check editor lock to manage click-through.

-                this.CheckEditorLock();

-            }

-            catch (Exception ex)

-            {

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

-                Logger.Exception(ex);

+                if (SimManager.Stages != null)

+                {

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

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

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

+                    {

+                        this.hasChanged = false;

+                        this.numberOfStages = stageCount;

+

+                        this.windowPosition.width = 0;

+                        this.windowPosition.height = 0;

+                    }

+

+                    this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, title, this.windowStyle).ClampToScreen();

+

+                    // Check editor lock to manage click-through.

+                    this.CheckEditorLock();

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->OnDraw");

             }

         }

 

@@ -280,15 +291,22 @@
         /// </summary>

         private void CheckEditorLock()

         {

-            if (this.windowPosition.MouseIsOver())

-            {

-                EditorLogic.fetch.State = EditorLogic.EditorState.GUI_SELECTED;

-                this.isEditorLocked = true;

-            }

-            else if (!this.windowPosition.MouseIsOver() && this.isEditorLocked)

-            {

-                EditorLogic.fetch.State = EditorLogic.EditorState.PAD_UNSELECTED;

-                this.isEditorLocked = false;

+            try

+            {

+                if (this.windowPosition.MouseIsOver())

+                {

+                    EditorLogic.fetch.State = EditorLogic.EditorState.GUI_SELECTED;

+                    this.isEditorLocked = true;

+                }

+                else if (!this.windowPosition.MouseIsOver() && this.isEditorLocked)

+                {

+                    EditorLogic.fetch.State = EditorLogic.EditorState.PAD_UNSELECTED;

+                    this.isEditorLocked = false;

+                }

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->CheckEditorLock");

             }

         }

 

@@ -297,94 +315,108 @@
         /// </summary>

         private void Window(int windowId)

         {

-            // Draw the compact mode toggle.

-            if (GUI.Toggle(new Rect(this.windowPosition.width - 70.0f, 5.0f, 65.0f, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode)

-            {

-                this.hasChanged = true;

-                this.compactMode = !this.compactMode;

-            }

-

-            // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.

-            if (!this.compactMode)

-            {

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 153.0f, 5.0f, 80.0f, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages)

+            try

+            {

+                // Draw the compact mode toggle.

+                if (GUI.Toggle(new Rect(this.windowPosition.width - 70.0f, 5.0f, 65.0f, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode)

                 {

                     this.hasChanged = true;

-                    this.showAllStages = !this.showAllStages;

-                }

-

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 251.0f, 5.0f, 95.0f, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails)

-                {

-                    this.hasChanged = true;

-                    this.showAtmosphericDetails = !this.showAtmosphericDetails;

-                }

-

-                if (GUI.Toggle(new Rect(this.windowPosition.width - 379.0f, 5.0f, 125.0f, 20.0f), this.showReferenceBodies, "REFERENCE BODIES", this.buttonStyle) != this.showReferenceBodies)

-                {

-                    this.hasChanged = true;

-                    this.showReferenceBodies = !this.showReferenceBodies;

-                }

-            }

-

-            // Draw the main informational display box.

-

-            if (!this.compactMode)

-            {

-                GUILayout.BeginHorizontal(this.areaStyle);

-                this.DrawStageNumbers();

-                //this.DrawPartCount();

-                this.DrawCost();

-                this.DrawMass();

-                this.DrawIsp();

-                this.DrawThrust();

-                this.DrawTwr();

-                this.DrawDeltaV();

-                this.DrawBurnTime();

+                    this.compactMode = !this.compactMode;

+                }

+

+                // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.

+                if (!this.compactMode)

+                {

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 153.0f, 5.0f, 80.0f, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages)

+                    {

+                        this.hasChanged = true;

+                        this.showAllStages = !this.showAllStages;

+                    }

+

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 251.0f, 5.0f, 95.0f, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails)

+                    {

+                        this.hasChanged = true;

+                        this.showAtmosphericDetails = !this.showAtmosphericDetails;

+                    }

+

+                    if (GUI.Toggle(new Rect(this.windowPosition.width - 379.0f, 5.0f, 125.0f, 20.0f), this.showReferenceBodies, "REFERENCE BODIES", this.buttonStyle) != this.showReferenceBodies)

+                    {

+                        this.hasChanged = true;

+                        this.showReferenceBodies = !this.showReferenceBodies;

+                    }

+                }

+

+                // Draw the main informational display box.

+

+                if (!this.compactMode)

+                {

+                    GUILayout.BeginHorizontal(this.areaStyle);

+                    this.DrawStageNumbers();

+                    //this.DrawPartCount();

+                    this.DrawCost();

+                    this.DrawMass();

+                    this.DrawIsp();

+                    this.DrawThrust();

+                    this.DrawTwr();

+                    this.DrawDeltaV();

+                    this.DrawBurnTime();

+                    GUILayout.EndHorizontal();

+

+                    if (this.showAtmosphericDetails)

+                    {

+                        GUILayout.BeginVertical(this.areaStyle);

+                        this.DrawAtmosphericDetails();

+                        GUILayout.EndVertical();

+                    }

+

+                    if (this.showReferenceBodies)

+                    {

+                        GUILayout.BeginVertical(this.areaBodiesStyle);

+                        this.DrawReferenceBodies();

+                        GUILayout.EndVertical();

+                    }

+                }

+                else // Draw only a few details when in compact mode.

+                {

+                    GUILayout.BeginHorizontal(this.areaStyle);

+                    this.DrawStageNumbers();

+                    this.DrawTwr();

+                    this.DrawDeltaV();

+                    GUILayout.EndHorizontal();

+                }

+

+                GUI.DragWindow();

+            }

+            catch (Exception ex)

+            {

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

+            }

+        }

+

+        /// <summary>

+        ///     Draws the atmospheric settings.

+        /// </summary>

+        private void DrawAtmosphericDetails()

+        {

+            try

+            {

+                GUILayout.BeginHorizontal();

+                GUILayout.Label("Pressure " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.titleStyle, GUILayout.Width(125.0f));

+                GUI.skin = HighLogic.Skin;

+                this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);

+                GUI.skin = null;

                 GUILayout.EndHorizontal();

-

-                if (this.showAtmosphericDetails)

-                {

-                    GUILayout.BeginVertical(this.areaStyle);

-                    this.DrawAtmosphericDetails();

-                    GUILayout.EndVertical();

-                }

-

-                if (this.showReferenceBodies)

-                {

-                    GUILayout.BeginVertical(this.areaBodiesStyle);

-                    this.DrawReferenceBodies();

-                    GUILayout.EndVertical();

-                }

-            }

-            else // Draw only a few details when in compact mode.

-            {

-                GUILayout.BeginHorizontal(this.areaStyle);

-                this.DrawStageNumbers();

-                this.DrawTwr();

-                this.DrawDeltaV();

+                GUILayout.BeginHorizontal();

+                GUILayout.Label("Velocity " + this.atmosphericVelocity.ToString("F1") + "m/s", this.titleStyle, GUILayout.Width(125.0f));

+                GUI.skin = HighLogic.Skin;

+                this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f);

+                GUI.skin = null;

                 GUILayout.EndHorizontal();

             }

-

-            GUI.DragWindow();

-        }

-

-        /// <summary>

-        ///     Draws the atmospheric settings.

-        /// </summary>

-        private void DrawAtmosphericDetails()

-        {

-            GUILayout.BeginHorizontal();

-            GUILayout.Label("Pressure " + (this.atmosphericPercentage * 100.0f).ToString("F1") + "%", this.titleStyle, GUILayout.Width(125.0f));

-            GUI.skin = HighLogic.Skin;

-            this.atmosphericPercentage = GUILayout.HorizontalSlider(this.atmosphericPercentage, 0, 1.0f);

-            GUI.skin = null;

-            GUILayout.EndHorizontal();

-            GUILayout.BeginHorizontal();

-            GUILayout.Label("Velocity " + this.atmosphericVelocity.ToString("F1") + "m/s", this.titleStyle, GUILayout.Width(125.0f));

-            GUI.skin = HighLogic.Skin;

-            this.atmosphericVelocity = GUILayout.HorizontalSlider(this.atmosphericVelocity, 0, 2500f);

-            GUI.skin = null;

-            GUILayout.EndHorizontal();

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawAtmosphericDetails");

+            }

         }

 

         /// <summary>

@@ -392,25 +424,32 @@
         /// </summary>

         private void DrawReferenceBodies()

         {

-            var index = 0;

-

-            foreach (var bodyName in CelestialBodies.Instance.BodyList.Keys)

-            {

-                if (index % 8 == 0)

-                {

-                    if (index > 0)

-                    {

-                        GUILayout.EndHorizontal();

-                    }

-                    GUILayout.BeginHorizontal();

-                }

-                if (GUILayout.Toggle(CelestialBodies.Instance.SelectedBodyName == bodyName, bodyName, this.buttonStyle))

-                {

-                    CelestialBodies.Instance.SelectedBodyName = bodyName;

-                }

-                index++;

-            }

-            GUILayout.EndHorizontal();

+            try

+            {

+                var index = 0;

+

+                foreach (var bodyName in CelestialBodies.Instance.BodyList.Keys)

+                {

+                    if (index % 8 == 0)

+                    {

+                        if (index > 0)

+                        {

+                            GUILayout.EndHorizontal();

+                        }

+                        GUILayout.BeginHorizontal();

+                    }

+                    if (GUILayout.Toggle(CelestialBodies.Instance.SelectedBodyName == bodyName, bodyName, this.buttonStyle))

+                    {

+                        CelestialBodies.Instance.SelectedBodyName = bodyName;

+                    }

+                    index++;

+                }

+                GUILayout.EndHorizontal();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawReferenceBodies");

+            }

         }

 

         /// <summary>

@@ -418,16 +457,23 @@
         /// </summary>

         private void DrawStageNumbers()

         {

-            GUILayout.BeginVertical(GUILayout.Width(30.0f));

-            GUILayout.Label(string.Empty, this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label("S" + stage.number, this.titleStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(30.0f));

+                GUILayout.Label(string.Empty, this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label("S" + stage.number, this.titleStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawStageNumbers");

+            }

         }

 

         /// <summary>

@@ -435,16 +481,24 @@
         /// </summary>

         private void DrawPartCount()

         {

-            GUILayout.BeginVertical(GUILayout.Width(50.0f));

-            GUILayout.Label("PARTS", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    //GUILayout.Label(stage.PartCount.ToString("N0"), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+

+                GUILayout.BeginVertical(GUILayout.Width(50.0f));

+                GUILayout.Label("PARTS", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        //GUILayout.Label(stage.PartCount.ToString("N0"), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawPartCount");

+            }

         }

 

         /// <summary>

@@ -452,16 +506,23 @@
         /// </summary>

         private void DrawCost()

         {

-            GUILayout.BeginVertical(GUILayout.Width(110.0f));

-            GUILayout.Label("COST", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(110.0f));

+                GUILayout.Label("COST", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.cost.ToString("N0") + " / " + stage.totalCost.ToString("N0"), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawCost");

+            }

         }

 

         /// <summary>

@@ -469,16 +530,24 @@
         /// </summary>

         private void DrawMass()

         {

-            GUILayout.BeginVertical(GUILayout.Width(110.0f));

-            GUILayout.Label("MASS", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.mass.ToMass(false) + " / " + stage.totalMass.ToMass(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+

+                GUILayout.BeginVertical(GUILayout.Width(110.0f));

+                GUILayout.Label("MASS", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.mass.ToMass(false) + " / " + stage.totalMass.ToMass(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawMass");

+            }

         }

 

         /// <summary>

@@ -486,16 +555,23 @@
         /// </summary>

         private void DrawIsp()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("ISP", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("ISP", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawIsp");

+            }

         }

 

         /// <summary>

@@ -503,16 +579,23 @@
         /// </summary>

         private void DrawThrust()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("THRUST", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("THRUST", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawThrust");

+            }

         }

 

         /// <summary>

@@ -520,16 +603,23 @@
         /// </summary>

         private void DrawTwr()

         {

-            GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            GUILayout.Label("TWR (MAX)", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(100.0f));

+                GUILayout.Label("TWR (MAX)", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawTwr");

+            }

         }

 

         /// <summary>

@@ -537,16 +627,23 @@
         /// </summary>

         private void DrawDeltaV()

         {

-            GUILayout.BeginVertical(GUILayout.Width(100.0f));

-            GUILayout.Label("DELTA-V", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(100.0f));

+                GUILayout.Label("DELTA-V", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawDeltaV");

+            }

         }

 

         /// <summary>

@@ -554,16 +651,23 @@
         /// </summary>

         private void DrawBurnTime()

         {

-            GUILayout.BeginVertical(GUILayout.Width(75.0f));

-            GUILayout.Label("BURN", this.titleStyle);

-            foreach (var stage in SimManager.Stages)

-            {

-                if (this.showAllStages || stage.deltaV > 0)

-                {

-                    GUILayout.Label(stage.time.ToTime(), this.infoStyle);

-                }

-            }

-            GUILayout.EndVertical();

+            try

+            {

+                GUILayout.BeginVertical(GUILayout.Width(75.0f));

+                GUILayout.Label("BURN", this.titleStyle);

+                foreach (var stage in SimManager.Stages)

+                {

+                    if (this.showAllStages || stage.deltaV > 0)

+                    {

+                        GUILayout.Label(stage.time.ToTime(), this.infoStyle);

+                    }

+                }

+                GUILayout.EndVertical();

+            }

+            catch (Exception ex)

+            {

+                Logger.Exception(ex, "BuildAdvanced->DrawBurnTime");

+            }

         }

 

         #endregion

@@ -590,8 +694,7 @@
             }

             catch (Exception ex)

             {

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

-                Logger.Exception(ex);

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

             }

         }

 

@@ -613,8 +716,7 @@
             }

             catch (Exception ex)

             {

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

-                Logger.Exception(ex);

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

             }

         }