Fixed flickering in the editor.
Fixed flickering in the editor.

--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -57,6 +57,7 @@
         private int numberOfStages;

         private int windowId;

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

+        private Stage[] stages;

 

         #region Styles

 

@@ -284,39 +285,47 @@
                     return;

                 }

 

+                if (SimManager.ResultsReady())

+                {

+                    this.stages = SimManager.Stages;

+                }

+

                 SimManager.RequestSimulation();

+

+                if (this.stages == null)

+                {

+                    return;

+                }

 

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

 

-                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();

-

-                    if (this.compactCheck > 0 && this.compactCollapseRight)

-                    {

-                        this.windowPosition.x = this.compactRight - this.windowPosition.width;

-                        this.compactCheck--;

-                    }

-                    else if (this.compactCheck > 0)

-                    {

-                        this.compactCheck = 0;

-                    }

-

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

-                    this.CheckEditorLock();

-                }

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

+                var stageCount = this.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();

+

+                if (this.compactCheck > 0 && this.compactCollapseRight)

+                {

+                    this.windowPosition.x = this.compactRight - this.windowPosition.width;

+                    this.compactCheck--;

+                }

+                else if (this.compactCheck > 0)

+                {

+                    this.compactCheck = 0;

+                }

+

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

+                this.CheckEditorLock();

+                

             }

             catch (Exception ex)

             {

@@ -548,7 +557,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -572,7 +581,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -596,7 +605,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -620,7 +629,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -644,7 +653,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -668,7 +677,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -692,7 +701,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -716,7 +725,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {

@@ -740,7 +749,7 @@
             {

                 GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));

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

-                foreach (var stage in SimManager.Stages)

+                foreach (var stage in this.stages)

                 {

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

                     {


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

 // 

 

-#region

+#region Using Directives

 

 using System;

 using System.Diagnostics;

@@ -47,6 +47,7 @@
         #region Fields

 

         private readonly Stopwatch tooltipInfoTimer = new Stopwatch();

+        private Stage lastStage;

 

         private Part selectedPart;

         private int windowId;

@@ -210,12 +211,22 @@
         {

             try

             {

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

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

                 {

                     return;

                 }

 

+                if (SimManager.ResultsReady())

+                {

+                    this.lastStage = SimManager.LastStage;

+                }

+

                 SimManager.RequestSimulation();

+

+                if (this.lastStage == null)

+                {

+                    return;

+                }

 

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

 

@@ -288,8 +299,8 @@
                 // Details

                 GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));

                 //GUILayout.Label(SimulationManager.Instance.LastStage.partCount.ToString("N0"), this.infoStyle);

-                GUILayout.Label(SimManager.LastStage.totalDeltaV.ToString("N0") + " m/s", this.infoStyle);

-                GUILayout.Label(SimManager.LastStage.thrustToWeight.ToString("F2"), this.infoStyle);

+                GUILayout.Label(this.lastStage.totalDeltaV.ToString("N0") + " m/s", this.infoStyle);

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

                 GUILayout.EndVertical();

 

                 GUILayout.EndHorizontal();