/
MechJebModuleSmartRcs.cs
133 lines (113 loc) · 4.7 KB
/
MechJebModuleSmartRcs.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
using System.Linq;
using JetBrains.Annotations;
using KSP.Localization;
using UnityEngine;
namespace MuMech
{
[UsedImplicitly]
internal class MechJebModuleSmartRcs : DisplayModule
{
public enum Target
{
OFF,
ZERO_RVEL
}
public static readonly string[]
TargetTexts = { Localizer.Format("#MechJeb_SmartRcs_button1"), Localizer.Format("#MechJeb_SmartRcs_button2") }; //"OFF", "ZERO RVEL"
public Target target;
private static GUIStyle btNormal, btActive, btAuto;
[Persistent(pass = (int)Pass.Global)]
public bool autoDisableSmartRCS = true;
[GeneralInfoItem("#MechJeb_DisableSmartRcsAutomatically", InfoItem.Category.Misc)] //Disable SmartRcs automatically
public void AutoDisableSmartRCS()
{
autoDisableSmartRCS =
GUILayout.Toggle(autoDisableSmartRCS, Localizer.Format("#MechJeb_SmartRcs_checkbox1 ")); //"Disable SmartRcs automatically"
}
protected void TargetButton(Target bt)
{
if (GUILayout.Button(TargetTexts[(int)bt], target == bt ? btActive : btNormal, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
target = bt;
Engage();
}
}
public MechJebModuleSmartRcs(MechJebCore core) : base(core)
{
}
protected override void WindowGUI(int windowID)
{
if (btNormal == null)
{
btNormal = new GUIStyle(GUI.skin.button);
btNormal.normal.textColor = btNormal.focused.textColor = Color.white;
btNormal.hover.textColor = btNormal.active.textColor = Color.yellow;
btNormal.onNormal.textColor =
btNormal.onFocused.textColor = btNormal.onHover.textColor = btNormal.onActive.textColor = Color.green;
btNormal.padding = new RectOffset(8, 8, 8, 8);
btActive = new GUIStyle(btNormal);
btActive.active = btActive.onActive;
btActive.normal = btActive.onNormal;
btActive.onFocused = btActive.focused;
btActive.hover = btActive.onHover;
btAuto = new GUIStyle(btNormal);
btAuto.normal.textColor = Color.red;
btAuto.onActive =
btAuto.onFocused = btAuto.onHover = btAuto.onNormal = btAuto.active = btAuto.focused = btAuto.hover = btAuto.normal;
}
// Disable if RCS is used by an other module
if (core.RCS.enabled && core.RCS.users.Count(u => !Equals(u)) > 0)
{
if (autoDisableSmartRCS)
{
target = Target.OFF;
if (core.RCS.users.Contains(this))
core.RCS.users.Remove(this); // so we don't suddenly turn on when the other autopilot finishes
}
GUILayout.Button(Localizer.Format("#MechJeb_SmartRcs_button3"), btAuto, GUILayout.ExpandWidth(true)); //"AUTO"
}
else if (core.Target.Target == null)
{
GUILayout.Label(Localizer.Format("#MechJeb_SmartRcs_label1")); //"Choose a target"
}
else
{
GUILayout.BeginVertical();
TargetButton(Target.OFF);
TargetButton(Target.ZERO_RVEL);
//TargetButton(Target.HOLD_RPOS);
GUILayout.EndVertical();
}
core.RCS.rcsThrottle =
GUILayout.Toggle(core.RCS.rcsThrottle, Localizer.Format("#MechJeb_SmartRcs_checkbox2")); //" RCS throttle when engines are offline"
core.RCS.rcsForRotation =
GUILayout.Toggle(core.RCS.rcsForRotation, Localizer.Format("#MechJeb_SmartRcs_checkbox3")); // " Use RCS for rotation"
base.WindowGUI(windowID);
}
public void Engage()
{
switch (target)
{
case Target.OFF:
core.RCS.users.Remove(this);
return;
case Target.ZERO_RVEL:
core.RCS.users.Add(this);
core.RCS.SetTargetRelative(Vector3d.zero);
break;
}
}
public override GUILayoutOption[] WindowOptions()
{
return new[] { GUILayout.Width(180), GUILayout.Height(100) };
}
public override string GetName()
{
return Localizer.Format("#MechJeb_SmartRcs_title"); //"SmartRcs"
}
public override string IconName()
{
return "SmartRcs";
}
}
}