Skip to content

Commit

Permalink
Show a loading popup while generating paramDB
Browse files Browse the repository at this point in the history
  • Loading branch information
ExplosBlue committed Nov 11, 2023
1 parent 4bc3a87 commit e273262
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions Fushigi/param/ParamDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public static void Reload()
sComponents.Clear();
sRails.Clear();
sRailParamList.Clear();
sIsInit = false;
Load();
}

Expand Down
12 changes: 9 additions & 3 deletions Fushigi/ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void LoadFromSettings(GL gl)
if (!ParamDB.sIsInit && !string.IsNullOrEmpty(RomFS.GetRoot()))
{
Console.WriteLine("Parameter database needs to be initialized...");
ParamDB.Load();
mIsGeneratingParamDB = true;
}

string? latestCourse = UserSettings.GetLatestCourse();
Expand Down Expand Up @@ -183,8 +183,7 @@ void DrawMainMenu(GL gl)
}

if (ImGui.MenuItem("Regenerate Parameter Database", ParamDB.sIsInit)) {
ParamDB.sIsInit = false;
ParamDB.Reload();
mIsGeneratingParamDB = true;
}

/* end Edit menu */
Expand Down Expand Up @@ -298,6 +297,12 @@ public void Render(GL gl, double delta, ImGuiController controller)
{
DrawWelcome();
}

if (mIsGeneratingParamDB)
{
ParamDBDialog.Draw(ref mIsGeneratingParamDB);
}

}

//Update viewport from any framebuffers being used
Expand All @@ -313,5 +318,6 @@ public void Render(GL gl, double delta, ImGuiController controller)
bool mIsChoosingCourse = true;
bool mIsChoosingPreferences = true;
bool mIsWelcome = true;
bool mIsGeneratingParamDB = false;
}
}
42 changes: 42 additions & 0 deletions Fushigi/ui/widgets/ParamDBDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Fushigi.param;
using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Fushigi.ui.widgets
{
class ParamDBDialog
{
static Task? mLoadParamDB;

public static void Draw(ref bool shouldDraw)
{
mLoadParamDB ??= ParamDB.sIsInit ? Task.Run(ParamDB.Reload) : Task.Run(ParamDB.Load);

if (mLoadParamDB.IsCompleted)
{
shouldDraw = false;
mLoadParamDB = null;
return;
}

Vector2 center = ImGui.GetMainViewport().GetCenter();
ImGui.SetNextWindowPos(center, ImGuiCond.Appearing, new Vector2(0.5f, 0.5f));

ImGui.OpenPopup("ParamDB");

if (ImGui.BeginPopupModal("ParamDB", ref shouldDraw, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoDecoration))
{
ImGui.Text("Generating ParamDB...");
// TODO: replace this progress bar with an animated loading bar
ImGui.ProgressBar(0.33f, new Vector2(0, 0), "Loading...");

ImGui.EndPopup();
}
}
}
}
10 changes: 8 additions & 2 deletions Fushigi/ui/widgets/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ class Preferences
static readonly Vector4 errCol = new Vector4(1f, 0, 0, 1);
static bool romfsTouched = false;
static bool modRomfsTouched = false;
static bool mIsGeneratingParamDB = false;

public static void Draw(ref bool continueDisplay)
{
if (mIsGeneratingParamDB)
{
ParamDBDialog.Draw(ref mIsGeneratingParamDB);
}

ImGui.SetNextWindowSize(new Vector2(700, 250), ImGuiCond.Once);
if (ImGui.Begin("Preferences", ImGuiWindowFlags.NoDocking))
{
Expand All @@ -39,11 +45,11 @@ public static void Draw(ref bool continueDisplay)

RomFS.SetRoot(romfs);
ChildActorParam.Load();

/* if our parameter database isn't set, set it */
if (!ParamDB.sIsInit)
{
ParamDB.Load();
mIsGeneratingParamDB = true;
}
}

Expand Down

0 comments on commit e273262

Please sign in to comment.