/
MechJebModuleThrustWindow.cs
136 lines (113 loc) · 5.75 KB
/
MechJebModuleThrustWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using JetBrains.Annotations;
using KSP.Localization;
using UnityEngine;
namespace MuMech
{
[UsedImplicitly]
public class MechJebModuleThrustWindow : DisplayModule
{
[Persistent(pass = (int)Pass.LOCAL)]
public bool autostageSavedState;
public MechJebModuleThrustWindow(MechJebCore core) : base(core) { }
public override void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global)
{
base.OnLoad(local, type, global);
if (autostageSavedState && !Core.Staging.Users.Contains(this))
{
Core.Staging.Users.Add(this);
}
}
[GeneralInfoItem("#MechJeb_AutostageOnce", InfoItem.Category.Misc)] //Autostage Once
public void AutostageOnceItem()
{
if (Core.Staging.Enabled)
{
GUILayout.Label(Localizer.Format("#MechJeb_Utilities_label1",
Core.Staging.AutostagingOnce
? Localizer.Format("#MechJeb_Utilities_label1_1")
: " ")); //"Autostaging"<<1>>"Active" -------<<1>>" once ":""
}
if (!Core.Staging.Enabled && GUILayout.Button(Localizer.Format("#MechJeb_Utilities_button1"))) //"Autostage once"
{
Core.Staging.AutostageOnce(this);
}
}
[GeneralInfoItem("#MechJeb_Autostage", InfoItem.Category.Misc)] //Autostage
public void Autostage()
{
bool oldAutostage = Core.Staging.Users.Contains(this);
bool newAutostage = GUILayout.Toggle(oldAutostage, Localizer.Format("#MechJeb_Utilities_checkbox1")); //"Autostage"
if (newAutostage && !oldAutostage) Core.Staging.Users.Add(this);
if (!newAutostage && oldAutostage) Core.Staging.Users.Remove(this);
autostageSavedState = newAutostage;
}
// UI stuff
protected override void WindowGUI(int windowID)
{
GUILayout.BeginVertical();
//core.thrust.LimitToTerminalVelocityInfoItem();
Core.Thrust.LimitToMaxDynamicPressureInfoItem();
Core.Thrust.LimitToPreventOverheatsInfoItem();
Core.Thrust.LimitAccelerationInfoItem();
Core.Thrust.LimitThrottleInfoItem();
Core.Thrust.LimiterMinThrottleInfoItem();
Core.Thrust.LimitElectricInfoItem();
Core.Thrust.LimitToPreventFlameoutInfoItem();
if (VesselState.isLoadedRealFuels)
{
// does nothing in stock, so we suppress displaying it if RF is not loaded
Core.Thrust.LimitToPreventUnstableIgnitionInfoItem();
Core.Thrust.AutoRCsUllageInfoItem();
}
Core.Thrust.SmoothThrottle =
GUILayout.Toggle(Core.Thrust.SmoothThrottle, Localizer.Format("#MechJeb_Utilities_checkbox2")); //"Smooth throttle"
Core.Thrust.ManageIntakes =
GUILayout.Toggle(Core.Thrust.ManageIntakes, Localizer.Format("#MechJeb_Utilities_checkbox3")); //"Manage air intakes"
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
try
{
GUILayout.Label(Localizer.Format("#MechJeb_Utilities_label2")); //"Jet safety margin"
Core.Thrust.FlameoutSafetyPct.text = GUILayout.TextField(Core.Thrust.FlameoutSafetyPct.text, 5);
GUILayout.Label("%");
}
finally
{
GUILayout.EndHorizontal();
}
Core.Thrust.DifferentialThrottleMenu();
if (Core.Thrust.DifferentialThrottle && Vessel.LiftedOff())
{
switch (Core.Thrust.DifferentialThrottleSuccess)
{
case MechJebModuleThrustController.DifferentialThrottleStatus.MORE_ENGINES_REQUIRED:
GUILayout.Label(Localizer.Format("#MechJeb_Utilities_label3"),
GuiUtils.yellowLabel); //"Differential throttle failed\nMore engines required"
break;
case MechJebModuleThrustController.DifferentialThrottleStatus.ALL_ENGINES_OFF:
GUILayout.Label(Localizer.Format("#MechJeb_Utilities_label4"),
GuiUtils.yellowLabel); //"Differential throttle failed\nNo active engine"
break;
case MechJebModuleThrustController.DifferentialThrottleStatus.SOLVER_FAILED:
GUILayout.Label(Localizer.Format("#MechJeb_Utilities_label5"),
GuiUtils.yellowLabel); //"Differential throttle failed\nCannot find solution"
break;
case MechJebModuleThrustController.DifferentialThrottleStatus.SUCCESS:
break;
}
}
Core.Solarpanel.SolarPanelDeployButton();
Core.AntennaControl.AntennaDeployButton();
Autostage();
if (!Core.Staging.Enabled && GUILayout.Button(Localizer.Format("#MechJeb_Utilities_button1")))
Core.Staging.AutostageOnce(this); //"Autostage once"
if (Core.Staging.Enabled) Core.Staging.AutostageSettingsInfoItem();
if (Core.Staging.Enabled) GUILayout.Label(Core.Staging.AutostageStatus());
GUILayout.EndVertical();
base.WindowGUI(windowID);
}
protected override GUILayoutOption[] WindowOptions() => new[] { GUILayout.Width(250), GUILayout.Height(30) };
public override bool IsActive() => Core.Thrust.Limiter != MechJebModuleThrustController.LimitMode.NONE;
public override string GetName() => Localizer.Format("#MechJeb_Utilities_title"); //"Utilities"
public override string IconName() => "Utilities";
}
}