Skip to content

Commit

Permalink
Ascent Guidance: Avoid Empty Boxes
Browse files Browse the repository at this point in the history
Use GUILayout.BeginVertical() in each section, but only if the section is enabled!
  • Loading branch information
DRVeyl committed Feb 28, 2022
1 parent 0a7a85d commit 594fd9a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions MechJeb2/MechJebModuleAscentGuidance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private void PerformanceTestGUIElements()

private void VisibleSectionsGUIElements(out bool showTargeting, out bool showGuidanceSettings, out bool showSettings, out bool showStatus)
{
Profiler.BeginSample("MJ.GUIWindow.TopButtons_PVG2buttons4toggles");
Profiler.BeginSample("MJ.GUIWindow.TopButtons");
GUILayout.BeginVertical(GUI.skin.box);
showTargeting = autopilot.showTargeting;
showGuidanceSettings = autopilot.showGuidanceSettings;
showSettings = autopilot.showSettings;
Expand All @@ -148,14 +149,16 @@ private void VisibleSectionsGUIElements(out bool showTargeting, out bool showGui
if (ascentPathIdx == ascentType.PVG)
showStatus = GUILayout.Toggle(showStatus,CachedLocalizer.Instance.MechJeb_Ascent_button7,showStatus ? btActive : btNormal);
GUILayout.EndHorizontal();
GUILayout.EndVertical();
Profiler.EndSample();
}

private void ShowTargetingGUIElements()
{
if (!autopilot.showTargeting) return;

Profiler.BeginSample("MJ.GUIWindow.ShowTargeting_PVG_3TextBox_1ToggledTextBox_1Button");
Profiler.BeginSample("MJ.GUIWindow.ShowTargeting");
GUILayout.BeginVertical(GUI.skin.box);

if (ascentPathIdx == ascentType.PVG)
{
Expand Down Expand Up @@ -190,15 +193,17 @@ private void ShowTargetingGUIElements()

autopilot.desiredInclination = desiredInclination;

GUILayout.EndVertical();
Profiler.EndSample();
}

private void ShowGuidanceSettingsGUIElements()
{
Profiler.BeginSample("MJ.GUIWindow.ShowGuidanceSettings_PVG_5TextBox_2ToggledTextBox");
Profiler.BeginSample("MJ.GUIWindow.ShowGuidanceSettings");

if (autopilot.showGuidanceSettings)
{
GUILayout.BeginVertical(GUI.skin.box);
if (ascentPathIdx == ascentType.GRAVITYTURN)
{
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label8,gtascent.turnStartAltitude,"km");//Turn start altitude:
Expand Down Expand Up @@ -230,6 +235,7 @@ private void ShowGuidanceSettingsGUIElements()
}
GuiUtils.ToggledTextBox(ref pvgascent.FixedCoast,"Fixed Coast Length:",pvgascent.FixedCoastLength,"s",width: 40);
}
GUILayout.EndVertical();
}

autopilot.limitQaEnabled = (ascentPathIdx == ascentType.PVG); // this is mandatory for PVG
Expand All @@ -248,6 +254,7 @@ private void ShowAscentSettingsGUIElements(out bool forceRoll, out bool correcti
if (!autopilot.showSettings) return;

Profiler.BeginSample("MJ.GUIWindow.AscentItems");
GUILayout.BeginVertical(GUI.skin.box);

ToggleAscentNavballGuidanceInfoItem();
core.thrust.LimitToPreventOverheatsInfoItem();
Expand Down Expand Up @@ -323,6 +330,7 @@ private void ShowAscentSettingsGUIElements(out bool forceRoll, out bool correcti
}
GUILayout.EndHorizontal();

GUILayout.EndVertical();
Profiler.EndSample();
}

Expand All @@ -331,6 +339,7 @@ private void ShowStatusGUIElements()
if (!autopilot.showStatus) return;

Profiler.BeginSample("MJ.GUIWindow.ShowStatus");
GUILayout.BeginVertical(GUI.skin.box);

if (ascentPathIdx == ascentType.PVG)
{
Expand Down Expand Up @@ -390,16 +399,18 @@ private void ShowStatusGUIElements()
}
}
Profiler.EndSample();

}

GUILayout.EndVertical();
Profiler.EndSample();
}

private void ShowAutoWarpGUIElements()
{
if (!vessel.LandedOrSplashed) return;

Profiler.BeginSample("MJ.GUIWindow.ShowAutoWarp");
GUILayout.BeginVertical(GUI.skin.box);

if (core.node.autowarp)
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label33,autopilot.warpCountDown,"s",35);//Launch countdown:
Expand Down Expand Up @@ -488,6 +499,7 @@ private void ShowAutoWarpGUIElements()
if (GUILayout.Button(CachedLocalizer.Instance.MechJeb_Ascent_button17))//Abort
launchingToPlane = launchingToRendezvous = launchingToMatchLAN = launchingToLAN = autopilot.timedLaunch = false;
}
GUILayout.EndVertical();
Profiler.EndSample();
}

Expand Down Expand Up @@ -555,24 +567,12 @@ protected override void WindowGUI(int windowID)
{
UpdateStrings();
//PerformanceTestGUIElements();
GUILayout.BeginVertical(GUI.skin.box);
VisibleSectionsGUIElements(out bool showTargeting,out bool showGuidanceSettings,out bool showSettings,out bool showStatus);
GUILayout.EndVertical();
GUILayout.BeginVertical(GUI.skin.box);
ShowTargetingGUIElements();
GUILayout.EndVertical();
GUILayout.BeginVertical(GUI.skin.box);
ShowGuidanceSettingsGUIElements();
GUILayout.EndVertical();
GUILayout.BeginVertical(GUI.skin.box);
ShowAscentSettingsGUIElements(out bool forceRoll,out bool correctiveSteering,out bool limitAoA,out bool autostage);
GUILayout.EndVertical();
GUILayout.BeginVertical(GUI.skin.box);
ShowStatusGUIElements();
GUILayout.EndVertical();
GUILayout.BeginVertical(GUI.skin.box);
ShowAutoWarpGUIElements();
GUILayout.EndVertical();

if (autopilot.enabled) GUILayout.Label(autopilotStatus);//Autopilot status:
if (core.DeactivateControl)
Expand Down

0 comments on commit 594fd9a

Please sign in to comment.