-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathModuleIndicatorToggle.cs
More file actions
106 lines (90 loc) · 3.35 KB
/
Copy pathModuleIndicatorToggle.cs
File metadata and controls
106 lines (90 loc) · 3.35 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
namespace IndicatorLights
{
/// <summary>
/// A simple module that doesn't actually do anything, other than "own" a particular toggle state.
/// </summary>
public class ModuleIndicatorToggle : PartModule, Identifiers.IIdentifiable, IToggle
{
[KSPField(guiName = "Status", isPersistant = true, guiActive = true, guiActiveEditor = true), UI_Toggle(affectSymCounterparts = UI_Scene.Editor, controlEnabled = true, enabledText = "On", disabledText = "Off")]
public bool status = false;
private BaseField StatusField { get { return Fields["status"]; } }
[KSPField]
public bool guiActive = true;
[KSPField]
public bool guiActiveEditor = true;
[KSPField]
public string toggleName = null;
[KSPField]
public string statusLabel = "Status";
[KSPField]
public string statusOn = "On";
[KSPField]
public string statusOff = "Off";
[KSPField]
public string toggleAction = "Toggle";
[KSPField]
public string activateAction = "Activate";
[KSPField]
public string deactivateAction = "Deactivate";
/// <summary>
/// Action-group method for toggling status.
/// </summary>
/// <param name="actionParam"></param>
[KSPAction("Toggle")]
public void OnToggleAction(KSPActionParam actionParam)
{
status = actionParam.type != KSPActionType.Deactivate;
}
private BaseAction ToggleAction { get { return Actions["OnToggleAction"]; } }
/// <summary>
/// Action-group method for setting status to true.
/// </summary>
/// <param name="actionParam"></param>
[KSPAction("Activate")]
public void OnActivateAction(KSPActionParam actionParam)
{
status = true;
}
private BaseAction ActivateAction { get { return Actions["OnActivateAction"]; } }
/// <summary>
/// Action-group method for setting status to false.
/// </summary>
/// <param name="actionParam"></param>
[KSPAction("Deactivate")]
public void OnDeactivateAction(KSPActionParam actionParam)
{
status = false;
}
private BaseAction DeactivateAction { get { return Actions["OnDeactivateAction"]; } }
public string Identifier
{
get { return toggleName; }
}
public bool ToggleStatus
{
get { return status; }
}
public override void OnStart(StartState state)
{
base.OnStart(state);
StatusField.guiActive = guiActive;
StatusField.guiActiveEditor = guiActiveEditor;
StatusField.guiName = statusLabel;
UI_Toggle toggle = StatusField.uiControlEditor as UI_Toggle;
if (toggle != null)
{
toggle.enabledText = statusOn;
toggle.disabledText = statusOff;
}
toggle = StatusField.uiControlFlight as UI_Toggle;
if (toggle != null)
{
toggle.enabledText = statusOn;
toggle.disabledText = statusOff;
}
ToggleAction.guiName = toggleAction;
ActivateAction.guiName = activateAction;
DeactivateAction.guiName = deactivateAction;
}
}
}