mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
Merge remote-tracking branch 'origin/dev' into distant-detail-merge
# Conflicts: # recomp/patches-v121.txt # recomp/patches-v143.txt # runtime/cfg.c # runtime/ui/menu.cpp # totk.ini.example
This commit is contained in:
commit
4403a3f8ea
186 files changed
+20879
-1287
No files matched your search
@@ -0,0 +1,305 @@
|
||||
// Amiibo / NFC menu page (Dear ImGui): browser and scan controls.
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cfloat>
|
||||
#include <filesystem>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "ui/amiibo_page.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "amiibo.h"
|
||||
#include "cfg.h"
|
||||
#include "folder_pick.h"
|
||||
#include "platform/platform.h"
|
||||
#include "ui_text.h"
|
||||
}
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
struct FileEntry {
|
||||
std::string name;
|
||||
bool is_dir;
|
||||
};
|
||||
|
||||
static const char kDefaultAmiiboDir[] = "./amiibo";
|
||||
static std::string g_current_dir = kDefaultAmiiboDir;
|
||||
static std::vector<FileEntry> g_entries;
|
||||
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;
|
||||
|
||||
static void set_status(UiTextId id, const std::string &arg = std::string()) {
|
||||
g_status_id = id;
|
||||
g_status_arg = arg;
|
||||
}
|
||||
|
||||
// Loads a dump and puts it on the reader; the status names the file.
|
||||
static void tap(const std::string &dir, const std::string &name) {
|
||||
std::string full_path = (fs::path(dir) / name).string();
|
||||
set_status(amiibo_scan_and_tap(full_path.c_str()) ? UI_MENU_AMIIBO_TAPPED : UI_MENU_AMIIBO_LOAD_FAILED, name);
|
||||
}
|
||||
|
||||
static bool iequals(std::string_view a, std::string_view b) {
|
||||
if (a.size() != b.size()) return false;
|
||||
for (size_t i = 0; i < a.size(); ++i) {
|
||||
if (std::tolower(static_cast<unsigned char>(a[i])) !=
|
||||
std::tolower(static_cast<unsigned char>(b[i]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void set_current_dir(const std::string &path) {
|
||||
g_current_dir = path;
|
||||
cfg_set("TOTK_AMIIBO_DIR", g_current_dir.c_str());
|
||||
}
|
||||
|
||||
// The host's folder dialog (folder_pick.h) answers on its own thread; the page takes the answer when it draws.
|
||||
static PlatMutex g_pick_lock = PLAT_MUTEX_INIT;
|
||||
static bool g_pick_open;
|
||||
static bool g_pick_ready;
|
||||
static std::string g_pick_path;
|
||||
|
||||
static void on_folder_picked(const char *path, void *ctx) {
|
||||
(void)ctx;
|
||||
plat_mutex_lock(&g_pick_lock);
|
||||
g_pick_ready = path != NULL;
|
||||
if (path) g_pick_path = path;
|
||||
g_pick_open = false;
|
||||
plat_mutex_unlock(&g_pick_lock);
|
||||
}
|
||||
|
||||
static void refresh_dir(void) {
|
||||
g_entries.clear();
|
||||
g_selected_entry = -1;
|
||||
|
||||
std::error_code ec;
|
||||
fs::path dir_path(g_current_dir);
|
||||
|
||||
// A missing folder lists nothing and says so; it is not replaced by another one, and opening the tab writes no
|
||||
// setting (the folder is saved only when the player sets one).
|
||||
if (!fs::exists(dir_path, ec) || !fs::is_directory(dir_path, ec)) {
|
||||
set_status(UI_MENU_AMIIBO_NO_DIR, g_current_dir);
|
||||
return;
|
||||
}
|
||||
if (g_status_id == UI_MENU_AMIIBO_NO_DIR) set_status(UI_MENU_AMIIBO_READY);
|
||||
|
||||
// Add parent navigation if not at root
|
||||
if (dir_path.has_parent_path() && dir_path != dir_path.parent_path()) {
|
||||
g_entries.push_back({"..", true});
|
||||
}
|
||||
|
||||
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) continue;
|
||||
|
||||
std::string filename = entry.path().filename().string();
|
||||
if (filename.empty() || filename == "." || filename == "..") continue;
|
||||
|
||||
if (!is_dir) {
|
||||
std::string ext = entry.path().extension().string();
|
||||
if (!iequals(ext, ".bin") && !iequals(ext, ".nfc")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
g_entries.push_back({std::move(filename), is_dir});
|
||||
}
|
||||
|
||||
std::sort(g_entries.begin(), g_entries.end(), [](const FileEntry &a, const FileEntry &b) {
|
||||
if (a.name == "..") return true;
|
||||
if (b.name == "..") return false;
|
||||
if (a.is_dir != b.is_dir) return a.is_dir;
|
||||
return a.name < b.name;
|
||||
});
|
||||
}
|
||||
|
||||
void tab_amiibo(float scale) {
|
||||
(void)scale; // the rows take ImGui's own sizes, already scaled with the font
|
||||
static bool s_inited = false;
|
||||
if (!s_inited) {
|
||||
const char *cfg_dir = cfg_get("TOTK_AMIIBO_DIR");
|
||||
if (cfg_dir && *cfg_dir) {
|
||||
g_current_dir = cfg_dir;
|
||||
} else {
|
||||
g_current_dir = kDefaultAmiiboDir;
|
||||
}
|
||||
refresh_dir();
|
||||
s_inited = true;
|
||||
}
|
||||
|
||||
plat_mutex_lock(&g_pick_lock);
|
||||
bool picking = g_pick_open;
|
||||
std::string picked;
|
||||
if (g_pick_ready) picked.swap(g_pick_path);
|
||||
g_pick_ready = false;
|
||||
plat_mutex_unlock(&g_pick_lock);
|
||||
if (!picked.empty()) {
|
||||
set_current_dir(picked);
|
||||
refresh_dir();
|
||||
}
|
||||
|
||||
// Two panes: Left (Directory Browser & Tag List), Right (Amiibo Tag Details & Controls)
|
||||
const float content_h = ImGui::GetContentRegionAvail().y - opt_bottom(); // Continue and Quit stay visible
|
||||
const float left_w = ImGui::GetContentRegionAvail().x * 0.58f;
|
||||
const float right_w = ImGui::GetContentRegionAvail().x - left_w - ImGui::GetStyle().ItemSpacing.x;
|
||||
|
||||
// ---- Left Pane: Explorer & List ----
|
||||
ImGui::BeginChild("##amiibo_explorer", ImVec2(left_w, content_h), true);
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1.0f), "%s", menu_text(UI_MENU_AMIIBO_DIR));
|
||||
|
||||
ImGui::TextWrapped("%s", g_current_dir.c_str());
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::BeginDisabled(picking);
|
||||
if (ImGui::Button(menu_text(UI_MENU_AMIIBO_OPEN))) {
|
||||
plat_mutex_lock(&g_pick_lock);
|
||||
g_pick_open = true;
|
||||
plat_mutex_unlock(&g_pick_lock);
|
||||
folder_pick(g_current_dir.c_str(), on_folder_picked, NULL);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(menu_text(UI_MENU_AMIIBO_DEFAULT_DIR))) {
|
||||
set_current_dir(kDefaultAmiiboDir);
|
||||
refresh_dir();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(menu_text(UI_MENU_AMIIBO_REFRESH))) {
|
||||
refresh_dir();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::TextDisabled("%s", menu_text(UI_MENU_AMIIBO_PICK));
|
||||
|
||||
ImGui::BeginChild("##file_list", ImVec2(0, 0), true);
|
||||
if (g_status_id == UI_MENU_AMIIBO_NO_DIR) {
|
||||
char missing[512];
|
||||
snprintf(missing, sizeof missing, menu_text(UI_MENU_AMIIBO_NO_DIR), g_current_dir.c_str());
|
||||
ImGui::TextWrapped("%s", missing);
|
||||
}
|
||||
for (size_t i = 0; i < g_entries.size(); i++) {
|
||||
const auto &e = g_entries[i];
|
||||
std::string label = e.is_dir ? e.name + "/" : e.name;
|
||||
bool selected = ((int)i == g_selected_entry);
|
||||
|
||||
if (ImGui::Selectable(label.c_str(), selected, ImGuiSelectableFlags_AllowDoubleClick)) {
|
||||
g_selected_entry = (int)i;
|
||||
if (e.is_dir) {
|
||||
if (ImGui::IsMouseDoubleClicked(0) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceDown)) {
|
||||
if (e.name == "..") {
|
||||
fs::path cur(g_current_dir);
|
||||
if (cur.has_parent_path() && cur != cur.parent_path()) {
|
||||
set_current_dir(cur.parent_path().string());
|
||||
} else {
|
||||
set_current_dir(".");
|
||||
}
|
||||
} else {
|
||||
set_current_dir((fs::path(g_current_dir) / e.name).string());
|
||||
}
|
||||
refresh_dir();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (ImGui::IsMouseDoubleClicked(0)) tap(g_current_dir, e.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
// ---- Right Pane: Controls & Status ----
|
||||
ImGui::BeginChild("##amiibo_controls", ImVec2(right_w, content_h), true);
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1.0f), "%s", menu_text(UI_MENU_AMIIBO_READER));
|
||||
ImGui::Separator();
|
||||
|
||||
AmiiboDeviceState state = amiibo_get_reader_state();
|
||||
UiTextId state_id = UI_MENU_AMIIBO_STATE_IDLE;
|
||||
ImVec4 state_col = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
switch (state) {
|
||||
case AMIIBO_DEV_STATE_INITIALIZED: state_id = UI_MENU_AMIIBO_STATE_IDLE; break;
|
||||
case AMIIBO_DEV_STATE_SEARCHING: state_id = UI_MENU_AMIIBO_STATE_SEARCHING; state_col = ImVec4(1.0f, 0.8f, 0.2f, 1.0f); break;
|
||||
case AMIIBO_DEV_STATE_TAG_FOUND: state_id = UI_MENU_AMIIBO_STATE_FOUND; state_col = ImVec4(0.3f, 0.9f, 0.3f, 1.0f); break;
|
||||
case AMIIBO_DEV_STATE_TAG_MOUNTED: state_id = UI_MENU_AMIIBO_STATE_MOUNTED; state_col = ImVec4(0.2f, 0.9f, 1.0f, 1.0f); break;
|
||||
case AMIIBO_DEV_STATE_UNAVAILABLE: state_id = UI_MENU_AMIIBO_STATE_OFF; state_col = ImVec4(0.9f, 0.3f, 0.3f, 1.0f); break;
|
||||
default: break;
|
||||
}
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_AMIIBO_STATE));
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(state_col, "%s", menu_text(state_id));
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_AMIIBO_FILE));
|
||||
if (g_selected_entry >= 0 && g_selected_entry < (int)g_entries.size() && !g_entries[g_selected_entry].is_dir) {
|
||||
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.4f, 1.0f), "%s", g_entries[g_selected_entry].name.c_str());
|
||||
|
||||
if (ImGui::Button(menu_text(UI_MENU_AMIIBO_TAP), ImVec2(ImGui::GetContentRegionAvail().x, 0)))
|
||||
tap(g_current_dir, g_entries[g_selected_entry].name);
|
||||
} else {
|
||||
ImGui::TextDisabled("%s", menu_text(UI_MENU_AMIIBO_NO_FILE));
|
||||
ImGui::BeginDisabled();
|
||||
ImGui::Button(menu_text(UI_MENU_AMIIBO_TAP), ImVec2(ImGui::GetContentRegionAvail().x, 0));
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
if (ImGui::Button(menu_text(UI_MENU_AMIIBO_REMOVE), ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
|
||||
amiibo_remove_tag();
|
||||
set_status(UI_MENU_AMIIBO_REMOVED);
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
bool auto_remove = amiibo_get_auto_remove();
|
||||
if (ImGui::Checkbox(menu_text(UI_MENU_AMIIBO_AUTO_REMOVE), &auto_remove)) {
|
||||
amiibo_set_auto_remove(auto_remove);
|
||||
}
|
||||
if (auto_remove) {
|
||||
float delay = amiibo_get_auto_remove_delay_s();
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_AMIIBO_HOLD)); // above the slider: beside it the text is cut off
|
||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||
if (ImGui::SliderFloat("##amiibo_hold", &delay, 1.0f, 6.0f, menu_text(UI_MENU_AMIIBO_SECONDS))) {
|
||||
amiibo_set_auto_remove_delay_s(delay);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_AMIIBO_TAG));
|
||||
if (amiibo_has_tag()) {
|
||||
const AmiiboInfo *info = amiibo_get_current_info();
|
||||
char character[8], uid[24];
|
||||
snprintf(character, sizeof character, "%02x%02x%02x", info->character_id[0], info->character_id[1],
|
||||
info->character_id[2]);
|
||||
snprintf(uid, sizeof uid, "%02x:%02x:%02x:%02x:%02x:%02x:%02x", info->uuid[0], info->uuid[1], info->uuid[2],
|
||||
info->uuid[3], info->uuid[4], info->uuid[5], info->uuid[6]);
|
||||
ImGui::Text(menu_text(UI_MENU_AMIIBO_TAG_FILE), info->filename);
|
||||
ImGui::Text(menu_text(UI_MENU_AMIIBO_TAG_ID), character, info->series_id, info->numbering_id, info->nfp_type);
|
||||
ImGui::Text(menu_text(UI_MENU_AMIIBO_TAG_UID), uid);
|
||||
} else {
|
||||
ImGui::TextDisabled("%s", menu_text(UI_MENU_AMIIBO_NO_TAG));
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Separator();
|
||||
char status[512];
|
||||
snprintf(status, sizeof status, menu_text(g_status_id), g_status_arg.c_str());
|
||||
ImGui::TextDisabled(menu_text(UI_MENU_AMIIBO_STATUS), status);
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Amiibo / NFC menu page (ui/amiibo_page.cpp).
|
||||
#pragma once
|
||||
|
||||
void tab_amiibo(float scale);
|
||||
@@ -0,0 +1,66 @@
|
||||
// The Cheats tab of the in-game menu: the cheats of the mods' cheat files (cheats.c), a heading per mod in the Mods
|
||||
// tab's order, then a row per cheat in file order and a line per group label of the file; a cheat that cannot be
|
||||
// switched here is greyed out with the reason. While code cheats wait for a rebuild, a row on top restarts the game
|
||||
// into it.
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cheats.h"
|
||||
#include "ui_text.h"
|
||||
}
|
||||
|
||||
// Returns true when "Rebuild the game now" was chosen: the menu then asks to restart (ui/menu.cpp restart_confirm).
|
||||
extern "C" bool tab_cheats(float scale) {
|
||||
opt_begin("##cheats", scale);
|
||||
static char line[512], desc[768], buttons[192];
|
||||
int n = cheats_count();
|
||||
if (!n) {
|
||||
snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_NONE), cheats_file()[0] ? cheats_file() : "<build id>.txt");
|
||||
opt_text_str(line);
|
||||
opt_end();
|
||||
return false;
|
||||
}
|
||||
bool rebuild =
|
||||
cheats_rebuild_pending() && opt_button("##restart", UI_MENU_CHEATS_REBUILD, UI_MENU_CHEATS_REBUILD_DESC);
|
||||
for (int i = 0; i < n; i++) {
|
||||
const CheatInfo *c = cheats_info(i);
|
||||
if (!i || strcmp(c->mod, cheats_info(i - 1)->mod)) {
|
||||
int listed = 0;
|
||||
for (int j = i; j < n && !strcmp(cheats_info(j)->mod, c->mod); j++)
|
||||
listed += cheats_info(j)->kind != CHEAT_HEADING;
|
||||
snprintf(line, sizeof line, menu_text(UI_MENU_CHEATS_MOD), c->mod, listed);
|
||||
opt_group_text(line);
|
||||
}
|
||||
UiTextId text = UI_MENU_CHEAT_CODE_DESC;
|
||||
switch (c->kind) {
|
||||
case CHEAT_HEADING:
|
||||
if (!strstr(c->name, "TID=")) opt_text_str(c->name); // the file's title line only names the game
|
||||
continue;
|
||||
case CHEAT_CODE: break;
|
||||
case CHEAT_KEY: text = UI_MENU_CHEAT_KEY_DESC; break;
|
||||
case CHEAT_DATA: text = UI_MENU_CHEAT_DATA_DESC; break;
|
||||
case CHEAT_MASTER: text = UI_MENU_CHEAT_MASTER_DESC, opt_disable_next(UI_MENU_CHEAT_MASTER); break;
|
||||
case CHEAT_RESTORE: text = UI_MENU_CHEAT_RESTORE_DESC, opt_disable_next(UI_MENU_CHEAT_RESTORE); break;
|
||||
case CHEAT_REBUILD: text = UI_MENU_CHEAT_REBUILD_DESC, opt_disable_next(UI_MENU_CHEAT_REBUILD); break;
|
||||
case CHEAT_UNSUPPORTED:
|
||||
text = UI_MENU_CHEAT_UNSUPPORTED_DESC, opt_disable_next(UI_MENU_CHEAT_UNSUPPORTED);
|
||||
break;
|
||||
}
|
||||
if (c->kind == CHEAT_KEY)
|
||||
snprintf(desc, sizeof desc, menu_text(text), cheats_buttons(c->buttons, buttons, sizeof buttons));
|
||||
else if (c->kind == CHEAT_UNSUPPORTED)
|
||||
snprintf(desc, sizeof desc, "%s %s", menu_text(text), c->note);
|
||||
else
|
||||
snprintf(desc, sizeof desc, "%s", menu_text(text));
|
||||
if (opt_toggle_text(c->key, c->name, desc, cheats_on(i) != 0)) {
|
||||
cheats_set(i, !cheats_on(i));
|
||||
opt_save_soon();
|
||||
}
|
||||
}
|
||||
opt_end();
|
||||
return rebuild;
|
||||
}
|
||||
+362
-55
@@ -30,13 +30,18 @@ static int g_font_bad;
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#include "imstb_truetype.h"
|
||||
#pragma clang diagnostic pop
|
||||
#include "ui/amiibo_page.h"
|
||||
#include "ui/binds_page.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "amiibo.h"
|
||||
#include "cheats.h"
|
||||
#include "cfg.h"
|
||||
#include "fs.h"
|
||||
#include "input.h"
|
||||
#include "input_map.h"
|
||||
#include "mods.h"
|
||||
#include "perfmon.h"
|
||||
#include "platform/platform.h"
|
||||
#include "sysinfo.h"
|
||||
@@ -49,10 +54,9 @@ void vk_queue_unlock(void);
|
||||
void res_sizes(unsigned out[2], unsigned scene[2]);
|
||||
double frame_step_limit_hz(void);
|
||||
extern const int rt_game_version;
|
||||
// fs.h (romfs.c): romfs-patches-xbox was next to romfs-index.bin at start, and was loaded.
|
||||
int romfs_xbox_prompts_ready(void);
|
||||
int romfs_xbox_prompts_active(void);
|
||||
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
|
||||
}
|
||||
|
||||
// Roboto Medium (Apache-2.0, ui/fonts/LICENSE-Roboto.txt) with Latin and Cyrillic glyphs.
|
||||
@@ -266,7 +270,9 @@ static int vk_up(const MenuTarget *t) {
|
||||
|
||||
// Roboto Medium (Latin, Cyrillic, dashes and quotes) at 26 px per 1080 lines, with the glyphs of the Japanese, Korean
|
||||
// and Chinese language names merged in from a system font when there is one (each language is named in its own script).
|
||||
// Made again when the window height changes; the old texture goes after the queue is idle (CreateFontsTexture).
|
||||
// A catalog row also holds menu text (Simplified Chinese), so every string of the row goes into the builder: the merged
|
||||
// font must cover the whole menu of that language, not only its name. Made again when the window height changes; the old
|
||||
// texture goes after the queue is idle (CreateFontsTexture).
|
||||
static const ImWchar kRanges[] = {0x0020, 0x00FF, 0x0400, 0x052F, 0x2010, 0x2027, 0};
|
||||
static const struct { const char *lang; UiTextId name; } kCjk[] = {
|
||||
{"ja", UI_MENU_LANGNAME_JA}, {"ko", UI_MENU_LANGNAME_KO}, {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS},
|
||||
@@ -310,6 +316,11 @@ extern "C" int menu_font_check(void) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The glyphs of every string of a catalog row (ui_text_visit), for the font that draws that language.
|
||||
static void add_row_glyphs(void *ctx, const char *text) {
|
||||
static_cast<ImFontGlyphRangesBuilder *>(ctx)->AddText(text);
|
||||
}
|
||||
|
||||
static int fonts_up(float scale) {
|
||||
enum { N = sizeof kCjk / sizeof *kCjk };
|
||||
ImFontAtlas *fa = ImGui::GetIO().Fonts;
|
||||
@@ -334,6 +345,13 @@ static int fonts_up(float scale) {
|
||||
merged++;
|
||||
ImFontGlyphRangesBuilder b;
|
||||
b.AddText(ui_text_in("en", kCjk[i].name));
|
||||
ui_text_visit(kCjk[i].lang, add_row_glyphs, &b);
|
||||
// Text the menu shows that no catalog row holds: a mod's cheat names and its folder name,
|
||||
// both read from disk at runtime. Their glyphs would otherwise fall back to the missing-glyph box.
|
||||
for (int k = 0; k < cheats_count(); k++)
|
||||
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);
|
||||
b.BuildRanges(&ranges[i]);
|
||||
ImFontConfig mc;
|
||||
mc.MergeMode = true;
|
||||
@@ -362,7 +380,7 @@ extern "C" void menu_vk_release(void) {
|
||||
// TOTK_MENU_TEST_SET=<frame>:<key>=<value>[,<key>=<value>...][;<frame>:...]: cfg_set of each key (TOTK_ prefix
|
||||
// optional) at that presented frame; changes live settings with no input, menu open or not. totk.ini is written only by
|
||||
// the pseudo-key SAVE=1 (cfg_save, as a row change does; a failed write shows the menu's save note).
|
||||
enum { TAB_SCREEN, TAB_GAME, TAB_SOUND, TAB_CONTROLS, TAB_MENU, TAB_ADVANCED, TAB_COUNT };
|
||||
enum { TAB_SCREEN, TAB_GAME, TAB_SOUND, TAB_CONTROLS, TAB_AMIIBO, TAB_MENU, TAB_ADVANCED, TAB_MODS, TAB_CHEATS, TAB_COUNT };
|
||||
enum { TEST_PAGE_FRAMES = 30, TEST_SETS = 16 };
|
||||
struct TestSet { uint64_t frame; char key[64], value[64]; };
|
||||
static struct {
|
||||
@@ -473,13 +491,15 @@ static void row_window_size(void) {
|
||||
}
|
||||
|
||||
// The game resolution (resolution.c): 16:9 sizes from its smallest, 1280x720 (for weak GPUs), up, the common 21:9 and
|
||||
// 32:9 monitor sizes and the 16:10 screens of the Steam Deck, handhelds and laptops (the camera and the HUD follow
|
||||
// 32:9 monitor sizes, the 16:10 screens of the Steam Deck, handhelds and laptops and the 3:2 screens of laptops and
|
||||
// tablets (Surface, Framework; the camera and the HUD follow
|
||||
// another shape, resolution.c res_init; the installer lays the HUD out for each, installer/steps.py ASPECT_SIZES), and
|
||||
// the current value when it is another size.
|
||||
static void row_output_res(void) {
|
||||
static const char *const vals[] = {"1280x720", "1600x900", "1920x1080", "2560x1440", "3200x1800", "3840x2160",
|
||||
"2560x1080", "3440x1440", "3840x1600", "5120x2160", "3840x1080", "5120x1440",
|
||||
"1280x800", "1680x1050", "1920x1200", "2560x1600"};
|
||||
"1280x800", "1680x1050", "1920x1200", "2560x1600",
|
||||
"1920x1280", "2160x1440", "2256x1504", "2880x1920", "3000x2000"};
|
||||
enum { N = sizeof vals / sizeof *vals };
|
||||
char shown[N][32];
|
||||
const char *names[N];
|
||||
@@ -505,6 +525,27 @@ static void row_render_scale(void) {
|
||||
opt_choice_list("TOTK_RENDER_SCALE", UI_MENU_RENDER_SCALE, vals, names, N, UI_MENU_RENDER_SCALE_DESC);
|
||||
}
|
||||
|
||||
static void row_shadow_res(void) {
|
||||
static const char *const vals[] = {"game", "256", "512", "768", "1024", "1536", "2048"};
|
||||
enum { N = sizeof vals / sizeof *vals };
|
||||
const char *names[N];
|
||||
names[0] = menu_text(UI_MENU_SHADOW_RES_GAME);
|
||||
for (int i = 1; i < N; i++) names[i] = vals[i];
|
||||
opt_choice_list("TOTK_SHADOW_RES", UI_MENU_SHADOW_RES, vals, names, N, UI_MENU_SHADOW_RES_DESC);
|
||||
}
|
||||
|
||||
static void row_shadow_scale(void) {
|
||||
static const char *const vals[] = {"1", "2", "3", "4"};
|
||||
static const char *const names[] = {"960 (1x)", "1920 (2x)", "2880 (3x)", "3840 (4x)"};
|
||||
opt_choice_list("TOTK_SHADOW_SCALE", UI_MENU_SHADOW_SCALE, vals, names, 4, UI_MENU_SHADOW_SCALE_DESC);
|
||||
}
|
||||
|
||||
static void row_shadow_range(void) {
|
||||
static const char *const vals[] = {"100", "150", "200", "300"};
|
||||
static const char *const names[] = {"160 m (1x)", "240 m (1.5x)", "320 m (2x)", "480 m (3x)"};
|
||||
opt_choice_list("TOTK_SHADOW_RANGE", UI_MENU_SHADOW_RANGE, vals, names, 4, UI_MENU_SHADOW_RANGE_DESC);
|
||||
}
|
||||
|
||||
static void row_gpu(void) {
|
||||
const char *vals[MAX_GPUS + 1], *names[MAX_GPUS + 1];
|
||||
char idx[MAX_GPUS][4];
|
||||
@@ -518,27 +559,25 @@ static void row_gpu(void) {
|
||||
opt_choice_list("TOTK_GPU_INDEX", UI_MENU_GPU, vals, names, g_gpu_n + 1, UI_MENU_GPU_DESC);
|
||||
}
|
||||
|
||||
// The game language: one entry per language TotK ships (a Switch code that names it), each under its own name. The
|
||||
// Switch's Portuguese is not among them.
|
||||
// The game language: one entry per Mals language file the running game build ships (ui_text_game_langs), each under
|
||||
// its own name. A code that names no entry exactly (older "en", "fr-CA" on a build without it) selects the first entry
|
||||
// of the same catalog language.
|
||||
static void row_game_lang(void) {
|
||||
static const struct { const char *code; UiTextId name; } langs[] = {
|
||||
{"en-US", UI_MENU_LANGNAME_EN}, {"ja", UI_MENU_LANGNAME_JA}, {"fr", UI_MENU_LANGNAME_FR},
|
||||
{"de", UI_MENU_LANGNAME_DE}, {"it", UI_MENU_LANGNAME_IT}, {"es", UI_MENU_LANGNAME_ES},
|
||||
{"nl", UI_MENU_LANGNAME_NL}, {"ru", UI_MENU_LANGNAME_RU},
|
||||
{"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT}, {"ko", UI_MENU_LANGNAME_KO},
|
||||
};
|
||||
enum { N = sizeof langs / sizeof *langs + 1 };
|
||||
const char *vals[N], *names[N];
|
||||
UiGameLang langs[16];
|
||||
int n = ui_text_game_langs(rt_game_version, langs, 16);
|
||||
const char *vals[17], *names[17];
|
||||
vals[0] = "";
|
||||
names[0] = menu_text(UI_MENU_GAME_LANG_AUTO);
|
||||
const char *now = cfg_value("TOTK_LANG");
|
||||
int cur = *now ? -1 : 0;
|
||||
for (int i = 1; i < N; i++) {
|
||||
for (int i = 1; i <= n; i++) {
|
||||
vals[i] = langs[i - 1].code;
|
||||
names[i] = menu_text(langs[i - 1].name);
|
||||
if (*now && !strcmp(ui_text_lang(now), ui_text_lang(vals[i]))) cur = i; // en-GB is English too
|
||||
if (*now && !strcmp(now, vals[i])) cur = i;
|
||||
}
|
||||
opt_choice_list("TOTK_LANG", UI_MENU_GAME_LANG, vals, names, N, UI_MENU_GAME_LANG_DESC, cur);
|
||||
for (int i = 1; i <= n && *now && cur < 0; i++)
|
||||
if (!strcmp(ui_text_lang(now), ui_text_lang(vals[i]))) cur = i;
|
||||
opt_choice_list("TOTK_LANG", UI_MENU_GAME_LANG, vals, names, n + 1, UI_MENU_GAME_LANG_DESC, cur);
|
||||
}
|
||||
|
||||
// The frame limit (frame_rate.c): unset, the older fps60 = 0 still means 30. The monitor choice shows the rate it gives.
|
||||
@@ -623,6 +662,7 @@ static void tab_screen(float scale) {
|
||||
opt_group(UI_MENU_GRAPHICS);
|
||||
row_output_res();
|
||||
row_render_scale();
|
||||
row_shadow_res();
|
||||
static const UiTextId up[] = {UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR};
|
||||
opt_choice("TOTK_UPSCALER", UI_MENU_UPSCALER, up, 2, UI_MENU_UPSCALER_DESC);
|
||||
opt_slider("TOTK_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%");
|
||||
@@ -634,16 +674,33 @@ static void tab_screen(float scale) {
|
||||
opt_choice_list("TOTK_ANISO", UI_MENU_ANISO, aniso, aniso_names, 5, UI_MENU_ANISO_DESC);
|
||||
opt_toggle("TOTK_LOD_DETAIL", UI_MENU_LOD_DETAIL, UI_MENU_LOD_DETAIL_DESC);
|
||||
opt_toggle("TOTK_LOD_STEADY", UI_MENU_LOD_STEADY, UI_MENU_LOD_STEADY_DESC);
|
||||
row_shadow_scale();
|
||||
row_shadow_range();
|
||||
opt_slider("TOTK_PCSS", UI_MENU_PCSS, 0, 200, UI_MENU_PCSS_DESC, 10, "%.0f %%");
|
||||
opt_slider("TOTK_CONTACT_SHADOWS", UI_MENU_CONTACT_SHADOWS, 0, 100, UI_MENU_CONTACT_SHADOWS_DESC, 10, "%.0f %%");
|
||||
opt_toggle("TOTK_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_DESC);
|
||||
static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
|
||||
UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA};
|
||||
opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 5, UI_MENU_DLSS_DESC);
|
||||
static const UiTextId preset[] = {UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J};
|
||||
opt_choice("TOTK_DLSS_PRESET", UI_MENU_DLSS_PRESET, preset, 3, UI_MENU_DLSS_PRESET_DESC);
|
||||
static const UiTextId chars[] = {UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM,
|
||||
UI_MENU_DLSS_CHARS_FULL};
|
||||
opt_choice("TOTK_DLSS_CHAR_MASK", UI_MENU_DLSS_CHARS, chars, 4, UI_MENU_DLSS_CHARS_DESC);
|
||||
opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC);
|
||||
rows_color();
|
||||
opt_group(UI_MENU_HDR_GROUP);
|
||||
opt_toggle("TOTK_HDR", UI_MENU_HDR, UI_MENU_HDR_DESC);
|
||||
opt_slider("TOTK_HDR_PEAK_NITS", UI_MENU_HDR_PEAK, 400, 10000, UI_MENU_HDR_PEAK_DESC, 50, "%.0f");
|
||||
opt_slider("TOTK_HDR_GAME_NITS", UI_MENU_HDR_GAME, 80, 500, UI_MENU_HDR_GAME_DESC, 5, "%.0f");
|
||||
opt_slider("TOTK_HDR_UI_NITS", UI_MENU_HDR_UI, 80, 500, UI_MENU_HDR_UI_DESC, 5, "%.0f");
|
||||
opt_slider("TOTK_HDR_HUE", UI_MENU_HDR_HUE, 0, 100, UI_MENU_HDR_HUE_DESC, 5, "%.0f %%");
|
||||
opt_end();
|
||||
}
|
||||
|
||||
static void tab_game(float scale) {
|
||||
opt_begin("##game", scale);
|
||||
row_fps_limit();
|
||||
opt_toggle("TOTK_REALTIME", UI_MENU_REALTIME, UI_MENU_REALTIME_DESC);
|
||||
opt_toggle("TOTK_CLOTH_REALTIME", UI_MENU_CLOTH_REALTIME, UI_MENU_CLOTH_REALTIME_DESC);
|
||||
opt_toggle("TOTK_HIGHFPS_FIX", UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC);
|
||||
row_game_lang();
|
||||
static const UiTextId mode[] = {UI_MENU_MODE_DOCKED, UI_MENU_MODE_HANDHELD};
|
||||
opt_choice("TOTK_OPERATION_MODE", UI_MENU_OPERATION_MODE, mode, 2, UI_MENU_OPERATION_MODE_DESC);
|
||||
@@ -654,17 +711,16 @@ static void tab_game(float scale) {
|
||||
static void tab_sound(float scale) {
|
||||
opt_begin("##sound", scale);
|
||||
opt_slider("TOTK_VOLUME", UI_MENU_VOLUME, 0, 100, UI_MENU_VOLUME_DESC, 5, "%.0f %%");
|
||||
static const UiTextId channels[] = {UI_MENU_CHANNELS_AUTO, UI_MENU_CHANNELS_STEREO, UI_MENU_CHANNELS_51};
|
||||
opt_choice("TOTK_AUDIO_CHANNELS", UI_MENU_AUDIO_CHANNELS, channels, 3, UI_MENU_AUDIO_CHANNELS_DESC);
|
||||
opt_end();
|
||||
}
|
||||
|
||||
// The note under the layout. Xbox prompts (the Nintendo layout with the A/B and X/Y prompts swapped, romfs.c
|
||||
// overlay_init) change the buttons at once but the prompts only at the next start: "files missing" without
|
||||
// romfs-patches-xbox, "prompts change after restart" while the prompts in use differ from the choice. Automatic with a
|
||||
// gamepad connected: "in use: Xbox". NULL otherwise.
|
||||
// A confirmation is open (Controls: restart, Advanced: reset): B and Esc close it, not the menu; L / R stay on the page.
|
||||
static bool g_modal;
|
||||
|
||||
// The note under the layout: Automatic with a gamepad connected, the layout it picked ("in use: Xbox"). NULL otherwise.
|
||||
static const char *pad_layout_note(void) {
|
||||
bool want = !strcasecmp(cfg_value("TOTK_PAD_LAYOUT"), "xbox_prompts");
|
||||
if (want && !romfs_xbox_prompts_ready()) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_MISSING);
|
||||
if (want != (romfs_xbox_prompts_active() != 0)) return menu_text(UI_MENU_PAD_LAYOUT_PROMPTS_RESTART);
|
||||
int got = input_pad_layout();
|
||||
if (got < 0 || strcmp(cfg_value("TOTK_PAD_LAYOUT"), "auto")) return nullptr;
|
||||
static char note[96];
|
||||
@@ -673,31 +729,149 @@ static const char *pad_layout_note(void) {
|
||||
return note;
|
||||
}
|
||||
|
||||
// The action a key presses, or -1: the walk key is a key of its own, but Shift is B in the default bindings, and a
|
||||
// walk key that also presses something walks and does that something at the same time. The bindings come from a
|
||||
// snapshot, and every key of an action is looked at: binds_refresh rebuilds the live table on the polling thread while
|
||||
// the menu draws, and an action may hold more than the two keys its cells show.
|
||||
static int key_action(const InputMap *m, int key) {
|
||||
for (int a = 0; a < ACTION_COUNT; a++) {
|
||||
uint8_t keys[INPUT_BINDING_MAX];
|
||||
int n = input_map_keys_of(m, a, keys, INPUT_BINDING_MAX);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (keys[i] == key) return a;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// The walk key as the handful of keys a player is likely to pick. "none" rather than an empty value closes it: an
|
||||
// unset key falls back to the default in the settings table, the same as a fresh installation. totk.ini takes any name
|
||||
// input_map.c knows (walks of the keyboard sticks, not of the gamepad). A key the current bindings also use says which
|
||||
// action it presses.
|
||||
static void row_walk_key(void) {
|
||||
static const char *const keys[] = {"none", "lshift", "lalt", "lctrl", "tab", "capslock"};
|
||||
const char *names[sizeof keys / sizeof *keys] = {menu_text(UI_MENU_OFF), "Shift", "Alt", "Ctrl", "Tab", "Caps Lock"};
|
||||
const char *cur = cfg_value("TOTK_WALK_KEY");
|
||||
static char note[64];
|
||||
const char *n = nullptr;
|
||||
InputMap m;
|
||||
input_map_snapshot(&m);
|
||||
for (int k = KEY_A; k < KEY_COUNT && !n; k++) {
|
||||
if (!input_key_name(k) || strcasecmp(input_key_name(k), cur)) continue;
|
||||
int a = key_action(&m, k);
|
||||
if (a >= 0 && input_action_name(a)) snprintf(note, sizeof note, menu_text(UI_MENU_WALK_KEY_TAKEN), input_action_name(a)), n = note;
|
||||
}
|
||||
opt_choice_list("TOTK_WALK_KEY", UI_MENU_WALK_KEY, keys, names, sizeof keys / sizeof *keys, UI_MENU_WALK_KEY_DESC,
|
||||
-1, n);
|
||||
}
|
||||
|
||||
// The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad
|
||||
// layout, as a layout that puts A on the right button needs the face buttons named the other way round), but the game
|
||||
// reads its fonts and UI archive once at start (romfs.c overlay_init). While the folder in use differs: "files
|
||||
// missing" when the setup did not write the one asked for, why it was left out at start (damaged, a game resolution
|
||||
// that is not 16:9, a RomFS mod with the same files, TOTK_ROMFS_PATCHES), else "prompts change after restart", and only then
|
||||
// *restart is set: a restart would bring the prompts asked for. NULL when they match.
|
||||
static const char *prompts_note(bool *restart) {
|
||||
*restart = false;
|
||||
const char *layout = cfg_value("TOTK_PAD_LAYOUT"), *used = romfs_prompts();
|
||||
const char *want = input_prompts_folder(input_prompts_pick(cfg_get("TOTK_PROMPTS"), layout), layout);
|
||||
if (want == used || (want && used && !strcmp(want, used))) return nullptr;
|
||||
if (want && !romfs_prompts_ready(want)) return menu_text(UI_MENU_PROMPTS_MISSING);
|
||||
switch (romfs_prompts_off(want)) {
|
||||
case ROMFS_PROMPTS_FAILED: return menu_text(UI_MENU_PROMPTS_FAILED);
|
||||
case ROMFS_PROMPTS_SHAPE: return menu_text(UI_MENU_PROMPTS_OFF_SHAPE);
|
||||
case ROMFS_PROMPTS_MODS: return menu_text(UI_MENU_PROMPTS_OFF_MODS);
|
||||
case ROMFS_PROMPTS_PATCHES: return menu_text(UI_MENU_PROMPTS_OFF_PATCHES);
|
||||
default: *restart = true; return menu_text(UI_MENU_PROMPTS_RESTART);
|
||||
}
|
||||
}
|
||||
|
||||
// The confirmation of "Restart now", over the menu; Cancel has the cursor first. Restart writes totk.ini, then closes
|
||||
// the game as Quit does and starts it again (gfx_window_request_restart). It waits while the game writes a save, and
|
||||
// the game stays when totk.ini cannot be written, as the new prompts would not come back. From the Cheats tab
|
||||
// (restart_rebuild) Restart also lets the next start rebuild for cheats whose last rebuild failed (cheats_rebuild_allow).
|
||||
static bool restart_rebuild;
|
||||
static void restart_confirm(void) {
|
||||
g_modal = false;
|
||||
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
if (!ImGui::BeginPopupModal("##restart_confirm", nullptr,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
return;
|
||||
g_modal = true;
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_RESTART_CONFIRM));
|
||||
bool saving = fs_save_busy() != 0;
|
||||
if (saving || !cfg_last_save_ok())
|
||||
ImGui::TextColored(ImVec4(0.95f, 0.45f, 0.35f, 1), "%s",
|
||||
menu_text(saving ? UI_MENU_RESTART_SAVING : UI_MENU_SAVE_FAILED));
|
||||
ImGui::Spacing();
|
||||
const char *yes = menu_text(UI_MENU_RESTART_YES), *no = menu_text(UI_MENU_RESET_NO);
|
||||
const ImGuiStyle &st = ImGui::GetStyle();
|
||||
float bw = fmaxf(ImGui::CalcTextSize(yes).x, ImGui::CalcTextSize(no).x) + st.FramePadding.x * 4;
|
||||
bool close = ImGui::Button(no, ImVec2(bw, 0));
|
||||
if (ImGui::IsWindowAppearing()) ImGui::SetItemDefaultFocus();
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(saving);
|
||||
if (ImGui::Button(yes, ImVec2(bw, 0)) && cfg_save()) {
|
||||
if (restart_rebuild) cheats_rebuild_allow();
|
||||
gfx_window_request_restart();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false))
|
||||
close = true;
|
||||
if (close) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
restart_rebuild = false;
|
||||
opt_focus_key("##restart"); // back on the row it came from
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
static void tab_controls(float scale) {
|
||||
opt_begin("##controls", scale);
|
||||
static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX,
|
||||
UI_MENU_PAD_LAYOUT_XBOX_PROMPTS};
|
||||
opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 4, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note());
|
||||
static const UiTextId layout[] = {UI_MENU_PAD_LAYOUT_AUTO, UI_MENU_PAD_LAYOUT_NINTENDO, UI_MENU_PAD_LAYOUT_XBOX};
|
||||
opt_choice("TOTK_PAD_LAYOUT", UI_MENU_PAD_LAYOUT, layout, 3, UI_MENU_PAD_LAYOUT_DESC, pad_layout_note());
|
||||
static const UiTextId prompts[] = {UI_MENU_PROMPTS_NINTENDO, UI_MENU_PROMPTS_XBOX};
|
||||
bool restart;
|
||||
const char *note = prompts_note(&restart);
|
||||
opt_choice("TOTK_PROMPTS", UI_MENU_PROMPTS, prompts, 2, UI_MENU_PROMPTS_DESC, note);
|
||||
bool ask = restart && opt_button("##restart", UI_MENU_RESTART, UI_MENU_RESTART_DESC);
|
||||
opt_toggle("TOTK_MOTION", UI_MENU_MOTION, UI_MENU_MOTION_DESC);
|
||||
opt_slider("TOTK_RUMBLE_STRENGTH", UI_MENU_RUMBLE_STRENGTH, 0, 300, UI_MENU_RUMBLE_STRENGTH_DESC, 10, "%.0f %%");
|
||||
opt_slider("TOTK_RUMBLE_CURVE", UI_MENU_RUMBLE_CURVE, 0.2f, 1.5f, UI_MENU_RUMBLE_CURVE_DESC, 0.05f, "%.2f");
|
||||
opt_toggle("TOTK_RUMBLE_TRIGGERS", UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC);
|
||||
opt_slider("TOTK_STICK_DEADZONE", UI_MENU_STICK_DEADZONE, 0, 50, UI_MENU_STICK_DEADZONE_DESC, 1, "%.0f %%");
|
||||
opt_slider("TOTK_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0, 10, UI_MENU_MOUSE_SENS_DESC, 0.1f, "%.1f");
|
||||
row_walk_key();
|
||||
opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f");
|
||||
// Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With
|
||||
// a gamepad connected each row shows its stick's deflection now, before the dead zone: a drifting stick's resting
|
||||
// value, to set it above.
|
||||
opt_group(UI_MENU_GROUP_STICKS);
|
||||
double now[2];
|
||||
bool pad = input_pad_stick_percent(now) != 0;
|
||||
char stick_note[2][64];
|
||||
for (int s = 0; s < 2; s++)
|
||||
snprintf(stick_note[s], sizeof stick_note[s], menu_text(UI_MENU_STICK_DEADZONE_NOW), now[s]);
|
||||
opt_slider("TOTK_LSTICK_DEADZONE", UI_MENU_LSTICK_DEADZONE, 0, 50, UI_MENU_STICK_DEADZONE_DESC, 1, "%.0f %%",
|
||||
pad ? stick_note[0] : nullptr, "TOTK_STICK_DEADZONE");
|
||||
opt_slider("TOTK_RSTICK_DEADZONE", UI_MENU_RSTICK_DEADZONE, 0, 50, UI_MENU_STICK_DEADZONE_DESC, 1, "%.0f %%",
|
||||
pad ? stick_note[1] : nullptr, "TOTK_STICK_DEADZONE");
|
||||
opt_slider("TOTK_STICK_SENS", UI_MENU_STICK_SENS, 0.1f, 3, UI_MENU_STICK_SENS_DESC, 0.05f, "%.2f");
|
||||
binds_rows(scale);
|
||||
opt_end();
|
||||
binds_after_page();
|
||||
if (ask) ImGui::OpenPopup("##restart_confirm"); // at the level BeginPopupModal looks it up
|
||||
restart_confirm();
|
||||
}
|
||||
|
||||
static void tab_menu(float scale) {
|
||||
opt_begin("##menu", scale);
|
||||
static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU};
|
||||
opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, 3, UI_MENU_MENU_LANG_DESC);
|
||||
static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU,
|
||||
UI_MENU_LANGNAME_PT_BR, UI_MENU_LANGNAME_ZH_HANS};
|
||||
opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, sizeof langs / sizeof *langs, UI_MENU_MENU_LANG_DESC);
|
||||
opt_toggle("TOTK_DISCORD_RPC", UI_MENU_DISCORD_RPC, UI_MENU_DISCORD_RPC_DESC);
|
||||
opt_end();
|
||||
}
|
||||
|
||||
// ---- Advanced: the testing and troubleshooting keys, the bug report helpers and the reset of every setting
|
||||
static bool g_modal; // the reset confirmation is open: B and Esc close it, not the menu; L / R stay on the page
|
||||
|
||||
// A thread count with no fixed default: Automatic (unset), then the common counts.
|
||||
static void row_threads(const char *key, UiTextId label, UiTextId desc) {
|
||||
@@ -779,7 +953,8 @@ static void tab_advanced(float scale) {
|
||||
opt_choice("TOTK_MEMORY", UI_MENU_MEMORY, mem, 4, UI_MENU_MEMORY_DESC);
|
||||
opt_toggle("TOTK_TEX_ALIAS", UI_MENU_TEX_ALIAS, UI_MENU_TEX_ALIAS_DESC);
|
||||
opt_slider("TOTK_TEX_VRAM_PRESSURE", UI_MENU_TEX_VRAM_PRESSURE, 0, 100, UI_MENU_TEX_VRAM_PRESSURE_DESC, 1, "%.0f%%");
|
||||
opt_toggle("TOTK_ASTC_BC", UI_MENU_ASTC_BC, UI_MENU_ASTC_BC_DESC);
|
||||
static const UiTextId astc_bc[] = {UI_MENU_AUTO, UI_MENU_OFF, UI_MENU_ON}; // unset, 0, 1
|
||||
opt_choice("TOTK_ASTC_BC", UI_MENU_ASTC_BC, astc_bc, 3, UI_MENU_ASTC_BC_DESC);
|
||||
|
||||
opt_group(UI_MENU_GROUP_FIXES);
|
||||
opt_toggle("TOTK_LOD_GUARD", UI_MENU_LOD_GUARD, UI_MENU_LOD_GUARD_DESC);
|
||||
@@ -805,6 +980,7 @@ static void tab_advanced(float scale) {
|
||||
row_set_or_not("TOTK_TRACE", UI_MENU_TRACE, UI_MENU_TRACE_DESC, "perf");
|
||||
opt_toggle("TOTK_FLIGHT", UI_MENU_FLIGHT, UI_MENU_FLIGHT_DESC);
|
||||
opt_slider("TOTK_FLIGHT_SPIKE_MS", UI_MENU_FLIGHT_SPIKE_MS, 20, 1000, UI_MENU_FLIGHT_SPIKE_MS_DESC, 10, "%.0f");
|
||||
opt_choice("TOTK_PASS_CRUMBS", UI_MENU_PASS_CRUMBS, dyn, 3, UI_MENU_PASS_CRUMBS_DESC); // vk_crumbs.c pass marks
|
||||
static char rec_path[600]; // the recording goes beside the log
|
||||
if (!rec_path[0]) {
|
||||
char dir[512];
|
||||
@@ -854,12 +1030,111 @@ static void tab_advanced(float scale) {
|
||||
}
|
||||
}
|
||||
|
||||
static const UiTextId kTabNames[TAB_COUNT] = {UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND,
|
||||
UI_MENU_TAB_CONTROLS, UI_MENU_TAB_MENU, UI_MENU_TAB_ADVANCED};
|
||||
static const UiTextId kTabNames[TAB_COUNT] = {UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND,
|
||||
UI_MENU_TAB_CONTROLS, UI_MENU_TAB_AMIIBO, UI_MENU_TAB_MENU,
|
||||
UI_MENU_TAB_ADVANCED, UI_MENU_TAB_MODS, UI_MENU_TAB_CHEATS};
|
||||
static int g_tab; // the tab shown
|
||||
static int g_tab_request = -1; // select this tab at the next layout; -1 none
|
||||
static int g_focus_page = -1; // this tab's first row takes the cursor once it is shown; -1 none
|
||||
|
||||
// A row of another tab: that tab opens with the row under the cursor.
|
||||
static void go_to(int tab, const char *key) {
|
||||
g_tab_request = tab;
|
||||
opt_focus_key(key);
|
||||
}
|
||||
|
||||
// ---- Mods: the mods folder (mods.c) with switches and the load order, then the port's own patches. The folder was
|
||||
// read at start; the rows change the order and switches for the next start.
|
||||
static void mods_builtin_rows(void) {
|
||||
opt_group(UI_MENU_MODS_BUILTIN);
|
||||
char fps[64], res[64];
|
||||
const char *lim = cfg_value("TOTK_FPS_LIMIT");
|
||||
if (!strcmp(lim, "display")) snprintf(fps, sizeof fps, "%s", menu_text(UI_MENU_FPS_DISPLAY));
|
||||
else snprintf(fps, sizeof fps, "%s FPS", lim);
|
||||
if (opt_button("##mods_fps60", UI_MENU_MODS_FPS60, UI_MENU_MODS_FPS60_DESC, fps)) go_to(TAB_GAME, "TOTK_FPS_LIMIT");
|
||||
int w = 0, h = 0;
|
||||
sscanf(cfg_value("TOTK_OUTPUT_RES"), "%dx%d", &w, &h);
|
||||
snprintf(res, sizeof res, "%d × %d", w, h); // U+00D7, as row_output_res shows it
|
||||
if (opt_button("##mods_res", UI_MENU_MODS_RES, UI_MENU_MODS_RES_DESC, res)) go_to(TAB_SCREEN, "TOTK_OUTPUT_RES");
|
||||
opt_toggle("TOTK_REALTIME", UI_MENU_REALTIME, UI_MENU_REALTIME_DESC);
|
||||
opt_toggle("TOTK_CLOTH_REALTIME", UI_MENU_CLOTH_REALTIME, UI_MENU_CLOTH_REALTIME_DESC);
|
||||
opt_toggle("TOTK_HIGHFPS_FIX", UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC);
|
||||
opt_button("##mods_quickmenu", UI_MENU_MODS_QUICKMENU, UI_MENU_MODS_QUICKMENU_DESC,
|
||||
menu_text(romfs_patches_loaded() ? UI_MENU_ON : UI_MENU_OFF));
|
||||
}
|
||||
|
||||
static void tab_mods(float scale) {
|
||||
opt_begin("##mods", scale);
|
||||
opt_group(UI_MENU_MODS_INSTALLED);
|
||||
int n = mods_count();
|
||||
if (!n) opt_text(UI_MENU_MODS_NONE);
|
||||
const char *after = mods_changed() ? menu_text(UI_MENU_AFTER_RESTART) : nullptr;
|
||||
for (int i = 0; i < n; i++) {
|
||||
const ModInfo *m = mods_at(i);
|
||||
char id[32], desc[1536];
|
||||
snprintf(id, sizeof id, "##mod%d", i);
|
||||
char over[512] = "", other[512] = "";
|
||||
if (m->overridden) snprintf(over, sizeof over, menu_text(UI_MENU_MODS_OVERRIDDEN), m->overridden, m->overridden_by);
|
||||
if (m->other_version) snprintf(other, sizeof other, menu_text(UI_MENU_MODS_OTHER_VERSION), m->other_version);
|
||||
char cheat[256] = "";
|
||||
if (m->kind & MOD_CHEATS) { // its cheats as read at start, or the file they come from
|
||||
int count = 0;
|
||||
for (int j = 0; j < cheats_count(); j++)
|
||||
count += !strcmp(cheats_info(j)->mod, m->name) && cheats_info(j)->kind != CHEAT_HEADING;
|
||||
if (count) snprintf(cheat, sizeof cheat, menu_text(UI_MENU_MODS_CHEATS), count);
|
||||
else snprintf(cheat, sizeof cheat, menu_text(UI_MENU_MODS_CHEATS_FILE), cheats_file());
|
||||
}
|
||||
char code[512] = "", problem[512] = "";
|
||||
if (m->nsets && m->overrides[0])
|
||||
snprintf(code, sizeof code, menu_text(UI_MENU_MODS_REPLACES_BUILTIN), m->nsets, m->overrides);
|
||||
else if (m->nsets)
|
||||
snprintf(code, sizeof code, menu_text(UI_MENU_MODS_EXEFS_ON), m->nsets);
|
||||
switch (m->problem) {
|
||||
case MOD_EMPTY: snprintf(problem, sizeof problem, "%s", menu_text(UI_MENU_MODS_EMPTY)); break;
|
||||
case MOD_PLUGIN: snprintf(problem, sizeof problem, "%s", menu_text(UI_MENU_MODS_SUBSDK)); break;
|
||||
case MOD_EXEFS_LATER: snprintf(problem, sizeof problem, "%s", menu_text(UI_MENU_MODS_EXEFS_LATER)); break;
|
||||
case MOD_EXEFS_UNSUPPORTED:
|
||||
snprintf(problem, sizeof problem, menu_text(UI_MENU_MODS_EXEFS_UNSUPPORTED), m->note);
|
||||
break;
|
||||
case MOD_EXEFS_OTHER: snprintf(problem, sizeof problem, "%s", menu_text(UI_MENU_MODS_EXEFS_OTHER)); break;
|
||||
case MOD_BAD_NAME: snprintf(problem, sizeof problem, "%s", menu_text(UI_MENU_MODS_BAD_NAME)); break;
|
||||
default: break;
|
||||
}
|
||||
int k = snprintf(desc, sizeof desc, menu_text(UI_MENU_MODS_ROW_DESC), m->replaced, m->added);
|
||||
const char *parts[] = {over, other, cheat, code, problem, menu_text(UI_MENU_MODS_MOVE_HINT)};
|
||||
for (const char *part : parts)
|
||||
if (*part && k >= 0 && k < (int)sizeof desc) k += snprintf(desc + k, sizeof desc - k, "\n\n%s", part);
|
||||
const char *note = m->enabled && m->problem != MOD_OK ? menu_text(UI_MENU_MODS_UNUSED) : after;
|
||||
int s = opt_text_row(id, m->name, menu_text(m->enabled ? UI_MENU_ON : UI_MENU_OFF), note, desc, true);
|
||||
if (s == 2 || s == -1 || s == 1) {
|
||||
mods_set_enabled(i, !m->enabled);
|
||||
opt_save_soon();
|
||||
} else if ((s == 3 && i > 0) || (s == 4 && i + 1 < n)) {
|
||||
int to = s == 3 ? i - 1 : i + 1;
|
||||
mods_move(i, to - i);
|
||||
snprintf(id, sizeof id, "##mod%d", to);
|
||||
opt_focus_key(id); // the cursor follows the mod
|
||||
opt_save_soon();
|
||||
}
|
||||
}
|
||||
bool rebuild =
|
||||
cheats_rebuild_pending() && opt_button("##restart", UI_MENU_CHEATS_REBUILD, UI_MENU_CHEATS_REBUILD_DESC);
|
||||
static uint64_t open_failed; // plat_now_ns until which the button says it failed
|
||||
if (opt_button("##mods_open", UI_MENU_MODS_OPEN, UI_MENU_MODS_OPEN_DESC,
|
||||
plat_now_ns() < open_failed ? menu_text(UI_MENU_ACTION_FAILED) : "")) {
|
||||
bool ok = mods_dir()[0] != 0;
|
||||
if (ok) plat_file_mkdir_p(mods_dir());
|
||||
if (!ok || !plat_open_folder(mods_dir())) open_failed = plat_now_ns() + 3000000000ull;
|
||||
}
|
||||
mods_builtin_rows();
|
||||
opt_end();
|
||||
if (rebuild) {
|
||||
restart_rebuild = true;
|
||||
ImGui::OpenPopup("##restart_confirm");
|
||||
}
|
||||
restart_confirm();
|
||||
}
|
||||
|
||||
// ---- the window: title, tabs (L / R or Q / E switch), the page, and the bottom row with "Continue" and "Quit game".
|
||||
// B on the gamepad and Esc close it.
|
||||
static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
@@ -904,9 +1179,18 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
switch (k) {
|
||||
case TAB_SCREEN: tab_screen(scale); break;
|
||||
case TAB_GAME: tab_game(scale); break;
|
||||
case TAB_MODS: tab_mods(scale); break;
|
||||
case TAB_SOUND: tab_sound(scale); break;
|
||||
case TAB_CONTROLS: tab_controls(scale); break;
|
||||
case TAB_AMIIBO: tab_amiibo(scale); break;
|
||||
case TAB_MENU: tab_menu(scale); break;
|
||||
case TAB_CHEATS:
|
||||
if (tab_cheats(scale)) {
|
||||
restart_rebuild = true;
|
||||
ImGui::OpenPopup("##restart_confirm");
|
||||
}
|
||||
restart_confirm();
|
||||
break;
|
||||
case TAB_ADVANCED: tab_advanced(scale); break;
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
@@ -929,7 +1213,7 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(quit, ImVec2(bw, 0))) gfx_window_request_close();
|
||||
bool was_modal = g_modal || binds_modal();
|
||||
if (g_tab != TAB_ADVANCED) g_modal = false;
|
||||
if (g_tab != TAB_ADVANCED && g_tab != TAB_CONTROLS) g_modal = false;
|
||||
if (!was_modal && (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false)))
|
||||
set_open(0);
|
||||
ImGui::End();
|
||||
@@ -1066,7 +1350,11 @@ static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
|
||||
int s = cfg_int("TOTK_SHARPNESS");
|
||||
snprintf(v[3], sizeof v[3], menu_text(UI_MENU_OV_FMT_FSR), s < 0 ? 0 : s > 100 ? 100 : s);
|
||||
} else {
|
||||
snprintf(v[3], sizeof v[3], "%s", menu_text(t->scaler ? UI_MENU_OV_SCALE_BILINEAR : UI_MENU_OV_SCALE_NONE));
|
||||
// FSR enlarges only (vk_fsr_record): an image larger than the window is shrunk by the blit even with FSR selected
|
||||
int down = t->scaler == 1 && !strcmp(cfg_value("TOTK_UPSCALER"), "fsr") &&
|
||||
(t->image_w > (int)t->width || t->image_h > (int)t->height);
|
||||
snprintf(v[3], sizeof v[3], "%s",
|
||||
menu_text(down ? UI_MENU_OV_SCALE_DOWN : t->scaler ? UI_MENU_OV_SCALE_BILINEAR : UI_MENU_OV_SCALE_NONE));
|
||||
}
|
||||
double hz = frame_step_limit_hz();
|
||||
snprintf(v[4], sizeof v[4], "%s", menu_text(UI_MENU_OV_NONE));
|
||||
@@ -1103,17 +1391,30 @@ static void perf_full_draw(const MenuTarget *t, float scale) {
|
||||
ImGui::SetWindowFontScale(0.72f);
|
||||
const ImVec4 gpu_c(0.55f, 0.83f, 0.31f, 1), cpu_c(0.18f, 0.59f, 0.80f, 1), ram_c(0.80f, 0.45f, 0.70f, 1),
|
||||
fps_c(0.95f, 0.95f, 0.95f, 1), wait_c(0.93f, 0.76f, 0.33f, 1), pic_c(0.62f, 0.70f, 0.95f, 1);
|
||||
// the port version and the game update first, so a screenshot in a bug report carries both; formatted once per
|
||||
// menu language
|
||||
static char ver[96];
|
||||
static const char *ver_fmt;
|
||||
if (ver_fmt != menu_text(UI_MENU_VERSION)) {
|
||||
ver_fmt = menu_text(UI_MENU_VERSION);
|
||||
char game[16];
|
||||
snprintf(game, sizeof game, "%d.%d.%d", rt_game_version / 100, rt_game_version / 10 % 10, rt_game_version % 10);
|
||||
snprintf(ver, sizeof ver, ver_fmt, rt_port_version, game);
|
||||
}
|
||||
ImGui::TextDisabled("%s", ver);
|
||||
if (ImGui::BeginTable("##perft", 4, ImGuiTableFlags_SizingFixedFit)) {
|
||||
static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM};
|
||||
static const PerfCol c0[] = {{UI_MENU_OV_FPS, 888}};
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FRAME_MS, 888.8f}};
|
||||
static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_MAX_MS, 8888.8f}};
|
||||
static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM,
|
||||
UI_MENU_OV_FPS_LABEL, UI_MENU_OV_FRAME_LABEL};
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FMT_FPS, 888},
|
||||
{UI_MENU_OV_FRAME_MS, 888.8f}};
|
||||
static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_LOW1, 888},
|
||||
{UI_MENU_OV_MAX_MS, 8888.8f}};
|
||||
static const PerfCol c3[] = {{UI_MENU_OV_FMT_POWER, 888}, {UI_MENU_OV_FMT_MHZ, 8888}, {UI_MENU_OV_GAME_PCT, 100},
|
||||
{UI_MENU_OV_GAME_GB, 888.8f}};
|
||||
perf_column("##c0", c0, 1, labels, 4);
|
||||
perf_column("##c1", c1, 3);
|
||||
perf_column("##c2", c2, 3);
|
||||
perf_column("##c3", c3, 4);
|
||||
{UI_MENU_OV_GAME_GB, 888.8f}, {UI_MENU_OV_LOW01, 888}};
|
||||
perf_column("##c0", nullptr, 0, labels, 6);
|
||||
perf_column("##c1", c1, 4);
|
||||
perf_column("##c2", c2, 4);
|
||||
perf_column("##c3", c3, 5);
|
||||
perf_label(UI_MENU_OV_GPU, gpu_c);
|
||||
perf_cell(UI_MENU_OV_FMT_PCT, s.gpu_pct);
|
||||
perf_cell(UI_MENU_OV_FMT_TEMP, s.gpu_temp_c);
|
||||
@@ -1130,12 +1431,16 @@ static void perf_full_draw(const MenuTarget *t, float scale) {
|
||||
perf_cell(UI_MENU_OV_FMT_GB, perf_gb(s.ram_used_mb));
|
||||
perf_cell(UI_MENU_OV_FMT_GB_OF, perf_gb(s.ram_total_mb));
|
||||
perf_cell(UI_MENU_OV_GAME_GB, perf_gb(s.ram_game_mb));
|
||||
ImGui::TableNextColumn(); // the frame row: no label, the rate in its place
|
||||
char b[64];
|
||||
snprintf(b, sizeof b, menu_text(UI_MENU_OV_FPS), s.fps);
|
||||
ImGui::TextColored(fps_c, "%s", b);
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, 6 * scale); // a gap between the machine and the frames
|
||||
// the frames: the rate over the last second with the lows over the last ten seconds, then the frame times
|
||||
perf_label(UI_MENU_OV_FPS_LABEL, fps_c);
|
||||
perf_cell(UI_MENU_OV_FMT_FPS, s.fps);
|
||||
perf_cell(UI_MENU_OV_LOW1, s.low1_fps);
|
||||
perf_cell(UI_MENU_OV_LOW01, s.low01_fps);
|
||||
perf_label(UI_MENU_OV_FRAME_LABEL, fps_c);
|
||||
perf_cell(UI_MENU_OV_FRAME_MS, s.frame_ms_avg);
|
||||
perf_cell(UI_MENU_OV_MAX_MS, s.frame_ms_max);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
float top = s.frame_ms_max > 50 ? s.frame_ms_max : 50;
|
||||
@@ -1183,10 +1488,12 @@ static void perf_draw(const MenuTarget *t, float scale) {
|
||||
|
||||
extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot) {
|
||||
*shot = NULL;
|
||||
cheats_frame(frame); // the data cheats and the buttons of the cheats that need them held
|
||||
if (!g_test.parsed) test_parse();
|
||||
if (g_test.next_set < g_test.n_sets && frame >= g_test.sets[g_test.next_set].frame) test_apply_sets(frame);
|
||||
if (g_perf_save.exchange(0)) cfg_save();
|
||||
perf_tick(plat_now_ns(), t);
|
||||
amiibo_tick();
|
||||
bool open = g_open.load(std::memory_order_relaxed);
|
||||
if (!open) {
|
||||
if (g_save_pending) g_save_pending = opt_save_tick(1); // closed: the last change goes to totk.ini now
|
||||
|
||||
+4
-2
@@ -5,8 +5,9 @@
|
||||
//
|
||||
// F1 or Esc on the keyboard and Minus and Plus held together (consumed in poll_merged, input_menu_gate in input.h) open it;
|
||||
// F1, Esc, B or "Continue" close it. While it is open the game gets no input (input_menu, input.h) and keeps running; the
|
||||
// cursor is released from the mouse camera. Tabs Screen, Game, Sound, Controls and Menu (L / R or Q / E switch them) hold
|
||||
// option rows (ui/option_rows.h) over the cfg settings; the bottom row has "Continue" and "Quit game".
|
||||
// cursor is released from the mouse camera. Tabs Screen, Game, Mods, Sound, Controls and Menu (L / R or Q / E switch
|
||||
// them) hold option rows (ui/option_rows.h) over the cfg settings and the mods folder (mods.h); the bottom row has
|
||||
// "Continue" and "Quit game".
|
||||
// Test hooks (ui/menu.cpp): TOTK_MENU_TEST=<frame>[:<frames per page>] opens the menu at that presented frame and saves
|
||||
// one swapchain shot per tab into TOTK_MENU_TEST_DIR; TOTK_MENU_TEST_SET=<frame>:<key>=<value>[,...][;...] sets settings
|
||||
// at given frames without input (SAVE=1 writes totk.ini).
|
||||
@@ -60,6 +61,7 @@ int menu_font_check(void);
|
||||
// ---- what the menu asks of the platform side (gfx_window_win.c, gfx_window_sdl.c)
|
||||
void gfx_window_apply_settings(void); // TOTK_FULLSCREEN or TOTK_WINDOW_SIZE changed: the window follows
|
||||
void gfx_window_request_close(void); // as the window's close button: the process ends
|
||||
void gfx_window_request_restart(void); // the same, then totk.exe starts again with the same command line
|
||||
int gfx_window_monitor_size(int *w, int *h); // pixels of the monitor the window is on; 0 when unknown
|
||||
double gfx_window_refresh_hz(void); // its refresh rate (TOTK_FPS_LIMIT=display); 0 when unknown
|
||||
unsigned gfx_window_dpi(void); // the window's DPI (96 at 100% display scale); any thread
|
||||
|
||||
+80
-19
@@ -33,15 +33,15 @@ static char g_focus_key[64]; // opt_focus_key: the row that takes th
|
||||
static bool g_held; // the last row's left / right has been held a while (steppers go faster)
|
||||
static float g_bottom; // opt_reserve_bottom: kept free under the panes
|
||||
static bool g_disable_next; // opt_disable_next: the next row is greyed out with g_disable_note
|
||||
static UiTextId g_disable_note;
|
||||
static const char *g_disable_note;
|
||||
|
||||
// The description pane: this frame's hovered and selected rows, the page's first row, and the last one shown.
|
||||
struct Desc { char text[UI_DESC_BYTES]; };
|
||||
static Desc g_hover, g_focus, g_first, g_shown;
|
||||
|
||||
// disabled: the note of a row opt_disable_next greyed out, else NULL.
|
||||
static void desc_set(Desc &d, UiTextId desc, const char *key, const CfgMeta *m, const char *disabled) {
|
||||
int n = snprintf(d.text, sizeof d.text, "%s", menu_text(desc));
|
||||
static void desc_set(Desc &d, const char *desc, const char *key, const CfgMeta *m, const char *disabled) {
|
||||
int n = snprintf(d.text, sizeof d.text, "%s", desc);
|
||||
if (n < 0 || n >= (int)sizeof d.text) return;
|
||||
if (disabled)
|
||||
snprintf(d.text + n, sizeof d.text - n, "\n\n%s", disabled);
|
||||
@@ -56,8 +56,11 @@ void opt_focus_first(void) { g_focus_req = true; }
|
||||
void opt_focus_key(const char *key) { snprintf(g_focus_key, sizeof g_focus_key, "%s", key); }
|
||||
|
||||
void opt_reserve_bottom(float h) { g_bottom = h; }
|
||||
float opt_bottom(void) { return g_bottom; }
|
||||
|
||||
void opt_disable_next(UiTextId note) {
|
||||
void opt_disable_next(UiTextId note) { opt_disable_next_text(menu_text(note)); }
|
||||
|
||||
void opt_disable_next_text(const char *note) {
|
||||
g_disable_next = true;
|
||||
g_disable_note = note;
|
||||
}
|
||||
@@ -107,11 +110,12 @@ struct RowView {
|
||||
const char *note; // under the value instead of the "default" mark; NULL for none
|
||||
};
|
||||
|
||||
// One row: draws it, handles A / click and left / right while selected. Returns 2 (A / click), -1 / +1 (left / right) or
|
||||
// 0; always 0 for a row the environment fixes (greyed out, still selectable so its description shows).
|
||||
static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v) {
|
||||
// One row: draws it, handles A / click and left / right while selected. Returns 2 (A / click), -1 / +1 (left / right),
|
||||
// 3 / 4 (move up / down, movable rows only) or 0; always 0 for a row the environment fixes (greyed out, still selectable
|
||||
// so its description shows). movable: the top / left face buttons, Ctrl+Up / Ctrl+Down and two drawn arrows move it.
|
||||
static int row_text(const char *key, const char *label, const char *desc, const RowView &v, bool movable) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
const char *disabled = g_disable_next ? menu_text(g_disable_note) : NULL;
|
||||
const char *disabled = g_disable_next ? g_disable_note : NULL;
|
||||
g_disable_next = false;
|
||||
bool off = disabled || cfg_from_env(key) != 0;
|
||||
ImGui::PushID(key);
|
||||
@@ -145,6 +149,13 @@ static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v)
|
||||
// left and right belong to the row (navigation would otherwise move sideways into the description pane)
|
||||
ImGui::SetKeyOwner(k, ImGui::GetItemID());
|
||||
}
|
||||
if (movable) {
|
||||
bool ctrl = ImGui::GetIO().KeyCtrl;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_GamepadFaceUp, false) || (ctrl && ImGui::IsKeyPressed(ImGuiKey_UpArrow)))
|
||||
step = 3;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_GamepadFaceLeft, false) || (ctrl && ImGui::IsKeyPressed(ImGuiKey_DownArrow)))
|
||||
step = 4;
|
||||
}
|
||||
}
|
||||
if (foc) desc_set(g_focus, desc, key, m, disabled);
|
||||
if (hov) desc_set(g_hover, desc, key, m, disabled);
|
||||
@@ -174,11 +185,25 @@ static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v)
|
||||
right = rx - gap;
|
||||
value_left = lx;
|
||||
}
|
||||
if (movable) { // up and down arrows left of the value; a click on one moves the row
|
||||
// a fixed value column (On / Off differ in width) keeps the arrows of the rows in one line
|
||||
float aw = fs * 0.42f, gap = fs * 0.55f;
|
||||
float cx = right - fmaxf(ImGui::CalcTextSize(v.value).x, fs * 2.8f) - gap * 2 - aw;
|
||||
float uy = ty + fs * 0.12f, dy = ty + fs * 0.92f;
|
||||
ImU32 ac = off ? kGrey : hov || foc ? kGold : IM_COL32(170, 170, 160, 255);
|
||||
dl->AddTriangleFilled(ImVec2(cx, uy + aw * 0.7f), ImVec2(cx + aw, uy + aw * 0.7f), ImVec2(cx + aw * 0.5f, uy), ac);
|
||||
dl->AddTriangleFilled(ImVec2(cx, dy - aw * 0.7f), ImVec2(cx + aw, dy - aw * 0.7f), ImVec2(cx + aw * 0.5f, dy), ac);
|
||||
if (clicked && !off) {
|
||||
ImVec2 mp = ImGui::GetIO().MousePos;
|
||||
if (mp.x >= cx - gap * 0.5f && mp.x <= cx + aw + gap * 0.5f) step = mp.y < ty + fs * 0.52f ? 3 : 4;
|
||||
}
|
||||
value_left = cx - gap;
|
||||
}
|
||||
if (v.value[0]) {
|
||||
float vx = right - ImGui::CalcTextSize(v.value).x;
|
||||
dl->AddText(ImVec2(vx, ty), off ? kGrey : v.is_default ? IM_COL32(205, 205, 195, 255) : IM_COL32(255, 255, 255, 255),
|
||||
v.value);
|
||||
if (!v.arrows) value_left = vx;
|
||||
if (!v.arrows && !movable) value_left = vx;
|
||||
}
|
||||
if (v.note || v.is_default) { // under the value, right-aligned with it
|
||||
const char *t = v.note ? v.note : menu_text(UI_MENU_DEFAULT_MARK);
|
||||
@@ -187,8 +212,7 @@ static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v)
|
||||
}
|
||||
// the label and its note, clipped before the value
|
||||
ImVec4 clip(p.x, p.y, value_left - fs * 0.6f, p.y + h);
|
||||
dl->AddText(font, fs, ImVec2(p.x + pad, ty), off ? kGrey : IM_COL32(240, 236, 224, 255), menu_text(label), NULL, 0,
|
||||
&clip);
|
||||
dl->AddText(font, fs, ImVec2(p.x + pad, ty), off ? kGrey : IM_COL32(240, 236, 224, 255), label, NULL, 0, &clip);
|
||||
const char *note = disabled ? disabled
|
||||
: off ? menu_text(UI_MENU_SET_BY_ENV)
|
||||
: m && !m->live ? menu_text(UI_MENU_AFTER_RESTART)
|
||||
@@ -198,6 +222,16 @@ static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v)
|
||||
return off ? 0 : step;
|
||||
}
|
||||
|
||||
static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v) {
|
||||
return row_text(key, menu_text(label), menu_text(desc), v, false);
|
||||
}
|
||||
|
||||
int opt_text_row(const char *id, const char *label, const char *value, const char *note, const char *desc,
|
||||
bool movable) {
|
||||
RowView v = {value ? value : "", false, false, note};
|
||||
return row_text(id, label, desc, v, movable);
|
||||
}
|
||||
|
||||
// ---- writing a setting: at once in memory (live settings follow), to totk.ini a moment later (opt_save_tick)
|
||||
static uint64_t g_save_at; // plat_now_ns deadline of the pending write; 0 none
|
||||
static bool g_save_logged;
|
||||
@@ -241,6 +275,26 @@ bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value
|
||||
return row(id, label, desc, v) == 2; // A or a click; left and right do nothing
|
||||
}
|
||||
|
||||
bool opt_toggle_text(const char *id, const char *label, const char *desc, bool on, const char *value) {
|
||||
// off is the plain state: its value drawn dim, without the "default" mark
|
||||
RowView v = {value ? value : menu_text(on ? UI_MENU_ON : UI_MENU_OFF), !on, false, on ? NULL : ""};
|
||||
return row_text(id, label, desc, v, false) != 0; // any step flips it
|
||||
}
|
||||
|
||||
void opt_group_text(const char *title) {
|
||||
ImGui::Dummy(ImVec2(0, 6 * g_scale));
|
||||
ImGui::PushTextWrapPos(0);
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1), "%s", title);
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
void opt_text_str(const char *text, bool warn) {
|
||||
ImGui::PushTextWrapPos(0);
|
||||
if (warn) ImGui::TextColored(ImVec4(0.95f, 0.66f, 0.40f, 1), "%s", text);
|
||||
else ImGui::TextUnformatted(text);
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
void opt_group(UiTextId title) {
|
||||
ImGui::Dummy(ImVec2(0, 6 * g_scale));
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1), "%s", menu_text(title));
|
||||
@@ -294,12 +348,18 @@ bool opt_choice(const char *key, UiTextId label, const UiTextId *names, int n, U
|
||||
return opt_choice_list(key, label, values, shown, n, desc, -1, note);
|
||||
}
|
||||
|
||||
bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId desc, float step, const char *fmt) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
double v = cfg_double(key), def = m ? strtod(m->def, NULL) : lo;
|
||||
bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId desc, float step, const char *fmt,
|
||||
const char *note, const char *fallback) {
|
||||
const char *set = cfg_get(key);
|
||||
const char *src = fallback && !(set && *set) ? fallback : key; // unset: show the value in effect, the fallback's
|
||||
const CfgMeta *m = cfg_meta(src);
|
||||
// A key without a table default of its own (the per-stick dead zones) defaults to its fallback: the "default" mark
|
||||
// follows the fallback's default, not 0, even once the key is set.
|
||||
if (fallback && m && !m->def[0]) m = cfg_meta(fallback);
|
||||
double v = cfg_double(src), def = m && m->def[0] ? strtod(m->def, NULL) : lo;
|
||||
char shown[48];
|
||||
snprintf(shown, sizeof shown, fmt, v);
|
||||
RowView rv = {shown, fabs(v - def) < step * 0.01, true, NULL};
|
||||
RowView rv = {shown, fabs(v - def) < step * 0.01, true, note};
|
||||
int s = row(key, label, desc, rv);
|
||||
if (!s) return false;
|
||||
int steps = g_held && (hi - lo) > 40 * step ? 10 : 1; // held: ten steps at a time over a long range
|
||||
@@ -310,7 +370,8 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de
|
||||
char out[32];
|
||||
if (step >= 1) snprintf(out, sizeof out, "%d", (int)lround(n));
|
||||
else snprintf(out, sizeof out, "%g", round(n / step) * step);
|
||||
apply(key, out);
|
||||
// Landing on the fallback's value unsets the key (its line leaves totk.ini), so the row follows the fallback again.
|
||||
apply(key, fallback && fabs(n - cfg_double(fallback)) < step * 0.01 ? "" : out);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -400,9 +461,9 @@ int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *
|
||||
}
|
||||
char k[64];
|
||||
snprintf(k, sizeof k, "TOTK_%s", key);
|
||||
if (row_foc) desc_set(g_focus, desc, k, NULL, NULL);
|
||||
if (row_hov) desc_set(g_hover, desc, k, NULL, NULL);
|
||||
if (!g_first.text[0]) desc_set(g_first, desc, k, NULL, NULL);
|
||||
if (row_foc) desc_set(g_focus, menu_text(desc), k, NULL, NULL);
|
||||
if (row_hov) desc_set(g_hover, menu_text(desc), k, NULL, NULL);
|
||||
if (!g_first.text[0]) desc_set(g_first, menu_text(desc), k, NULL, NULL);
|
||||
if (note && (row_foc || row_hov)) { // e.g. what moved here, after the description
|
||||
Desc &d = row_hov ? g_hover : g_focus;
|
||||
size_t n = strlen(d.text);
|
||||
|
||||
@@ -19,12 +19,15 @@ void opt_begin(const char *id, float scale);
|
||||
void opt_end(void);
|
||||
// The height the next pages leave free under their panes (the menu's bottom row).
|
||||
void opt_reserve_bottom(float h);
|
||||
// The height opt_reserve_bottom keeps free, for a tab that lays out its own panes (ui/amiibo_page.cpp).
|
||||
float opt_bottom(void);
|
||||
// The next page's first row takes the controller's cursor (opening the menu, switching tabs).
|
||||
void opt_focus_first(void);
|
||||
// The row of key (or button id) takes the cursor, scrolled into view, when it is next drawn.
|
||||
void opt_focus_key(const char *key);
|
||||
// The next row is greyed out like one the environment fixes, with note under its label and in its description.
|
||||
void opt_disable_next(UiTextId note);
|
||||
void opt_disable_next_text(const char *note); // note must outlive the frame
|
||||
|
||||
// Page text that is not a row: a group heading in the accent colour, a wrapped paragraph (warn: the warning colour).
|
||||
void opt_group(UiTextId title);
|
||||
@@ -45,9 +48,23 @@ bool opt_choice_list(const char *key, UiTextId label, const char *const *values,
|
||||
// A row that runs an action: true on A or a click. id: unique on the page and not a setting ("##copy_info"); value:
|
||||
// shown on the right ("" none).
|
||||
bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value = "");
|
||||
// A row whose label, value, note (under the value) and description are text, not catalog ids: a mod's folder name.
|
||||
// Returns 2 (A / click), -1 / +1 (left / right), 3 / 4 (move up / down: the top / left face buttons, Ctrl+Up /
|
||||
// Ctrl+Down, the drawn arrows; movable rows only) or 0.
|
||||
int opt_text_row(const char *id, const char *label, const char *value, const char *note, const char *desc,
|
||||
bool movable);
|
||||
// Rows and text that are not settings of the cfg table: a label and description of the caller's own (the cheats of
|
||||
// the cheat files). opt_toggle_text shows on / off (value: shown instead, NULL for On / Off) and returns true on A, a
|
||||
// click, left or right; the caller changes its state. id: unique on the page, the environment check uses it.
|
||||
bool opt_toggle_text(const char *id, const char *label, const char *desc, bool on, const char *value = nullptr);
|
||||
void opt_group_text(const char *title);
|
||||
void opt_text_str(const char *text, bool warn = false);
|
||||
// lo..hi in steps of step (left and right held for a second go ten times as fast); fmt formats the value ("%.0f %%").
|
||||
// note: a short line under the value in place of the "default" mark (NULL: none). fallback: the setting that applies
|
||||
// while key is unset; the row shows its value then, and a change sets key. A key with no table default of its own takes
|
||||
// the "default" mark from the fallback's default, and a step onto the fallback's value unsets key again.
|
||||
bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId desc, float step = 1,
|
||||
const char *fmt = "%g");
|
||||
const char *fmt = "%g", const char *note = nullptr, const char *fallback = nullptr);
|
||||
|
||||
// Binding rows (remapping on the Controls tab): a label and three cells, each selectable on its own (left / right move between them).
|
||||
// opt_bind_header: the column titles above them. opt_bind_row: key is the setting's name without TOTK_ (BIND_A; the
|
||||
|
||||
Reference in new issue
Block a user