mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 06:29:58 -04:00
Import the base tree (MIT, see LICENSE)
This commit is contained in:
305
runtime/ui/amiibo_page.cpp
Normal file
305
runtime/ui/amiibo_page.cpp
Normal file
@@ -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("NX2NAVI_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("NX2NAVI_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();
|
||||
}
|
||||
4
runtime/ui/amiibo_page.h
Normal file
4
runtime/ui/amiibo_page.h
Normal file
@@ -0,0 +1,4 @@
|
||||
// Amiibo / NFC menu page (ui/amiibo_page.cpp).
|
||||
#pragma once
|
||||
|
||||
void tab_amiibo(float scale);
|
||||
249
runtime/ui/binds_page.cpp
Normal file
249
runtime/ui/binds_page.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
// The remapping rows of the Controls tab (binds_page.h): edits a copy of the input tables (input_map.h), writes the NX2NAVI_BIND_* lines that
|
||||
// give the copy, and input_win.c applies them at its next poll; nx2navi.ini follows a moment later (opt_save_soon). The
|
||||
// gamepad cells show and change the table of the button layout in use (NX2NAVI_PAD_LAYOUT).
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "ui/binds_page.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "input.h"
|
||||
#include "input_map.h"
|
||||
#include "platform/platform.h"
|
||||
#include "ui_text.h"
|
||||
// host.h pulls in cpu.h, which is C only: the one function needed from it, as declared there.
|
||||
void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
}
|
||||
|
||||
static_assert(UI_BIND_SHAKE - UI_BIND_A == ACTION_COUNT - 1 && B_SHAKE == ACTION_COUNT - 1, "UI_BIND_* follow the actions");
|
||||
static_assert(UI_BIND_DESC_MINUS - UI_BIND_DESC_A == B_MINUS, "UI_BIND_DESC_* follow the actions");
|
||||
static_assert(UI_KEY_PAGEDOWN - UI_KEY_SPACE == KEY_PAGEDOWN - KEY_SPACE, "UI_KEY_* follow the key ids");
|
||||
static_assert(UI_PAD_RPADDLE2 - UI_PAD_SOUTH == PAD_RPADDLE2 - PAD_SOUTH && PAD_RPADDLE2 == PAD_COUNT - 1,
|
||||
"UI_PAD_* follow the pad ids");
|
||||
|
||||
enum { CAPTURE_SECONDS = 5 };
|
||||
// The capture window stays this long after the press: the press and its click reach ImGui a frame or two later and must
|
||||
// land on the window, not on a cell (a new capture), on Continue or as Esc closing the menu.
|
||||
static const uint64_t kDoneNs = 350000000ull;
|
||||
|
||||
static const int kButtons[] = {B_A, B_B, B_X, B_Y, B_L, B_R, B_ZL, B_ZR, B_STICK_L, B_STICK_R, B_PLUS, B_MINUS,
|
||||
B_UP, B_DOWN, B_LEFT, B_RIGHT};
|
||||
static const int kMove[] = {B_SL_UP, B_SL_DOWN, B_SL_LEFT, B_SL_RIGHT};
|
||||
static const int kCamera[] = {B_SR_UP, B_SR_DOWN, B_SR_LEFT, B_SR_RIGHT};
|
||||
|
||||
static struct {
|
||||
int action = -1, cell; // the cell waiting for a press (0, 1 keys, 2 the controller); action -1 none
|
||||
bool reset; // the next capture poll takes what is held as the start
|
||||
uint64_t start, done; // plat_now_ns of the start and of the press, timeout or Esc (0 still waiting)
|
||||
} g_cap;
|
||||
static char g_note[160]; // what the last change took or swapped, after its row's description
|
||||
static int g_note_action = -1;
|
||||
static uint64_t g_note_until;
|
||||
|
||||
static const char *action_label(int a) { return menu_text((UiTextId)(UI_BIND_A + a)); }
|
||||
|
||||
static UiTextId action_desc(int a) {
|
||||
if (a <= B_MINUS) return (UiTextId)(UI_BIND_DESC_A + a);
|
||||
if (a <= B_DOWN) return UI_BIND_DESC_DPAD;
|
||||
if (a == B_SHAKE) return UI_BIND_DESC_SHAKE;
|
||||
return a <= B_SL_DOWN ? UI_BIND_DESC_MOVE : UI_BIND_DESC_CAMERA;
|
||||
}
|
||||
|
||||
static void utf8(uint32_t c, char *out, size_t n) {
|
||||
if (n < 5) { out[0] = 0; return; }
|
||||
if (c < 0x80) { out[0] = (char)c; out[1] = 0; }
|
||||
else if (c < 0x800) { out[0] = (char)(0xC0 | c >> 6); out[1] = (char)(0x80 | (c & 0x3F)); out[2] = 0; }
|
||||
else {
|
||||
out[0] = (char)(0xE0 | c >> 12); out[1] = (char)(0x80 | (c >> 6 & 0x3F)); out[2] = (char)(0x80 | (c & 0x3F));
|
||||
out[3] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// A key as the player sees it: its catalog name, the numpad format, the character on a punctuation key in the keyboard
|
||||
// layout in use, else its nx2navi.ini name in capitals (letters, digits, F keys).
|
||||
static const char *key_label(int k, char *buf, size_t n) {
|
||||
if (k == KEY_NONE) return "";
|
||||
if (k >= KEY_SPACE && k <= KEY_PAGEDOWN) return menu_text((UiTextId)(UI_KEY_SPACE + (k - KEY_SPACE)));
|
||||
if (k >= KEY_NUM0 && k <= KEY_NUM_DECIMAL) {
|
||||
static const char *const ops[] = {"+", "-", "*", "/", "."};
|
||||
char d[4];
|
||||
if (k <= KEY_NUM9) snprintf(d, sizeof d, "%d", k - KEY_NUM0);
|
||||
else snprintf(d, sizeof d, "%s", ops[k - KEY_NUM_ADD]);
|
||||
snprintf(buf, n, menu_text(UI_KEY_NUM_FMT), d);
|
||||
return buf;
|
||||
}
|
||||
if (uint32_t c = input_key_char(k)) {
|
||||
utf8(c, buf, n);
|
||||
return buf;
|
||||
}
|
||||
snprintf(buf, n, "%s", input_key_name(k));
|
||||
for (char *p = buf; *p; p++)
|
||||
if (*p >= 'a' && *p <= 'z') *p = (char)(*p - 'a' + 'A');
|
||||
return buf;
|
||||
}
|
||||
|
||||
// A gamepad button: the label the open pad has on a face button, else its place on the pad.
|
||||
static const char *pad_label(int p) {
|
||||
if (p == PAD_NONE) return "";
|
||||
switch (input_pad_label(p)) {
|
||||
case PAD_LABEL_A: return "A";
|
||||
case PAD_LABEL_B: return "B";
|
||||
case PAD_LABEL_X: return "X";
|
||||
case PAD_LABEL_Y: return "Y";
|
||||
case PAD_LABEL_CROSS: return menu_text(UI_PAD_CROSS);
|
||||
case PAD_LABEL_CIRCLE: return menu_text(UI_PAD_CIRCLE);
|
||||
case PAD_LABEL_SQUARE: return menu_text(UI_PAD_SQUARE);
|
||||
case PAD_LABEL_TRIANGLE: return menu_text(UI_PAD_TRIANGLE);
|
||||
}
|
||||
return menu_text((UiTextId)(UI_PAD_SOUTH + (p - PAD_SOUTH)));
|
||||
}
|
||||
|
||||
// The layout the gamepad cells show: the one in effect, or without a gamepad the one the setting names (Xbox for auto).
|
||||
static int shown_layout(void) {
|
||||
int l = input_pad_layout();
|
||||
return l >= 0 ? l : input_pad_layout_pick(cfg_value("NX2NAVI_PAD_LAYOUT"), 0);
|
||||
}
|
||||
|
||||
// Writes the bind_ line of every action whose line for m differs from the one set; a line at the defaults goes away.
|
||||
static void write_lines(const InputMap *m) {
|
||||
for (int a = 0; a < ACTION_COUNT; a++) {
|
||||
char var[40], line[256];
|
||||
snprintf(var, sizeof var, "NX2NAVI_BIND_%s", input_action_name(a));
|
||||
input_map_line(m, a, line, sizeof line);
|
||||
const char *now = cfg_get(var);
|
||||
if (!strcmp(line, now ? now : "")) continue;
|
||||
if (line[0]) {
|
||||
cfg_set(var, line);
|
||||
} else {
|
||||
const char *k = var + 5;
|
||||
cfg_reset(&k, 1);
|
||||
}
|
||||
rt_log("menu: bind_%s = %s", input_action_name(a), line[0] ? line : "(default)");
|
||||
}
|
||||
opt_save_soon();
|
||||
}
|
||||
|
||||
static void set_note(int action, UiTextId fmt, const char *a, const char *b) {
|
||||
snprintf(g_note, sizeof g_note, menu_text(fmt), a, b);
|
||||
g_note_action = action;
|
||||
g_note_until = plat_now_ns() + 5000000000ull;
|
||||
}
|
||||
|
||||
// cell 0, 1: a key (KEY_NONE clears it); 2: a gamepad button (PAD_NONE clears it).
|
||||
static void change(int action, int cell, int id) {
|
||||
InputMap m;
|
||||
input_map_snapshot(&m);
|
||||
char buf[48];
|
||||
if (cell < 2) {
|
||||
int lost = input_map_set_key(&m, action, cell, id);
|
||||
if (lost >= 0) set_note(action, UI_BINDS_TAKEN, key_label(id, buf, sizeof buf), action_label(lost));
|
||||
} else {
|
||||
int other = input_map_set_pad(&m, action, shown_layout(), id);
|
||||
if (other >= 0) set_note(action, UI_BINDS_SWAPPED, action_label(action), action_label(other));
|
||||
}
|
||||
write_lines(&m);
|
||||
}
|
||||
|
||||
static void reset_binds(void) {
|
||||
char names[ACTION_COUNT][32];
|
||||
const char *keys[ACTION_COUNT];
|
||||
for (int a = 0; a < ACTION_COUNT; a++) {
|
||||
snprintf(names[a], sizeof names[a], "BIND_%s", input_action_name(a));
|
||||
keys[a] = names[a];
|
||||
}
|
||||
int n = cfg_reset(keys, ACTION_COUNT);
|
||||
opt_save_soon();
|
||||
g_note_action = -1;
|
||||
rt_log("menu: reset %d button bindings", n);
|
||||
}
|
||||
|
||||
static void row_action(int a, const InputMap &m, int layout) {
|
||||
uint8_t k[INPUT_BINDING_MAX], p[INPUT_PAD_BINDING_MAX];
|
||||
int nk = input_map_keys_of(&m, a, k, INPUT_BINDING_MAX);
|
||||
int np = a < B_SL_LEFT ? input_map_pads_of(&m, a, layout, p, INPUT_PAD_BINDING_MAX) : 0;
|
||||
char b0[48], b1[48];
|
||||
const char *cells[3] = {nk > 0 ? key_label(k[0], b0, sizeof b0) : "", nk > 1 ? key_label(k[1], b1, sizeof b1) : "",
|
||||
a >= B_SL_LEFT ? menu_text(a <= B_SL_DOWN ? UI_PAD_LSTICK : UI_PAD_RSTICK)
|
||||
: np ? pad_label(p[0])
|
||||
: ""};
|
||||
const bool enabled[3] = {true, true, a < B_SL_LEFT}; // the sticks stay sticks (and the shake is the right stick's)
|
||||
char key[32];
|
||||
snprintf(key, sizeof key, "BIND_%s", input_action_name(a));
|
||||
const char *note = g_note_action == a && plat_now_ns() < g_note_until ? g_note : nullptr;
|
||||
int r = opt_bind_row(key, action_label(a), action_desc(a), cells, enabled, note);
|
||||
if (g_cap.action >= 0 || r < 0) return;
|
||||
if (r < 3) {
|
||||
g_cap.action = a;
|
||||
g_cap.cell = r;
|
||||
g_cap.reset = true;
|
||||
g_cap.start = plat_now_ns();
|
||||
g_cap.done = 0;
|
||||
} else {
|
||||
change(a, r - 10, 0); // KEY_NONE / PAD_NONE
|
||||
}
|
||||
}
|
||||
|
||||
// The window over the page while a cell waits: the press is polled from the devices (input_capture), so the menu's own
|
||||
// keys (Enter, arrows, Q / E) bind like any other. Esc or the timeout cancels; a controller button cancels a key cell.
|
||||
static void capture_window(void) {
|
||||
if (g_cap.action < 0) return;
|
||||
if (!ImGui::IsPopupOpen("##bind_capture")) ImGui::OpenPopup("##bind_capture");
|
||||
uint64_t now = plat_now_ns();
|
||||
bool pad_cell = g_cap.cell == 2;
|
||||
if (!g_cap.done) {
|
||||
int id = 0, got = input_capture(g_cap.reset, &id);
|
||||
g_cap.reset = false;
|
||||
if (got == INPUT_CAPTURE_KEY && !pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got == INPUT_CAPTURE_PAD && pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got != INPUT_CAPTURE_NONE && !(got == INPUT_CAPTURE_KEY && pad_cell)) g_cap.done = now;
|
||||
if (now - g_cap.start > CAPTURE_SECONDS * 1000000000ull) g_cap.done = now;
|
||||
}
|
||||
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
if (ImGui::BeginPopupModal("##bind_capture", nullptr,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
char t[256];
|
||||
snprintf(t, sizeof t, menu_text(pad_cell ? UI_BINDS_PRESS_PAD : UI_BINDS_PRESS_KEY), action_label(g_cap.action));
|
||||
ImGui::TextUnformatted(t);
|
||||
int left = CAPTURE_SECONDS - (int)((now - g_cap.start) / 1000000000ull);
|
||||
snprintf(t, sizeof t, menu_text(UI_BINDS_CANCEL_HINT), left < 1 ? 1 : left);
|
||||
ImGui::TextDisabled("%s", t);
|
||||
if (g_cap.done && now - g_cap.done > kDoneNs) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
char id[48];
|
||||
snprintf(id, sizeof id, "BIND_%s#%d", input_action_name(g_cap.action), g_cap.cell);
|
||||
opt_focus_key(id); // back on the cell it came from
|
||||
g_cap.action = -1;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
bool binds_modal(void) { return g_cap.action >= 0; }
|
||||
|
||||
static bool g_reset_asked; // the reset row was chosen this frame (acted on after the page)
|
||||
|
||||
void binds_rows(float scale) {
|
||||
InputMap m;
|
||||
input_map_snapshot(&m);
|
||||
int layout = shown_layout();
|
||||
opt_group(UI_BINDS_GROUP_BUTTONS);
|
||||
opt_text(UI_BINDS_HELP);
|
||||
opt_bind_header(UI_BINDS_COL_KEY1, UI_BINDS_COL_KEY2, UI_BINDS_COL_PAD);
|
||||
for (int a : kButtons) row_action(a, m, layout);
|
||||
opt_group(UI_BINDS_GROUP_MOVE);
|
||||
for (int a : kMove) row_action(a, m, layout);
|
||||
opt_group(UI_BINDS_GROUP_CAMERA);
|
||||
for (int a : kCamera) row_action(a, m, layout);
|
||||
row_action(B_SHAKE, m, layout); // keys only; its controller cell shows the right stick, which the pad shakes itself
|
||||
ImGui::Dummy(ImVec2(0, 6 * scale));
|
||||
g_reset_asked = opt_button("##binds_reset", UI_BINDS_RESET, UI_BINDS_RESET_DESC);
|
||||
}
|
||||
|
||||
void binds_after_page(void) {
|
||||
if (g_reset_asked && g_cap.action < 0) reset_binds();
|
||||
g_reset_asked = false;
|
||||
capture_window();
|
||||
}
|
||||
10
runtime/ui/binds_page.h
Normal file
10
runtime/ui/binds_page.h
Normal file
@@ -0,0 +1,10 @@
|
||||
// The remapping rows of the menu's Controls tab (ui/binds_page.cpp). Present path only (ImGui).
|
||||
#pragma once
|
||||
|
||||
// Inside the page's opt_begin / opt_end: every action's two keys and its controller button, remapped by selecting a
|
||||
// cell and pressing the new one, and the reset of them all. binds_after_page, after opt_end: the window that waits for
|
||||
// the press.
|
||||
void binds_rows(float scale);
|
||||
void binds_after_page(void);
|
||||
// A cell waits for a press (or its press is still reaching the menu): B, Esc, L / R and the tab keys stay on the page.
|
||||
bool binds_modal(void);
|
||||
66
runtime/ui/cheats_tab.cpp
Normal file
66
runtime/ui/cheats_tab.cpp
Normal file
@@ -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;
|
||||
}
|
||||
69
runtime/ui/fonts/LICENSE-Roboto.txt
Normal file
69
runtime/ui/fonts/LICENSE-Roboto.txt
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
------------
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
BIN
runtime/ui/fonts/Roboto-Medium.ttf
Normal file
BIN
runtime/ui/fonts/Roboto-Medium.ttf
Normal file
Binary file not shown.
1586
runtime/ui/menu.cpp
Normal file
1586
runtime/ui/menu.cpp
Normal file
File diff suppressed because it is too large
Load Diff
74
runtime/ui/menu.h
Normal file
74
runtime/ui/menu.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// The in-game menu (ui/menu.cpp, Dear ImGui) and its seams to the platform side: the window and its input (ui/menu_win.cpp
|
||||
// on Windows, ui/menu_sdl.cpp with SDL), the gamepad (input_pad_read, input.h) and the present path
|
||||
// (gfx_present.c). The menu core calls no window system: events come in through menu_event_*, the drawing happens in the
|
||||
// present path's command buffer.
|
||||
//
|
||||
// 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, 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): NX2NAVI_MENU_TEST=<frame>[:<frames per page>] opens the menu at that presented frame and saves
|
||||
// one swapchain shot per tab into NX2NAVI_MENU_TEST_DIR; NX2NAVI_MENU_TEST_SET=<frame>:<key>=<value>[,...][;...] sets settings
|
||||
// at given frames without input (SAVE=1 writes nx2navi.ini).
|
||||
//
|
||||
// Threads: the event functions are called by the window thread, menu_toggle by whichever thread polls the pad, the
|
||||
// overlay functions by the present path under its lock. ImGui itself runs on the present path only.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---- state, any thread
|
||||
int menu_is_open(void);
|
||||
void menu_toggle(void); // F1 / Esc on the keyboard, Minus+Plus on the pad
|
||||
void menu_perf_cycle(void); // F10: the performance overlay off, fps, full
|
||||
|
||||
// ---- events from the window adapter, used only while the menu is open. key: an ImGuiKey; coordinates in pixels of the
|
||||
// window's client area, which is the swapchain image.
|
||||
void menu_event_key(int key, int down);
|
||||
void menu_event_mouse_pos(float x, float y);
|
||||
void menu_event_mouse_button(int button, int down); // 0 left, 1 right, 2 middle
|
||||
void menu_event_wheel(float dx, float dy);
|
||||
void menu_event_focus(int focused);
|
||||
|
||||
// ---- the overlay, drawn into the swapchain image after the game image (gfx_present.c, present lock held)
|
||||
typedef struct {
|
||||
VkInstance instance;
|
||||
VkPhysicalDevice phys;
|
||||
VkDevice device;
|
||||
uint32_t queue_family;
|
||||
VkQueue queue; // submissions take vk_queue_lock
|
||||
VkFormat format; // of the swapchain image, a colour attachment
|
||||
uint32_t width, height;
|
||||
int image_w, image_h; // the game image this present shows (its crop)
|
||||
int scaler; // how the last present scaled it to the window: 0 not, 1 bilinear blit, 2 FSR 1
|
||||
} MenuTarget;
|
||||
// Lays out this frame's overlay; 1 when there is something to draw. frame: the presented frame (0 unknown). *shot: a
|
||||
// path when the test hook wants this frame's swapchain image saved, else NULL. The first open starts ImGui's Vulkan
|
||||
// back end and uploads the font. With the menu closed it costs two loads and a compare.
|
||||
int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot);
|
||||
// Records the frame menu_overlay_frame laid out into cb, which is inside dynamic rendering on the image.
|
||||
void menu_overlay_draw(VkCommandBuffer cb);
|
||||
void menu_vk_release(void); // before the device goes away (gfx_window_release_vk)
|
||||
// The check the font atlas runs on a system font, on the embedded font and damaged copies of it: 1 when it takes the
|
||||
// whole font and refuses a cut-off one, one without a character map and one with an unknown tag (--probe-window).
|
||||
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); // NX2NAVI_FULLSCREEN or NX2NAVI_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 nx2navi.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 (NX2NAVI_FPS_LIMIT=display); 0 when unknown
|
||||
unsigned gfx_window_dpi(void); // the window's DPI (96 at 100% display scale); any thread
|
||||
// The present mode the swapchain got, as a NX2NAVI_VK_PRESENT value ("fifo" when mailbox is missing); "" before the first
|
||||
// swapchain. Any thread.
|
||||
const char *gfx_window_present_mode(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
82
runtime/ui/menu_sdl.cpp
Normal file
82
runtime/ui/menu_sdl.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
// SDL3 adapter of the in-game menu: the window's events to menu events (menu.h), as ui/menu_win.cpp does for Win32.
|
||||
// Window thread (gfx_window_sdl.c's event loop, after input_sdl_event).
|
||||
//
|
||||
// F1 opens and closes the menu, Esc opens it (with the menu open, Esc goes to the menu, which closes). Esc also releases
|
||||
// the cursor (input_sdl.c sees the event first; closing the menu gives the capture back). While the menu is open, its
|
||||
// keys, the mouse and focus changes go to it; the game reads the keyboard through input_sdl.c and gets nothing while
|
||||
// the menu is open (input_menu). Mouse positions come in window units and go to the menu in pixels.
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C" {
|
||||
#include "input.h"
|
||||
#include "input_sdl.h"
|
||||
#include "ui/menu.h"
|
||||
}
|
||||
|
||||
static ImGuiKey key_of(SDL_Scancode sc) {
|
||||
switch (sc) {
|
||||
case SDL_SCANCODE_UP: return ImGuiKey_UpArrow;
|
||||
case SDL_SCANCODE_DOWN: return ImGuiKey_DownArrow;
|
||||
case SDL_SCANCODE_LEFT: return ImGuiKey_LeftArrow;
|
||||
case SDL_SCANCODE_RIGHT: return ImGuiKey_RightArrow;
|
||||
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_KP_ENTER: return ImGuiKey_Enter;
|
||||
case SDL_SCANCODE_SPACE: return ImGuiKey_Space;
|
||||
case SDL_SCANCODE_ESCAPE: return ImGuiKey_Escape;
|
||||
case SDL_SCANCODE_TAB: return ImGuiKey_Tab;
|
||||
case SDL_SCANCODE_BACKSPACE: return ImGuiKey_Backspace;
|
||||
case SDL_SCANCODE_DELETE: return ImGuiKey_Delete; // clears a cell of the remapping rows
|
||||
case SDL_SCANCODE_HOME: return ImGuiKey_Home;
|
||||
case SDL_SCANCODE_END: return ImGuiKey_End;
|
||||
case SDL_SCANCODE_PAGEUP: return ImGuiKey_PageUp;
|
||||
case SDL_SCANCODE_PAGEDOWN: return ImGuiKey_PageDown;
|
||||
case SDL_SCANCODE_LSHIFT: case SDL_SCANCODE_RSHIFT: return ImGuiKey_LeftShift;
|
||||
case SDL_SCANCODE_LCTRL: case SDL_SCANCODE_RCTRL: return ImGuiKey_LeftCtrl;
|
||||
case SDL_SCANCODE_Q: return ImGuiKey_Q; // previous tab
|
||||
case SDL_SCANCODE_E: return ImGuiKey_E; // next tab
|
||||
default: return ImGuiKey_None;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void menu_sdl_event(const SDL_Event *e) {
|
||||
float d = (float)gfx_window_sdl_density();
|
||||
switch (e->type) {
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
// Esc with the menu open (opened by F1 too) is not a toggle here: it goes to the menu, which closes itself
|
||||
if (!e->key.repeat && (e->key.scancode == SDL_SCANCODE_F1 ||
|
||||
(e->key.scancode == SDL_SCANCODE_ESCAPE && !menu_is_open()))) {
|
||||
menu_toggle();
|
||||
return;
|
||||
}
|
||||
if (e->key.scancode == SDL_SCANCODE_F10) {
|
||||
if (!e->key.repeat) menu_perf_cycle();
|
||||
return;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case SDL_EVENT_KEY_UP:
|
||||
if (!menu_is_open()) return;
|
||||
if (ImGuiKey k = key_of(e->key.scancode)) menu_event_key(k, e->type == SDL_EVENT_KEY_DOWN);
|
||||
return;
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
if (menu_is_open()) menu_event_mouse_pos(e->motion.x * d, e->motion.y * d);
|
||||
return;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
||||
if (!menu_is_open()) return;
|
||||
int b = e->button.button == SDL_BUTTON_LEFT ? 0 : e->button.button == SDL_BUTTON_RIGHT ? 1
|
||||
: e->button.button == SDL_BUTTON_MIDDLE ? 2 : -1;
|
||||
if (b < 0) return;
|
||||
menu_event_mouse_pos(e->button.x * d, e->button.y * d);
|
||||
menu_event_mouse_button(b, e->type == SDL_EVENT_MOUSE_BUTTON_DOWN);
|
||||
return;
|
||||
}
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
if (menu_is_open()) menu_event_wheel(e->wheel.x, e->wheel.y);
|
||||
return;
|
||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
menu_event_focus(e->type == SDL_EVENT_WINDOW_FOCUS_GAINED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
88
runtime/ui/menu_win.cpp
Normal file
88
runtime/ui/menu_win.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Win32 adapter of the in-game menu: window messages to menu events (menu.h). The only Win32 code of the menu; the SDL3
|
||||
// window has its own (ui/menu_sdl.cpp). Window thread.
|
||||
//
|
||||
// F1 opens and closes the menu, Esc opens it (with the menu open, Esc goes to the menu, which closes). Esc also releases
|
||||
// the cursor (input_window_msg runs first; closing the menu gives the capture back). While the menu is open, its keys,
|
||||
// the mouse and focus changes go to it; the game polls the keyboard on its own (input_win.c) and gets nothing while the
|
||||
// menu is open (input_menu).
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C" {
|
||||
#include "input.h"
|
||||
#include "input_win.h"
|
||||
#include "ui/menu.h"
|
||||
}
|
||||
|
||||
static ImGuiKey key_of(WPARAM vk) {
|
||||
switch (vk) {
|
||||
case VK_UP: return ImGuiKey_UpArrow;
|
||||
case VK_DOWN: return ImGuiKey_DownArrow;
|
||||
case VK_LEFT: return ImGuiKey_LeftArrow;
|
||||
case VK_RIGHT: return ImGuiKey_RightArrow;
|
||||
case VK_RETURN: return ImGuiKey_Enter;
|
||||
case VK_SPACE: return ImGuiKey_Space;
|
||||
case VK_ESCAPE: return ImGuiKey_Escape;
|
||||
case VK_TAB: return ImGuiKey_Tab;
|
||||
case VK_BACK: return ImGuiKey_Backspace;
|
||||
case VK_DELETE: return ImGuiKey_Delete; // clears a cell of the remapping rows
|
||||
case VK_HOME: return ImGuiKey_Home;
|
||||
case VK_END: return ImGuiKey_End;
|
||||
case VK_PRIOR: return ImGuiKey_PageUp;
|
||||
case VK_NEXT: return ImGuiKey_PageDown;
|
||||
case VK_SHIFT: return ImGuiKey_LeftShift;
|
||||
case VK_CONTROL: return ImGuiKey_LeftCtrl;
|
||||
case 'Q': return ImGuiKey_Q; // previous tab
|
||||
case 'E': return ImGuiKey_E; // next tab
|
||||
default: return ImGuiKey_None;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
(void)h;
|
||||
switch (m) {
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
// bit 30: auto-repeat
|
||||
// Esc with the menu open (opened by F1 too) is not a toggle here: it goes to the menu, which closes itself
|
||||
if (!(l & (1 << 30)) && (w == VK_F1 || (w == VK_ESCAPE && !menu_is_open()))) {
|
||||
menu_toggle();
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
if (w == VK_F10) { // also keeps F10 from opening the window menu
|
||||
if (!(l & (1 << 30))) menu_perf_cycle();
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
[[fallthrough]];
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
if (!menu_is_open()) return 0;
|
||||
if (ImGuiKey k = key_of(w)) menu_event_key(k, m == WM_KEYDOWN || m == WM_SYSKEYDOWN);
|
||||
return 0; // F11 and the system keys keep working
|
||||
case WM_MOUSEMOVE:
|
||||
if (menu_is_open()) menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
return 0;
|
||||
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
|
||||
case WM_RBUTTONDOWN: case WM_RBUTTONUP:
|
||||
case WM_MBUTTONDOWN: case WM_MBUTTONUP: {
|
||||
if (!menu_is_open()) return 0;
|
||||
int b = m == WM_LBUTTONDOWN || m == WM_LBUTTONUP ? 0 : m == WM_RBUTTONDOWN || m == WM_RBUTTONUP ? 1 : 2;
|
||||
int down = m == WM_LBUTTONDOWN || m == WM_RBUTTONDOWN || m == WM_MBUTTONDOWN;
|
||||
menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
menu_event_mouse_button(b, down);
|
||||
return 0;
|
||||
}
|
||||
case WM_MOUSEWHEEL:
|
||||
if (menu_is_open()) menu_event_wheel(0, (float)GET_WHEEL_DELTA_WPARAM(w) / WHEEL_DELTA);
|
||||
return 0;
|
||||
case WM_SETFOCUS:
|
||||
case WM_KILLFOCUS:
|
||||
menu_event_focus(m == WM_SETFOCUS);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
476
runtime/ui/option_rows.cpp
Normal file
476
runtime/ui/option_rows.cpp
Normal file
@@ -0,0 +1,476 @@
|
||||
// Two-pane settings pages (option_rows.h): rows on the left, the selected or hovered row's description on the right.
|
||||
//
|
||||
// Adapted from SavageWindRecomp's runtime/ui/option_rows.mm (https://github.com/Revivedx/SavageWindRecomp @
|
||||
// 575ad88e02f9a89a9a885d90039d48af33c982f4, MIT, Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors,
|
||||
// Copyright (c) 2026 Peiikai): the row look, the two panes, the left / right stepping and the hold speed-up. The rows
|
||||
// read and write cfg keys instead of a settings struct, take their text from the menu catalog (menu_text), and show
|
||||
// the default, "after restart" and environment notes; the text field, radio and on-screen keyboard rows are not ported.
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h" // SetKeyOwner, SetFocusID, NavCursorVisible
|
||||
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "platform/platform.h"
|
||||
#include "ui_text.h"
|
||||
// host.h pulls in cpu.h, which is C only: the one function needed from it, as declared there.
|
||||
void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
}
|
||||
|
||||
static const ImU32 kGold = IM_COL32(236, 194, 84, 255);
|
||||
static const ImU32 kDim = IM_COL32(150, 150, 140, 255);
|
||||
static const ImU32 kGrey = IM_COL32(110, 110, 102, 255);
|
||||
|
||||
static float g_scale = 1;
|
||||
static bool g_focus_req, g_take_first; // opt_focus_first: requested / this page's first row takes it
|
||||
static char g_focus_key[64]; // opt_focus_key: the row that takes the cursor when it is next drawn
|
||||
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 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, 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);
|
||||
else if (cfg_from_env(key))
|
||||
snprintf(d.text + n, sizeof d.text - n, "\n\n%s %s", menu_text(UI_MENU_SET_BY_ENV), key);
|
||||
else if (m && !m->live)
|
||||
snprintf(d.text + n, sizeof d.text - n, "\n\n%s", menu_text(UI_MENU_AFTER_RESTART));
|
||||
}
|
||||
|
||||
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) { opt_disable_next_text(menu_text(note)); }
|
||||
|
||||
void opt_disable_next_text(const char *note) {
|
||||
g_disable_next = true;
|
||||
g_disable_note = note;
|
||||
}
|
||||
|
||||
void opt_begin(const char *id, float scale) {
|
||||
g_scale = scale;
|
||||
g_take_first = g_focus_req;
|
||||
g_focus_req = false;
|
||||
if (g_take_first) ImGui::NavMoveRequestCancel(); // this frame's move goes to the first row instead
|
||||
g_hover.text[0] = g_focus.text[0] = g_first.text[0] = 0;
|
||||
ImVec2 avail = ImGui::GetContentRegionAvail();
|
||||
avail.y -= g_bottom;
|
||||
ImGui::PushID(id);
|
||||
ImGui::BeginChild("##rows", ImVec2(avail.x * 0.58f, avail.y), ImGuiChildFlags_NavFlattened);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 5 * scale));
|
||||
}
|
||||
|
||||
void opt_end(void) {
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndChild();
|
||||
// the hovered row (mouse) wins, else the selected one (controller), else the last shown, else the first row
|
||||
if (g_hover.text[0]) g_shown = g_hover;
|
||||
else if (g_focus.text[0]) g_shown = g_focus;
|
||||
else if (!g_shown.text[0]) g_shown = g_first;
|
||||
ImGui::SameLine(0, 0);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos(), avail = ImGui::GetContentRegionAvail();
|
||||
avail.y -= g_bottom;
|
||||
float gap = 24 * g_scale;
|
||||
ImGui::GetWindowDrawList()->AddLine(ImVec2(p.x + gap * 0.5f, p.y), ImVec2(p.x + gap * 0.5f, p.y + avail.y),
|
||||
IM_COL32(236, 194, 84, 110), 1.0f);
|
||||
ImGui::SetCursorScreenPos(ImVec2(p.x + gap, p.y));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14 * g_scale, 6 * g_scale));
|
||||
ImGui::BeginChild("##desc", ImVec2(0, avail.y), ImGuiChildFlags_AlwaysUseWindowPadding, ImGuiWindowFlags_NoNav);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PushTextWrapPos(0);
|
||||
ImGui::TextUnformatted(g_shown.text);
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
// What a row shows besides its label.
|
||||
struct RowView {
|
||||
const char *value; // right side; "" for none
|
||||
bool is_default; // the value is the setting's default: the "default" mark, the value not highlighted
|
||||
bool arrows; // a stepper: < value >, the arrows click too
|
||||
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),
|
||||
// 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 ? g_disable_note : NULL;
|
||||
g_disable_next = false;
|
||||
bool off = disabled || cfg_from_env(key) != 0;
|
||||
ImGui::PushID(key);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
// h whole pixels: ImGui truncates cursor positions, which rounds a fractional height the other way above the window's
|
||||
// top (negative y), so the page grew a pixel per row scrolled out and a row scrolled to the bottom was cut off
|
||||
float fs = ImGui::GetFontSize(), w = ImGui::GetContentRegionAvail().x, h = floorf(fs * 2.2f);
|
||||
ImGui::PushStyleColor(ImGuiCol_NavCursor, ImVec4(0, 0, 0, 0)); // the row's own border shows the selection
|
||||
bool clicked = ImGui::InvisibleButton("##row", ImVec2(w, h), ImGuiButtonFlags_EnableNav);
|
||||
ImGui::PopStyleColor();
|
||||
bool to_key = g_focus_key[0] && !strcmp(key, g_focus_key);
|
||||
if (g_take_first || to_key) {
|
||||
ImGui::SetFocusID(ImGui::GetItemID(), ImGui::GetCurrentWindow());
|
||||
ImGui::SetNavCursorVisible(true);
|
||||
if (g_take_first) ImGui::SetScrollY(0); // the page's top: text and a heading above the first row show
|
||||
else ImGui::ScrollToItem(ImGuiScrollFlags_KeepVisibleEdgeY); // as a cursor move would (the last row whole)
|
||||
g_take_first = false;
|
||||
if (to_key) g_focus_key[0] = 0;
|
||||
}
|
||||
bool hov = ImGui::IsItemHovered(), foc = ImGui::IsItemFocused() && ImGui::GetCurrentContext()->NavCursorVisible;
|
||||
int step = clicked && !off ? 2 : 0;
|
||||
g_held = false;
|
||||
if (foc && !off) {
|
||||
// the left stick arrives as the D-pad (menu.cpp pad_events)
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft) || ImGui::IsKeyPressed(ImGuiKey_LeftArrow)) step = -1;
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight) || ImGui::IsKeyPressed(ImGuiKey_RightArrow)) step = 1;
|
||||
static const ImGuiKey steps[] = {ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadRight, ImGuiKey_LeftArrow,
|
||||
ImGuiKey_RightArrow};
|
||||
for (ImGuiKey k : steps) {
|
||||
if (ImGui::GetKeyData(k)->DownDuration > 1.0f) g_held = true;
|
||||
// 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);
|
||||
if (!g_first.text[0]) desc_set(g_first, desc, key, m, disabled);
|
||||
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
ImFont *font = ImGui::GetFont();
|
||||
float r = 9 * g_scale, pad = 16 * g_scale, small = fs * 0.72f;
|
||||
dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), hov || foc ? IM_COL32(255, 255, 255, 22) : IM_COL32(0, 0, 0, 40), r);
|
||||
dl->AddRect(p, ImVec2(p.x + w, p.y + h),
|
||||
hov || foc ? (off ? IM_COL32(236, 194, 84, 120) : kGold) : IM_COL32(255, 255, 255, off ? 18 : 38), r, 0,
|
||||
hov || foc ? 2.0f : 1.0f);
|
||||
float ty = p.y + fs * 0.25f, ny = p.y + fs * 1.3f; // the label line and the note line under it
|
||||
float right = p.x + w - pad; // the value's right edge
|
||||
float value_left = right;
|
||||
if (v.arrows && v.value[0]) { // < value >, drawn (the font has no arrow glyphs); a click on one steps
|
||||
float aw = fs * 0.42f, gap = fs * 0.55f, cy = ty + fs * 0.52f;
|
||||
float rx = right - aw, lx = rx - gap - ImGui::CalcTextSize(v.value).x - gap - aw;
|
||||
ImU32 ac = off ? kGrey : hov || foc ? kGold : IM_COL32(170, 170, 160, 255);
|
||||
dl->AddTriangleFilled(ImVec2(lx, cy), ImVec2(lx + aw, cy - aw * 0.75f), ImVec2(lx + aw, cy + aw * 0.75f), ac);
|
||||
dl->AddTriangleFilled(ImVec2(rx + aw, cy), ImVec2(rx, cy - aw * 0.75f), ImVec2(rx, cy + aw * 0.75f), ac);
|
||||
if (clicked && !off) {
|
||||
float mx = ImGui::GetIO().MousePos.x;
|
||||
if (mx >= lx - gap && mx <= lx + aw + gap) step = -1;
|
||||
else if (mx >= rx - gap && mx <= rx + aw + gap) step = 1;
|
||||
}
|
||||
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 && !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);
|
||||
float tw = font->CalcTextSizeA(small, FLT_MAX, 0, t).x;
|
||||
dl->AddText(font, small, ImVec2(right - tw, ny), v.note ? IM_COL32(220, 170, 100, 255) : kDim, t);
|
||||
}
|
||||
// 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), 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)
|
||||
: NULL;
|
||||
if (note) dl->AddText(font, small, ImVec2(p.x + pad, ny), off ? IM_COL32(200, 150, 90, 255) : kDim, note);
|
||||
ImGui::PopID();
|
||||
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 nx2navi.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;
|
||||
|
||||
static void apply(const char *key, const char *value) {
|
||||
if (*value) {
|
||||
cfg_set(key, value);
|
||||
} else { // the automatic choice: the key unset, its line removed from nx2navi.ini
|
||||
const char *k = key;
|
||||
cfg_reset(&k, 1);
|
||||
}
|
||||
opt_save_soon();
|
||||
}
|
||||
|
||||
void opt_save_soon(void) { g_save_at = plat_now_ns() + 400000000ull; }
|
||||
|
||||
int opt_save_tick(int force) {
|
||||
if (!g_save_at || (!force && plat_now_ns() < g_save_at)) return g_save_at != 0;
|
||||
g_save_at = 0;
|
||||
if (!cfg_save() && !g_save_logged) {
|
||||
g_save_logged = true;
|
||||
rt_log("menu: could not write nx2navi.ini; the changed settings hold for this session");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- rows
|
||||
|
||||
bool opt_toggle(const char *key, UiTextId label, UiTextId desc, bool inverted) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
bool set = cfg_bool(key) != 0, def = m && strcmp(m->def, "0") != 0;
|
||||
bool on = set != inverted; // what the row shows
|
||||
RowView v = {menu_text(on ? UI_MENU_ON : UI_MENU_OFF), set == def, false, NULL};
|
||||
if (!row(key, label, desc, v)) return false; // any step flips it
|
||||
apply(key, set ? "0" : "1");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value) {
|
||||
RowView v = {value ? value : "", false, false, NULL};
|
||||
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));
|
||||
}
|
||||
|
||||
void opt_text(UiTextId text, bool warn) {
|
||||
ImGui::PushTextWrapPos(0);
|
||||
if (warn) ImGui::TextColored(ImVec4(0.95f, 0.66f, 0.40f, 1), "%s", menu_text(text));
|
||||
else ImGui::TextUnformatted(menu_text(text));
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
bool opt_choice_list(const char *key, UiTextId label, const char *const *values, const char *const *names, int n,
|
||||
UiTextId desc, int cur, const char *note) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
const char *now = cfg_value(key);
|
||||
if (cur < 0)
|
||||
for (int i = 0; i < n; i++)
|
||||
if (!strcmp(values[i], now)) cur = i;
|
||||
int def = -1;
|
||||
for (int i = 0; m && i < n; i++)
|
||||
if (!strcmp(values[i], m->def)) def = i;
|
||||
RowView v = {cur >= 0 ? names[cur] : now, cur == def, true, note};
|
||||
int step = row(key, label, desc, v);
|
||||
if (!step || n <= 0) return false;
|
||||
int nv;
|
||||
if (cur < 0) nv = 0;
|
||||
else if (step == 2) nv = (cur + 1) % n; // A / click: the next value, round to the first
|
||||
else nv = cur + step < 0 ? 0 : cur + step >= n ? n - 1 : cur + step; // left / right stop at the ends
|
||||
if (nv == cur) return false;
|
||||
apply(key, values[nv]);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opt_choice(const char *key, UiTextId label, const UiTextId *names, int n, UiTextId desc, const char *note) {
|
||||
enum { MAX = 32 };
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
const char *values[MAX], *shown[MAX];
|
||||
char buf[256];
|
||||
int k = 0;
|
||||
if (m && !m->def[0]) values[k++] = ""; // the automatic choice
|
||||
snprintf(buf, sizeof buf, "%s", m && m->values ? m->values : "");
|
||||
for (char *s = buf, *e; *s && k < MAX; s = e) {
|
||||
e = strchr(s, '|');
|
||||
if (e) *e++ = 0;
|
||||
else e = s + strlen(s);
|
||||
values[k++] = s;
|
||||
}
|
||||
if (n > k) n = k;
|
||||
for (int i = 0; i < n; i++) shown[i] = menu_text(names[i]);
|
||||
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 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, 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
|
||||
double n = round(v / step) * step + (s == 2 ? step : s * step * steps);
|
||||
if (s == 2 && n > hi + step * 0.01) n = lo; // A / click past the top goes round; left / right stop at the ends
|
||||
n = n < lo ? lo : n > hi ? hi : n;
|
||||
if (fabs(n - v) < step * 0.01) return false;
|
||||
char out[32];
|
||||
if (step >= 1) snprintf(out, sizeof out, "%d", (int)lround(n));
|
||||
else snprintf(out, sizeof out, "%g", round(n / step) * step);
|
||||
// Landing on the fallback's value unsets the key (its line leaves nx2navi.ini), so the row follows the fallback again.
|
||||
apply(key, fallback && fabs(n - cfg_double(fallback)) < step * 0.01 ? "" : out);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- binding rows (the remapping rows of the Controls tab): a label and three cells, each its own nav item
|
||||
|
||||
// Text centred (left-aligned when centred is false) in [x0, x1] on a row from y to y + h, at the font size or smaller so
|
||||
// a long name ("Нажатие правого стика", "Стрелка вправо") fits; under 65 % it is clipped instead.
|
||||
static void fit_text(ImDrawList *dl, float x0, float x1, float y, float h, ImU32 col, const char *t, bool centred) {
|
||||
ImFont *font = ImGui::GetFont();
|
||||
float fs = ImGui::GetFontSize(), room = x1 - x0, tw = font->CalcTextSizeA(fs, FLT_MAX, 0, t).x;
|
||||
if (tw > room) {
|
||||
fs = fmaxf(fs * room / tw, fs * 0.65f);
|
||||
tw = font->CalcTextSizeA(fs, FLT_MAX, 0, t).x;
|
||||
}
|
||||
float x = centred && tw < room ? x0 + (room - tw) * 0.5f : x0;
|
||||
ImVec4 clip(x0, y, x1, y + h);
|
||||
dl->AddText(font, fs, ImVec2(x, y + (h - fs) * 0.5f), col, t, NULL, 0, &clip);
|
||||
}
|
||||
|
||||
// The label column and the three cells of a binding row of width w.
|
||||
static void bind_columns(float x, float w, float cx[3], float *cw) {
|
||||
float lw = floorf(w * 0.34f), gap = floorf(8 * g_scale);
|
||||
*cw = floorf((w - lw - gap * 3) / 3);
|
||||
for (int c = 0; c < 3; c++) cx[c] = x + lw + gap + c * (*cw + gap);
|
||||
}
|
||||
|
||||
void opt_bind_header(UiTextId c0, UiTextId c1, UiTextId c2) {
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float w = ImGui::GetContentRegionAvail().x, cx[3], cw, fs = ImGui::GetFontSize() * 0.8f;
|
||||
bind_columns(p.x, w, cx, &cw);
|
||||
const UiTextId cols[3] = {c0, c1, c2};
|
||||
ImFont *font = ImGui::GetFont();
|
||||
for (int c = 0; c < 3; c++) {
|
||||
const char *t = menu_text(cols[c]);
|
||||
float tw = font->CalcTextSizeA(fs, FLT_MAX, 0, t).x;
|
||||
ImGui::GetWindowDrawList()->AddText(font, fs, ImVec2(cx[c] + (cw - tw) * 0.5f, p.y), kDim, t);
|
||||
}
|
||||
ImGui::Dummy(ImVec2(w, fs * 1.2f));
|
||||
}
|
||||
|
||||
int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *const cells[3], const bool enabled[3],
|
||||
const char *note) {
|
||||
ImGui::PushID(key);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float fs = ImGui::GetFontSize(), w = ImGui::GetContentRegionAvail().x, h = floorf(fs * 1.9f), cx[3], cw;
|
||||
bind_columns(p.x, w, cx, &cw);
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
float r = 8 * g_scale, pad = 6 * g_scale;
|
||||
fit_text(dl, p.x + 16 * g_scale, cx[0] - fs * 0.3f, p.y, h, IM_COL32(240, 236, 224, 255), label, false);
|
||||
int result = -1;
|
||||
bool row_foc = false, row_hov = false;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
ImVec2 a(cx[c], p.y), b(cx[c] + cw, p.y + h);
|
||||
const char *t = cells[c] && cells[c][0] ? cells[c] : "-";
|
||||
if (!enabled[c]) { // not a nav item: the cursor skips it
|
||||
dl->AddRect(a, b, IM_COL32(255, 255, 255, 14), r);
|
||||
fit_text(dl, a.x + pad, b.x - pad, a.y, h, kGrey, t, true);
|
||||
continue;
|
||||
}
|
||||
ImGui::SetCursorScreenPos(a);
|
||||
ImGui::PushID(c);
|
||||
ImGui::PushStyleColor(ImGuiCol_NavCursor, ImVec4(0, 0, 0, 0)); // the cell's own border shows the selection
|
||||
bool clicked = ImGui::InvisibleButton("##cell", ImVec2(cw, h), ImGuiButtonFlags_EnableNav);
|
||||
ImGui::PopStyleColor();
|
||||
char id[80];
|
||||
snprintf(id, sizeof id, "%s#%d", key, c);
|
||||
bool to_key = g_focus_key[0] && !strcmp(id, g_focus_key);
|
||||
if (g_take_first || to_key) {
|
||||
ImGui::SetFocusID(ImGui::GetItemID(), ImGui::GetCurrentWindow());
|
||||
ImGui::SetNavCursorVisible(true);
|
||||
if (g_take_first) ImGui::SetScrollY(0);
|
||||
else ImGui::ScrollToItem(ImGuiScrollFlags_KeepVisibleEdgeY);
|
||||
g_take_first = false;
|
||||
if (to_key) g_focus_key[0] = 0;
|
||||
}
|
||||
bool hov = ImGui::IsItemHovered(), foc = ImGui::IsItemFocused() && ImGui::GetCurrentContext()->NavCursorVisible;
|
||||
row_foc |= foc;
|
||||
row_hov |= hov;
|
||||
if (clicked) result = c;
|
||||
if (foc && (ImGui::IsKeyPressed(ImGuiKey_Delete, false) || ImGui::IsKeyPressed(ImGuiKey_Backspace, false) ||
|
||||
ImGui::IsKeyPressed(ImGuiKey_GamepadFaceUp, false)))
|
||||
result = 10 + c;
|
||||
dl->AddRectFilled(a, b, hov || foc ? IM_COL32(255, 255, 255, 22) : IM_COL32(0, 0, 0, 40), r);
|
||||
dl->AddRect(a, b, hov || foc ? kGold : IM_COL32(255, 255, 255, 38), r, 0, hov || foc ? 2.0f : 1.0f);
|
||||
fit_text(dl, a.x + pad, b.x - pad, a.y, h, IM_COL32(255, 255, 255, 255), t, true);
|
||||
ImGui::PopID();
|
||||
}
|
||||
char k[64];
|
||||
snprintf(k, sizeof k, "NX2NAVI_%s", key);
|
||||
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);
|
||||
snprintf(d.text + n, sizeof d.text - n, "\n\n%s", note);
|
||||
}
|
||||
ImGui::SetCursorScreenPos(p);
|
||||
ImGui::Dummy(ImVec2(w, h));
|
||||
ImGui::PopID();
|
||||
return result;
|
||||
}
|
||||
83
runtime/ui/option_rows.h
Normal file
83
runtime/ui/option_rows.h
Normal file
@@ -0,0 +1,83 @@
|
||||
// Settings pages in two panes (ui/option_rows.cpp): option rows on the left, the selected (controller) or hovered (mouse)
|
||||
// row's description on the right. Each row shows a setting of the cfg table (cfg.h) and changes it through cfg_set: A or
|
||||
// a click steps it (toggle, next value), left and right step it. A row marks the default value, says "after restart" when
|
||||
// the setting is read at start, and is greyed out with a note when an environment variable fixes it.
|
||||
//
|
||||
// opt_begin("##screen", scale);
|
||||
// opt_toggle("NX2NAVI_FULLSCREEN", UI_MENU_FULLSCREEN, UI_MENU_FULLSCREEN_DESC);
|
||||
// opt_end();
|
||||
//
|
||||
// key: the setting's NX2NAVI_ name, which must have a cfg_meta row. Present path only (ImGui).
|
||||
#pragma once
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C" {
|
||||
#include "ui_text.h"
|
||||
}
|
||||
|
||||
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);
|
||||
void opt_text(UiTextId text, bool warn = false);
|
||||
|
||||
// The return value of every row: true when it changed the setting this frame.
|
||||
// inverted: the row shows "on" while the key is 0 (a setting whose key names the opposite).
|
||||
bool opt_toggle(const char *key, UiTextId label, UiTextId desc, bool inverted = false);
|
||||
// One name per value of the key's cfg_meta values list, in its order. When the key has no fixed default (an empty
|
||||
// def), names[0] is the automatic choice (the key unset) and names[1..] follow the values. note: a short line under
|
||||
// the value in place of the "default" mark (NULL: none).
|
||||
bool opt_choice(const char *key, UiTextId label, const UiTextId *names, int n, UiTextId desc,
|
||||
const char *note = nullptr);
|
||||
// A choice over a list the caller builds (devices, window sizes): values[i] is written, names[i] shown; "" means the key
|
||||
// unset. cur: the index in effect, -1 to find cfg_value(key) in values (no match: the value shown as it is).
|
||||
bool opt_choice_list(const char *key, UiTextId label, const char *const *values, const char *const *names, int n,
|
||||
UiTextId desc, int cur = -1, const char *note = nullptr);
|
||||
// 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 *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 NX2NAVI_ (BIND_A; the
|
||||
// description names it when the environment sets it); a disabled cell shows its text greyed and takes no cursor; note
|
||||
// (NULL none) follows the description. Returns the cell A / Enter / a click activated (0..2), 10 + the cell Delete,
|
||||
// Backspace or X cleared, or -1. opt_focus_key("<key>#<cell>") puts the cursor on a cell.
|
||||
void opt_bind_header(UiTextId c0, UiTextId c1, UiTextId c2);
|
||||
int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *const cells[3], const bool enabled[3],
|
||||
const char *note = nullptr);
|
||||
|
||||
// nx2navi.ini is written a moment after the last change (a held slider would rewrite it every frame) and when the menu
|
||||
// closes. opt_save_tick: on every frame the menu lays out; force: write now if anything is pending. 1 while a write is
|
||||
// pending.
|
||||
int opt_save_tick(int force);
|
||||
// A change made outside a row (Reset, F10): nx2navi.ini is written as after a row's change.
|
||||
void opt_save_soon(void);
|
||||
Reference in New Issue
Block a user