Skip to content

Commit 75240ec

Browse files
committed
Refactoring: decoupling KSP 131 specific code, allowing backporting the thing to KSP 1.2.2
1 parent c5c93a6 commit 75240ec

14 files changed

+410
-155
lines changed

ModuleManager.122.version

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"NAME" : "Module Manager /L Experimental",
3+
"URL" : "https://raw.githubusercontent.com/net-lisias-ksp/ModuleManager/master/ModuleManager.122.version",
4+
"DOWNLOAD" : "https://github.com/net-lisias-ksp/ModuleManager/releases",
5+
"CHANGE_LOG" : "https://raw.githubusercontent.com/net-lisias-ksp/ModuleManager/master/CHANGE_LOG.md",
6+
"CHANGE_LOG_URL": "https://raw.githubusercontent.com/net-lisias-ksp/ModuleManager/master/CHANGES.md",
7+
"VERSION":{
8+
"MAJOR":4,
9+
"MINOR":1,
10+
"PATCH":4,
11+
"BUILD":4
12+
},
13+
"KSP_VERSION":{
14+
"MAJOR":1,
15+
"MINOR":2,
16+
"PATCH":2
17+
}
18+
}

ModuleManager.sln

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,52 @@ VisualStudioVersion = 15.0.26730.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleManager", "Source\ModuleManager\ModuleManager.csproj", "{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModuleManagerTests", "Source\ModuleManagerTests\ModuleManagerTests.csproj", "{BC2A08C8-64EF-4823-A40B-8889C1CCFD75}"
8+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "ModuleManagerTests", "Source\ModuleManagerTests\ModuleManagerTests.csproj", "{6F96EE04-BB4E-40D8-B02E-17131FB880F0}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "Source\TestUtils\TestUtils.csproj", "{20EAAFE6-510D-4374-8D2F-6B52D0178E85}"
10+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "TestUtils", "Source\TestUtils\TestUtils.csproj", "{4C56CA7C-04D8-411E-822A-508847FA010E}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtilsTests", "Source\TestUtilsTests\TestUtilsTests.csproj", "{E695C11F-4217-4014-9B51-7232A654C205}"
12+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "TestUtilsTests", "Source\TestUtilsTests\TestUtilsTests.csproj", "{4681DD1A-8C26-4620-AAEA-31DF430A61BC}"
1313
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1616
Debug|Any CPU = Debug|Any CPU
1717
Release|Any CPU = Release|Any CPU
18+
122.Release|Any CPU = 122.Release|Any CPU
19+
122.Debug|Any CPU = 122.Debug|Any CPU
1820
EndGlobalSection
1921
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2022
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2123
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{BC2A08C8-64EF-4823-A40B-8889C1CCFD75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{BC2A08C8-64EF-4823-A40B-8889C1CCFD75}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{BC2A08C8-64EF-4823-A40B-8889C1CCFD75}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{BC2A08C8-64EF-4823-A40B-8889C1CCFD75}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{20EAAFE6-510D-4374-8D2F-6B52D0178E85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29-
{20EAAFE6-510D-4374-8D2F-6B52D0178E85}.Debug|Any CPU.Build.0 = Debug|Any CPU
30-
{20EAAFE6-510D-4374-8D2F-6B52D0178E85}.Release|Any CPU.ActiveCfg = Release|Any CPU
31-
{20EAAFE6-510D-4374-8D2F-6B52D0178E85}.Release|Any CPU.Build.0 = Release|Any CPU
32-
{E695C11F-4217-4014-9B51-7232A654C205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33-
{E695C11F-4217-4014-9B51-7232A654C205}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{E695C11F-4217-4014-9B51-7232A654C205}.Release|Any CPU.ActiveCfg = Release|Any CPU
35-
{E695C11F-4217-4014-9B51-7232A654C205}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.122.Release|Any CPU.ActiveCfg = 122.Release|Any CPU
27+
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.122.Release|Any CPU.Build.0 = 122.Release|Any CPU
28+
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.122.Debug|Any CPU.ActiveCfg = 122.Debug|Any CPU
29+
{02C8E3AF-69F9-4102-AB60-DD6DE60662D3}.122.Debug|Any CPU.Build.0 = 122.Debug|Any CPU
30+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.122.Release|Any CPU.ActiveCfg = 122.Release|Any CPU
35+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.122.Release|Any CPU.Build.0 = 122.Release|Any CPU
36+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.122.Debug|Any CPU.ActiveCfg = 122.Debug|Any CPU
37+
{6F96EE04-BB4E-40D8-B02E-17131FB880F0}.122.Debug|Any CPU.Build.0 = 122.Debug|Any CPU
38+
{4C56CA7C-04D8-411E-822A-508847FA010E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{4C56CA7C-04D8-411E-822A-508847FA010E}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{4C56CA7C-04D8-411E-822A-508847FA010E}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{4C56CA7C-04D8-411E-822A-508847FA010E}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{4C56CA7C-04D8-411E-822A-508847FA010E}.122.Release|Any CPU.ActiveCfg = 122.Release|Any CPU
43+
{4C56CA7C-04D8-411E-822A-508847FA010E}.122.Release|Any CPU.Build.0 = 122.Release|Any CPU
44+
{4C56CA7C-04D8-411E-822A-508847FA010E}.122.Debug|Any CPU.ActiveCfg = 122.Debug|Any CPU
45+
{4C56CA7C-04D8-411E-822A-508847FA010E}.122.Debug|Any CPU.Build.0 = 122.Debug|Any CPU
46+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.122.Release|Any CPU.ActiveCfg = 122.Release|Any CPU
51+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.122.Release|Any CPU.Build.0 = 122.Release|Any CPU
52+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.122.Debug|Any CPU.ActiveCfg = 122.Debug|Any CPU
53+
{4681DD1A-8C26-4620-AAEA-31DF430A61BC}.122.Debug|Any CPU.Build.0 = 122.Debug|Any CPU
3654
EndGlobalSection
3755
GlobalSection(SolutionProperties) = preSolution
3856
HideSolutionNode = FALSE
@@ -51,8 +69,6 @@ Global
5169
$2.scope = text/x-csharp
5270
$0.TextStylePolicy = $3
5371
$3.FileWidth = 132
54-
$3.TabsToSpaces = True
55-
$3.NoTabsAfterNonTabs = True
5672
$3.EolMarker = Unix
5773
$3.scope = text/plain
5874
$0.TextStylePolicy = $4

Source/ModuleManager/Fix16.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ private IEnumerator DoFix()
7575
yield return null;
7676
}
7777

78+
#if !KSP12
7879
public override float LoadWeight()
7980
{
8081
return 0.1f;
8182
}
83+
#endif
8284
}
8385
}

Source/ModuleManager/GUI/Menu.12.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
This file is part of Module Manager /L
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager /L is distributed in the hope that it will be useful,
6+
but WITHOUT ANY WARRANTY; without even the implied warranty of
7+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
*/
9+
using UnityEngine;
10+
using UGUI = UnityEngine.GUI;
11+
12+
namespace ModuleManager.GUI
13+
{
14+
#if KSP12
15+
internal class Menu
16+
{
17+
internal static Menu Show(ModuleManager parent)
18+
{
19+
return new Menu(parent);
20+
}
21+
22+
internal Menu Dismiss()
23+
{
24+
this.instance = null;
25+
return null;
26+
}
27+
28+
private ModuleManager parent;
29+
private PopupDialog instance;
30+
private Menu(ModuleManager parent)
31+
{
32+
this.parent = parent;
33+
}
34+
}
35+
#endif
36+
}

Source/ModuleManager/GUI/Menu.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
This file is part of Module Manager /L
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager /L is distributed in the hope that it will be useful,
6+
but WITHOUT ANY WARRANTY; without even the implied warranty of
7+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
*/
9+
using UnityEngine;
10+
11+
namespace ModuleManager.GUI
12+
{
13+
#if !KSP12
14+
internal class Menu
15+
{
16+
internal static Menu Show(ModuleManager parent)
17+
{
18+
return new Menu(parent);
19+
}
20+
21+
internal Menu Dismiss()
22+
{
23+
this.instance.Dismiss();
24+
this.instance = null;
25+
return null;
26+
}
27+
28+
private ModuleManager parent;
29+
private PopupDialog instance;
30+
private Menu(ModuleManager parent)
31+
{
32+
this.parent = parent;
33+
this.instance = PopupDialog.SpawnPopupDialog(
34+
new Vector2(0.5f, 0.5f),
35+
new Vector2(0.5f, 0.5f),
36+
new MultiOptionDialog(
37+
"ModuleManagerMenu",
38+
"",
39+
"ModuleManager",
40+
HighLogic.UISkin,
41+
new Rect(0.5f, 0.5f, 150f, 60f),
42+
new DialogGUIFlexibleSpace(),
43+
new DialogGUIVerticalLayout(
44+
new DialogGUIFlexibleSpace(),
45+
new DialogGUIButton("Reload Database",
46+
delegate
47+
{
48+
MMPatchLoader.keepPartDB = false;
49+
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM());
50+
}, 140.0f, 30.0f, true),
51+
new DialogGUIButton("Quick Reload Database",
52+
delegate
53+
{
54+
MMPatchLoader.keepPartDB = true;
55+
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM());
56+
}, 140.0f, 30.0f, true),
57+
new DialogGUIButton("Dump Database to Files",
58+
delegate
59+
{
60+
this.parent.StartCoroutine(this.parent.DataBaseReloadWithMM(true));
61+
}, 140.0f, 30.0f, true),
62+
new DialogGUIButton("Close", () => { }, 140.0f, 30.0f, true)
63+
)),
64+
false,
65+
HighLogic.UISkin);
66+
}
67+
}
68+
#endif
69+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
This file is part of Module Manager /L
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager /L is distributed in the hope that it will be useful,
6+
but WITHOUT ANY WARRANTY; without even the implied warranty of
7+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
*/
9+
using UnityEngine;
10+
using UGUI = UnityEngine.GUI;
11+
12+
namespace ModuleManager.GUI
13+
{
14+
#if KSP12
15+
public class ReloadingDatabaseDialog
16+
{
17+
internal static ReloadingDatabaseDialog Show(ModuleManager parent, bool startedReload)
18+
{
19+
return new ReloadingDatabaseDialog(parent, startedReload);
20+
}
21+
22+
internal Menu Dismiss()
23+
{
24+
this.instance.Dismiss();
25+
this.instance = null;
26+
return null;
27+
}
28+
29+
private ModuleManager parent;
30+
private PopupDialog instance;
31+
private ReloadingDatabaseDialog(ModuleManager parent, bool startedReload)
32+
{
33+
this.parent = parent;
34+
}
35+
}
36+
#endif
37+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
This file is part of Module Manager /L
3+
(C) 2020 Lisias T : http://lisias.net <support@lisias.net>
4+
5+
Module Manager /L is distributed in the hope that it will be useful,
6+
but WITHOUT ANY WARRANTY; without even the implied warranty of
7+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
*/
9+
using UnityEngine;
10+
using UGUI = UnityEngine.GUI;
11+
12+
namespace ModuleManager.GUI
13+
{
14+
#if !KSP12
15+
public class ReloadingDatabaseDialog
16+
{
17+
internal static ReloadingDatabaseDialog Show(ModuleManager parent, bool startedReload)
18+
{
19+
return new ReloadingDatabaseDialog(parent, startedReload);
20+
}
21+
22+
internal Menu Dismiss()
23+
{
24+
this.instance.Dismiss();
25+
this.instance = null;
26+
return null;
27+
}
28+
29+
private ModuleManager parent;
30+
private PopupDialog instance;
31+
private ReloadingDatabaseDialog(ModuleManager parent, bool startedReload)
32+
{
33+
this.parent = parent;
34+
35+
UISkinDef skinDef = HighLogic.UISkin;
36+
UIStyle centeredTextStyle = new UIStyle() // FIXME: There must be a smarter way to do that on Unity5, right?
37+
{
38+
name = skinDef.label.name,
39+
normal = skinDef.label.normal,
40+
highlight = skinDef.label.highlight,
41+
disabled = skinDef.label.disabled,
42+
font = skinDef.label.font,
43+
fontSize = skinDef.label.fontSize,
44+
fontStyle = skinDef.label.fontStyle,
45+
wordWrap = skinDef.label.wordWrap,
46+
richText = skinDef.label.richText,
47+
alignment = TextAnchor.UpperCenter,
48+
clipping = skinDef.label.clipping,
49+
lineHeight = skinDef.label.lineHeight,
50+
stretchHeight = skinDef.label.stretchHeight,
51+
stretchWidth = skinDef.label.stretchWidth,
52+
fixedHeight = skinDef.label.fixedHeight,
53+
fixedWidth = skinDef.label.fixedWidth
54+
};
55+
56+
float totalLoadWeight = GameDatabase.Instance.LoadWeight() + PartLoader.Instance.LoadWeight();
57+
58+
PopupDialog reloadingDialog = PopupDialog.SpawnPopupDialog(
59+
new Vector2(0.5f, 0.5f),
60+
new Vector2(0.5f, 0.5f),
61+
new MultiOptionDialog(
62+
"ModuleManagerReloading",
63+
"",
64+
"ModuleManager - Reloading Database",
65+
skinDef,
66+
new Rect(0.5f, 0.5f, 600f, 60f),
67+
new DialogGUIFlexibleSpace(),
68+
new DialogGUIVerticalLayout(
69+
new DialogGUIFlexibleSpace(),
70+
new DialogGUILabel(delegate ()
71+
{
72+
float progressFraction;
73+
if (!startedReload)
74+
{
75+
progressFraction = 0f;
76+
}
77+
else if (!GameDatabase.Instance.IsReady() || !PostPatchLoader.Instance.IsReady())
78+
{
79+
progressFraction = GameDatabase.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight();
80+
progressFraction /= totalLoadWeight;
81+
}
82+
else if (!PartLoader.Instance.IsReady())
83+
{
84+
progressFraction = GameDatabase.Instance.LoadWeight() + (PartLoader.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight());
85+
progressFraction /= totalLoadWeight;
86+
}
87+
else
88+
{
89+
progressFraction = 1f;
90+
}
91+
92+
return $"Overall progress: {progressFraction:P0}";
93+
}, centeredTextStyle, expandW: true),
94+
new DialogGUILabel(delegate ()
95+
{
96+
if (!startedReload)
97+
return "Starting";
98+
else if (!GameDatabase.Instance.IsReady())
99+
return GameDatabase.Instance.ProgressTitle();
100+
else if (!PostPatchLoader.Instance.IsReady())
101+
return PostPatchLoader.Instance.ProgressTitle();
102+
else if (!PartLoader.Instance.IsReady())
103+
return PartLoader.Instance.ProgressTitle();
104+
else
105+
return "";
106+
}),
107+
new DialogGUISpace(5f),
108+
new DialogGUILabel(() => this.parent.patchRunner.Status)
109+
)
110+
),
111+
false,
112+
skinDef);
113+
}
114+
}
115+
#endif
116+
}

0 commit comments

Comments
 (0)