Skip to content

Commit ed78083

Browse files
committed
Replace reloading screen messages with dialog
1 parent aeca335 commit ed78083

1 file changed

Lines changed: 70 additions & 22 deletions

File tree

ModuleManager/ModuleManager.cs

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public class ModuleManager : MonoBehaviour
2020

2121
private bool inRnDCenter;
2222

23-
private bool reloading;
24-
2523
public bool showUI = false;
2624

2725
private Rect windowPos = new Rect(80f, 60f, 240f, 40f);
@@ -296,19 +294,6 @@ internal void Update()
296294
errors.transform.localPosition = new Vector3(0, offsetY);
297295
}
298296
}
299-
300-
if (reloading)
301-
{
302-
float percent = 0;
303-
if (!GameDatabase.Instance.IsReady())
304-
percent = GameDatabase.Instance.ProgressFraction();
305-
else if (!PartLoader.Instance.IsReady())
306-
percent = 2f + PartLoader.Instance.ProgressFraction();
307-
308-
int intPercent = Mathf.CeilToInt(percent * 100f / 3f);
309-
ScreenMessages.PostScreenMessage("Database reloading " + intPercent + "%", Time.deltaTime,
310-
ScreenMessageStyle.UPPER_CENTER);
311-
}
312297
}
313298

314299
#region GUI stuff.
@@ -323,20 +308,83 @@ public static bool IsABadIdea()
323308

324309
private IEnumerator DataBaseReloadWithMM(bool dump = false)
325310
{
326-
reloading = true;
327-
328311
QualitySettings.vSyncCount = 0;
329312
Application.targetFrameRate = -1;
330313

331-
ScreenMessages.PostScreenMessage("Database reloading started", 1, ScreenMessageStyle.UPPER_CENTER);
314+
patchRunner = new MMPatchRunner(new ModLogger("ModuleManager", new UnityLogger(Debug.unityLogger)));
315+
316+
float totalLoadWeight = GameDatabase.Instance.LoadWeight() + PartLoader.Instance.LoadWeight();
317+
bool startedReload = false;
318+
319+
UISkinDef skinDef = HighLogic.UISkin;
320+
UIStyle centeredTextStyle = new UIStyle(skinDef.label)
321+
{
322+
alignment = TextAnchor.UpperCenter
323+
};
324+
325+
PopupDialog reloadingDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
326+
new Vector2(0.5f, 0.5f),
327+
new MultiOptionDialog(
328+
"ModuleManagerReloading",
329+
"",
330+
"ModuleManager - Reloading Database",
331+
skinDef,
332+
new Rect(0.5f, 0.5f, 600f, 60f),
333+
new DialogGUIFlexibleSpace(),
334+
new DialogGUIVerticalLayout(
335+
new DialogGUIFlexibleSpace(),
336+
new DialogGUILabel(delegate ()
337+
{
338+
float progressFraction;
339+
if (!startedReload)
340+
{
341+
progressFraction = 0f;
342+
}
343+
else if (!GameDatabase.Instance.IsReady())
344+
{
345+
progressFraction = GameDatabase.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight();
346+
progressFraction /= totalLoadWeight;
347+
}
348+
else if (!PartLoader.Instance.IsReady())
349+
{
350+
progressFraction = GameDatabase.Instance.LoadWeight() + (PartLoader.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight());
351+
progressFraction /= totalLoadWeight;
352+
}
353+
else
354+
{
355+
progressFraction = 1f;
356+
}
357+
358+
return $"Overall progress: {progressFraction:P0}";
359+
}, centeredTextStyle, expandW: true),
360+
new DialogGUILabel(delegate ()
361+
{
362+
if (!startedReload)
363+
return "Starting";
364+
else if (!GameDatabase.Instance.IsReady())
365+
return GameDatabase.Instance.ProgressTitle();
366+
else if (!PostPatchLoader.Instance.IsReady())
367+
return PostPatchLoader.Instance.ProgressTitle();
368+
else if (!PartLoader.Instance.IsReady())
369+
return PartLoader.Instance.ProgressTitle();
370+
else
371+
return "";
372+
}),
373+
new DialogGUISpace(5f),
374+
new DialogGUILabel(() => patchRunner.Status)
375+
)
376+
),
377+
false,
378+
skinDef);
379+
332380
yield return null;
333381

334382
GameDatabase.Instance.Recompile = true;
335383
GameDatabase.Instance.StartLoad();
336384

337-
yield return null;
385+
startedReload = true;
338386

339-
patchRunner = new MMPatchRunner(new ModLogger("ModuleManager", new UnityLogger(Debug.unityLogger)));
387+
yield return null;
340388
StartCoroutine(patchRunner.Run());
341389

342390
// wait for it to finish
@@ -372,8 +420,8 @@ private IEnumerator DataBaseReloadWithMM(bool dump = false)
372420

373421
QualitySettings.vSyncCount = GameSettings.SYNC_VBL;
374422
Application.targetFrameRate = GameSettings.FRAMERATE_LIMIT;
375-
reloading = false;
376-
ScreenMessages.PostScreenMessage("Database reloading finished", 1, ScreenMessageStyle.UPPER_CENTER);
423+
424+
reloadingDialog.Dismiss();
377425
}
378426

379427
public static void OutputAllConfigs()

0 commit comments

Comments
 (0)