diff --git a/docs/controls.md b/docs/controls.md index 8263c8ed..12c4d7c0 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -94,7 +94,7 @@ Mouse motion (raw input) becomes right-stick deflection. Each presented frame ta `TOTK_MOUSE_SENS` (0 to 10, default 1; higher turns faster, 0 turns the mouse camera and the cursor capture off). While the window is the foreground window the cursor is hidden and confined to the client area. It is released on focus loss, minimise, while F11 changes the window, during a size or move loop and while a text entry is open. Esc releases it by hand: the cursor shows, the mouse camera and mouse buttons stop, and the window can be moved, minimised or closed. A mouse click inside the client area captures it again; that click does not reach the game. Activating the window by a click on its title bar or border does not capture, so it can be dragged or closed right away; Alt+Tab or a click in the client area captures as before. `TOTK_INPUT=none` disables the capture too. -`TOTK_STICK_DEADZONE` (0 to 50, default 8) is the gamepad stick dead zone in percent of full deflection, the same for both sticks. It is round: a stick inside the circle reads centred, and the rest of its travel is scaled to start at 0 at the edge, so full deflection still reaches full. Raise it for a stick that drifts. The game's own dead zone applies after it. `TOTK_LSTICK_DEADZONE` and `TOTK_RSTICK_DEADZONE` (the *Left/Right stick dead zone* rows on the Controls tab) set one stick each and fall back to `TOTK_STICK_DEADZONE` while unset, so a worn stick can get a larger zone than the other. With a gamepad connected each row shows its stick's deflection now, before the dead zone (*stick now*): let go of the stick and set the row a few percent above the value it rests at. +`TOTK_STICK_DEADZONE` (0 to 50, default 8) is the gamepad stick dead zone in percent of full deflection, the same for both sticks. It is round: a stick inside the circle reads centred, and the rest of its travel is scaled to start at 0 at the edge, so full deflection still reaches full. Raise it for a stick that drifts. The game's own dead zone applies after it. `TOTK_LSTICK_DEADZONE` and `TOTK_RSTICK_DEADZONE` (the *Left/Right stick dead zone* rows under *Analog sticks* on the Controls tab) set one stick each and fall back to `TOTK_STICK_DEADZONE` while unset, so a worn stick can get a larger zone than the other. With a gamepad connected each row shows its stick's deflection now, before the dead zone (*stick now*): let go of the stick and set the row a few percent above the value it rests at. The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sticks at 50% deflection. A gamepad plugged in later is picked up within one second; with none connected the log says `input: no gamepad`. diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index c6a2ac7a..ecc75a9f 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -822,8 +822,13 @@ static void tab_controls(float scale) { opt_slider("TOTK_RUMBLE_STRENGTH", UI_MENU_RUMBLE_STRENGTH, 0, 300, UI_MENU_RUMBLE_STRENGTH_DESC, 10, "%.0f %%"); opt_slider("TOTK_RUMBLE_CURVE", UI_MENU_RUMBLE_CURVE, 0.2f, 1.5f, UI_MENU_RUMBLE_CURVE_DESC, 0.05f, "%.2f"); opt_toggle("TOTK_RUMBLE_TRIGGERS", UI_MENU_RUMBLE_TRIGGERS, UI_MENU_RUMBLE_TRIGGERS_DESC); - // One row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With a gamepad connected each - // row shows its stick's deflection now, before the dead zone: a drifting stick's resting value, to set it above. + opt_slider("TOTK_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0, 10, UI_MENU_MOUSE_SENS_DESC, 0.1f, "%.1f"); + row_walk_key(); + opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f"); + // Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With + // a gamepad connected each row shows its stick's deflection now, before the dead zone: a drifting stick's resting + // value, to set it above. + opt_group(UI_MENU_GROUP_STICKS); double now[2]; bool pad = input_pad_stick_percent(now) != 0; char stick_note[2][64]; @@ -834,9 +839,6 @@ static void tab_controls(float scale) { opt_slider("TOTK_RSTICK_DEADZONE", UI_MENU_RSTICK_DEADZONE, 0, 50, UI_MENU_STICK_DEADZONE_DESC, 1, "%.0f %%", pad ? stick_note[1] : nullptr, "TOTK_STICK_DEADZONE"); opt_slider("TOTK_STICK_SENS", UI_MENU_STICK_SENS, 0.1f, 3, UI_MENU_STICK_SENS_DESC, 0.05f, "%.2f"); - opt_slider("TOTK_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0, 10, UI_MENU_MOUSE_SENS_DESC, 0.1f, "%.1f"); - row_walk_key(); - opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f"); binds_rows(scale); opt_end(); binds_after_page(); diff --git a/runtime/ui/option_rows.cpp b/runtime/ui/option_rows.cpp index 78725fd3..6074ca12 100644 --- a/runtime/ui/option_rows.cpp +++ b/runtime/ui/option_rows.cpp @@ -353,7 +353,10 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de 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); - double v = cfg_double(src), def = m ? strtod(m->def, NULL) : lo; + // 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}; @@ -367,7 +370,8 @@ bool opt_slider(const char *key, UiTextId label, float lo, float hi, UiTextId de char out[32]; if (step >= 1) snprintf(out, sizeof out, "%d", (int)lround(n)); else snprintf(out, sizeof out, "%g", round(n / step) * step); - apply(key, out); + // Landing on the fallback's value unsets the key (its line leaves totk.ini), so the row follows the fallback again. + apply(key, fallback && fabs(n - cfg_double(fallback)) < step * 0.01 ? "" : out); return true; } diff --git a/runtime/ui/option_rows.h b/runtime/ui/option_rows.h index 83cf4f87..b15933b3 100644 --- a/runtime/ui/option_rows.h +++ b/runtime/ui/option_rows.h @@ -61,7 +61,8 @@ 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. +// 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); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index dc845006..719dd9df 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -227,6 +227,7 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_RESTART_CONFIRM] = "Restart the game now? Progress since your last save is lost.", [UI_MENU_RESTART_YES] = "Restart", [UI_MENU_RESTART_SAVING] = "The game is saving: Restart is possible in a moment.", + [UI_MENU_GROUP_STICKS] = "Analog sticks", [UI_MENU_LSTICK_DEADZONE] = "Left stick dead zone", [UI_MENU_RSTICK_DEADZONE] = "Right stick dead zone", [UI_MENU_STICK_DEADZONE_DESC] = "How far a gamepad stick moves before the game sees it. Raise it if the character or the camera moves on its own: let go of the stick, read \"stick now\" and set the dead zone a few percent above it.", [UI_MENU_STICK_DEADZONE_NOW] = "stick now: %.0f %%", @@ -650,6 +651,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_RESTART_CONFIRM] = "Перезапустить игру сейчас? Прогресс после последнего сохранения будет потерян.", [UI_MENU_RESTART_YES] = "Перезапустить", [UI_MENU_RESTART_SAVING] = "Игра сохраняется: перезапуск будет доступен через мгновение.", + [UI_MENU_GROUP_STICKS] = "Стики", [UI_MENU_LSTICK_DEADZONE] = "Мёртвая зона левого стика", [UI_MENU_RSTICK_DEADZONE] = "Мёртвая зона правого стика", [UI_MENU_STICK_DEADZONE_DESC] = "Насколько нужно отклонить стик геймпада, чтобы игра это заметила. Увеличьте, если персонаж или камера двигаются сами: отпустите стик, посмотрите «стик сейчас» и поставьте мёртвую зону на несколько процентов выше.", [UI_MENU_STICK_DEADZONE_NOW] = "стик сейчас: %.0f %%", @@ -1000,6 +1002,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_PAD_LAYOUT_AUTO] = "Automático", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo (A à direita)", [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox (A embaixo)", [UI_MENU_PAD_LAYOUT_IN_USE] = "em uso: %s", + [UI_MENU_GROUP_STICKS] = "Analógicos", [UI_MENU_LSTICK_DEADZONE] = "Zona morta do analógico esquerdo", [UI_MENU_RSTICK_DEADZONE] = "Zona morta do analógico direito", [UI_MENU_STICK_DEADZONE_DESC] = "Quanto um analógico do controle precisa se mover antes que o jogo perceba. Aumente " @@ -1500,6 +1503,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo(A 在右)", [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox(A 在下)", [UI_MENU_PAD_LAYOUT_IN_USE] = "使用中:%s", + [UI_MENU_GROUP_STICKS] = "摇杆", [UI_MENU_LSTICK_DEADZONE] = "左摇杆死区", [UI_MENU_RSTICK_DEADZONE] = "右摇杆死区", [UI_MENU_STICK_DEADZONE_DESC] = "手柄摇杆要推动多远游戏才会响应。如果角色或视角会自己移动," "请调高此值:松开摇杆,查看“当前摇杆”,把死区设得比它高几个百分点。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 92856857..a7fc7fcf 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -102,7 +102,7 @@ typedef enum { UI_MENU_PROMPTS_OFF_MODS, UI_MENU_PROMPTS_OFF_PATCHES, // "Restart now" under the prompts while they change after restart, and its confirmation (Cancel: UI_MENU_RESET_NO) UI_MENU_RESTART, UI_MENU_RESTART_DESC, UI_MENU_RESTART_CONFIRM, UI_MENU_RESTART_YES, UI_MENU_RESTART_SAVING, - UI_MENU_LSTICK_DEADZONE, UI_MENU_RSTICK_DEADZONE, UI_MENU_STICK_DEADZONE_DESC, + UI_MENU_GROUP_STICKS, UI_MENU_LSTICK_DEADZONE, UI_MENU_RSTICK_DEADZONE, UI_MENU_STICK_DEADZONE_DESC, UI_MENU_STICK_DEADZONE_NOW, UI_MENU_STICK_SENS, UI_MENU_STICK_SENS_DESC, UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC, UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC,