mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 04:35:57 +00:00
Remap keys, mouse buttons and controller buttons from the Controls tab
Every Switch button and the eight stick directions the keys drive get two key cells and a controller cell under the button layout. A cell takes the next key, mouse button or controller button pressed; a key in use moves over, a controller button swaps. The tab writes bind_ lines (new: bind_LSTICK_* / bind_RSTICK_*, key:default, pad:default) and input_win.c builds the tables again when one changes, so remapping applies while the game runs. More keys can be bound: Enter, Backspace, right Shift and Ctrl, Alt, the numpad, punctuation, F2-F7, F9, F12, mouse buttons 4 and 5. Alt alone no longer enters the window menu loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f307b1cdea
commit
8691f6d724
16 files changed
+990
-99
No files matched your search
+7
-4
@@ -28,7 +28,7 @@ The log names the layout in effect (`input: gamepad layout ...`); the menu shows
|
||||
| Plus | Start | Tab | menu, inventory |
|
||||
| Minus | Back | M | map |
|
||||
|
||||
Esc is unbound in the game; it opens the settings menu and releases the mouse cursor (see Mouse camera). Z and X duplicate ZL and ZR so menu pages turn with two neighbouring keys; the menu tabs (L, R) are Q and R. The mouse wheel is unbound. The bindings are two tables in `runtime/input_map.c`, `input_bindings` (platform-neutral key ids) and `input_pad_bindings` (gamepad inputs by position); `runtime/input_win.c` translates Win32 virtual keys and SDL buttons, so a remapping page can edit both later.
|
||||
Esc is unbound in the game; it opens the settings menu and releases the mouse cursor (see Mouse camera). Z and X duplicate ZL and ZR so menu pages turn with two neighbouring keys; the menu tabs (L, R) are Q and R. The mouse wheel is unbound. The bindings are the tables of `input_map` in `runtime/input_map.c`: the keys (platform-neutral key ids) and one gamepad table per layout (gamepad inputs by position); `runtime/input_win.c` translates Win32 virtual keys and SDL buttons.
|
||||
|
||||
## Window keys
|
||||
|
||||
@@ -42,13 +42,16 @@ The Minus+Plus combo never reaches the game. In the menu the arrow keys, the D-p
|
||||
|
||||
## Remapping
|
||||
|
||||
`totk.ini` rebinds the buttons, one line per Switch button: `bind_<button> = <entry>, <entry>, ...`. The button is `A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK`. An entry is `pad:<name>` or `key:<name>`:
|
||||
The *Controls* tab of the settings menu lists, under the button layout, every Switch button and the eight stick directions the keys drive (movement and camera), each with two key cells and a controller cell. Select a cell, press A or Enter, then press the new key, mouse button or controller button; Esc or five seconds without a press cancel, and a controller button cancels a key cell. Delete, Backspace or X clears the selected cell. A key another action has moves to the new one (the description names the action it left); a controller button swaps with the one it replaces. A remapped controller button is physical: from then on the face buttons (A B X Y) stay where they are in both layouts, until the buttons are put back as the layout in use has them or *Reset all buttons* is chosen. F1, F8, F10, F11 and Esc cannot be bound (the menu, the flight recorder and the window keep them). Punctuation keys are named by their place on a US keyboard; the menu shows the character the keyboard layout in use puts there.
|
||||
|
||||
The tab writes `totk.ini` lines, one per Switch button or stick direction: `bind_<button> = <entry>, <entry>, ...`. The button is `A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK`, or a stick direction `LSTICK_LEFT LSTICK_UP LSTICK_RIGHT LSTICK_DOWN` (movement, W A S D by default) and `RSTICK_...` (camera, the arrow keys). An entry is `pad:<name>` or `key:<name>`:
|
||||
|
||||
- pad names: `south east west north l r zl zr start back lstick rstick dpad_left dpad_up dpad_right dpad_down` (`zl`, `zr` are the triggers)
|
||||
- key names: `a` to `z`, `0` to `9`, `space tab lshift lctrl up down left right mouse_l mouse_r mouse_m`
|
||||
- key names: `a` to `z`, `0` to `9`, `f2` to `f7`, `f9`, `f12`, `num0` to `num9`, `space tab enter backspace lshift rshift lctrl rctrl lalt capslock insert delete home end pageup pagedown up down left right`, `num_add num_sub num_mul num_div num_decimal`, `minus equals lbracket rbracket semicolon apostrophe comma period slash backslash grave`, `mouse_l mouse_r mouse_m mouse_x1 mouse_x2`
|
||||
- `key:default` and `pad:default` keep that part's defaults (`pad:default` is each layout's own button).
|
||||
- `none` leaves the button unbound.
|
||||
|
||||
A line replaces every default of that button, pad and keyboard, so list the keys you still want. Pad names are physical positions, so a line means the same in both layouts and replaces the layout's own button for that Switch button. Buttons without a line keep the table above. Names are case-insensitive. An invalid entry logs one `input: bind ...` line and is skipped; a line without a valid entry changes nothing. The sticks and the mouse camera are not remappable. The `TOTK_BIND_<button>` environment variables work like any other setting. Bindings are read once at start.
|
||||
A line replaces every default of that button, pad and keyboard, so list the keys you still want or use `key:default`. Pad names are physical positions, so a line means the same in both layouts and replaces the layout's own button for that Switch button. Stick directions take keys only: the controller's sticks and the mouse camera always work. Buttons without a line keep the table above. Names are case-insensitive. An invalid entry logs one `input: bind ...` line and is skipped; a line without a valid entry changes nothing. The `TOTK_BIND_<button>` environment variables work like any other setting. A changed line applies at once (`runtime/input_win.c` builds the tables again at its next poll).
|
||||
|
||||
A pad that reports its face buttons swapped (A/B and X/Y, as some GuliKit models do) is fixed with:
|
||||
|
||||
|
||||
+10
-2
@@ -31,8 +31,10 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line.
|
||||
static const char *const known[] = {
|
||||
"AB", "APP_POOL", "ASSUME_FOCUS", "ASTC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_MINUS",
|
||||
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
|
||||
"BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS",
|
||||
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP",
|
||||
"BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y",
|
||||
"BIND_ZL", "BIND_ZR", "CLOTH_REALTIME", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG",
|
||||
"EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS",
|
||||
"FLIGHT_THUMBS", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "GPL", "GPL_DRAW_BUILD", "GPU",
|
||||
@@ -62,6 +64,12 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"VOLUME", "audio"},
|
||||
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
|
||||
{"PAD_LAYOUT", "input"}, {"MOUSE_SENS", "input"}, {"INPUT_RECORD", "input"},
|
||||
{"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"},
|
||||
{"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"},
|
||||
{"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"},
|
||||
{"BIND_RIGHT", "input"}, {"BIND_DOWN", "input"}, {"BIND_LSTICK_LEFT", "input"}, {"BIND_LSTICK_UP", "input"},
|
||||
{"BIND_LSTICK_RIGHT", "input"}, {"BIND_LSTICK_DOWN", "input"}, {"BIND_RSTICK_LEFT", "input"},
|
||||
{"BIND_RSTICK_UP", "input"}, {"BIND_RSTICK_RIGHT", "input"}, {"BIND_RSTICK_DOWN", "input"},
|
||||
{"ASYNC_PREEMPT", "performance"}, {"REPLAY_ASYNC", "performance"}, {"FREE_CORES", "performance"},
|
||||
{"TIMER_1MS", "performance"}, {"PIPE_WAIT", "performance"}, {"PIPE_SKIP", "performance"},
|
||||
{"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"PIPE_PREBUILD", "performance"},
|
||||
|
||||
@@ -280,6 +280,55 @@ int probe_cfg(void) {
|
||||
CHECK(input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_SOUTH] = 1}, PAD_LAYOUT_XBOX) == 0,
|
||||
"pad layout: a bind line replaces the layout's own button");
|
||||
input_map_reset();
|
||||
// Bind lines for stick directions and default parts; the remapping rows' edits (input_map.c)
|
||||
memset(dn, 0, sizeof dn);
|
||||
dn[KEY_I] = 1;
|
||||
CHECK(input_map_bind("LSTICK_UP", "key:i, pad:south") == 1, "bind: a stick direction takes keys, skips pad entries");
|
||||
input_map_stick(dn, 0, st);
|
||||
CHECK(st[1] == 32767, "bind: I moves forward after bind_LSTICK_UP = key:i");
|
||||
dn[KEY_I] = 0, dn[KEY_W] = 1;
|
||||
input_map_stick(dn, 0, st);
|
||||
CHECK(st[1] == 0, "bind: W no longer moves forward");
|
||||
CHECK(input_map_bind("A", "key:default, pad:north") == 1, "bind: key:default with a pad entry");
|
||||
memset(dn, 0, sizeof dn);
|
||||
dn[KEY_E] = 1;
|
||||
CHECK(input_map_buttons(dn) == 1ull << B_A &&
|
||||
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_NORTH] = 1}, PAD_LAYOUT_XBOX) == (1ull << B_A | 1ull << B_Y),
|
||||
"bind: key:default keeps E, pad:north adds the top button in every layout");
|
||||
CHECK(input_map_bind("B", "key:j, pad:default") == 1 &&
|
||||
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_EAST] = 1}, PAD_LAYOUT_XBOX) == 1ull << B_B &&
|
||||
input_map_pad_buttons((uint8_t[PAD_COUNT]){[PAD_SOUTH] = 1}, PAD_LAYOUT_NINTENDO) == 1ull << B_B,
|
||||
"bind: pad:default keeps each layout's own button");
|
||||
input_map_reset();
|
||||
InputMap mp = input_map;
|
||||
char line[256];
|
||||
input_map_line(&mp, B_ZR, line, sizeof line);
|
||||
CHECK(!line[0], "edit: an action at its defaults needs no line");
|
||||
CHECK(input_map_set_key(&mp, B_A, 0, KEY_F) == B_ZR, "edit: F taken from ZR");
|
||||
input_map_line(&mp, B_A, line, sizeof line);
|
||||
CHECK(!strcmp(line, "key:f, pad:default"), "edit: A's line is key:f, pad:default");
|
||||
input_map_line(&mp, B_ZR, line, sizeof line);
|
||||
CHECK(!strcmp(line, "key:x, pad:default"), "edit: ZR keeps X");
|
||||
CHECK(input_map_set_key(&mp, B_ZL, 1, KEY_NONE) == -1, "edit: clearing a key takes from no one");
|
||||
uint8_t ks[8];
|
||||
CHECK(input_map_keys_of(&mp, B_ZL, ks, 8) == 1 && ks[0] == KEY_MOUSE_R, "edit: ZL keeps its first key only");
|
||||
mp = input_map;
|
||||
CHECK(input_map_set_pad(&mp, B_X, PAD_LAYOUT_XBOX, PAD_SOUTH) == B_A, "edit: south swaps X with A (Xbox layout)");
|
||||
uint8_t ps[8];
|
||||
CHECK(input_map_pads_of(&mp, B_A, PAD_LAYOUT_XBOX, ps, 8) == 1 && ps[0] == PAD_WEST, "edit: A takes X's west button");
|
||||
CHECK(input_map_pads_of(&mp, B_A, PAD_LAYOUT_NINTENDO, ps, 8) == 1 && ps[0] == PAD_WEST &&
|
||||
input_map_pads_of(&mp, B_B, PAD_LAYOUT_NINTENDO, ps, 8) == 1 && ps[0] == PAD_EAST,
|
||||
"edit: the face buttons are pinned in every layout after a gamepad edit");
|
||||
input_map_line(&mp, B_X, line, sizeof line);
|
||||
CHECK(!strcmp(line, "key:default, pad:south"), "edit: X's line is key:default, pad:south");
|
||||
input_map_set_pad(&mp, B_X, PAD_LAYOUT_XBOX, PAD_WEST); // and back
|
||||
input_map_line(&mp, B_A, line, sizeof line);
|
||||
CHECK(!line[0] && input_map_pads_of(&mp, B_A, PAD_LAYOUT_NINTENDO, ps, 8) == 1 && ps[0] == PAD_EAST,
|
||||
"edit: swapping back restores every layout's defaults");
|
||||
mp = input_map;
|
||||
input_map_set_key(&mp, B_SL_UP, 0, KEY_NONE);
|
||||
input_map_line(&mp, B_SL_UP, line, sizeof line);
|
||||
CHECK(!strcmp(line, "none"), "edit: a stick direction without keys is none");
|
||||
// defaults live in the CfgMeta table: cfg_value and the typed accessors fall back to it
|
||||
cfg_load("cfg-probe-missing.ini");
|
||||
_putenv_s("TOTK_FPS60", "");
|
||||
|
||||
@@ -23,6 +23,21 @@ int input_menu_gate(int *held, int menu_open, uint64_t *buttons, int32_t sticks[
|
||||
int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly);
|
||||
// The gamepad layout in effect (PAD_LAYOUT_*, input_map.h; TOTK_PAD_LAYOUT, live); -1 without a gamepad. Any thread.
|
||||
int input_pad_layout(void);
|
||||
// The label on a face button of the open gamepad (input_map.h PAD_SOUTH..PAD_NORTH, as SDL reports it); PAD_LABEL_NONE for another
|
||||
// button, an unknown label or no gamepad. Any thread.
|
||||
enum { PAD_LABEL_NONE, PAD_LABEL_A, PAD_LABEL_B, PAD_LABEL_X, PAD_LABEL_Y, PAD_LABEL_CROSS, PAD_LABEL_CIRCLE,
|
||||
PAD_LABEL_SQUARE, PAD_LABEL_TRIANGLE };
|
||||
int input_pad_label(int pad);
|
||||
// The menu's remapping rows (Controls tab). input_map_snapshot copies the tables in effect (after any changed TOTK_BIND_* line).
|
||||
// input_capture polls the keys, the mouse buttons and the gamepad for a press: reset 1 takes what is held now as the
|
||||
// start (a held key counts once released and pressed again) and returns NONE; then it returns KEY or PAD with *id the
|
||||
// key or pad id (input_map.h) pressed since the last call, or CANCEL for Esc. Keys count only while the game window is in front.
|
||||
enum { INPUT_CAPTURE_NONE, INPUT_CAPTURE_KEY, INPUT_CAPTURE_PAD, INPUT_CAPTURE_CANCEL };
|
||||
struct InputMap; // input_map.h (not included here: swkbd_win.c has button names of its own)
|
||||
void input_map_snapshot(struct InputMap *m);
|
||||
int input_capture(int reset, int *id);
|
||||
// The character on a punctuation key (KEY_MINUS..KEY_GRAVE) in the keyboard layout in use, 0 for another key.
|
||||
uint32_t input_key_char(int key);
|
||||
|
||||
// Mouse camera and cursor (input_win.c, Win32 window thread). The window procedure calls input_window_msg first for raw
|
||||
// mouse input, cursor hiding and confinement; it returns 1 with *res set when the message is handled. input_cursor_suspend(1)
|
||||
|
||||
+216
-64
@@ -1,5 +1,5 @@
|
||||
// Binding tables (keyboard/mouse and gamepad), their totk.ini overrides and the pure mapping functions (input_map.h).
|
||||
// No Win32 or SDL here.
|
||||
// Binding tables (keyboard/mouse and gamepad), their totk.ini overrides, the pure mapping functions and the Buttons
|
||||
// tab's edits (input_map.h). No Win32 or SDL here.
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
@@ -24,44 +24,49 @@
|
||||
|
||||
// By position: south is Switch B, east A, west Y, north X (Nintendo layout); the Xbox layout swaps A with B and X with Y
|
||||
// (south A, as the Xbox labels; cross A on a PlayStation pad). The triggers are ZL and ZR.
|
||||
#define DEFAULT_PADS(south, east, west, north) {PAD_SOUTH, south}, {PAD_EAST, east}, {PAD_WEST, west}, {PAD_NORTH, north}, {PAD_LSTICK, B_STICK_L}, {PAD_RSTICK, B_STICK_R}, {PAD_L, B_L}, {PAD_R, B_R}, {PAD_START, B_PLUS}, {PAD_BACK, B_MINUS}, {PAD_DPAD_LEFT, B_LEFT}, {PAD_DPAD_UP, B_UP}, {PAD_DPAD_RIGHT, B_RIGHT}, {PAD_DPAD_DOWN, B_DOWN}, {PAD_ZL, B_ZL}, {PAD_ZR, B_ZR}
|
||||
#define DEFAULT_PADS(south, east, west, north) \
|
||||
{PAD_SOUTH, south}, {PAD_EAST, east}, {PAD_WEST, west}, {PAD_NORTH, north}, {PAD_LSTICK, B_STICK_L}, \
|
||||
{PAD_RSTICK, B_STICK_R}, {PAD_L, B_L}, {PAD_R, B_R}, {PAD_START, B_PLUS}, {PAD_BACK, B_MINUS}, \
|
||||
{PAD_DPAD_LEFT, B_LEFT}, {PAD_DPAD_UP, B_UP}, {PAD_DPAD_RIGHT, B_RIGHT}, {PAD_DPAD_DOWN, B_DOWN}, {PAD_ZL, B_ZL}, \
|
||||
{PAD_ZR, B_ZR}
|
||||
#define NINTENDO_PADS DEFAULT_PADS(B_B, B_A, B_Y, B_X)
|
||||
#define XBOX_PADS DEFAULT_PADS(B_A, B_B, B_X, B_Y)
|
||||
enum { DEFAULT_PAD_COUNT = 16 };
|
||||
enum { DEFAULT_KEY_COUNT = 26, DEFAULT_PAD_COUNT = 16 };
|
||||
_Static_assert(sizeof (Binding[]){DEFAULT_KEYS} / sizeof (Binding) == DEFAULT_KEY_COUNT, "DEFAULT_KEY_COUNT");
|
||||
|
||||
static const Binding default_keys[] = {DEFAULT_KEYS};
|
||||
static const PadBinding default_pads[PAD_LAYOUT_COUNT][DEFAULT_PAD_COUNT] = {{NINTENDO_PADS}, {XBOX_PADS}};
|
||||
Binding input_bindings[INPUT_BINDING_MAX] = {DEFAULT_KEYS};
|
||||
int input_binding_count = (int)(sizeof default_keys / sizeof *default_keys);
|
||||
PadBinding input_pad_bindings[PAD_LAYOUT_COUNT][INPUT_PAD_BINDING_MAX] = {{NINTENDO_PADS}, {XBOX_PADS}};
|
||||
int input_pad_binding_count[PAD_LAYOUT_COUNT] = {DEFAULT_PAD_COUNT, DEFAULT_PAD_COUNT};
|
||||
static const InputMap defaults = {{DEFAULT_KEYS}, DEFAULT_KEY_COUNT, {{NINTENDO_PADS}, {XBOX_PADS}},
|
||||
{DEFAULT_PAD_COUNT, DEFAULT_PAD_COUNT}};
|
||||
InputMap input_map = {{DEFAULT_KEYS}, DEFAULT_KEY_COUNT, {{NINTENDO_PADS}, {XBOX_PADS}},
|
||||
{DEFAULT_PAD_COUNT, DEFAULT_PAD_COUNT}};
|
||||
|
||||
static const char *const button_names[16] = {"A", "B", "X", "Y", "LCLICK", "RCLICK", "L", "R", "ZL", "ZR", "PLUS", "MINUS",
|
||||
"LEFT", "UP", "RIGHT", "DOWN"}; // indexed by action
|
||||
static const char *const action_names[ACTION_COUNT] = {
|
||||
"A", "B", "X", "Y", "LCLICK", "RCLICK", "L", "R", "ZL", "ZR", "PLUS", "MINUS", "LEFT", "UP", "RIGHT", "DOWN",
|
||||
"LSTICK_LEFT", "LSTICK_UP", "LSTICK_RIGHT", "LSTICK_DOWN", "RSTICK_LEFT", "RSTICK_UP", "RSTICK_RIGHT", "RSTICK_DOWN"};
|
||||
static const char *const pad_names[PAD_COUNT] = {
|
||||
NULL, "south", "east", "west", "north", "lstick", "rstick", "l", "r", "start", "back",
|
||||
"dpad_left", "dpad_up", "dpad_right", "dpad_down", "zl", "zr"};
|
||||
static const char *const key_names[KEY_COUNT] = { // letters and digits are handled in key_id
|
||||
[KEY_SPACE] = "space", [KEY_TAB] = "tab", [KEY_LSHIFT] = "lshift", [KEY_LCTRL] = "lctrl", [KEY_UP] = "up",
|
||||
[KEY_DOWN] = "down", [KEY_LEFT] = "left", [KEY_RIGHT] = "right", [KEY_MOUSE_L] = "mouse_l", [KEY_MOUSE_R] = "mouse_r",
|
||||
[KEY_MOUSE_M] = "mouse_m"};
|
||||
static const char *const key_names[KEY_COUNT] = { // each group starts at its id; the ids of a group are consecutive
|
||||
[KEY_A] = "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
|
||||
"v", "w", "x", "y", "z",
|
||||
[KEY_0] = "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
[KEY_SPACE] = "space", "tab", "lshift", "lctrl", "up", "down", "left", "right",
|
||||
[KEY_MOUSE_L] = "mouse_l", "mouse_r", "mouse_m", "mouse_x1", "mouse_x2",
|
||||
[KEY_ENTER] = "enter", "backspace", "rshift", "rctrl", "lalt", "capslock", "insert", "delete", "home", "end",
|
||||
"pageup", "pagedown",
|
||||
[KEY_F2] = "f2", "f3", "f4", "f5", "f6", "f7", "f9", "f12",
|
||||
[KEY_NUM0] = "num0", "num1", "num2", "num3", "num4", "num5", "num6", "num7", "num8", "num9",
|
||||
[KEY_NUM_ADD] = "num_add", "num_sub", "num_mul", "num_div", "num_decimal",
|
||||
[KEY_MINUS] = "minus", "equals", "lbracket", "rbracket", "semicolon", "apostrophe", "comma", "period", "slash",
|
||||
"backslash", "grave"};
|
||||
|
||||
void input_map_reset(void) {
|
||||
memcpy(input_bindings, default_keys, sizeof default_keys);
|
||||
input_binding_count = (int)(sizeof default_keys / sizeof *default_keys);
|
||||
for (int l = 0; l < PAD_LAYOUT_COUNT; l++) {
|
||||
memcpy(input_pad_bindings[l], default_pads[l], sizeof default_pads[l]);
|
||||
input_pad_binding_count[l] = DEFAULT_PAD_COUNT;
|
||||
}
|
||||
}
|
||||
const char *input_action_name(int action) { return action >= 0 && action < ACTION_COUNT ? action_names[action] : NULL; }
|
||||
const char *input_key_name(int key) { return key > KEY_NONE && key < KEY_COUNT ? key_names[key] : NULL; }
|
||||
const char *input_pad_name(int pad) { return pad > PAD_NONE && pad < PAD_COUNT ? pad_names[pad] : NULL; }
|
||||
|
||||
void input_map_reset(void) { input_map = defaults; }
|
||||
|
||||
static int key_id(const char *name) {
|
||||
if (name[0] && !name[1]) {
|
||||
int c = tolower((unsigned char)name[0]);
|
||||
if (c >= 'a' && c <= 'z') return KEY_A + (c - 'a');
|
||||
if (c >= '0' && c <= '9') return KEY_0 + (c - '0');
|
||||
}
|
||||
for (int k = KEY_SPACE; k < KEY_COUNT; k++)
|
||||
for (int k = KEY_A; k < KEY_COUNT; k++)
|
||||
if (key_names[k] && !_stricmp(key_names[k], name)) return k;
|
||||
return KEY_NONE;
|
||||
}
|
||||
@@ -79,57 +84,204 @@ static char *trim(char *s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
int input_map_keys_of(const InputMap *m, int action, uint8_t *out, int max) {
|
||||
int n = 0;
|
||||
for (int i = 0; i < m->nkeys; i++)
|
||||
if (m->keys[i].action == action && n < max) out[n++] = m->keys[i].key;
|
||||
return n;
|
||||
}
|
||||
|
||||
int input_map_pads_of(const InputMap *m, int action, int layout, uint8_t *out, int max) {
|
||||
int n = 0;
|
||||
for (int i = 0; i < m->npads[layout]; i++)
|
||||
if (m->pads[layout][i].action == action && n < max) out[n++] = m->pads[layout][i].pad;
|
||||
return n;
|
||||
}
|
||||
|
||||
// action's keys become list[0..n): its old ones go, the new ones are appended (the table keeps its order otherwise).
|
||||
static void keys_put(InputMap *m, int action, const uint8_t *list, int n) {
|
||||
int w = 0;
|
||||
for (int i = 0; i < m->nkeys; i++)
|
||||
if (m->keys[i].action != action) m->keys[w++] = m->keys[i];
|
||||
m->nkeys = w;
|
||||
for (int i = 0; i < n && m->nkeys < INPUT_BINDING_MAX; i++) m->keys[m->nkeys++] = (Binding){list[i], (uint8_t)action};
|
||||
}
|
||||
|
||||
static void pads_put(InputMap *m, int layout, int action, const uint8_t *list, int n) {
|
||||
PadBinding *t = m->pads[layout];
|
||||
int w = 0;
|
||||
for (int i = 0; i < m->npads[layout]; i++)
|
||||
if (t[i].action != action) t[w++] = t[i];
|
||||
m->npads[layout] = w;
|
||||
for (int i = 0; i < n && m->npads[layout] < INPUT_PAD_BINDING_MAX; i++)
|
||||
t[m->npads[layout]++] = (PadBinding){list[i], (uint8_t)action};
|
||||
}
|
||||
|
||||
int input_map_bind(const char *button, const char *list) {
|
||||
int action = -1;
|
||||
for (int a = 0; a < 16; a++)
|
||||
if (!_stricmp(button_names[a], button)) action = a;
|
||||
for (int a = 0; a < ACTION_COUNT; a++)
|
||||
if (!_stricmp(action_names[a], button)) action = a;
|
||||
if (action < 0) { rt_log("input: bind: unknown button '%s'", button); return 0; }
|
||||
Binding keys[INPUT_BINDING_MAX];
|
||||
PadBinding pads[INPUT_PAD_BINDING_MAX];
|
||||
int nk = 0, np = 0, none = 0, bad = 0;
|
||||
uint8_t keys[INPUT_BINDING_MAX], pads[INPUT_PAD_BINDING_MAX];
|
||||
int nk = 0, np = 0, none = 0, key_def = 0, pad_def = 0, bad = 0;
|
||||
char buf[256];
|
||||
snprintf(buf, sizeof buf, "%s", list);
|
||||
for (char *save = NULL, *tok = strtok_s(buf, ",", &save); tok; tok = strtok_s(NULL, ",", &save)) {
|
||||
tok = trim(tok);
|
||||
if (!_stricmp(tok, "none")) { none = 1; continue; }
|
||||
int ok = 0;
|
||||
if (!_strnicmp(tok, "pad:", 4)) {
|
||||
int p = pad_id(trim(tok + 4));
|
||||
if (p && np < INPUT_PAD_BINDING_MAX) pads[np++] = (PadBinding){(uint8_t)p, (uint8_t)action}, ok = 1;
|
||||
if (!_strnicmp(tok, "pad:", 4) && action < B_SL_LEFT) {
|
||||
const char *name = trim(tok + 4);
|
||||
int p = pad_id(name);
|
||||
if (!_stricmp(name, "default")) pad_def = ok = 1;
|
||||
else if (p && np < INPUT_PAD_BINDING_MAX) pads[np++] = (uint8_t)p, ok = 1;
|
||||
} else if (!_strnicmp(tok, "key:", 4)) {
|
||||
int k = key_id(trim(tok + 4));
|
||||
if (k && nk < INPUT_BINDING_MAX) keys[nk++] = (Binding){(uint8_t)k, (uint8_t)action}, ok = 1;
|
||||
const char *name = trim(tok + 4);
|
||||
int k = key_id(name);
|
||||
if (!_stricmp(name, "default")) key_def = ok = 1;
|
||||
else if (k && nk < INPUT_BINDING_MAX) keys[nk++] = (uint8_t)k, ok = 1;
|
||||
}
|
||||
if (!ok) {
|
||||
bad++;
|
||||
rt_log("input: bind %s: ignoring '%s' (expected pad:<name> or key:<name>; stick directions take keys only)",
|
||||
button, tok);
|
||||
}
|
||||
if (!ok) { bad++; rt_log("input: bind %s: ignoring '%s' (expected pad:<name> or key:<name>)", button, tok); }
|
||||
}
|
||||
if (!nk && !np && !none) { if (bad) rt_log("input: bind %s: no valid entry, keeping the defaults", button); return 0; }
|
||||
int w = 0;
|
||||
for (int i = 0; i < input_binding_count; i++)
|
||||
if (input_bindings[i].action != action) input_bindings[w++] = input_bindings[i];
|
||||
input_binding_count = w;
|
||||
for (int i = 0; i < nk && input_binding_count < INPUT_BINDING_MAX; i++) input_bindings[input_binding_count++] = keys[i];
|
||||
if (!nk && !np && !none && !key_def && !pad_def) {
|
||||
if (bad) rt_log("input: bind %s: no valid entry, keeping the defaults", button);
|
||||
return 0;
|
||||
}
|
||||
uint8_t list_k[INPUT_BINDING_MAX];
|
||||
int n = key_def ? input_map_keys_of(&defaults, action, list_k, INPUT_BINDING_MAX) : 0;
|
||||
for (int i = 0; i < nk && n < INPUT_BINDING_MAX; i++) list_k[n++] = keys[i];
|
||||
keys_put(&input_map, action, list_k, n);
|
||||
for (int l = 0; l < PAD_LAYOUT_COUNT; l++) { // a bind line names physical buttons: the same in every layout
|
||||
PadBinding *t = input_pad_bindings[l];
|
||||
int *n = &input_pad_binding_count[l];
|
||||
w = 0;
|
||||
for (int i = 0; i < *n; i++)
|
||||
if (t[i].action != action) t[w++] = t[i];
|
||||
*n = w;
|
||||
for (int i = 0; i < np && *n < INPUT_PAD_BINDING_MAX; i++) t[(*n)++] = pads[i];
|
||||
uint8_t list_p[INPUT_PAD_BINDING_MAX];
|
||||
int c = pad_def ? input_map_pads_of(&defaults, action, l, list_p, INPUT_PAD_BINDING_MAX) : 0;
|
||||
for (int i = 0; i < np && c < INPUT_PAD_BINDING_MAX; i++) list_p[c++] = pads[i];
|
||||
pads_put(&input_map, l, action, list_p, c);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void input_map_configure(void) {
|
||||
input_map_reset();
|
||||
for (int a = 0; a < 16; a++) {
|
||||
for (int a = 0; a < ACTION_COUNT; a++) {
|
||||
char var[32];
|
||||
snprintf(var, sizeof var, "TOTK_BIND_%s", button_names[a]);
|
||||
snprintf(var, sizeof var, "TOTK_BIND_%s", action_names[a]);
|
||||
const char *v = cfg_get(var);
|
||||
if (v && input_map_bind(button_names[a], v)) rt_log("input: %s = %s", var + 5, v);
|
||||
if (v && *v && input_map_bind(action_names[a], v)) rt_log("input: %s = %s", var + 5, v);
|
||||
}
|
||||
}
|
||||
|
||||
int input_map_set_key(InputMap *m, int action, int slot, int key) {
|
||||
uint8_t list[INPUT_BINDING_MAX];
|
||||
int n = input_map_keys_of(m, action, list, INPUT_BINDING_MAX), lost = -1;
|
||||
if (key != KEY_NONE) {
|
||||
for (int i = 0; i < m->nkeys; i++)
|
||||
if (m->keys[i].key == key && m->keys[i].action != action) lost = m->keys[i].action;
|
||||
if (lost >= 0) {
|
||||
uint8_t other[INPUT_BINDING_MAX];
|
||||
int c = 0;
|
||||
for (int i = 0; i < m->nkeys; i++)
|
||||
if (m->keys[i].action == lost && m->keys[i].key != key) other[c++] = m->keys[i].key;
|
||||
keys_put(m, lost, other, c);
|
||||
}
|
||||
int w = 0; // the key once in this action's list too
|
||||
for (int i = 0; i < n; i++)
|
||||
if (list[i] != key) list[w++] = list[i];
|
||||
n = w;
|
||||
if (slot < n) list[slot] = (uint8_t)key;
|
||||
else if (n < INPUT_BINDING_MAX) list[n++] = (uint8_t)key;
|
||||
} else if (slot < n) {
|
||||
memmove(list + slot, list + slot + 1, (size_t)(n - slot - 1));
|
||||
n--;
|
||||
}
|
||||
keys_put(m, action, list, n);
|
||||
return lost;
|
||||
}
|
||||
|
||||
static int same_set(const uint8_t *a, int na, const uint8_t *b, int nb);
|
||||
|
||||
// Every action has its default gamepad buttons in layout.
|
||||
static int pads_at_defaults(const InputMap *m, int layout) {
|
||||
for (int a = 0; a < B_SL_LEFT; a++) {
|
||||
uint8_t p[INPUT_PAD_BINDING_MAX], dp[INPUT_PAD_BINDING_MAX];
|
||||
int np = input_map_pads_of(m, a, layout, p, INPUT_PAD_BINDING_MAX);
|
||||
if (!same_set(p, np, dp, input_map_pads_of(&defaults, a, layout, dp, INPUT_PAD_BINDING_MAX))) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int input_map_set_pad(InputMap *m, int action, int layout, int pad) {
|
||||
uint8_t mine[INPUT_PAD_BINDING_MAX];
|
||||
int n = input_map_pads_of(m, action, layout, mine, INPUT_PAD_BINDING_MAX), other = -1;
|
||||
if (pad != PAD_NONE)
|
||||
for (int i = 0; i < m->npads[layout]; i++)
|
||||
if (m->pads[layout][i].pad == pad && m->pads[layout][i].action != action) other = m->pads[layout][i].action;
|
||||
if (other >= 0) { // the other action gives up pad and takes this action's old button
|
||||
uint8_t list[INPUT_PAD_BINDING_MAX];
|
||||
int c = 0;
|
||||
for (int i = 0; i < m->npads[layout]; i++)
|
||||
if (m->pads[layout][i].action == other && m->pads[layout][i].pad != pad) list[c++] = m->pads[layout][i].pad;
|
||||
if (n && mine[0] != pad && c < INPUT_PAD_BINDING_MAX) list[c++] = mine[0];
|
||||
pads_put(m, layout, other, list, c);
|
||||
}
|
||||
uint8_t p = (uint8_t)pad;
|
||||
pads_put(m, layout, action, &p, pad != PAD_NONE);
|
||||
if (pads_at_defaults(m, layout)) { // put back as it was: the layout setting moves the face buttons again
|
||||
memcpy(m->pads, defaults.pads, sizeof m->pads);
|
||||
memcpy(m->npads, defaults.npads, sizeof m->npads);
|
||||
return other;
|
||||
}
|
||||
int pin[6] = {B_A, B_B, B_X, B_Y, action, other}, npin = other >= 0 ? 6 : 5;
|
||||
for (int i = 0; i < npin; i++) {
|
||||
uint8_t list[INPUT_PAD_BINDING_MAX];
|
||||
int c = input_map_pads_of(m, pin[i], layout, list, INPUT_PAD_BINDING_MAX);
|
||||
for (int l = 0; l < PAD_LAYOUT_COUNT; l++)
|
||||
if (l != layout) pads_put(m, l, pin[i], list, c);
|
||||
}
|
||||
return other;
|
||||
}
|
||||
|
||||
// The same bindings in any order (the menu appends; a line lists them its own way).
|
||||
static int same_set(const uint8_t *a, int na, const uint8_t *b, int nb) {
|
||||
if (na != nb) return 0;
|
||||
for (int i = 0; i < na; i++) {
|
||||
int ca = 0, cb = 0;
|
||||
for (int j = 0; j < na; j++) ca += a[j] == a[i], cb += b[j] == a[i];
|
||||
if (ca != cb) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void input_map_line(const InputMap *m, int action, char *out, size_t n) {
|
||||
uint8_t k[INPUT_BINDING_MAX], dk[INPUT_BINDING_MAX];
|
||||
int nk = input_map_keys_of(m, action, k, INPUT_BINDING_MAX);
|
||||
int key_def = same_set(k, nk, dk, input_map_keys_of(&defaults, action, dk, INPUT_BINDING_MAX));
|
||||
int pad_def = 1;
|
||||
for (int l = 0; l < PAD_LAYOUT_COUNT; l++) {
|
||||
uint8_t p[INPUT_PAD_BINDING_MAX], dp[INPUT_PAD_BINDING_MAX];
|
||||
int np = input_map_pads_of(m, action, l, p, INPUT_PAD_BINDING_MAX);
|
||||
pad_def &= same_set(p, np, dp, input_map_pads_of(&defaults, action, l, dp, INPUT_PAD_BINDING_MAX));
|
||||
}
|
||||
out[0] = 0;
|
||||
if (key_def && pad_def) return;
|
||||
size_t len = 0;
|
||||
#define PUT(...) (len += (size_t)snprintf(out + len, len < n ? n - len : 0, __VA_ARGS__))
|
||||
if (key_def) PUT("key:default");
|
||||
else
|
||||
for (int i = 0; i < nk; i++) PUT("%skey:%s", len ? ", " : "", key_names[k[i]]);
|
||||
if (pad_def && action < B_SL_LEFT) PUT("%spad:default", len ? ", " : "");
|
||||
else if (!pad_def) {
|
||||
uint8_t p[INPUT_PAD_BINDING_MAX];
|
||||
int np = input_map_pads_of(m, action, PAD_LAYOUT_NINTENDO, p, INPUT_PAD_BINDING_MAX);
|
||||
for (int i = 0; i < np; i++) PUT("%spad:%s", len ? ", " : "", pad_names[p[i]]);
|
||||
}
|
||||
if (!len) PUT("none");
|
||||
#undef PUT
|
||||
}
|
||||
|
||||
int input_pad_layout_pick(const char *setting, int east_labelled_a) {
|
||||
if (setting && !_stricmp(setting, "nintendo")) return PAD_LAYOUT_NINTENDO;
|
||||
if (setting && !_stricmp(setting, "xbox")) return PAD_LAYOUT_XBOX;
|
||||
@@ -137,25 +289,25 @@ int input_pad_layout_pick(const char *setting, int east_labelled_a) {
|
||||
}
|
||||
|
||||
uint64_t input_map_pad_buttons(const uint8_t down[PAD_COUNT], int layout) {
|
||||
const PadBinding *t = input_pad_bindings[layout];
|
||||
const PadBinding *t = input_map.pads[layout];
|
||||
uint64_t b = 0;
|
||||
for (int i = 0; i < input_pad_binding_count[layout]; i++)
|
||||
for (int i = 0; i < input_map.npads[layout]; i++)
|
||||
if (down[t[i].pad]) b |= 1ull << t[i].action;
|
||||
return b;
|
||||
}
|
||||
|
||||
uint64_t input_map_buttons(const uint8_t down[KEY_COUNT]) {
|
||||
uint64_t b = 0;
|
||||
for (int i = 0; i < input_binding_count; i++)
|
||||
if (input_bindings[i].action < B_SL_LEFT && down[input_bindings[i].key]) b |= 1ull << input_bindings[i].action;
|
||||
for (int i = 0; i < input_map.nkeys; i++)
|
||||
if (input_map.keys[i].action < B_SL_LEFT && down[input_map.keys[i].key]) b |= 1ull << input_map.keys[i].action;
|
||||
return b;
|
||||
}
|
||||
|
||||
void input_map_stick(const uint8_t down[KEY_COUNT], int stick, int32_t out[2]) {
|
||||
int first = stick ? B_SR_LEFT : B_SL_LEFT, dir[4] = {0, 0, 0, 0}; // left, up, right, down
|
||||
for (int i = 0; i < input_binding_count; i++) {
|
||||
int a = input_bindings[i].action - first;
|
||||
if (a >= 0 && a < 4 && down[input_bindings[i].key]) dir[a] = 1;
|
||||
for (int i = 0; i < input_map.nkeys; i++) {
|
||||
int a = input_map.keys[i].action - first;
|
||||
if (a >= 0 && a < 4 && down[input_map.keys[i].key]) dir[a] = 1;
|
||||
}
|
||||
int dx = dir[2] - dir[0], dy = dir[1] - dir[3];
|
||||
int32_t m = dx && dy ? DIAGONAL : STICK_MAX;
|
||||
|
||||
+56
-17
@@ -1,7 +1,9 @@
|
||||
// Keyboard and mouse bindings, free of any window system: the table maps platform-neutral key ids to Switch actions.
|
||||
// input_win.c translates Win32 virtual keys to key ids (one place); a Linux port translates SDL scancodes the same way.
|
||||
// A remapping page can later edit the table at run time. Layout in docs/controls.md.
|
||||
// Keyboard, mouse and gamepad bindings, free of any window system: the tables map platform-neutral key and pad ids to
|
||||
// Switch actions. input_win.c translates Win32 virtual keys and SDL buttons to these ids (one place); a Linux port
|
||||
// translates SDL scancodes the same way. The remapping rows of the menu's Controls tab (ui/binds_page.cpp) edits a copy of the tables and writes
|
||||
// the bind_ lines; input_win.c applies changed lines while the game runs. Layout in docs/controls.md.
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Actions are the bit numbers of libnx HidNpadButton (input.h); 16..23 are the stick directions, which keys drive as
|
||||
@@ -12,13 +14,22 @@ enum {
|
||||
ACTION_COUNT = 24
|
||||
};
|
||||
|
||||
// Keys and mouse buttons. F1, F10, F11 and Esc belong to the menu and the window, F8 to the flight recorder: no ids.
|
||||
enum {
|
||||
KEY_NONE = 0,
|
||||
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, // letters and digits are
|
||||
KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, // consecutive
|
||||
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
|
||||
KEY_SPACE, KEY_TAB, KEY_LSHIFT, KEY_LCTRL, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_MOUSE_L, KEY_MOUSE_R, KEY_MOUSE_M,
|
||||
KEY_MOUSE_L, KEY_MOUSE_R, KEY_MOUSE_M, KEY_MOUSE_X1, KEY_MOUSE_X2, // the mouse buttons are consecutive
|
||||
KEY_ENTER, KEY_BACKSPACE, KEY_RSHIFT, KEY_RCTRL, KEY_LALT, KEY_CAPSLOCK, KEY_INSERT, KEY_DELETE, KEY_HOME, KEY_END,
|
||||
KEY_PAGEUP, KEY_PAGEDOWN,
|
||||
KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F9, KEY_F12,
|
||||
KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, // consecutive
|
||||
KEY_NUM_ADD, KEY_NUM_SUB, KEY_NUM_MUL, KEY_NUM_DIV, KEY_NUM_DECIMAL,
|
||||
// the punctuation keys of a US keyboard, by position; the character on the key follows the keyboard layout
|
||||
KEY_MINUS, KEY_EQUALS, KEY_LBRACKET, KEY_RBRACKET, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_COMMA, KEY_PERIOD, KEY_SLASH,
|
||||
KEY_BACKSLASH, KEY_GRAVE,
|
||||
KEY_COUNT
|
||||
};
|
||||
|
||||
@@ -31,29 +42,41 @@ enum {
|
||||
PAD_COUNT
|
||||
};
|
||||
|
||||
enum { INPUT_BINDING_MAX = 96, INPUT_PAD_BINDING_MAX = 48 };
|
||||
|
||||
// Gamepad layouts (TOTK_PAD_LAYOUT): which face button is Switch A. Nintendo: by position, east A, south B, west Y,
|
||||
// north X. Xbox: south A, east B, west X, north Y, as an Xbox pad labels them (cross A, circle B on a PlayStation pad).
|
||||
enum { PAD_LAYOUT_NINTENDO, PAD_LAYOUT_XBOX, PAD_LAYOUT_COUNT };
|
||||
|
||||
// The tables a remapping page edits, one gamepad table per layout. Defaults are the layout in docs/controls.md;
|
||||
// input_map_reset restores them.
|
||||
enum { INPUT_BINDING_MAX = 96, INPUT_PAD_BINDING_MAX = 48 };
|
||||
|
||||
typedef struct { uint8_t key; uint8_t action; } Binding;
|
||||
typedef struct { uint8_t pad; uint8_t action; } PadBinding;
|
||||
extern Binding input_bindings[INPUT_BINDING_MAX];
|
||||
extern int input_binding_count;
|
||||
extern PadBinding input_pad_bindings[PAD_LAYOUT_COUNT][INPUT_PAD_BINDING_MAX];
|
||||
extern int input_pad_binding_count[PAD_LAYOUT_COUNT];
|
||||
// The keyboard and mouse table and one gamepad table per layout.
|
||||
typedef struct InputMap {
|
||||
Binding keys[INPUT_BINDING_MAX];
|
||||
int nkeys;
|
||||
PadBinding pads[PAD_LAYOUT_COUNT][INPUT_PAD_BINDING_MAX];
|
||||
int npads[PAD_LAYOUT_COUNT];
|
||||
} InputMap;
|
||||
|
||||
// The tables in effect. Defaults are the layout in docs/controls.md; input_map_reset restores them.
|
||||
extern InputMap input_map;
|
||||
|
||||
void input_map_reset(void);
|
||||
// Replaces every binding of the Switch button `button` (script name: A B X Y LCLICK RCLICK L R ZL ZR PLUS MINUS LEFT UP
|
||||
// RIGHT DOWN, any case) with `list`: comma separated "pad:<name>" and "key:<name>" entries, or "none" for no input.
|
||||
// Pad names are physical buttons, so the entries go into the gamepad table of every layout. Invalid entries are logged
|
||||
// and skipped; when none is valid the button keeps its bindings. 1 when applied.
|
||||
// The script and totk.ini names, any case when parsed; NULL for an id without one. Actions: A B X Y LCLICK RCLICK L R ZL
|
||||
// ZR PLUS MINUS LEFT UP RIGHT DOWN, then LSTICK_LEFT LSTICK_UP LSTICK_RIGHT LSTICK_DOWN and the same for RSTICK (the
|
||||
// stick directions the keys drive). Keys: a-z 0-9 space tab lshift ... (key_names in input_map.c). Pads: south east ...
|
||||
const char *input_action_name(int action);
|
||||
const char *input_key_name(int key);
|
||||
const char *input_pad_name(int pad);
|
||||
// Replaces every binding of the action `button` (an action name) with `list`: comma separated "pad:<name>" and
|
||||
// "key:<name>" entries, "key:default" / "pad:default" for that part's defaults, or "none" for no input. A part the list
|
||||
// names neither way is left unbound. Pad names are physical buttons, so pad entries go into the gamepad table of every
|
||||
// layout; pad:default keeps each layout's own button. Stick directions take keys only. Invalid entries are logged and
|
||||
// skipped; when none is valid the action keeps its bindings. 1 when applied.
|
||||
int input_map_bind(const char *button, const char *list);
|
||||
// Applies the TOTK_BIND_<button> settings (cfg_get) over the defaults. Once, at start.
|
||||
// Applies the TOTK_BIND_<action> settings (cfg_get) over the defaults: at start, and again when one of them changes.
|
||||
void input_map_configure(void);
|
||||
|
||||
// The layout for a TOTK_PAD_LAYOUT value: "nintendo" or "xbox" (any case); anything else ("auto", NULL) picks Nintendo
|
||||
// when the pad's east button is labelled A (a Switch Pro Controller, a GuliKit) and Xbox otherwise.
|
||||
int input_pad_layout_pick(const char *setting, int east_labelled_a);
|
||||
@@ -68,3 +91,19 @@ void input_map_stick(const uint8_t down[KEY_COUNT], int stick, int32_t out[2]);
|
||||
// Mouse motion in raw counts over dt_s seconds to right-stick deflection: full deflection at 3000 / sens counts/s.
|
||||
// Clamped to the unit circle, up (negative dy) is +y.
|
||||
void input_mouse_stick(int32_t dx, int32_t dy, double dt_s, float sens, int32_t out[2]);
|
||||
|
||||
// ---- the remapping rows' edits, on a copy of input_map. Pure.
|
||||
// action's keys (table order) / its gamepad buttons in layout, at most max; returns how many.
|
||||
int input_map_keys_of(const InputMap *m, int action, uint8_t *out, int max);
|
||||
int input_map_pads_of(const InputMap *m, int action, int layout, uint8_t *out, int max);
|
||||
// Key slot (0 or 1) of action becomes key; KEY_NONE clears the slot. A key another action has moves here: returns that
|
||||
// action, -1 when none lost it.
|
||||
int input_map_set_key(InputMap *m, int action, int slot, int key);
|
||||
// action's gamepad button in layout becomes pad; PAD_NONE clears it. The action that had pad takes action's old button
|
||||
// (a swap): returns it, -1 when none. A remapped button is physical, so the face buttons (A B X Y) and the changed actions
|
||||
// get the result in every layout: the layout setting no longer moves them. A change that puts every button of layout
|
||||
// back at its default restores the defaults of every layout instead.
|
||||
int input_map_set_pad(InputMap *m, int action, int layout, int pad);
|
||||
// The bind_ value that gives action its bindings of m: "" when they are the defaults (no line needed), else the entries,
|
||||
// with key:default / pad:default for a part at its defaults, or "none".
|
||||
void input_map_line(const InputMap *m, int action, char *out, size_t n);
|
||||
+136
-6
@@ -26,6 +26,7 @@ static int state; // 0 not started, 1 running, -1 disabled or
|
||||
static SDL_Gamepad *pad;
|
||||
static uint64_t next_scan;
|
||||
static int pad_rumble; // the open gamepad has rumble motors
|
||||
static volatile LONG pad_labels[4]; // ... and the labels of its south, east, west, north buttons (PAD_LABEL_*), any thread
|
||||
static int pad_east_a; // ... and labels its east face button A (Nintendo layout under TOTK_PAD_LAYOUT=auto)
|
||||
static int pad_layout = -1; // PAD_LAYOUT_* in effect for the open gamepad, -1 to pick again; live (cfg_version)
|
||||
static unsigned pad_layout_seen;
|
||||
@@ -221,6 +222,7 @@ static void rec_apply(uint64_t b, const int32_t sl[2], const int32_t sr[2]) {
|
||||
static int key_vk(int key) {
|
||||
if (key >= KEY_A && key <= KEY_Z) return 'A' + (key - KEY_A);
|
||||
if (key >= KEY_0 && key <= KEY_9) return '0' + (key - KEY_0);
|
||||
if (key >= KEY_NUM0 && key <= KEY_NUM9) return VK_NUMPAD0 + (key - KEY_NUM0);
|
||||
switch (key) {
|
||||
case KEY_SPACE: return VK_SPACE;
|
||||
case KEY_TAB: return VK_TAB;
|
||||
@@ -233,10 +235,53 @@ static int key_vk(int key) {
|
||||
case KEY_MOUSE_L: return VK_LBUTTON;
|
||||
case KEY_MOUSE_R: return VK_RBUTTON;
|
||||
case KEY_MOUSE_M: return VK_MBUTTON;
|
||||
case KEY_MOUSE_X1: return VK_XBUTTON1;
|
||||
case KEY_MOUSE_X2: return VK_XBUTTON2;
|
||||
case KEY_ENTER: return VK_RETURN;
|
||||
case KEY_BACKSPACE: return VK_BACK;
|
||||
case KEY_RSHIFT: return VK_RSHIFT;
|
||||
case KEY_RCTRL: return VK_RCONTROL;
|
||||
case KEY_LALT: return VK_LMENU;
|
||||
case KEY_CAPSLOCK: return VK_CAPITAL;
|
||||
case KEY_INSERT: return VK_INSERT;
|
||||
case KEY_DELETE: return VK_DELETE;
|
||||
case KEY_HOME: return VK_HOME;
|
||||
case KEY_END: return VK_END;
|
||||
case KEY_PAGEUP: return VK_PRIOR;
|
||||
case KEY_PAGEDOWN: return VK_NEXT;
|
||||
case KEY_F2: return VK_F2;
|
||||
case KEY_F3: return VK_F3;
|
||||
case KEY_F4: return VK_F4;
|
||||
case KEY_F5: return VK_F5;
|
||||
case KEY_F6: return VK_F6;
|
||||
case KEY_F7: return VK_F7;
|
||||
case KEY_F9: return VK_F9;
|
||||
case KEY_F12: return VK_F12;
|
||||
case KEY_NUM_ADD: return VK_ADD;
|
||||
case KEY_NUM_SUB: return VK_SUBTRACT;
|
||||
case KEY_NUM_MUL: return VK_MULTIPLY;
|
||||
case KEY_NUM_DIV: return VK_DIVIDE;
|
||||
case KEY_NUM_DECIMAL: return VK_DECIMAL;
|
||||
case KEY_MINUS: return VK_OEM_MINUS;
|
||||
case KEY_EQUALS: return VK_OEM_PLUS;
|
||||
case KEY_LBRACKET: return VK_OEM_4;
|
||||
case KEY_RBRACKET: return VK_OEM_6;
|
||||
case KEY_SEMICOLON: return VK_OEM_1;
|
||||
case KEY_APOSTROPHE: return VK_OEM_7;
|
||||
case KEY_COMMA: return VK_OEM_COMMA;
|
||||
case KEY_PERIOD: return VK_OEM_PERIOD;
|
||||
case KEY_SLASH: return VK_OEM_2;
|
||||
case KEY_BACKSLASH: return VK_OEM_5;
|
||||
case KEY_GRAVE: return VK_OEM_3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t input_key_char(int key) {
|
||||
if (key < KEY_MINUS || key > KEY_GRAVE) return 0;
|
||||
return MapVirtualKeyW((UINT)key_vk(key), MAPVK_VK_TO_CHAR) & 0x7fffffffu; // the top bit marks a dead key
|
||||
}
|
||||
|
||||
// ---- mouse camera: raw motion accumulated by the window thread, one stick sample per presented frame
|
||||
static volatile LONG mouse_dx, mouse_dy; // raw counts since the last frame sample
|
||||
static volatile LONG cur_captured; // cursor hidden and confined to the client area
|
||||
@@ -318,6 +363,9 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
case WM_SETCURSOR:
|
||||
if (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; }
|
||||
break;
|
||||
case WM_SYSCOMMAND: // Alt pressed alone would enter the window menu loop, which stalls the game: Alt is a game key
|
||||
if ((w & 0xFFF0) == SC_KEYMENU && l == 0) { *res = 0; return 1; }
|
||||
break;
|
||||
case WM_KEYDOWN: // Esc is unbound in the game layout: it releases the cursor and opens the menu (menu_window_msg)
|
||||
if (w == VK_ESCAPE && !(cur_rel & CUR_REL)) { cur_rel_update(rel_esc); cursor_update(h); }
|
||||
break;
|
||||
@@ -391,6 +439,7 @@ static void scan_pads(void) {
|
||||
if (pad) {
|
||||
SDL_CloseGamepad(pad); pad = NULL; sensor_pad = 0; sensor_ok = 0;
|
||||
InterlockedExchange(&pad_layout_shown, -1);
|
||||
for (int i = 0; i < 4; i++) InterlockedExchange(&pad_labels[i], PAD_LABEL_NONE);
|
||||
rt_log("input: gamepad disconnected");
|
||||
}
|
||||
int n = 0;
|
||||
@@ -400,6 +449,18 @@ static void scan_pads(void) {
|
||||
if (!pad) return;
|
||||
pad_rumble = SDL_GetBooleanProperty(SDL_GetGamepadProperties(pad), SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, false);
|
||||
pad_east_a = SDL_GetGamepadButtonLabel(pad, SDL_GAMEPAD_BUTTON_EAST) == SDL_GAMEPAD_BUTTON_LABEL_A;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
SDL_GamepadButtonLabel lb = SDL_GetGamepadButtonLabel(pad, pad_sdl[PAD_SOUTH + i]);
|
||||
InterlockedExchange(&pad_labels[i], lb == SDL_GAMEPAD_BUTTON_LABEL_A ? PAD_LABEL_A
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_B ? PAD_LABEL_B
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_X ? PAD_LABEL_X
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_Y ? PAD_LABEL_Y
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_CROSS ? PAD_LABEL_CROSS
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_CIRCLE ? PAD_LABEL_CIRCLE
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_SQUARE ? PAD_LABEL_SQUARE
|
||||
: lb == SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE ? PAD_LABEL_TRIANGLE
|
||||
: PAD_LABEL_NONE);
|
||||
}
|
||||
pad_layout = -1;
|
||||
int motion = SDL_GamepadHasSensor(pad, SDL_SENSOR_GYRO) && SDL_GamepadHasSensor(pad, SDL_SENSOR_ACCEL);
|
||||
rt_log("input: gamepad \"%s\" (%s, %s, east button %s)", SDL_GetGamepadName(pad), pad_rumble ? "rumble" : "no rumble",
|
||||
@@ -420,8 +481,30 @@ static int pad_layout_get(void) {
|
||||
return pad_layout;
|
||||
}
|
||||
|
||||
static void start(void) {
|
||||
// The TOTK_BIND_* values last applied, one per line; the tables are built again when one changes (the menu's remapping rows write
|
||||
// them while the game runs). Under lock.
|
||||
static unsigned binds_seen = ~0u;
|
||||
static char binds_applied[4096];
|
||||
|
||||
static void binds_refresh(void) {
|
||||
unsigned v = cfg_version();
|
||||
if (v == binds_seen) return;
|
||||
binds_seen = v;
|
||||
char now[sizeof binds_applied];
|
||||
size_t len = 0;
|
||||
for (int a = 0; a < ACTION_COUNT; a++) {
|
||||
char var[32];
|
||||
snprintf(var, sizeof var, "TOTK_BIND_%s", input_action_name(a));
|
||||
const char *s = cfg_get(var);
|
||||
len += (size_t)snprintf(now + len, len < sizeof now ? sizeof now - len : 0, "%s\n", s ? s : "");
|
||||
}
|
||||
if (!strcmp(now, binds_applied)) return;
|
||||
memcpy(binds_applied, now, sizeof now);
|
||||
input_map_configure();
|
||||
}
|
||||
|
||||
static void start(void) {
|
||||
binds_refresh();
|
||||
const char *e = cfg_get("TOTK_INPUT");
|
||||
if (e && !strcmp(e, "none")) { state = -1; rt_log("input: disabled (TOTK_INPUT=none)"); return; }
|
||||
if (!SDL_Init(SDL_INIT_GAMEPAD)) { state = -1; rt_log("input: SDL gamepad init failed (%s), keyboard only", SDL_GetError()); }
|
||||
@@ -445,16 +528,22 @@ static void pick(int32_t *x, int32_t *y, int32_t kx, int32_t ky) {
|
||||
if (b > a) { *x = kx; *y = ky; }
|
||||
}
|
||||
|
||||
// Under lock, state 1: the open gamepad's buttons (Switch bits after TOTK_PAD_LAYOUT and the TOTK_BIND_* lines) and
|
||||
// sticks; 0 without a connected gamepad.
|
||||
static int pad_read(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
// Under lock, state 1: the open gamepad's inputs by position (pd[PAD_*] != 0 held); 0 without a connected gamepad.
|
||||
static int pad_physical(uint8_t pd[PAD_COUNT]) {
|
||||
if ((!pad || !SDL_GamepadConnected(pad)) && GetTickCount64() >= next_scan) { next_scan = GetTickCount64() + RESCAN_MS; scan_pads(); }
|
||||
SDL_UpdateGamepads();
|
||||
if (!pad || !SDL_GamepadConnected(pad)) return 0;
|
||||
uint8_t pd[PAD_COUNT] = {0};
|
||||
for (int p = PAD_SOUTH; p < PAD_ZL; p++) pd[p] = SDL_GetGamepadButton(pad, pad_sdl[p]);
|
||||
pd[PAD_ZL] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER) > TRIGGER_ON;
|
||||
pd[PAD_ZR] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) > TRIGGER_ON;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Under lock, state 1: the open gamepad's buttons (Switch bits after TOTK_PAD_LAYOUT and the TOTK_BIND_* lines) and
|
||||
// sticks; 0 without a connected gamepad.
|
||||
static int pad_read(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
uint8_t pd[PAD_COUNT] = {0};
|
||||
if (!pad_physical(pd)) return 0;
|
||||
*b |= input_map_pad_buttons(pd, pad_layout_get());
|
||||
sl[0] = axis(SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFTX));
|
||||
sl[1] = -axis(SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFTY));
|
||||
@@ -469,6 +558,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
if (!state) start();
|
||||
if (state > 0) {
|
||||
binds_refresh();
|
||||
if (state == 1) pad_read(&b, sl, sr);
|
||||
HWND w = gfx_window_handle();
|
||||
if (w && w == GetForegroundWindow()) {
|
||||
@@ -481,7 +571,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
for (int k = 1; k < KEY_COUNT; k++) {
|
||||
int vk = key_vk(k);
|
||||
down[k] = vk && key_down(vk);
|
||||
if (k < KEY_MOUSE_L || k > KEY_MOUSE_M) continue;
|
||||
if (k < KEY_MOUSE_L || k > KEY_MOUSE_X2) continue;
|
||||
if (cap && !was_captured) mouse_ignore[k] = down[k];
|
||||
if (!down[k]) mouse_ignore[k] = 0;
|
||||
if (!cap || mouse_ignore[k]) down[k] = 0;
|
||||
@@ -549,6 +639,7 @@ int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly) {
|
||||
int32_t sl[2] = {0, 0}, sr[2] = {0, 0};
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
if (!state) start();
|
||||
if (state > 0) binds_refresh();
|
||||
int ok = state == 1 && pad_read(&b, sl, sr);
|
||||
ReleaseSRWLockExclusive(&lock);
|
||||
*buttons = b;
|
||||
@@ -567,6 +658,45 @@ int input_pad_layout(void) {
|
||||
return (int)InterlockedCompareExchange(&pad_layout_shown, 0, 0);
|
||||
}
|
||||
|
||||
int input_pad_label(int pad_id) {
|
||||
if (pad_id < PAD_SOUTH || pad_id > PAD_NORTH) return PAD_LABEL_NONE;
|
||||
return (int)InterlockedCompareExchange(&pad_labels[pad_id - PAD_SOUTH], 0, 0);
|
||||
}
|
||||
|
||||
void input_map_snapshot(InputMap *m) {
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
if (!state) start();
|
||||
if (state > 0) binds_refresh();
|
||||
*m = input_map;
|
||||
ReleaseSRWLockExclusive(&lock);
|
||||
}
|
||||
|
||||
int input_capture(int reset, int *id) {
|
||||
static uint8_t prev_k[KEY_COUNT], prev_p[PAD_COUNT];
|
||||
static int prev_esc;
|
||||
uint8_t k[KEY_COUNT] = {0}, p[PAD_COUNT] = {0};
|
||||
HWND w = gfx_window_handle();
|
||||
int fg = w && w == GetForegroundWindow();
|
||||
for (int i = 1; i < KEY_COUNT; i++) k[i] = fg && key_down(key_vk(i));
|
||||
int esc = fg && key_down(VK_ESCAPE);
|
||||
AcquireSRWLockExclusive(&lock);
|
||||
if (!state) start();
|
||||
if (state == 1) pad_physical(p);
|
||||
ReleaseSRWLockExclusive(&lock);
|
||||
int got = INPUT_CAPTURE_NONE;
|
||||
if (!reset) {
|
||||
if (esc && !prev_esc) got = INPUT_CAPTURE_CANCEL;
|
||||
for (int i = 1; i < KEY_COUNT && !got; i++)
|
||||
if (k[i] && !prev_k[i]) got = INPUT_CAPTURE_KEY, *id = i;
|
||||
for (int i = 1; i < PAD_COUNT && !got; i++)
|
||||
if (p[i] && !prev_p[i]) got = INPUT_CAPTURE_PAD, *id = i;
|
||||
}
|
||||
memcpy(prev_k, k, sizeof k);
|
||||
memcpy(prev_p, p, sizeof p);
|
||||
prev_esc = esc;
|
||||
return got;
|
||||
}
|
||||
|
||||
int input_rumble_triggers_enabled(void) {
|
||||
return cfg_bool("TOTK_RUMBLE_TRIGGERS");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
// The remapping rows of the Controls tab (binds_page.h): edits a copy of the input tables (input_map.h), writes the TOTK_BIND_* lines that
|
||||
// give the copy, and input_win.c applies them at its next poll; totk.ini follows a moment later (opt_save_soon). The
|
||||
// gamepad cells show and change the table of the button layout in use (TOTK_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_RSTICK_DOWN - UI_BIND_A == 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_ZR - UI_PAD_SOUTH == PAD_ZR - PAD_SOUTH, "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;
|
||||
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 totk.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("TOTK_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, "TOTK_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
|
||||
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);
|
||||
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();
|
||||
}
|
||||
@@ -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);
|
||||
+5
-2
@@ -19,6 +19,7 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h" // SetFocusID, NavCursorVisible
|
||||
#include "backends/imgui_impl_vulkan.h"
|
||||
#include "ui/binds_page.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
@@ -567,7 +568,9 @@ static void tab_controls(float scale) {
|
||||
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_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0, 10, UI_MENU_MOUSE_SENS_DESC, 0.1f, "%.1f");
|
||||
binds_rows(scale);
|
||||
opt_end();
|
||||
binds_after_page();
|
||||
}
|
||||
|
||||
static void tab_menu(float scale) {
|
||||
@@ -756,7 +759,7 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetStyle().WindowPadding.x - ImGui::CalcTextSize(version).x);
|
||||
ImGui::TextDisabled("%s", version);
|
||||
|
||||
int step = g_modal ? 0
|
||||
int step = g_modal || binds_modal() ? 0
|
||||
: ImGui::IsKeyPressed(ImGuiKey_GamepadR1, false) || ImGui::IsKeyPressed(ImGuiKey_E, false) ? 1
|
||||
: ImGui::IsKeyPressed(ImGuiKey_GamepadL1, false) || ImGui::IsKeyPressed(ImGuiKey_Q, false) ? -1
|
||||
: 0;
|
||||
@@ -807,7 +810,7 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
if (ImGui::Button(cont, ImVec2(bw, 0))) set_open(0);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(quit, ImVec2(bw, 0))) gfx_window_request_close();
|
||||
bool was_modal = g_modal;
|
||||
bool was_modal = g_modal || binds_modal();
|
||||
if (g_tab != TAB_ADVANCED) g_modal = false;
|
||||
if (!was_modal && (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false)))
|
||||
set_open(0);
|
||||
|
||||
@@ -26,6 +26,7 @@ static ImGuiKey key_of(WPARAM vk) {
|
||||
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;
|
||||
|
||||
@@ -313,3 +313,103 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de
|
||||
apply(key, 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, "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 (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;
|
||||
}
|
||||
@@ -49,6 +49,15 @@ bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value
|
||||
bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId desc, float step = 1,
|
||||
const char *fmt = "%g");
|
||||
|
||||
// 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
|
||||
// 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);
|
||||
|
||||
// totk.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.
|
||||
|
||||
@@ -100,6 +100,50 @@ static const char *const text_en[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_MOUSE_SENS] = "Mouse camera sensitivity",
|
||||
[UI_MENU_MOUSE_SENS_DESC] = "How fast the mouse turns the camera.",
|
||||
|
||||
[UI_BINDS_HELP] = "Select a cell and press A or Enter, then the key, mouse button or controller button. Delete or "
|
||||
"X clears a cell. A key in use moves here; a controller button swaps with the one it replaces.",
|
||||
[UI_BINDS_COL_KEY1] = "Key 1", [UI_BINDS_COL_KEY2] = "Key 2", [UI_BINDS_COL_PAD] = "Controller",
|
||||
[UI_BINDS_GROUP_BUTTONS] = "Buttons", [UI_BINDS_GROUP_MOVE] = "Movement", [UI_BINDS_GROUP_CAMERA] = "Camera",
|
||||
[UI_BINDS_PRESS_KEY] = "Press a key or mouse button for %s",
|
||||
[UI_BINDS_PRESS_PAD] = "Press a controller button for %s",
|
||||
[UI_BINDS_CANCEL_HINT] = "Esc cancels, or wait %d s",
|
||||
[UI_BINDS_TAKEN] = "%s was taken from %s", [UI_BINDS_SWAPPED] = "%s swapped with %s",
|
||||
[UI_BINDS_RESET] = "Reset all buttons",
|
||||
[UI_BINDS_RESET_DESC] = "Back to the default keys and controller buttons. The button layout above applies again: remapped controller buttons stay where you put them until this reset.",
|
||||
[UI_BIND_A] = "A", [UI_BIND_B] = "B", [UI_BIND_X] = "X", [UI_BIND_Y] = "Y",
|
||||
[UI_BIND_LCLICK] = "Left stick click", [UI_BIND_RCLICK] = "Right stick click", [UI_BIND_L] = "L",
|
||||
[UI_BIND_R] = "R", [UI_BIND_ZL] = "ZL", [UI_BIND_ZR] = "ZR", [UI_BIND_PLUS] = "Plus", [UI_BIND_MINUS] = "Minus",
|
||||
[UI_BIND_LEFT] = "D-pad left", [UI_BIND_UP] = "D-pad up", [UI_BIND_RIGHT] = "D-pad right",
|
||||
[UI_BIND_DOWN] = "D-pad down",
|
||||
[UI_BIND_LSTICK_LEFT] = "Move left", [UI_BIND_LSTICK_UP] = "Move forward", [UI_BIND_LSTICK_RIGHT] = "Move right",
|
||||
[UI_BIND_LSTICK_DOWN] = "Move back",
|
||||
[UI_BIND_RSTICK_LEFT] = "Camera left", [UI_BIND_RSTICK_UP] = "Camera up", [UI_BIND_RSTICK_RIGHT] = "Camera right",
|
||||
[UI_BIND_RSTICK_DOWN] = "Camera down",
|
||||
[UI_BIND_DESC_A] = "Interact, pick up, talk.", [UI_BIND_DESC_B] = "Run, cancel, go back.",
|
||||
[UI_BIND_DESC_X] = "Jump.", [UI_BIND_DESC_Y] = "Attack.", [UI_BIND_DESC_LCLICK] = "Crouch.",
|
||||
[UI_BIND_DESC_RCLICK] = "First-person view.", [UI_BIND_DESC_L] = "Abilities.",
|
||||
[UI_BIND_DESC_R] = "Throw a weapon.", [UI_BIND_DESC_ZL] = "Shield, lock on.", [UI_BIND_DESC_ZR] = "Bow.",
|
||||
[UI_BIND_DESC_PLUS] = "Menu, inventory.", [UI_BIND_DESC_MINUS] = "Map.",
|
||||
[UI_BIND_DESC_DPAD] = "Quick-select.",
|
||||
[UI_BIND_DESC_MOVE] = "Moves Link like the left stick. The controller's left stick always works too.",
|
||||
[UI_BIND_DESC_CAMERA] = "Turns the camera like the right stick. The mouse and the controller's right stick always "
|
||||
"work too.",
|
||||
[UI_KEY_SPACE] = "Space", [UI_KEY_TAB] = "Tab", [UI_KEY_LSHIFT] = "Left Shift", [UI_KEY_LCTRL] = "Left Ctrl",
|
||||
[UI_KEY_UP] = "Up arrow", [UI_KEY_DOWN] = "Down arrow", [UI_KEY_LEFT] = "Left arrow",
|
||||
[UI_KEY_RIGHT] = "Right arrow",
|
||||
[UI_KEY_MOUSE_L] = "Left mouse", [UI_KEY_MOUSE_R] = "Right mouse", [UI_KEY_MOUSE_M] = "Middle mouse",
|
||||
[UI_KEY_MOUSE_X1] = "Mouse 4", [UI_KEY_MOUSE_X2] = "Mouse 5",
|
||||
[UI_KEY_ENTER] = "Enter", [UI_KEY_BACKSPACE] = "Backspace", [UI_KEY_RSHIFT] = "Right Shift",
|
||||
[UI_KEY_RCTRL] = "Right Ctrl", [UI_KEY_LALT] = "Alt", [UI_KEY_CAPSLOCK] = "Caps Lock", [UI_KEY_INSERT] = "Insert",
|
||||
[UI_KEY_DELETE] = "Delete", [UI_KEY_HOME] = "Home", [UI_KEY_END] = "End", [UI_KEY_PAGEUP] = "Page Up",
|
||||
[UI_KEY_PAGEDOWN] = "Page Down", [UI_KEY_NUM_FMT] = "Num %s",
|
||||
[UI_PAD_SOUTH] = "Bottom button", [UI_PAD_EAST] = "Right button", [UI_PAD_WEST] = "Left button",
|
||||
[UI_PAD_NORTH] = "Top button", [UI_PAD_LSTICK] = "Left stick", [UI_PAD_RSTICK] = "Right stick",
|
||||
[UI_PAD_L] = "Left bumper", [UI_PAD_R] = "Right bumper", [UI_PAD_START] = "Start", [UI_PAD_BACK] = "Back",
|
||||
[UI_PAD_DPAD_LEFT] = "D-pad left", [UI_PAD_DPAD_UP] = "D-pad up", [UI_PAD_DPAD_RIGHT] = "D-pad right",
|
||||
[UI_PAD_DPAD_DOWN] = "D-pad down", [UI_PAD_ZL] = "Left trigger", [UI_PAD_ZR] = "Right trigger",
|
||||
[UI_PAD_CROSS] = "Cross", [UI_PAD_CIRCLE] = "Circle", [UI_PAD_SQUARE] = "Square", [UI_PAD_TRIANGLE] = "Triangle",
|
||||
|
||||
[UI_MENU_MENU_LANG] = "Menu language", [UI_MENU_MENU_LANG_DESC] = "Language of this menu and the overlay.",
|
||||
[UI_MENU_MENU_LANG_AUTO] = "Automatic (from Windows)",
|
||||
|
||||
@@ -273,6 +317,54 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_MOUSE_SENS] = "Чувствительность мыши",
|
||||
[UI_MENU_MOUSE_SENS_DESC] = "Как быстро мышь поворачивает камеру.",
|
||||
|
||||
[UI_BINDS_HELP] = "Выберите ячейку и нажмите A или Enter, затем клавишу, кнопку мыши или кнопку контроллера. "
|
||||
"Delete или X очищает ячейку. Занятая клавиша переходит сюда; кнопка контроллера меняется "
|
||||
"местами с той, которую заменяет.",
|
||||
[UI_BINDS_COL_KEY1] = "Клавиша 1", [UI_BINDS_COL_KEY2] = "Клавиша 2", [UI_BINDS_COL_PAD] = "Контроллер",
|
||||
[UI_BINDS_GROUP_BUTTONS] = "Кнопки", [UI_BINDS_GROUP_MOVE] = "Движение", [UI_BINDS_GROUP_CAMERA] = "Камера",
|
||||
[UI_BINDS_PRESS_KEY] = "Нажмите клавишу или кнопку мыши для «%s»",
|
||||
[UI_BINDS_PRESS_PAD] = "Нажмите кнопку контроллера для «%s»",
|
||||
[UI_BINDS_CANCEL_HINT] = "Esc отменяет, или подождите %d с",
|
||||
[UI_BINDS_TAKEN] = "%s: убрано с «%s»", [UI_BINDS_SWAPPED] = "«%s» и «%s» поменялись местами",
|
||||
[UI_BINDS_RESET] = "Сбросить все кнопки",
|
||||
[UI_BINDS_RESET_DESC] = "Вернуть клавиши и кнопки контроллера по умолчанию. Снова действует раскладка кнопок выше: "
|
||||
"переназначенные кнопки контроллера остаются на своих местах до "
|
||||
"этого сброса.",
|
||||
[UI_BIND_A] = "A", [UI_BIND_B] = "B", [UI_BIND_X] = "X", [UI_BIND_Y] = "Y",
|
||||
[UI_BIND_LCLICK] = "Нажатие левого стика", [UI_BIND_RCLICK] = "Нажатие правого стика", [UI_BIND_L] = "L",
|
||||
[UI_BIND_R] = "R", [UI_BIND_ZL] = "ZL", [UI_BIND_ZR] = "ZR", [UI_BIND_PLUS] = "Плюс", [UI_BIND_MINUS] = "Минус",
|
||||
[UI_BIND_LEFT] = "Крестовина влево", [UI_BIND_UP] = "Крестовина вверх", [UI_BIND_RIGHT] = "Крестовина вправо",
|
||||
[UI_BIND_DOWN] = "Крестовина вниз",
|
||||
[UI_BIND_LSTICK_LEFT] = "Влево", [UI_BIND_LSTICK_UP] = "Вперёд", [UI_BIND_LSTICK_RIGHT] = "Вправо",
|
||||
[UI_BIND_LSTICK_DOWN] = "Назад",
|
||||
[UI_BIND_RSTICK_LEFT] = "Камера влево", [UI_BIND_RSTICK_UP] = "Камера вверх",
|
||||
[UI_BIND_RSTICK_RIGHT] = "Камера вправо", [UI_BIND_RSTICK_DOWN] = "Камера вниз",
|
||||
[UI_BIND_DESC_A] = "Взаимодействие, подобрать, поговорить.", [UI_BIND_DESC_B] = "Бег, отмена, назад.",
|
||||
[UI_BIND_DESC_X] = "Прыжок.", [UI_BIND_DESC_Y] = "Атака.", [UI_BIND_DESC_LCLICK] = "Присесть.",
|
||||
[UI_BIND_DESC_RCLICK] = "Вид от первого лица.", [UI_BIND_DESC_L] = "Способности.",
|
||||
[UI_BIND_DESC_R] = "Бросок оружия.", [UI_BIND_DESC_ZL] = "Щит, захват цели.", [UI_BIND_DESC_ZR] = "Лук.",
|
||||
[UI_BIND_DESC_PLUS] = "Меню, инвентарь.", [UI_BIND_DESC_MINUS] = "Карта.",
|
||||
[UI_BIND_DESC_DPAD] = "Быстрый выбор.",
|
||||
[UI_BIND_DESC_MOVE] = "Двигает Линка, как левый стик. Левый стик контроллера тоже всегда работает.",
|
||||
[UI_BIND_DESC_CAMERA] = "Поворачивает камеру, как правый стик. Мышь и правый стик контроллера тоже всегда "
|
||||
"работают.",
|
||||
[UI_KEY_SPACE] = "Пробел", [UI_KEY_TAB] = "Tab", [UI_KEY_LSHIFT] = "Левый Shift", [UI_KEY_LCTRL] = "Левый Ctrl",
|
||||
[UI_KEY_UP] = "Стрелка вверх", [UI_KEY_DOWN] = "Стрелка вниз", [UI_KEY_LEFT] = "Стрелка влево",
|
||||
[UI_KEY_RIGHT] = "Стрелка вправо",
|
||||
[UI_KEY_MOUSE_L] = "ЛКМ", [UI_KEY_MOUSE_R] = "ПКМ", [UI_KEY_MOUSE_M] = "СКМ", [UI_KEY_MOUSE_X1] = "Мышь 4",
|
||||
[UI_KEY_MOUSE_X2] = "Мышь 5",
|
||||
[UI_KEY_ENTER] = "Enter", [UI_KEY_BACKSPACE] = "Backspace", [UI_KEY_RSHIFT] = "Правый Shift",
|
||||
[UI_KEY_RCTRL] = "Правый Ctrl", [UI_KEY_LALT] = "Alt", [UI_KEY_CAPSLOCK] = "Caps Lock", [UI_KEY_INSERT] = "Insert",
|
||||
[UI_KEY_DELETE] = "Delete", [UI_KEY_HOME] = "Home", [UI_KEY_END] = "End", [UI_KEY_PAGEUP] = "Page Up",
|
||||
[UI_KEY_PAGEDOWN] = "Page Down", [UI_KEY_NUM_FMT] = "Num %s",
|
||||
[UI_PAD_SOUTH] = "Нижняя кнопка", [UI_PAD_EAST] = "Правая кнопка", [UI_PAD_WEST] = "Левая кнопка",
|
||||
[UI_PAD_NORTH] = "Верхняя кнопка", [UI_PAD_LSTICK] = "Левый стик", [UI_PAD_RSTICK] = "Правый стик",
|
||||
[UI_PAD_L] = "Левый бампер", [UI_PAD_R] = "Правый бампер", [UI_PAD_START] = "Start", [UI_PAD_BACK] = "Back",
|
||||
[UI_PAD_DPAD_LEFT] = "Крестовина влево", [UI_PAD_DPAD_UP] = "Крестовина вверх",
|
||||
[UI_PAD_DPAD_RIGHT] = "Крестовина вправо", [UI_PAD_DPAD_DOWN] = "Крестовина вниз", [UI_PAD_ZL] = "Левый курок",
|
||||
[UI_PAD_ZR] = "Правый курок",
|
||||
[UI_PAD_CROSS] = "Крест", [UI_PAD_CIRCLE] = "Круг", [UI_PAD_SQUARE] = "Квадрат", [UI_PAD_TRIANGLE] = "Треугольник",
|
||||
|
||||
[UI_MENU_MENU_LANG] = "Язык меню", [UI_MENU_MENU_LANG_DESC] = "Язык этого меню и индикатора.",
|
||||
[UI_MENU_MENU_LANG_AUTO] = "Автоматически (из Windows)",
|
||||
|
||||
|
||||
@@ -58,6 +58,36 @@ typedef enum {
|
||||
UI_MENU_PAD_LAYOUT_XBOX, UI_MENU_PAD_LAYOUT_IN_USE,
|
||||
UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC,
|
||||
|
||||
// Controls tab: the remapping rows (ui/binds_page.cpp)
|
||||
UI_BINDS_HELP, UI_BINDS_COL_KEY1, UI_BINDS_COL_KEY2, UI_BINDS_COL_PAD,
|
||||
UI_BINDS_GROUP_BUTTONS, UI_BINDS_GROUP_MOVE, UI_BINDS_GROUP_CAMERA,
|
||||
UI_BINDS_PRESS_KEY, // "Press a key or mouse button for %s"
|
||||
UI_BINDS_PRESS_PAD, // "Press a controller button for %s"
|
||||
UI_BINDS_CANCEL_HINT, // "Esc cancels, or wait %d s"
|
||||
UI_BINDS_TAKEN, // "%s was taken from %s": the key, the action that lost it
|
||||
UI_BINDS_SWAPPED, // "%s swapped with %s": the two actions
|
||||
UI_BINDS_RESET, UI_BINDS_RESET_DESC,
|
||||
// the actions, in action order (input_map.h B_A .. B_SR_DOWN)
|
||||
UI_BIND_A, UI_BIND_B, UI_BIND_X, UI_BIND_Y, UI_BIND_LCLICK, UI_BIND_RCLICK, UI_BIND_L, UI_BIND_R, UI_BIND_ZL,
|
||||
UI_BIND_ZR, UI_BIND_PLUS, UI_BIND_MINUS, UI_BIND_LEFT, UI_BIND_UP, UI_BIND_RIGHT, UI_BIND_DOWN,
|
||||
UI_BIND_LSTICK_LEFT, UI_BIND_LSTICK_UP, UI_BIND_LSTICK_RIGHT, UI_BIND_LSTICK_DOWN,
|
||||
UI_BIND_RSTICK_LEFT, UI_BIND_RSTICK_UP, UI_BIND_RSTICK_RIGHT, UI_BIND_RSTICK_DOWN,
|
||||
// what an action does in the world, in action order up to Minus
|
||||
UI_BIND_DESC_A, UI_BIND_DESC_B, UI_BIND_DESC_X, UI_BIND_DESC_Y, UI_BIND_DESC_LCLICK, UI_BIND_DESC_RCLICK,
|
||||
UI_BIND_DESC_L, UI_BIND_DESC_R, UI_BIND_DESC_ZL, UI_BIND_DESC_ZR, UI_BIND_DESC_PLUS, UI_BIND_DESC_MINUS,
|
||||
UI_BIND_DESC_DPAD, UI_BIND_DESC_MOVE, UI_BIND_DESC_CAMERA,
|
||||
// key names, in key id order KEY_SPACE .. KEY_PAGEDOWN (letters, digits, F keys and punctuation show as themselves)
|
||||
UI_KEY_SPACE, UI_KEY_TAB, UI_KEY_LSHIFT, UI_KEY_LCTRL, UI_KEY_UP, UI_KEY_DOWN, UI_KEY_LEFT, UI_KEY_RIGHT,
|
||||
UI_KEY_MOUSE_L, UI_KEY_MOUSE_R, UI_KEY_MOUSE_M, UI_KEY_MOUSE_X1, UI_KEY_MOUSE_X2,
|
||||
UI_KEY_ENTER, UI_KEY_BACKSPACE, UI_KEY_RSHIFT, UI_KEY_RCTRL, UI_KEY_LALT, UI_KEY_CAPSLOCK, UI_KEY_INSERT,
|
||||
UI_KEY_DELETE, UI_KEY_HOME, UI_KEY_END, UI_KEY_PAGEUP, UI_KEY_PAGEDOWN,
|
||||
UI_KEY_NUM_FMT, // "Num %s": a numpad key
|
||||
// gamepad buttons, in pad id order PAD_SOUTH .. PAD_ZR, then the PlayStation face labels
|
||||
UI_PAD_SOUTH, UI_PAD_EAST, UI_PAD_WEST, UI_PAD_NORTH, UI_PAD_LSTICK, UI_PAD_RSTICK, UI_PAD_L, UI_PAD_R,
|
||||
UI_PAD_START, UI_PAD_BACK, UI_PAD_DPAD_LEFT, UI_PAD_DPAD_UP, UI_PAD_DPAD_RIGHT, UI_PAD_DPAD_DOWN, UI_PAD_ZL,
|
||||
UI_PAD_ZR,
|
||||
UI_PAD_CROSS, UI_PAD_CIRCLE, UI_PAD_SQUARE, UI_PAD_TRIANGLE,
|
||||
|
||||
// Menu tab
|
||||
UI_MENU_MENU_LANG, UI_MENU_MENU_LANG_DESC, UI_MENU_MENU_LANG_AUTO,
|
||||
|
||||
|
||||
+8
-4
@@ -151,11 +151,15 @@
|
||||
# mouse_sens = 1
|
||||
# Write the input of this run to a file that replays as a script (docs/controls.md, "Scripted input"). Default: off.
|
||||
# input_record = input.txt
|
||||
# Remap buttons, one line per Switch button: bind_<A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK> =
|
||||
# comma separated pad:<name> and key:<name> entries, or none. A line replaces that button's defaults (pad and keyboard);
|
||||
# buttons without a line keep them. Invalid entries are logged and skipped.
|
||||
# Remap buttons: the Controls tab of the settings menu (F1) writes these lines. One line per Switch button or stick
|
||||
# direction: bind_<A B X Y L R ZL ZR PLUS MINUS LEFT UP RIGHT DOWN LCLICK RCLICK> or bind_<LSTICK RSTICK>_<LEFT UP RIGHT
|
||||
# DOWN> = comma separated pad:<name> and key:<name> entries, key:default / pad:default for that part's defaults, or none.
|
||||
# A line replaces that button's defaults (pad and keyboard); buttons without a line keep them. Stick directions take keys
|
||||
# only. Invalid entries are logged and skipped. Changes while the game runs take effect at once.
|
||||
# pad names: south east west north l r zl zr start back lstick rstick dpad_left dpad_up dpad_right dpad_down
|
||||
# key names: a-z 0-9 space tab lshift lctrl up down left right mouse_l mouse_r mouse_m
|
||||
# key names: a-z 0-9 f2-f7 f9 f12 num0-num9 space tab enter backspace lshift rshift lctrl rctrl lalt capslock insert
|
||||
# delete home end pageup pagedown up down left right num_add num_sub num_mul num_div num_decimal minus equals
|
||||
# lbracket rbracket semicolon apostrophe comma period slash backslash grave mouse_l mouse_r mouse_m mouse_x1 mouse_x2
|
||||
# Defaults (pad_layout = nintendo): A = pad:east, key:E. B = pad:south, key:lshift. X = pad:north, key:space.
|
||||
# Y = pad:west, key:mouse_l. A pad that reports A/B and X/Y swapped (some GuliKit models): set pad_layout = xbox, or
|
||||
# swap them back here (keyboard keys stay):
|
||||
|
||||
Reference in new issue
Block a user