Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/shibbo/Fushigi
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Nov 21, 2023
2 parents 496c30b + f3776dc commit 98c1ba0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
27 changes: 17 additions & 10 deletions Fushigi/RomFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Fushigi
{
public class RomFS
{
public static void SetRoot(string root)
public static void SetRoot(string root, GL gl)
{
if (!IsValidRoot(root))
{
Expand All @@ -22,6 +22,7 @@ public static void SetRoot(string root)

sRomFSRoot = root;
CacheCourseFiles();
CacheCourseThumbnails(gl);
}

public static string GetRoot()
Expand Down Expand Up @@ -120,14 +121,22 @@ private static void CacheCourseFiles()
}
}

public static void CacheCourseThumbnails(GL gl)
{
foreach (var world in sCourseEntries.Keys)
{
CacheCourseThumbnails(gl, world);
}
}

public static void CacheCourseThumbnails(GL gl, string world)
{
var thumbnailFolder = Path.Combine(GetRoot(), "UI", "Tex", "Thumbnail");

foreach (var course in sCourseEntries[world].courseEntries.Keys)
foreach (var course in sCourseEntries[world].courseEntries!.Keys)
{
// Skip the process if this course's thumbnail is already cached
if (sCourseEntries[world].courseEntries[course].thumbnail != null)
if (sCourseEntries[world].courseEntries![course].thumbnail != null)
{
continue;
}
Expand All @@ -139,26 +148,24 @@ public static void CacheCourseThumbnails(GL gl, string world)
path = Path.Combine(thumbnailFolder, "Default.bntx.zs");
}

Console.WriteLine($"Thumbnail - {course}");

byte[] fileBytes = FileUtil.DecompressFile(path);
var bntx = new BntxFile(new MemoryStream(fileBytes));
var render = new BfresTextureRender(gl, bntx.Textures[0]);

sCourseEntries[world].courseEntries[course].thumbnail = render;
sCourseEntries[world].courseEntries![course].thumbnail = render;
}
}

public class WorldEntry
{
public class CourseEntry
{
public string name;
public BfresTextureRender thumbnail;
public string? name;
public BfresTextureRender? thumbnail;
}

public string name;
public Dictionary<string, CourseEntry> courseEntries;
public string? name;
public Dictionary<string, CourseEntry>? courseEntries;
}


Expand Down
34 changes: 18 additions & 16 deletions Fushigi/ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,23 @@ void LoadFromSettings(GL gl)
string romFSPath = UserSettings.GetRomFSPath();
if (RomFS.IsValidRoot(romFSPath))
{
RomFS.SetRoot(romFSPath);
RomFS.SetRoot(romFSPath, gl);
ChildActorParam.Load();

if (!ParamDB.sIsInit)
{
Console.WriteLine("Parameter database needs to be initialized...");
mIsGeneratingParamDB = true;
}

string? latestCourse = UserSettings.GetLatestCourse();
if (latestCourse != null && ParamDB.sIsInit)
{
mCurrentCourseName = latestCourse;
mSelectedCourseScene = new(new(mCurrentCourseName), gl);
mIsChoosingPreferences = false;
mIsWelcome = false;
}
}

ActorIconLoader.Init();
Expand All @@ -131,20 +146,7 @@ void LoadFromSettings(GL gl)
mIsWelcome = false;
}

if (!ParamDB.sIsInit && !string.IsNullOrEmpty(RomFS.GetRoot()))
{
Console.WriteLine("Parameter database needs to be initialized...");
mIsGeneratingParamDB = true;
}

string? latestCourse = UserSettings.GetLatestCourse();
if (latestCourse != null && ParamDB.sIsInit)
{
mCurrentCourseName = latestCourse;
mSelectedCourseScene = new(new(mCurrentCourseName), gl);
mIsChoosingPreferences = false;
mIsWelcome = false;
}

}

void DrawMainMenu(GL gl)
Expand Down Expand Up @@ -327,7 +329,7 @@ public void Render(GL gl, double delta, ImGuiController controller)

if (mIsChoosingPreferences)
{
Preferences.Draw(ref mIsChoosingPreferences);
Preferences.Draw(ref mIsChoosingPreferences, gl);
}

if (mIsWelcome)
Expand Down
5 changes: 2 additions & 3 deletions Fushigi/ui/widgets/CourseSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ void DrawCourses()
}
ImGui.TableNextRow();

RomFS.CacheCourseThumbnails(gl, selectedWorld!);
var courses = RomFS.GetCourseEntries()[selectedWorld!].courseEntries;

float em = ImGui.GetFrameHeight();

foreach (var course in courses)
foreach (var course in courses!)
{
ImGui.PushID(course.Key);
ImGui.TableNextColumn();
Expand All @@ -128,7 +127,7 @@ void DrawCourses()

dl.PushClipRect(min, max, true);

course.Value.thumbnail.CheckState(false);
course.Value.thumbnail!.CheckState(false);
dl.AddImage((IntPtr)course.Value.thumbnail.ID,
(min + max - thumbnailSize) / 2 - new Vector2(0, em * 1.25f),
(min + max + thumbnailSize) / 2 - new Vector2(0, em * 1.25f));
Expand Down
5 changes: 3 additions & 2 deletions Fushigi/ui/widgets/Preferences.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Fushigi.param;
using Fushigi.util;
using ImGuiNET;
using Silk.NET.OpenGL;
using System.Numerics;

namespace Fushigi.ui.widgets
Expand All @@ -12,7 +13,7 @@ class Preferences
static bool modRomfsTouched = false;
static bool mIsGeneratingParamDB = false;

public static void Draw(ref bool continueDisplay)
public static void Draw(ref bool continueDisplay, GL gl)
{
if (mIsGeneratingParamDB)
{
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void Draw(ref bool continueDisplay)
return;
}

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

/* if our parameter database isn't set, set it */
Expand Down

0 comments on commit 98c1ba0

Please sign in to comment.