-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModuleSasIndicator.cs
More file actions
184 lines (163 loc) · 7.04 KB
/
Copy pathModuleSasIndicator.cs
File metadata and controls
184 lines (163 loc) · 7.04 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using UnityEngine;
namespace IndicatorLights
{
public class ModuleSasIndicator : ModuleEmissiveController, IToggle
{
private static readonly Color COLOR_STABILITY_ASSIST = Color.white;
private static readonly Color COLOR_PROGRADE = new Color(1, 1, 0); // since Color.yellow is actually something else
private static readonly Color COLOR_RADIAL = Color.cyan;
private static readonly Color COLOR_NORMAL = Color.magenta;
private static readonly Color COLOR_TARGET = Color.magenta;
private static readonly Color COLOR_MANEUVER = Color.blue;
private StartState startState = StartState.None;
private IColorSource stabilityAssistSource = null;
private IColorSource progradeSource = null;
private IColorSource retrogradeSource = null;
private IColorSource normalSource = null;
private IColorSource antinormalSource = null;
private IColorSource radialInSource = null;
private IColorSource radialOutSource = null;
private IColorSource targetSource = null;
private IColorSource antitargetSource = null;
private IColorSource maneuverSource = null;
private IColorSource inactiveSource = null;
/// <summary>
/// The color to display when SAS is set to "stability assist" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string stabilityAssistColor = Colors.ToString(COLOR_STABILITY_ASSIST);
/// <summary>
/// The color to display when SAS is set to "prograde" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string progradeColor = Colors.ToString(COLOR_PROGRADE);
/// <summary>
/// The color to display when SAS is set to "retrograde" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string retrogradeColor = Colors.ToString(COLOR_PROGRADE);
/// <summary>
/// The color to display when SAS is set to "normal" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string normalColor = Colors.ToString(COLOR_NORMAL);
/// <summary>
/// The color to display when SAS is set to "antinormal" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string antinormalColor = Colors.ToString(COLOR_NORMAL);
/// <summary>
/// The color to display when SAS is set to "radial in" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string radialInColor = Colors.ToString(COLOR_RADIAL);
/// <summary>
/// The color to display when SAS is set to "radial out" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string radialOutColor = Colors.ToString(COLOR_RADIAL);
/// <summary>
/// The color to display when SAS is set to "target" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string targetColor = Colors.ToString(COLOR_TARGET);
/// <summary>
/// The color to display when SAS is set to "antitarget" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string antitargetColor = Colors.ToString(COLOR_TARGET);
/// <summary>
/// The color to display when SAS is set to "maneuver" mode.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string maneuverColor = Colors.ToString(COLOR_MANEUVER);
/// <summary>
/// The color to display when SAS is inactive.
/// </summary>
[KSPField]
[ColorSourceIDField]
public string inactiveColor = Colors.ToString(DefaultColor.Off);
public override Color OutputColor => CurrentSource.OutputColor;
public override void OnStart(StartState state)
{
base.OnStart(state);
startState = state;
}
public override void ParseIDs()
{
base.ParseIDs();
stabilityAssistSource = FindColorSource(stabilityAssistColor);
progradeSource = FindColorSource(progradeColor);
retrogradeSource = FindColorSource(retrogradeColor);
normalSource = FindColorSource(normalColor);
antinormalSource = FindColorSource(antinormalColor);
radialInSource = FindColorSource(radialInColor);
radialOutSource = FindColorSource(radialOutColor);
targetSource = FindColorSource(targetColor);
antitargetSource = FindColorSource(antitargetColor);
maneuverSource = FindColorSource(maneuverColor);
inactiveSource = FindColorSource(inactiveColor);
}
private IColorSource CurrentSource
{
get
{
// in the editor, act like stability assist is on
if (startState == StartState.Editor) return stabilityAssistSource;
VesselAutopilot autopilot = Autopilot;
if (!ToggleStatus) return inactiveSource;
switch (autopilot.Mode)
{
case VesselAutopilot.AutopilotMode.StabilityAssist:
return stabilityAssistSource;
case VesselAutopilot.AutopilotMode.Prograde:
return progradeSource;
case VesselAutopilot.AutopilotMode.Retrograde:
return retrogradeSource;
case VesselAutopilot.AutopilotMode.Normal:
return normalSource;
case VesselAutopilot.AutopilotMode.Antinormal:
return antinormalSource;
// yes, I know that RadialOut and RadialIn are flipped. Has to be
// that way to deal with a KSP bug.
case VesselAutopilot.AutopilotMode.RadialOut:
return radialInSource;
case VesselAutopilot.AutopilotMode.RadialIn:
return radialOutSource;
case VesselAutopilot.AutopilotMode.Target:
return targetSource;
case VesselAutopilot.AutopilotMode.AntiTarget:
return antitargetSource;
case VesselAutopilot.AutopilotMode.Maneuver:
return maneuverSource;
default:
// unknown enum value, should never happen unless KSP adds more modes,
// which will never happen
return ColorSources.ERROR;
}
}
}
/// <summary>
/// IToggle implementation.
/// </summary>
public bool ToggleStatus
{
get
{
VesselAutopilot autopilot = Autopilot;
return (autopilot != null) && autopilot.Enabled;
}
}
private VesselAutopilot Autopilot => (vessel == null) ? null : vessel.Autopilot;
}
}