Skip to content

Commit 331c26a

Browse files
committed
Fix #87: switchable labels can persist the active index
1 parent ac4ee2f commit 331c26a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

RasterPropMonitor/Auxiliary modules/JSISwitchableVariableLabel.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ public class JSISwitchableVariableLabel : InternalModule
4646
public string colorName = "_EmissiveColor";
4747
[KSPField]
4848
public string alignment = "TopLeft";
49+
[KSPField]
50+
public bool persistActiveLabel = false;
4951

5052
private int colorNameId = -1;
5153
private readonly List<VariableLabelSet> labelsEx = new List<VariableLabelSet>();
52-
private int activeLabel;
54+
private int activeLabel = 0;
55+
private string persistentVariableName;
5356
private const string fontName = "Arial";
5457
private InternalText textObj;
5558
private Transform textObjTransform;
@@ -71,7 +74,16 @@ public void Start()
7174

7275
textObjTransform = JUtil.FindPropTransform(internalProp, labelTransform);
7376
textObj = InternalComponents.Instance.CreateText(fontName, fontSize * 15.5f, textObjTransform, "", Color.green, false, alignment);
74-
activeLabel = 0;
77+
78+
if (persistActiveLabel)
79+
{
80+
persistentVariableName = "switchableLabel_" + internalProp.propID + "_" + moduleID;
81+
activeLabel = (int)rpmComp.GetPersistentVariable(persistentVariableName, activeLabel, false);
82+
}
83+
else
84+
{
85+
activeLabel = 0;
86+
}
7587

7688
SmarterButton.CreateButton(internalProp, switchTransform, Click);
7789

@@ -214,6 +226,11 @@ void UpdateActiveLabel(int direction)
214226

215227
activeLabel = (activeLabel + direction + labelsEx.Count) % labelsEx.Count;
216228

229+
if (persistActiveLabel)
230+
{
231+
rpmComp.SetPersistentVariable(persistentVariableName, activeLabel, false);
232+
}
233+
217234
if (labelsEx.Count > 1 && !labelsEx[activeLabel].oneShot)
218235
{
219236
rpmComp.RestoreInternalModule(this);

0 commit comments

Comments
 (0)