forked from KSP-ModularManagement/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReloadingDatabase.cs
More file actions
124 lines (114 loc) · 3.73 KB
/
Copy pathReloadingDatabase.cs
File metadata and controls
124 lines (114 loc) · 3.73 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
/*
This file is part of Module Manager /L
© 2018-2023 LisiasT
Module Manager /L is licensed as follows:
* GPL 3.0 : https://www.gnu.org/licenses/gpl-3.0.txt
Module Manager /L is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License 3.0
along with Module Manager /L. If not, see <https://www.gnu.org/licenses/>.
*/
using UnityEngine;
using UGUI = UnityEngine.GUI;
namespace ModuleManager.GUI
{
#if !KSP12
public class ReloadingDatabaseDialog
{
internal static ReloadingDatabaseDialog Show(ModuleManager parent)
{
return new ReloadingDatabaseDialog(parent);
}
internal ReloadingDatabaseDialog Dismiss()
{
this.instance.Dismiss();
this.instance = null;
return null;
}
private ModuleManager parent;
private PopupDialog instance;
private ReloadingDatabaseDialog(ModuleManager parent)
{
bool startedReload = false;
this.parent = parent;
UISkinDef skinDef = HighLogic.UISkin;
UIStyle centeredTextStyle = new UIStyle() // FIXME: There must be a smarter way to do that on Unity5, right?
{
name = skinDef.label.name,
normal = skinDef.label.normal,
highlight = skinDef.label.highlight,
disabled = skinDef.label.disabled,
font = skinDef.label.font,
fontSize = skinDef.label.fontSize,
fontStyle = skinDef.label.fontStyle,
wordWrap = skinDef.label.wordWrap,
richText = skinDef.label.richText,
alignment = TextAnchor.UpperCenter,
clipping = skinDef.label.clipping,
lineHeight = skinDef.label.lineHeight,
stretchHeight = skinDef.label.stretchHeight,
stretchWidth = skinDef.label.stretchWidth,
fixedHeight = skinDef.label.fixedHeight,
fixedWidth = skinDef.label.fixedWidth
};
float totalLoadWeight = GameDatabase.Instance.LoadWeight() + PartLoader.Instance.LoadWeight();
PopupDialog reloadingDialog = PopupDialog.SpawnPopupDialog(
new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
new MultiOptionDialog(
"ModuleManagerReloading",
"",
"ModuleManager - Reloading Database",
skinDef,
new Rect(0.5f, 0.5f, 600f, 60f),
new DialogGUIFlexibleSpace(),
new DialogGUIVerticalLayout(
new DialogGUIFlexibleSpace(),
new DialogGUILabel(delegate ()
{
float progressFraction;
if (!startedReload)
{
progressFraction = 0f;
startedReload = true;
}
else if (!GameDatabase.Instance.IsReady() || !PostPatchLoader.Instance.IsReady())
{
progressFraction = GameDatabase.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight();
progressFraction /= totalLoadWeight;
}
else if (!PartLoader.Instance.IsReady())
{
progressFraction = GameDatabase.Instance.LoadWeight() + (PartLoader.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight());
progressFraction /= totalLoadWeight;
}
else
{
progressFraction = 1f;
}
return $"Overall progress: {progressFraction:P0}";
}, centeredTextStyle, expandW: true),
new DialogGUILabel(delegate ()
{
if (!startedReload)
return "Starting";
else if (!GameDatabase.Instance.IsReady())
return GameDatabase.Instance.ProgressTitle();
else if (!PostPatchLoader.Instance.IsReady())
return PostPatchLoader.Instance.ProgressTitle();
else if (!PartLoader.Instance.IsReady())
return PartLoader.Instance.ProgressTitle();
else
return "";
}),
new DialogGUISpace(5f),
new DialogGUILabel(() => this.parent.patchRunner.Status)
)
),
false,
skinDef);
}
}
#endif
}