Skip to content

Commit 2e48a7d

Browse files
committed
Fixing a long standing bug on ModuleManager's UI intoduced by me when I refactored the UI, incepting KSP 1.2.2 compatibility... (shame on me...)
1 parent c9d8bd5 commit 2e48a7d

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

Source/ModuleManager/GUI/Menu.12.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ namespace ModuleManager.GUI
1414
#if KSP12
1515
internal class Menu
1616
{
17-
internal static Menu Show(ModuleManager parent)
17+
private readonly ModuleManager parent;
18+
private PopupDialog instance;
19+
20+
internal Menu(ModuleManager parent)
1821
{
19-
return new Menu(parent);
22+
this.parent = parent;
2023
}
2124

22-
internal Menu Dismiss()
25+
internal void Dismiss()
2326
{
27+
this.instance.Dismiss();
2428
this.instance = null;
25-
return null;
2629
}
2730

28-
private ModuleManager parent;
29-
private PopupDialog instance;
30-
private Menu(ModuleManager parent)
31+
internal void OnUpdate(bool inRnDCenter)
3132
{
32-
this.parent = parent;
33+
// TODO Make this work on KSP 1.2!
3334
}
3435
}
3536
#endif

Source/ModuleManager/GUI/Menu.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,35 @@ namespace ModuleManager.GUI
1313
#if !KSP12
1414
internal class Menu
1515
{
16-
internal static Menu Show(ModuleManager parent)
16+
private readonly ModuleManager parent;
17+
private PopupDialog instance;
18+
19+
internal Menu(ModuleManager parent)
1720
{
18-
return new Menu(parent);
21+
this.parent = parent;
1922
}
2023

21-
internal Menu Dismiss()
24+
internal void Dismiss()
2225
{
2326
this.instance.Dismiss();
2427
this.instance = null;
25-
return null;
2628
}
2729

28-
private ModuleManager parent;
29-
private PopupDialog instance;
30-
private Menu(ModuleManager parent)
30+
internal void OnUpdate(bool inRnDCenter)
31+
{
32+
if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(KeyCode.F11)
33+
&& (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.MAINMENU)
34+
&& !inRnDCenter)
35+
{
36+
if (null == this.instance)
37+
this.Show();
38+
else
39+
this.Dismiss();
40+
}
41+
}
42+
43+
private void Show ()
3144
{
32-
this.parent = parent;
3345
this.instance = PopupDialog.SpawnPopupDialog(
3446
new Vector2(0.5f, 0.5f),
3547
new Vector2(0.5f, 0.5f),
@@ -47,19 +59,22 @@ private Menu(ModuleManager parent)
4759
{
4860
MMPatchLoader.keepPartDB = false;
4961
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM());
50-
}, 140.0f, 30.0f, true),
62+
this.Dismiss();
63+
}, 140.0f, 30.0f, false),
5164
new DialogGUIButton("Quick Reload Database",
5265
delegate
5366
{
5467
MMPatchLoader.keepPartDB = true;
5568
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM());
56-
}, 140.0f, 30.0f, true),
69+
this.Dismiss();
70+
}, 140.0f, 30.0f, false),
5771
new DialogGUIButton("Dump Database to Files",
5872
delegate
5973
{
6074
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM(true));
61-
}, 140.0f, 30.0f, true),
62-
new DialogGUIButton("Close", () => { }, 140.0f, 30.0f, true)
75+
this.Dismiss();
76+
}, 140.0f, 30.0f, false),
77+
new DialogGUIButton("Close", () => { this.Dismiss(); } , 140.0f, 30.0f, false)
6378
)),
6479
false,
6580
HighLogic.UISkin);

Source/ModuleManager/ModuleManager.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ internal void OnRnDCenterDeSpawn()
7171

7272
internal void Awake()
7373
{
74+
this.menu = new GUI.Menu(this);
75+
7476
if (LoadingScreen.Instance == null)
7577
{
7678
Destroy(gameObject);
@@ -222,15 +224,7 @@ internal void OnDestroy()
222224

223225
internal void Update()
224226
{
225-
if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(KeyCode.F11)
226-
&& (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.MAINMENU)
227-
&& !inRnDCenter)
228-
{
229-
if (null == this.menu)
230-
this.menu = GUI.Menu.Show(this);
231-
else
232-
this.menu = this.menu.Dismiss();
233-
}
227+
this.menu.OnUpdate(this.inRnDCenter);
234228

235229
if (PerformanceMetrics.Instance.IsRunning && HighLogic.LoadedScene == GameScenes.MAINMENU)
236230
{

0 commit comments

Comments
 (0)