mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 05:05:56 +00:00
Merge pull request #978: draw amiibo file names in any script in the F1 menu (KyokoMiki)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7e440be7ca
3 files changed
+59
-1
No files matched your search
@@ -36,6 +36,8 @@ static int g_selected_entry = -1;
|
||||
// The last action: a catalog id and the file or folder it names, formatted when drawn (the menu language can change)
|
||||
static UiTextId g_status_id = UI_MENU_AMIIBO_READY;
|
||||
static std::string g_status_arg;
|
||||
// Flag to request font rebuild (set when amiibo directory is refreshed with new files)
|
||||
static bool g_font_rebuild_requested = false;
|
||||
|
||||
static void set_status(UiTextId id, const std::string &arg = std::string()) {
|
||||
g_status_id = id;
|
||||
@@ -124,6 +126,9 @@ static void refresh_dir(void) {
|
||||
if (a.is_dir != b.is_dir) return a.is_dir;
|
||||
return a.name < b.name;
|
||||
});
|
||||
|
||||
// Request font rebuild to include any new filenames
|
||||
amiibo_request_font_rebuild();
|
||||
}
|
||||
|
||||
void tab_amiibo(float scale) {
|
||||
@@ -303,3 +308,44 @@ void tab_amiibo(float scale) {
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
// Collect amiibo filenames for font glyph building (called from menu.cpp fonts_up)
|
||||
void amiibo_collect_filenames(void (*callback)(void *, const char *), void *ctx) {
|
||||
std::error_code ec;
|
||||
fs::path dir_path(g_current_dir);
|
||||
|
||||
if (!fs::exists(dir_path, ec) || !fs::is_directory(dir_path, ec)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &entry : fs::directory_iterator(dir_path, fs::directory_options::skip_permission_denied, ec)) {
|
||||
if (ec) break;
|
||||
std::error_code status_ec;
|
||||
bool is_dir = entry.is_directory(status_ec);
|
||||
if (status_ec || is_dir) continue;
|
||||
|
||||
std::string ext = entry.path().extension().string();
|
||||
if (!iequals(ext, ".bin") && !iequals(ext, ".nfc")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string filename = entry.path().filename().string();
|
||||
if (!filename.empty()) {
|
||||
callback(ctx, filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Request font atlas rebuild on next frame
|
||||
void amiibo_request_font_rebuild(void) {
|
||||
g_font_rebuild_requested = true;
|
||||
}
|
||||
|
||||
// Check and clear font rebuild request flag
|
||||
extern "C" bool amiibo_check_font_rebuild(void) {
|
||||
if (g_font_rebuild_requested) {
|
||||
g_font_rebuild_requested = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2,3 +2,9 @@
|
||||
#pragma once
|
||||
|
||||
void tab_amiibo(float scale);
|
||||
|
||||
// Collect amiibo filenames for font glyph building (called from menu.cpp fonts_up)
|
||||
void amiibo_collect_filenames(void (*callback)(void *, const char *), void *ctx);
|
||||
|
||||
// Request font atlas rebuild on next frame (called when amiibo directory is refreshed)
|
||||
void amiibo_request_font_rebuild(void);
|
||||
+7
-1
@@ -59,6 +59,7 @@ extern const char rt_port_version[];
|
||||
void cheats_frame(uint64_t frame); // cheats.c
|
||||
bool tab_cheats(float scale); // ui/cheats_tab.cpp; true: restart into the rebuild
|
||||
int playtime_get(uint64_t *total_s, uint64_t *session_s); // playtime.c
|
||||
bool amiibo_check_font_rebuild(void); // ui/amiibo_page.cpp; check and clear font rebuild request
|
||||
}
|
||||
|
||||
// Roboto Medium (Apache-2.0, ui/fonts/LICENSE-Roboto.txt) with Latin and Cyrillic glyphs.
|
||||
@@ -354,6 +355,9 @@ static int fonts_up(float scale) {
|
||||
if (const CheatInfo *ci = cheats_info(k); ci && ci->name) b.AddText(ci->name);
|
||||
for (int k = 0; k < mods_count(); k++)
|
||||
if (const ModInfo *mi = mods_at(k); mi) b.AddText(mi->name);
|
||||
// Add amiibo filenames so they display correctly in the menu
|
||||
amiibo_collect_filenames(add_row_glyphs, &b);
|
||||
|
||||
b.BuildRanges(&ranges[i]);
|
||||
ImFontConfig mc;
|
||||
mc.MergeMode = true;
|
||||
@@ -1555,7 +1559,9 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
uint64_t t0 = plat_now_ns();
|
||||
if (!g_ctx_ok) make_context();
|
||||
float scale = menu_scale(t->height);
|
||||
if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale))) {
|
||||
// Check if amiibo page requested font rebuild (e.g., after refreshing directory with new files)
|
||||
bool amiibo_rebuild = amiibo_check_font_rebuild();
|
||||
if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale)) || (amiibo_rebuild && !fonts_up(scale))) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; the menu stays closed");
|
||||
g_failed.store(1);
|
||||
set_open(0);
|
||||
|
||||
Reference in new issue
Block a user