diff --git a/docs/controls.md b/docs/controls.md index fbac30c2..36b96fd8 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -29,7 +29,7 @@ The log names the layout in effect (`input: gamepad layout ...`); the menu shows | Minus | Back | M | map | | Right stick shaken left and right | shake the right stick | G | detach a fused part from what Ultrahand holds | -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. T duplicates Y for the game's menus, where the left mouse button is A while the pointer is shown (sort the inventory with T). The mouse wheel zooms the Purah Pad's map, steps the game's menus and the d-pad strips (see Mouse in the game's menus), and is unbound elsewhere. 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. +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. T duplicates Y for the game's menus, where the left mouse button is A while the pointer is shown (sort the inventory with T). The mouse wheel zooms the Purah Pad's map and its camera, steps the game's menus and the d-pad strips (see Mouse in the game's menus), and is unbound elsewhere. 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. ## Xbox button prompts @@ -200,7 +200,7 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti ## Mouse in the game's menus -On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The scroll wheel moves the focus up and down, one step a notch (a full-tilt push of the left stick for 70 ms with 50 ms of neutral after it, up for a turn away from you), so a long list of items scrolls without moving the pointer; `menu_cursor = 0` turns this off with the pointer. The keys and the pad keep working, and the focus moves with the pointer only when the pointer moves: after the wheel, a key or the pad moved the focus off the pointer's item, the pointer takes it back once it has moved 6 layout units (the menus' 1280 x 720: about 9 window pixels at 1080p, 18 at 4K) from where it was then (`DEAD_ZONE` in `runtime/menu_cursor.c`), so a hand resting on the mouse does not undo a scroll; a click acts at once. While the cursor is not captured the game window shows a pointer of its own, a gold arrowhead drawn at the window's DPI (`runtime/cursor_art.c`), in place of the system arrow. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. When the menu closes the cursor is captured again. +On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The scroll wheel moves the focus up and down, one step a notch (a full-tilt push of the left stick for 70 ms with 50 ms of neutral after it, up for a turn away from you), so a long list of items scrolls without moving the pointer; `menu_cursor = 0` turns this off with the pointer. The keys and the pad keep working, and the focus moves with the pointer only when the pointer moves: after the wheel, a key or the pad moved the focus off the pointer's item, the pointer takes it back once it has moved 6 layout units (the menus' 1280 x 720: about 9 window pixels at 1080p, 18 at 4K) from where it was then (`DEAD_ZONE` in `runtime/menu_cursor.c`), so a hand resting on the mouse does not undo a scroll; a click acts at once. While the cursor is not captured the game window shows a pointer of its own, a gold arrowhead drawn at the window's DPI (`runtime/cursor_art.c`), in place of the system arrow. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. The Purah Pad's camera (the ability wheel's camera) opens the frame and its pointer `CameraPointer_00` without `AppMap_00` (the Scope has it); there the scroll wheel zooms as the camera's guide shows: each notch is a press of the d-pad's up (in, for a turn away from you) or down for 100 ms with 50 ms of release after it (`menu_cursor_camera`). The Scope itself has no zoom; the wheel does nothing there. When the menu closes the cursor is captured again. `runtime/menu_cursor.c` reads eui's screens at each pad read and moves the focus with the writes `eui::BoxCursorMgr::moveBoxCursor` makes, so no game code is called. `menu_cursor = 0` (`TOTK_MENU_CURSOR=0`, live; the *Mouse in the game's menus* row of the Controls tab) turns it off; `TOTK_MENU_CURSOR_LOG=1` logs every screen it reads (by default the first six), with the layout size, the node count and the hit panes it uses. diff --git a/runtime/input.c b/runtime/input.c index d9ba4069..27bf5f18 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -566,15 +566,17 @@ static int32_t shake_stick(int held) { // - while a D-pad strip (weapons, shields, bows, materials) is held open it steps the choice: the right stick's x, away // from the player to the left, towards the player to the right; // - in a menu with the game's focus box (the inventory, shops, Options, the save list; menu_cursor_menu) it steps the -// focus: the left stick's y, away from the player up. +// focus: the left stick's y, away from the player up; +// - in the Purah Pad's camera (menu_cursor_camera) it zooms: the D-pad's up (away from the player, in) or down, the +// buttons its guide shows for the zoom. // Each notch is a full-tilt pulse with neutral after it (wheel_timing), so the game sees one notch as one step, and a // fast scroll's notches wait their turn (at most WHEEL_QUEUE); a turn the other way drops them. A strip's pulse is the // mouse's (input_direct_mouse_row: 32 ms each way); a menu takes the stick on its own update, a frame of the game's // 30 Hz or less, so its pulse covers two. Elsewhere, and while the settings menu is open, the notches are dropped. -enum { WHEEL_NONE, WHEEL_MAP, WHEEL_STRIP, WHEEL_MENU }; +enum { WHEEL_NONE, WHEEL_MAP, WHEEL_STRIP, WHEEL_MENU, WHEEL_CAMERA }; static const struct { uint64_t pulse_ns, gap_ns; } wheel_timing[] = { [WHEEL_MAP] = {100000000ull, 50000000ull}, [WHEEL_STRIP] = {32000000ull, 32000000ull}, - [WHEEL_MENU] = {70000000ull, 50000000ull}}; + [WHEEL_MENU] = {70000000ull, 50000000ull}, [WHEEL_CAMERA] = {100000000ull, 50000000ull}}; #define WHEEL_QUEUE 4 #define WHEEL_GAP_NS 300000000ull // a menu's focus gap (a tab switch): queued notches wait this long for its next screen @@ -611,7 +613,8 @@ static int32_t wheel_stick(int32_t notches, int where) { // After the keys, the gamepad and the script: where the wheel goes this poll (b holds the script's D-pad too, so a // scripted strip takes scripted notches). Under lock. -static void wheel_route(uint64_t b, int32_t sl[2], int32_t sr[2]) { +static void wheel_route(uint64_t *bp, int32_t sl[2], int32_t sr[2]) { + uint64_t b = *bp; int32_t real = state > 0 ? ikb_wheel_take() : 0, notches = real + script_wheel; // the script's under TOTK_INPUT=none too script_wheel = 0; if (menu_is_open()) notches = 0; @@ -623,10 +626,15 @@ static void wheel_route(uint64_t b, int32_t sl[2], int32_t sr[2]) { // menu_cursor_shortcut -1) the buttons alone decide, as for the mouse's selectors int sc = b & (1ull << B_UP | 1ull << B_LEFT | 1ull << B_RIGHT) && !(b & 1ull << B_L) ? menu_cursor_shortcut() : 0; int strip = sc == -1 || sc == 1 || (sc == 0 && menu_cursor_strip()); - int where = menu_cursor_map() ? WHEEL_MAP : strip ? WHEEL_STRIP : menu_cursor_menu() ? WHEEL_MENU : WHEEL_NONE; + int where = menu_cursor_map() ? WHEEL_MAP + : strip ? WHEEL_STRIP + : menu_cursor_camera() ? WHEEL_CAMERA + : menu_cursor_menu() ? WHEEL_MENU + : WHEEL_NONE; int32_t v = wheel_stick(notches, where); if (!v) return; - if (where == WHEEL_MAP) pick(&sr[0], &sr[1], 0, v); + if (where == WHEEL_CAMERA) *bp |= 1ull << (v > 0 ? B_UP : B_DOWN); + else if (where == WHEEL_MAP) pick(&sr[0], &sr[1], 0, v); else if (where == WHEEL_STRIP) pick(&sr[0], &sr[1], -v, 0); else pick(&sl[0], &sl[1], 0, v); } @@ -737,7 +745,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx else if (kbm_used) __atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED); } script_apply(&b, sl, sr); - wheel_route(b, sl, sr); + wheel_route(&b, sl, sr); rec_apply(b, sl, sr); // Minus and Plus held together (gamepad or keys) open or close the menu and never reach the game static int combo_held; diff --git a/runtime/input.h b/runtime/input.h index 668a4e69..15b311b4 100644 --- a/runtime/input.h +++ b/runtime/input.h @@ -40,6 +40,8 @@ int menu_cursor_map(void); // the Purah Pad's map is open: the mouse's stick i int menu_cursor_menu(void); // A D-pad strip's screen (ShortCut_00) is open; it has no focus box while held. 0 with the menu cursor off. int menu_cursor_strip(void); +// The Purah Pad's camera is open: its frame and pointer without the map the Scope has. 0 with the menu cursor off. +int menu_cursor_camera(void); // The same for host UI (the text entry): never blocked. input_block(1) while a text entry is open: input_poll then // reports nothing; input_block(0) when it closes: nothing until all buttons and stick directions are released. void input_poll_ui(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry); diff --git a/runtime/menu_cursor.c b/runtime/menu_cursor.c index d6bcf266..14b28e0e 100644 --- a/runtime/menu_cursor.c +++ b/runtime/menu_cursor.c @@ -170,18 +170,20 @@ static void layout_name(uint64_t scr, char *out, size_t n) { // 1.4.3 constructor keeps). The map has no focus box, so it is found here: the Purah Pad's frame (AppMenuOverlay_00) // with AppMap_00 and the menu's background AppMenuBG_00 open. The Scope opens the frame over AppMap_00 without that // background (Weeping of the Empire's engine/runtime/totk_menu_cursor.cpp census tells them apart the same way). -// A D-pad strip has no focus box either while it is held open: *strip is ShortCut_00 being open. +// A D-pad strip has no focus box either while it is held open: *strip is ShortCut_00 being open. *camera is the +// Purah Pad's camera (the ability wheel's camera): the frame and its pointer CameraPointer_00 open without AppMap_00, +// which the Scope has with them. // TOTK_MENU_CURSOR_LOG=1 logs the open screens whenever the set changes. enum { SM_COUNT = 0x8, SM_SCREENS = 0x10 }; -static int map_open(int *strip) { +static int map_open(int *strip, int *camera) { uint64_t sm = screen_mgr(); if (!sm) return 0; int32_t n = (int32_t)rd32(sm + SM_COUNT); uint64_t arr = rd64(sm + SM_SCREENS); - *strip = 0; + *strip = *camera = 0; if (n <= 0 || n > 1024 || !ok_at(arr, 8ull * (uint64_t)n)) return 0; const char *e = cfg_get("TOTK_MENU_CURSOR_LOG"); - int verbose = e && !strcmp(e, "1"), pad = 0, map = 0, bg = 0; + int verbose = e && !strcmp(e, "1"), pad = 0, map = 0, bg = 0, pointer = 0; char list[1024]; size_t len = 0; uint64_t h = 1469598103934665603ull; @@ -193,6 +195,7 @@ static int map_open(int *strip) { pad |= !strcmp(nm, "AppMenuOverlay_00"); map |= !strcmp(nm, "AppMap_00"); bg |= !strcmp(nm, "AppMenuBG_00"); + pointer |= !strcmp(nm, "CameraPointer_00"); *strip |= !strcmp(nm, "ShortCut_00"); if (!verbose) continue; for (const char *c = nm; *c; c++) h = (h ^ (uint8_t)*c) * 1099511628211ull; @@ -201,6 +204,7 @@ static int map_open(int *strip) { static uint64_t last; static int lines; if (verbose && h != last && lines < 200) last = h, lines++, rt_log("menu_cursor: open screens: %s", list); + *camera = pad && pointer && !map && !bg; return pad && map && bg; } static void layout_size(uint64_t scr, float *lw, float *lh) { @@ -289,11 +293,13 @@ static volatile int32_t g_pointer; // a menu has the pointer: input_cursor_all static volatile int32_t g_map; // the Purah Pad's map is open (not the Scope): the mouse moves its cursor static volatile int32_t g_menu; // a menu screen has the focus box, from either device (the scroll wheel's steps) static volatile int32_t g_strip; // a D-pad strip's screen is open (the scroll wheel's steps along it) +static volatile int32_t g_camera; // the Purah Pad's camera is open (the scroll wheel zooms it) int menu_cursor_pointer(void) { return __atomic_load_n(&g_pointer, __ATOMIC_RELAXED); } int menu_cursor_map(void) { return __atomic_load_n(&g_map, __ATOMIC_RELAXED); } int menu_cursor_menu(void) { return __atomic_load_n(&g_menu, __ATOMIC_RELAXED); } int menu_cursor_strip(void) { return __atomic_load_n(&g_strip, __ATOMIC_RELAXED); } +int menu_cursor_camera(void) { return __atomic_load_n(&g_camera, __ATOMIC_RELAXED); } static int enabled(void) { if (!RT_V143) return 0; @@ -342,6 +348,7 @@ void menu_cursor_poll(uint64_t *buttons) { __atomic_store_n(&g_map, 0, __ATOMIC_RELAXED); __atomic_store_n(&g_menu, 0, __ATOMIC_RELAXED); __atomic_store_n(&g_strip, 0, __ATOMIC_RELAXED); + __atomic_store_n(&g_camera, 0, __ATOMIC_RELAXED); return; } Focus f = focus_now(); @@ -350,9 +357,10 @@ void menu_cursor_poll(uint64_t *buttons) { // The open screens are scanned every 100 ms, not at every pad read: each screen costs memory queries uint64_t now = plat_now_ms(); static uint64_t map_at; - static int map, map_logged, strip; - if (!map_at || now - map_at >= 100) map_at = now, map = map_open(&strip); + static int map, map_logged, strip, camera; + if (!map_at || now - map_at >= 100) map_at = now, map = map_open(&strip, &camera); __atomic_store_n(&g_strip, strip, __ATOMIC_RELAXED); + __atomic_store_n(&g_camera, camera, __ATOMIC_RELAXED); if (map && !map_logged) map_logged = 1, rt_log("menu_cursor: the map is open: the mouse moves its cursor"); __atomic_store_n(&g_map, map, __ATOMIC_RELAXED); // With the gamepad as the last device the menus stay as they are on the console: no pointer, the capture kept.