Skip to content

Commit

Permalink
Apply New Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
DRVeyl committed Feb 20, 2022
1 parent fde916a commit cc23b90
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
21 changes: 20 additions & 1 deletion MechJeb2/CachedLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ public class CachedLocalizer : MonoBehaviour
public string MechJeb_Ascent_label21, MechJeb_Ascent_label22, MechJeb_Ascent_label23, MechJeb_Ascent_label24, MechJeb_Ascent_label25;
public string MechJeb_Ascent_label26, MechJeb_Ascent_label27, MechJeb_Ascent_label28, MechJeb_Ascent_label29, MechJeb_Ascent_label30;
public string MechJeb_Ascent_label31, MechJeb_Ascent_label32, MechJeb_Ascent_label33, MechJeb_Ascent_label34, MechJeb_Ascent_label35;
public string MechJeb_Ascent_label36, MechJeb_Ascent_label37;
public string MechJeb_Ascent_label36, MechJeb_Ascent_label37, MechJeb_Ascent_label38, MechJeb_Ascent_label39, MechJeb_Ascent_label40;
public string MechJeb_Ascent_label41, MechJeb_Ascent_label42, MechJeb_Ascent_label44;
public string MechJeb_Ascent_attachAlt, MechJeb_Ascent_warnAttachAltHigh, MechJeb_Ascent_warnAttachAltLow;
public string MechJeb_Ascent_LaunchToTargetLan, MechJeb_Ascent_LaunchToLan, MechJeb_Ascent_LaunchingToTargetLAN, MechJeb_Ascent_LaunchingToManualLAN;
public string MechJeb_Ascent_msg2, MechJeb_Ascent_msg3;
public string MechJeb_Ascent_hotStaging, MechJeb_Ascent_dropSolids, MechJeb_Ascent_leadTime;

public string MechJeb_Ascent_checkbox2, MechJeb_Ascent_checkbox3, MechJeb_Ascent_checkbox4, MechJeb_Ascent_checkbox5;
public string MechJeb_Ascent_checkbox6, MechJeb_Ascent_checkbox7, MechJeb_Ascent_checkbox8, MechJeb_Ascent_checkbox9, MechJeb_Ascent_checkbox10;
public string MechJeb_Ascent_checkbox11, MechJeb_Ascent_checkbox12, MechJeb_Ascent_checkbox13, MechJeb_Ascent_checkbox14, MechJeb_Ascent_checkbox15;

public string MechJeb_Ascent_status9, MechJeb_Ascent_status10;
public string MechJeb_Ascent_status11;

public string MechJeb_Ascent_checkbox16, MechJeb_Ascent_checkbox17, MechJeb_Ascent_checkbox18, MechJeb_Ascent_checkbox19, MechJeb_Ascent_checkbox20;
public string MechJeb_NavBallGuidance_btn1, MechJeb_NavBallGuidance_btn2;

Expand Down Expand Up @@ -108,6 +113,13 @@ private IEnumerator UpdateCachedStrings()
MechJeb_Ascent_label35 = Localizer.Format("#MechJeb_Ascent_label35");
MechJeb_Ascent_label36 = Localizer.Format("#MechJeb_Ascent_label36");
MechJeb_Ascent_label37 = Localizer.Format("#MechJeb_Ascent_label37");
MechJeb_Ascent_label38 = Localizer.Format("#MechJeb_Ascent_label38");
MechJeb_Ascent_label39 = Localizer.Format("#MechJeb_Ascent_label39");
MechJeb_Ascent_label40 = Localizer.Format("#MechJeb_Ascent_label40");
MechJeb_Ascent_label41 = Localizer.Format("#MechJeb_Ascent_label41");
MechJeb_Ascent_label42 = Localizer.Format("#MechJeb_Ascent_label42");

MechJeb_Ascent_label44 = Localizer.Format("#MechJeb_Ascent_label44");

MechJeb_Ascent_checkbox2 = Localizer.Format("#MechJeb_Ascent_checkbox2");
MechJeb_Ascent_checkbox3 = Localizer.Format("#MechJeb_Ascent_checkbox3");
Expand All @@ -129,6 +141,10 @@ private IEnumerator UpdateCachedStrings()
MechJeb_Ascent_checkbox19 = Localizer.Format("#MechJeb_Ascent_checkbox19");
MechJeb_Ascent_checkbox20 = Localizer.Format("#MechJeb_Ascent_checkbox20");

MechJeb_Ascent_status9 = Localizer.Format("#MechJeb_Ascent_status9");
MechJeb_Ascent_status10 = Localizer.Format("#MechJeb_Ascent_status10");
MechJeb_Ascent_status11 = Localizer.Format("#MechJeb_Ascent_status11");


MechJeb_Ascent_attachAlt = Localizer.Format("#MechJeb_Ascent_attachAlt");
MechJeb_Ascent_warnAttachAltHigh = Localizer.Format("#MechJeb_Ascent_warnAttachAltHigh");
Expand All @@ -140,6 +156,9 @@ private IEnumerator UpdateCachedStrings()

MechJeb_Ascent_msg2 = Localizer.Format("#MechJeb_Ascent_msg2");
MechJeb_Ascent_msg3 = Localizer.Format("#MechJeb_Ascent_msg3");
MechJeb_Ascent_hotStaging = Localizer.Format("#MechJeb_Ascent_hotStaging");
MechJeb_Ascent_dropSolids = Localizer.Format("#MechJeb_Ascent_dropSolids");
MechJeb_Ascent_leadTime = Localizer.Format("#MechJeb_Ascent_leadTime");

MechJeb_NavBallGuidance_btn1 = Localizer.Format("#MechJeb_NavBallGuidance_btn1");
MechJeb_NavBallGuidance_btn2 = Localizer.Format("#MechJeb_NavBallGuidance_btn2");
Expand Down
45 changes: 24 additions & 21 deletions MechJeb2/MechJebModuleStagingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,50 +111,53 @@ public void AutostageSettingsInfoItem()
GUILayout.BeginVertical();

GUILayout.BeginHorizontal();
GUILayout.Label("Delays: pre:", GUILayout.ExpandWidth(false));
autostagePreDelay.text = GUILayout.TextField(autostagePreDelay.text, GUILayout.Width(35));
GUILayout.Label("s post:", GUILayout.ExpandWidth(false));
autostagePostDelay.text = GUILayout.TextField(autostagePostDelay.text, GUILayout.Width(35));
GUILayout.Label("s", GUILayout.ExpandWidth(true));
GuiUtils.SimpleTextBox("Delays: pre:",autostagePreDelay,"s",35,horizontalFraming: false);
GuiUtils.SimpleTextBox(" post:",autostagePostDelay,"s",35,horizontalFraming: false);
GUILayout.EndHorizontal();

ClampAutostageThrust();

GUILayout.Label(Localizer.Format("#MechJeb_Ascent_label38"));//"Stage fairings when:"
GuiUtils.SimpleTextBox(" "+Localizer.Format("#MechJeb_Ascent_label39") +" <", fairingMaxDynamicPressure, "kPa", 50);//"dynamic pressure"
GuiUtils.SimpleTextBox(" "+Localizer.Format("#MechJeb_Ascent_label40") +" >", fairingMinAltitude, "km", 50);//altitude
GuiUtils.SimpleTextBox(" "+Localizer.Format("#MechJeb_Ascent_label41") +" <", fairingMaxAerothermalFlux, "W/m²", 50);//aerothermal flux
GUILayout.Label(CachedLocalizer.Instance.MechJeb_Ascent_label38);//"Stage fairings when:"
GuiUtils.SimpleTextBox($" {CachedLocalizer.Instance.MechJeb_Ascent_label39} <", fairingMaxDynamicPressure, "kPa", 50);//"dynamic pressure"
GuiUtils.SimpleTextBox($" {CachedLocalizer.Instance.MechJeb_Ascent_label40} >", fairingMinAltitude, "km", 50);//altitude
GuiUtils.SimpleTextBox($" {CachedLocalizer.Instance.MechJeb_Ascent_label41} <", fairingMaxAerothermalFlux, "W/m²", 50);//aerothermal flux

GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_Ascent_label42"), autostageLimit, "");//"Stop at stage #"
GuiUtils.SimpleTextBox(CachedLocalizer.Instance.MechJeb_Ascent_label42, autostageLimit);//"Stop at stage #"
//GuiUtils.ToggledTextBox(ref hotStaging,CachedLocalizer.Instance.MechJeb_Ascent_hotStaging,hotStagingLeadTime,$"s {CachedLocalizer.Instance.MechJeb_Ascent_leadTime}",width: 35);

hotStaging = GUILayout.Toggle(hotStaging, Localizer.Format("#MechJeb_Ascent_hotStaging"));//"Support hotstaging"
hotStaging = GUILayout.Toggle(hotStaging,CachedLocalizer.Instance.MechJeb_Ascent_hotStaging);//"Support hotstaging"
if (hotStaging)
GuiUtils.SimpleTextBox(" "+Localizer.Format("#MechJeb_Ascent_leadTime"), hotStagingLeadTime, "s");//"lead time"
GuiUtils.SimpleTextBox($" {CachedLocalizer.Instance.MechJeb_Ascent_leadTime}", hotStagingLeadTime, "s");//"lead time"

dropSolids = GUILayout.Toggle(dropSolids, Localizer.Format("#MechJeb_Ascent_dropSolids"));//"Drop solids early"
dropSolids = GUILayout.Toggle(dropSolids,CachedLocalizer.Instance.MechJeb_Ascent_dropSolids);//"Drop solids early"
if (dropSolids)
GuiUtils.SimpleTextBox(" "+Localizer.Format("#MechJeb_Ascent_leadTime"), dropSolidsLeadTime, "s");//"lead time"
GuiUtils.SimpleTextBox($" {CachedLocalizer.Instance.MechJeb_Ascent_leadTime}", dropSolidsLeadTime, "s");//"lead time"

GUILayout.EndVertical();
}

[ValueInfoItem("#MechJeb_Autostagingstatus", InfoItem.Category.Misc)]//Autostaging status
public string AutostageStatus()
{
if (!this.enabled) return Localizer.Format("#MechJeb_Ascent_status9");//"Autostaging off"
if (autostagingOnce) return Localizer.Format("#MechJeb_Ascent_status10");//"Will autostage next stage only"
return Localizer.Format("#MechJeb_Ascent_status11") + (int)autostageLimit;//"Autostaging until stage #"
if (!this.enabled) return CachedLocalizer.Instance.MechJeb_Ascent_status9;//"Autostaging off"
if (autostagingOnce) return CachedLocalizer.Instance.MechJeb_Ascent_status10;//"Will autostage next stage only"
return CachedLocalizer.Instance.MechJeb_Ascent_status11 + (int)autostageLimit;//"Autostaging until stage #"
}

[GeneralInfoItem("#MechJeb_ClampAutostageThrust", InfoItem.Category.Misc)]//Clamp Autostage Thrust
public void ClampAutostageThrust()
{
GUILayout.BeginHorizontal();
GUILayout.Label(Localizer.Format("#MechJeb_Ascent_label44"));//"Clamp AutoStage Thrust "
core.staging.clampAutoStageThrustPct.text = GUILayout.TextField(core.staging.clampAutoStageThrustPct.text, 5);
GUILayout.Label(CachedLocalizer.Instance.MechJeb_Ascent_label44);//"Clamp AutoStage Thrust "
string cur = GUILayout.TextField(core.staging.clampAutoStageThrustPct.text, 5);
if (!cur.Equals(core.staging.clampAutoStageThrustPct.text))
{
core.staging.clampAutoStageThrustPct.text = cur;
core.staging.clampAutoStageThrustPct = UtilMath.Clamp(core.staging.clampAutoStageThrustPct,0,100);
}
GUILayout.Label("%");
core.staging.clampAutoStageThrustPct = UtilMath.Clamp(core.staging.clampAutoStageThrustPct, 0, 100);
GUILayout.EndVertical();

GUILayout.EndHorizontal();
}

//internal state:
Expand Down
52 changes: 18 additions & 34 deletions MechJeb2/MechJebModuleThrustController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ public MechJebModuleThrustController(MechJebCore core)
[GeneralInfoItem("#MechJeb_LimittoMaxQ", InfoItem.Category.Thrust)]//Limit to Max Q
public void LimitToMaxDynamicPressureInfoItem()
{
GUILayout.BeginHorizontal();
GUIStyle s = limiter == LimitMode.DynamicPressure ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limitDynamicPressure = GUILayout.Toggle(limitDynamicPressure, Localizer.Format("#MechJeb_Ascent_checkbox11"), s, GUILayout.Width(140));//"Limit Q to"
maxDynamicPressure.text = GUILayout.TextField(maxDynamicPressure.text, GUILayout.Width(80));
GUILayout.Label("pa", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUIStyle s = limiter == LimitMode.DynamicPressure ? GuiUtils.greenToggle : null;
GuiUtils.ToggledTextBox(ref limitDynamicPressure,CachedLocalizer.Instance.MechJeb_Ascent_checkbox11,maxDynamicPressure,"pa",s,80);
}

[Persistent(pass = (int)Pass.Global)]
Expand All @@ -66,7 +62,7 @@ public void LimitToMaxDynamicPressureInfoItem()
public void LimitToPreventOverheatsInfoItem()
{
GUIStyle s = limiter == LimitMode.Temperature ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limitToPreventOverheats = GUILayout.Toggle(limitToPreventOverheats, Localizer.Format("#MechJeb_Ascent_checkbox12"), s);//"Prevent engine overheats"
limitToPreventOverheats = GUILayout.Toggle(limitToPreventOverheats, CachedLocalizer.Instance.MechJeb_Ascent_checkbox12, s);//"Prevent engine overheats"
}

[ToggleInfoItem("#MechJeb_SmoothThrottle", InfoItem.Category.Thrust)]//Smooth throttle
Expand All @@ -83,7 +79,7 @@ public void LimitToPreventOverheatsInfoItem()
public void LimitToPreventFlameoutInfoItem()
{
GUIStyle s = limiter == LimitMode.Flameout ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limitToPreventFlameout = GUILayout.Toggle(limitToPreventFlameout, Localizer.Format("#MechJeb_Ascent_checkbox13"), s);//"Prevent jet flameout"
limitToPreventFlameout = GUILayout.Toggle(limitToPreventFlameout, CachedLocalizer.Instance.MechJeb_Ascent_checkbox13, s);//"Prevent jet flameout"
}

[Persistent(pass = (int)Pass.Global)]
Expand All @@ -93,7 +89,7 @@ public void LimitToPreventFlameoutInfoItem()
public void LimitToPreventUnstableIgnitionInfoItem()
{
GUIStyle s = (limiter == LimitMode.UnstableIgnition) ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limitToPreventUnstableIgnition = GUILayout.Toggle(limitToPreventUnstableIgnition, Localizer.Format("#MechJeb_Ascent_checkbox14"), s);//"Prevent unstable ignition"
limitToPreventUnstableIgnition = GUILayout.Toggle(limitToPreventUnstableIgnition, CachedLocalizer.Instance.MechJeb_Ascent_checkbox14, s);//"Prevent unstable ignition"
}

[Persistent(pass = (int)Pass.Global)]
Expand All @@ -103,7 +99,7 @@ public void LimitToPreventUnstableIgnitionInfoItem()
public void AutoRCsUllageInfoItem()
{
GUIStyle s = limiter == LimitMode.AutoRCSUllage ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
autoRCSUllaging = GUILayout.Toggle(autoRCSUllaging, Localizer.Format("#MechJeb_Ascent_checkbox15"), s);//"Use RCS to ullage"
autoRCSUllaging = GUILayout.Toggle(autoRCSUllaging, CachedLocalizer.Instance.MechJeb_Ascent_checkbox15, s);//"Use RCS to ullage"
}

// 5% safety margin on flameouts
Expand All @@ -123,12 +119,8 @@ public void AutoRCsUllageInfoItem()
[GeneralInfoItem("#MechJeb_LimitAcceleration", InfoItem.Category.Thrust)]//Limit Acceleration
public void LimitAccelerationInfoItem()
{
GUILayout.BeginHorizontal();
GUIStyle s = limiter == LimitMode.Acceleration ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limitAcceleration = GUILayout.Toggle(limitAcceleration, Localizer.Format("#MechJeb_Ascent_checkbox16"), s, GUILayout.Width(140));//"Limit acceleration to"
maxAcceleration.text = GUILayout.TextField(maxAcceleration.text, GUILayout.Width(30));
GUILayout.Label("m/s²", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUIStyle s = limiter == LimitMode.Acceleration ? GuiUtils.greenToggle : null;
GuiUtils.ToggledTextBox(ref limitAcceleration,CachedLocalizer.Instance.MechJeb_Ascent_checkbox16,maxAcceleration,"m/s²",s,30);//"Limit acceleration to"
}

[Persistent(pass = (int)Pass.Local)]
Expand All @@ -140,12 +132,8 @@ public void LimitAccelerationInfoItem()
[GeneralInfoItem("#MechJeb_LimitThrottle", InfoItem.Category.Thrust)]//Limit throttle
public void LimitThrottleInfoItem()
{
GUILayout.BeginHorizontal();
GUIStyle s = limiter == LimitMode.Throttle ? maxThrottle > 0d ? GuiUtils.greenToggle : GuiUtils.redToggle : GuiUtils.skin.toggle;
limitThrottle = GUILayout.Toggle(limitThrottle, Localizer.Format("#MechJeb_Ascent_checkbox17"), s, GUILayout.Width(110));//"Limit throttle to"
maxThrottle.text = GUILayout.TextField(maxThrottle.text, GUILayout.Width(30));
GUILayout.Label("%", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUIStyle s = limiter == LimitMode.Throttle ? maxThrottle > 0d ? GuiUtils.greenToggle : GuiUtils.redToggle : null;
GuiUtils.ToggledTextBox(ref limitThrottle,CachedLocalizer.Instance.MechJeb_Ascent_checkbox17,maxAcceleration,"%",s,30);//"Limit throttle to"
}

[Persistent(pass = (int) (Pass.Local | Pass.Type | Pass.Global))]
Expand All @@ -157,12 +145,8 @@ public void LimitThrottleInfoItem()
[GeneralInfoItem("#MechJeb_LowerThrottleLimit", InfoItem.Category.Thrust)]//Lower throttle limit
public void LimiterMinThrottleInfoItem()
{
GUILayout.BeginHorizontal();
GUIStyle s = (limiter == LimitMode.MinThrottle) ? GuiUtils.greenToggle : GuiUtils.skin.toggle;
limiterMinThrottle = GUILayout.Toggle(limiterMinThrottle, Localizer.Format("#MechJeb_Ascent_checkbox18"), s, GUILayout.Width(160));//"Keep limited throttle over"
minThrottle.text = GUILayout.TextField(minThrottle.text, GUILayout.Width(30));
GUILayout.Label("%", GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUIStyle s = (limiter == LimitMode.MinThrottle) ? GuiUtils.greenToggle : null;
GuiUtils.ToggledTextBox(ref limiterMinThrottle,CachedLocalizer.Instance.MechJeb_Ascent_checkbox18,minThrottle,"%",s,30);//"Keep limited throttle over"
}

[Persistent(pass = (int)Pass.Type)]
Expand All @@ -173,7 +157,7 @@ public void DifferentialThrottle()
{
bool oldDifferentialThrottle = core.thrust.differentialThrottle;
GUIStyle s = differentialThrottle && vessel.LiftedOff() ? core.thrust.differentialThrottleSuccess == DifferentialThrottleStatus.Success ? GuiUtils.greenToggle : GuiUtils.yellowToggle : GuiUtils.skin.toggle;
differentialThrottle = GUILayout.Toggle(differentialThrottle, Localizer.Format("#MechJeb_Ascent_checkbox19"), s);//"Differential throttle"
differentialThrottle = GUILayout.Toggle(differentialThrottle, CachedLocalizer.Instance.MechJeb_Ascent_checkbox19, s);//"Differential throttle"

if (oldDifferentialThrottle && !core.thrust.differentialThrottle)
core.thrust.DisableDifferentialThrottle();
Expand Down Expand Up @@ -205,11 +189,11 @@ public void LimitElectricInfoItem()
}
else if (ElectricEngineRunning()) s = GuiUtils.greenLabel;

electricThrottle = GUILayout.Toggle(electricThrottle, Localizer.Format("#MechJeb_Ascent_checkbox20"), s, GUILayout.Width(110));//"Electric limit Lo"
electricThrottleLo.text = GUILayout.TextField(electricThrottleLo.text, GUILayout.Width(30));
GUILayout.Label("% Hi", GUILayout.ExpandWidth(false));
electricThrottleHi.text = GUILayout.TextField(electricThrottleHi.text, GUILayout.Width(30));
GUILayout.Label("%", GUILayout.ExpandWidth(false));
electricThrottle = GUILayout.Toggle(electricThrottle, CachedLocalizer.Instance.MechJeb_Ascent_checkbox20, s, GuiUtils.LayoutWidth(110));//"Electric limit Lo"
GuiUtils.SimpleTextField(electricThrottleLo,30);
GUILayout.Label("% Hi", GuiUtils.ExpandWidth(false));
GuiUtils.SimpleTextField(electricThrottleHi,30);
GUILayout.Label("%",GuiUtils.ExpandWidth(false));
GUILayout.EndHorizontal();
}

Expand Down

0 comments on commit cc23b90

Please sign in to comment.