mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 12:25:56 +00:00
Merge pull request #1092 into task/kbmwave
# Conflicts: # runtime/input.h # runtime/menu_cursor.c
This commit is contained in:
commit
deba1a9b82
8 files changed
+318
-43
No files matched your search
+6
-3
@@ -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 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
|
||||
|
||||
@@ -175,7 +175,8 @@ The horizontal quick lists (D-pad up/left/right: materials, shields and weapons)
|
||||
with at least 32 ms of neutral between them. At sensitivity 1, 32 horizontal counts request a step; a large flick
|
||||
cannot queue continued scrolling after the mouse stops. Vertical movement is ignored in these lists. Switching or
|
||||
releasing a selector resets its cursor/step state without sending the last movement to the camera. Selector input is
|
||||
not consumed by the direct camera or Ultrahand hooks.
|
||||
not consumed by the direct camera or Ultrahand hooks. The scroll wheel steps these lists too: each notch is one step,
|
||||
away from you to the left, towards you to the right.
|
||||
To detach a fused part from what Ultrahand holds, shake the mouse left and right, or press G (`bind_SHAKE`). A press
|
||||
swings the right stick left and right for 0.8 s, holding the key keeps it swinging. With `mouse_mode = direct` a shake
|
||||
of the mouse while Ultrahand holds an object swings the right stick with it: once the swings (10 degrees of camera turn
|
||||
@@ -200,7 +201,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 keys and the pad keep working, and the focus moves only when the pointer moves. 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.
|
||||
|
||||
@@ -229,6 +230,8 @@ Bridges that output a ViGEm DualShock 4 (ProCon2Windows, connectyourpro as teste
|
||||
@<ms> <button> [hold_ms] # timed on the world clock
|
||||
@<ms> LSTICK|RSTICK <x> <y> [hold_ms]
|
||||
@<ms> MOUSE <dx> <dy>
|
||||
<frame> WHEEL <notches> # scroll wheel notches, once; + away from the player
|
||||
@<ms> WHEEL <notches>
|
||||
```
|
||||
|
||||
`<frame>` counts 60 Hz ticks of game time since the first frame (presented frames at 60 fps), so the title menus get the presses at the same game time at any frame limit. `@<ms>` counts milliseconds of the world clock: game time stepped since the end of the first save load (the player leaves the title screen's origin), so a timed event lands at the same game time at any frame rate and load length. A later load, such as fast travel, still shifts what follows. In a script with timed lines the untimed ones stop when the world clock starts, as the load ends at another tick in each run. Each event logs once (`input: script frame N tick T: A`). `tools/input/load_save.txt` loads the first save from the title screen.
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// The mouse pointer's image in the game window while the cursor is not captured (the game's menus, the settings menu):
|
||||
// a gold arrowhead with a notched back, a dark outline, a turquoise gem and a soft shadow, drawn here at the size the
|
||||
// window's DPI asks for instead of the Windows arrow. input_win.c and input_sdl.c make the system cursor from it.
|
||||
// Nothing comes from the game's files.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "input_wsys.h"
|
||||
|
||||
typedef struct { float x, y; } V;
|
||||
|
||||
// In units of a 32-pixel cursor: the tip at the top left (the hotspot), the wings to the right and below, the notch
|
||||
// between them
|
||||
static const V SHAPE[] = {{1.5f, 1.5f}, {25.0f, 10.5f}, {14.5f, 14.5f}, {10.5f, 25.0f}};
|
||||
static const V GEM[] = {{10.4f, 7.6f}, {13.0f, 10.2f}, {10.4f, 12.8f}, {7.8f, 10.2f}};
|
||||
#define OUTLINE 1.7f // the dark edge's width
|
||||
#define SHADOW 1.6f // the shadow's offset to the bottom right
|
||||
|
||||
static float seg_dist(V p, V a, V b) {
|
||||
float dx = b.x - a.x, dy = b.y - a.y, t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy);
|
||||
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
||||
float ex = a.x + t * dx - p.x, ey = a.y + t * dy - p.y;
|
||||
return sqrtf(ex * ex + ey * ey);
|
||||
}
|
||||
|
||||
// Distance to the polygon's edge, negative inside (even-odd: the shapes are simple)
|
||||
static float poly_sdf(V p, const V *v, int n) {
|
||||
float d = 1e9f;
|
||||
int in = 0;
|
||||
for (int i = 0, j = n - 1; i < n; j = i++) {
|
||||
float e = seg_dist(p, v[j], v[i]);
|
||||
if (e < d) d = e;
|
||||
if ((v[i].y > p.y) != (v[j].y > p.y) && p.x < (v[j].x - v[i].x) * (p.y - v[i].y) / (v[j].y - v[i].y) + v[i].x)
|
||||
in = !in;
|
||||
}
|
||||
return in ? -d : d;
|
||||
}
|
||||
|
||||
// One sample's colour (straight r, g, b in 0..1) and coverage
|
||||
static float sample(V p, float *r, float *g, float *b) {
|
||||
float d = poly_sdf(p, SHAPE, 4);
|
||||
if (d < 0) {
|
||||
if (-d < OUTLINE) { *r = 0.17f, *g = 0.11f, *b = 0.04f; return 1; }
|
||||
if (poly_sdf(p, GEM, 4) < 0) { // the gem, lighter towards its top left
|
||||
float t = (p.x + p.y - 20.4f) / 5.2f + 0.5f;
|
||||
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
||||
*r = 0.62f - 0.42f * t, *g = 0.98f - 0.22f * t, *b = 0.92f - 0.12f * t;
|
||||
return 1;
|
||||
}
|
||||
// gold, pale at the tip and deeper at the wings; a thin light line inside the outline
|
||||
float t = (p.x + p.y) / 34.0f;
|
||||
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
||||
float rim = -d < OUTLINE + 1.0f ? 0.12f : 0;
|
||||
*r = fminf(1, 1.00f - 0.12f * t + rim), *g = fminf(1, 0.93f - 0.32f * t + rim),
|
||||
*b = fminf(1, 0.70f - 0.52f * t + rim);
|
||||
return 1;
|
||||
}
|
||||
V s = {p.x - SHADOW, p.y - SHADOW};
|
||||
float ds = poly_sdf(s, SHAPE, 4);
|
||||
if (ds < 0.8f) { // the shadow, soft at its edge
|
||||
*r = *g = *b = 0;
|
||||
float a = ds < -0.8f ? 1 : (0.8f - ds) / 1.6f;
|
||||
return 0.38f * a;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cursor_art(uint32_t *argb, int size, int *hot) {
|
||||
float k = 32.0f / (float)size;
|
||||
enum { SS = 4 }; // 4 x 4 samples a pixel
|
||||
for (int y = 0; y < size; y++)
|
||||
for (int x = 0; x < size; x++) {
|
||||
float r = 0, g = 0, b = 0, a = 0;
|
||||
for (int sy = 0; sy < SS; sy++)
|
||||
for (int sx = 0; sx < SS; sx++) {
|
||||
V p = {(x + (sx + 0.5f) / SS) * k, (y + (sy + 0.5f) / SS) * k};
|
||||
float sr, sg, sb, c = sample(p, &sr, &sg, &sb);
|
||||
r += sr * c, g += sg * c, b += sb * c, a += c;
|
||||
}
|
||||
uint32_t px = 0;
|
||||
if (a > 0) { // straight alpha, as Windows and SDL take it
|
||||
r /= a, g /= a, b /= a, a /= SS * SS;
|
||||
px = (uint32_t)lrintf(a * 255) << 24 | (uint32_t)lrintf(r * 255) << 16 |
|
||||
(uint32_t)lrintf(g * 255) << 8 | (uint32_t)lrintf(b * 255);
|
||||
}
|
||||
argb[y * size + x] = px;
|
||||
}
|
||||
*hot = (int)(1.5f / k);
|
||||
}
|
||||
+91
-24
@@ -57,7 +57,8 @@ static const SDL_GamepadButton pad_sdl[PAD_COUNT] = {
|
||||
[PAD_LPADDLE2] = SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, [PAD_RPADDLE2] = SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2,
|
||||
};
|
||||
|
||||
// TOTK_INPUT_SCRIPT=<file>: lines "<frame> <button> [hold]" or "<frame> LSTICK|RSTICK <x> <y> [hold]", ORed into the real input.
|
||||
// TOTK_INPUT_SCRIPT=<file>: lines "<frame> <button> [hold]", "<frame> LSTICK|RSTICK <x> <y> [hold]", "<frame> MOUSE
|
||||
// <dx> <dy>" or "<frame> WHEEL <notches>" (+ away from the player), ORed into the real input.
|
||||
// <frame> and its hold are 60 Hz ticks of game time since the first present (frame_step_ticks: presents at 60 fps), so
|
||||
// the title menus get the presses at the same game time at any frame limit. A line "@<ms> ..." is timed instead: <ms>
|
||||
// and its hold are milliseconds of the world clock (frame_step_world_us, game time since the loaded save's first
|
||||
@@ -74,6 +75,7 @@ static ScriptEv *script_ev;
|
||||
static int script_n, script_state; // 0 not loaded, 1 loaded
|
||||
static int script_mixed; // the script has timed lines: its untimed ones end where the world clock starts
|
||||
static int32_t script_mouse[2]; // one-shot raw counts, consumed by the camera hook; under lock
|
||||
static int32_t script_wheel; // one-shot wheel notches, taken with the real ones (wheel_stick); under lock
|
||||
|
||||
static void script_load(void) {
|
||||
script_state = 1;
|
||||
@@ -96,7 +98,11 @@ static void script_load(void) {
|
||||
ScriptEv e = {.at = (uint64_t)(at * unit + 0.5), .hold = timed ? 66667 : 4, .bit = -1, .timed = timed};
|
||||
long a, b;
|
||||
double c;
|
||||
if (!strcmp(name, "MOUSE") || !strcmp(name, "LSTICK") || !strcmp(name, "RSTICK")) {
|
||||
if (!strcmp(name, "WHEEL")) {
|
||||
if (sscanf(line + off, "%ld", &a) != 1) { rt_log("input: script line %d: WHEEL needs notches", ln); continue; }
|
||||
e.stick = 4, e.x = (int32_t)a, e.hold = 1; // one turn, never held
|
||||
snprintf(e.text, sizeof e.text, "WHEEL %d", e.x);
|
||||
} else if (!strcmp(name, "MOUSE") || !strcmp(name, "LSTICK") || !strcmp(name, "RSTICK")) {
|
||||
int n = sscanf(line + off, "%ld %ld %lf", &a, &b, &c);
|
||||
if (n < 2) { rt_log("input: script line %d: %s needs x y [hold]", ln, name); continue; }
|
||||
e.stick = name[0] == 'M' ? 3 : name[0] == 'L' ? 1 : 2; e.x = (int32_t)a; e.y = (int32_t)b;
|
||||
@@ -131,14 +137,17 @@ static void script_apply(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
ScriptEv *e = &script_ev[i];
|
||||
if (e->timed ? w < 0 : script_mixed && w >= 0) continue;
|
||||
uint64_t now = e->timed ? (uint64_t)w : tick;
|
||||
if (now < e->at || (now >= e->at + e->hold && (e->logged || !e->timed))) continue;
|
||||
if (e->stick == 3 && e->logged) continue;
|
||||
// A one-shot (MOUSE, WHEEL) goes in at the first poll at or after its time: a poll that skips a tick (the
|
||||
// game below 60 fps) would otherwise lose it
|
||||
if (e->stick >= 3 ? e->logged || now < e->at
|
||||
: now < e->at || (now >= e->at + e->hold && (e->logged || !e->timed))) continue;
|
||||
if (!e->logged) {
|
||||
e->logged = 1;
|
||||
if (e->timed) rt_log("input: script frame %llu at %.1f ms: %s", (unsigned long long)fr, w / 1000.0, e->text);
|
||||
else rt_log("input: script frame %llu tick %llu: %s", (unsigned long long)fr, (unsigned long long)tick, e->text);
|
||||
}
|
||||
if (e->stick == 3) {
|
||||
if (e->stick == 4) script_wheel += e->x;
|
||||
else if (e->stick == 3) {
|
||||
int64_t x = (int64_t)script_mouse[0] + e->x, y = (int64_t)script_mouse[1] + e->y;
|
||||
script_mouse[0] = (int32_t)(x < INT32_MIN ? INT32_MIN : x > INT32_MAX ? INT32_MAX : x);
|
||||
script_mouse[1] = (int32_t)(y < INT32_MIN ? INT32_MIN : y > INT32_MAX ? INT32_MAX : y);
|
||||
@@ -261,6 +270,17 @@ void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy) {
|
||||
plat_mutex_unlock(&lock);
|
||||
}
|
||||
|
||||
// A turn of the real wheel as a WHEEL line of the recording (one-shot, as a MOUSE line). Under lock.
|
||||
static void rec_wheel(int32_t notches) {
|
||||
if (rec_state != 1) return;
|
||||
char what[32];
|
||||
snprintf(what, sizeof what, "WHEEL %d", notches);
|
||||
int64_t w = frame_step_world_us();
|
||||
uint64_t tick = frame_step_ticks();
|
||||
rec_line(tick, w, tick + 1, w, what);
|
||||
fflush(rec);
|
||||
}
|
||||
|
||||
static float mouse_sens = -1; // TOTK_MOUSE_SENS, 0 = mouse camera off; live (cfg_version)
|
||||
static unsigned mouse_sens_seen;
|
||||
|
||||
@@ -541,35 +561,84 @@ static int32_t shake_stick(int held) {
|
||||
return (now - from) / SHAKE_SIDE_NS % 2 ? STICK_MAX : -STICK_MAX;
|
||||
}
|
||||
|
||||
// The scroll wheel on the Purah Pad's map, which zooms with the right stick's y (up: in): each notch is a full-tilt
|
||||
// pulse of MAP_ZOOM_PULSE_NS on that stick with MAP_ZOOM_GAP_NS of neutral after it, so a step of the zoom and a
|
||||
// held zoom both see one notch as one push. A fast scroll's notches wait their turn (at most MAP_ZOOM_QUEUE), a turn the
|
||||
// other way drops them. Returns the stick y for this poll, 0 between pulses and off the map. Under lock.
|
||||
#define MAP_ZOOM_PULSE_NS 100000000ull
|
||||
#define MAP_ZOOM_GAP_NS 50000000ull
|
||||
#define MAP_ZOOM_QUEUE 4
|
||||
static int32_t map_zoom_stick(int32_t notches, int on_map) {
|
||||
// The scroll wheel (ikb_wheel_take, and an input script's WHEEL lines) as the stick a gamepad player would move:
|
||||
// - on the Purah Pad's map it zooms: the right stick's y, away from the player zooming in;
|
||||
// - 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;
|
||||
// - 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, 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_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
|
||||
|
||||
// The stick value for this poll at the place `where` (WHEEL_*): -STICK_MAX, 0 or STICK_MAX. Under lock.
|
||||
static int32_t wheel_stick(int32_t notches, int where) {
|
||||
static int32_t queued, dir;
|
||||
static uint64_t until; // the end of the pulse (dir != 0) or of the neutral after it
|
||||
static int place;
|
||||
static uint64_t until, none_since; // until: the end of the pulse (dir != 0) or of the neutral after it
|
||||
uint64_t now = plat_now_ns();
|
||||
if (!on_map) { queued = dir = 0, until = 0; return 0; }
|
||||
if (where == WHEEL_NONE) {
|
||||
if (!none_since) none_since = now;
|
||||
if (now - none_since > WHEEL_GAP_NS) queued = 0, place = WHEEL_NONE;
|
||||
dir = 0;
|
||||
return 0;
|
||||
}
|
||||
none_since = 0;
|
||||
if (where != place) queued = dir = 0, until = 0, place = where;
|
||||
if (notches) {
|
||||
if (queued && (notches > 0) != (queued > 0)) queued = 0;
|
||||
queued += notches;
|
||||
queued = queued > MAP_ZOOM_QUEUE ? MAP_ZOOM_QUEUE : queued < -MAP_ZOOM_QUEUE ? -MAP_ZOOM_QUEUE : queued;
|
||||
queued = queued > WHEEL_QUEUE ? WHEEL_QUEUE : queued < -WHEEL_QUEUE ? -WHEEL_QUEUE : queued;
|
||||
}
|
||||
if (dir) {
|
||||
if (now < until) return dir * STICK_MAX;
|
||||
dir = 0, until = now + MAP_ZOOM_GAP_NS;
|
||||
dir = 0, until = now + wheel_timing[where].gap_ns;
|
||||
return 0;
|
||||
}
|
||||
if (now < until || !queued) return 0;
|
||||
dir = queued > 0 ? 1 : -1;
|
||||
queued -= dir;
|
||||
until = now + MAP_ZOOM_PULSE_NS;
|
||||
until = now + wheel_timing[where].pulse_ns;
|
||||
return dir * STICK_MAX;
|
||||
}
|
||||
|
||||
// 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 *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;
|
||||
if (real && notches) {
|
||||
__atomic_store_n(&g_kbm_last, 1, __ATOMIC_RELAXED); // the pointer comes to a menu the wheel turns in
|
||||
rec_wheel(real);
|
||||
}
|
||||
// A strip is its D-pad direction held with its screen open; with the menu cursor off (the screens not read,
|
||||
// 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_camera() ? WHEEL_CAMERA
|
||||
: menu_cursor_menu() ? WHEEL_MENU
|
||||
: WHEEL_NONE;
|
||||
int32_t v = wheel_stick(notches, where);
|
||||
if (!v) return;
|
||||
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);
|
||||
}
|
||||
|
||||
// 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)) && plat_now_ns() / 1000000u >= next_scan) { next_scan = plat_now_ns() / 1000000u + RESCAN_MS; scan_pads(); }
|
||||
@@ -680,13 +749,10 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
// Before the screens were read (the menu cursor off) the buttons alone decide, as before.
|
||||
if (selector && menu_cursor_shortcut() == 0) selector = 0;
|
||||
mouse_camera(k, selector);
|
||||
// On the map the left stick moves the cursor and the right one zooms: the mouse moves the cursor there,
|
||||
// the scroll wheel zooms (map_zoom_stick). Elsewhere the wheel is unbound; its notches are dropped.
|
||||
int map = menu_cursor_map();
|
||||
if (map) pick(&sl[0], &sl[1], k[0], k[1]);
|
||||
// On the map the left stick moves the cursor and the right one zooms: the mouse moves the cursor there
|
||||
// (the scroll wheel zooms, wheel_route)
|
||||
if (menu_cursor_map()) pick(&sl[0], &sl[1], k[0], k[1]);
|
||||
else pick(&sr[0], &sr[1], k[0], k[1]);
|
||||
int32_t zoom = map_zoom_stick(ikb_wheel_take(), map);
|
||||
if (zoom) pick(&sr[0], &sr[1], 0, zoom);
|
||||
int32_t shake = shake_stick(input_map_held(down, B_SHAKE));
|
||||
if (shake) sr[0] = shake, sr[1] = 0;
|
||||
// A mouse shake (mouse_direct.c) moves the stick with the mouse, side by side, and lets go when it rests
|
||||
@@ -701,6 +767,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);
|
||||
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;
|
||||
|
||||
@@ -37,6 +37,13 @@ int menu_cursor_pointer(void);
|
||||
int menu_cursor_map(void); // the Purah Pad's map is open: the mouse's stick is the left one (its cursor)
|
||||
// a dialogue box is on screen and TOTK_DIALOGUE_CLICK is on: left click is B, right click A (input.c poll_merged)
|
||||
int menu_cursor_dialogue(void);
|
||||
// A menu screen (not the ability wheel, a D-pad strip or the map) has the game's focus box, whichever device was used
|
||||
// last: input.c turns the scroll wheel into steps of its focus. 0 with the menu cursor off.
|
||||
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);
|
||||
|
||||
+22
-2
@@ -23,7 +23,8 @@ static SDL_Window *win;
|
||||
static volatile uint8_t key_held[KEY_COUNT];
|
||||
static volatile int32_t esc_held, f8_held, focused;
|
||||
static volatile int32_t mouse_dx, mouse_dy; // relative motion since the last ikb_mouse_take, whole counts
|
||||
static volatile int32_t mouse_wheel; // wheel turned while captured, in 1/120 notches (ikb_wheel_take)
|
||||
static volatile int32_t mouse_wheel; // wheel turned while captured or over the window, in 1/120 notches
|
||||
// (ikb_wheel_take)
|
||||
static float rem_x, rem_y; // window thread: the fractions SDL reported beyond them
|
||||
static volatile int32_t mouse_travel; // raw counts moved in total, captured or not (ikb_mouse_travel)
|
||||
static float travel_rem; // window thread: the fraction of a count beyond mouse_travel
|
||||
@@ -199,8 +200,26 @@ void ikb_menu_closed(void) {
|
||||
if (o & CUR_ESC) plat_cas32(&cur_rel, 0, o);
|
||||
}
|
||||
|
||||
// The pointer over the window while the cursor is not captured (cursor_art.c), sized by the window's display scale.
|
||||
// The default arrow stays when SDL refuses it.
|
||||
static void art_cursor(SDL_Window *w) {
|
||||
float scale = SDL_GetWindowDisplayScale(w);
|
||||
int size = (int)lrintf(32 * (scale > 0 ? scale : 1)), hot;
|
||||
size = size < 32 ? 32 : size > 128 ? 128 : size;
|
||||
SDL_Surface *s = SDL_CreateSurface(size, size, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (!s) return;
|
||||
if (s->pitch == size * 4) {
|
||||
cursor_art(s->pixels, size, &hot);
|
||||
SDL_Cursor *c = SDL_CreateColorCursor(s, hot, hot);
|
||||
if (c) SDL_SetCursor(c);
|
||||
else rt_log("input: the pointer's image failed (%s); the arrow stays", SDL_GetError());
|
||||
}
|
||||
SDL_DestroySurface(s);
|
||||
}
|
||||
|
||||
void input_sdl_window(SDL_Window *w) {
|
||||
win = w;
|
||||
art_cursor(w);
|
||||
wake_event = SDL_RegisterEvents(1);
|
||||
plat_xchg32(&focused, (SDL_GetWindowFlags(w) & SDL_WINDOW_INPUT_FOCUS) != 0);
|
||||
__atomic_store_n(&ptr_have, 0, __ATOMIC_RELEASE); // the pointer's place is unknown until it enters or moves
|
||||
@@ -266,7 +285,8 @@ void input_sdl_event(const SDL_Event *e) {
|
||||
__atomic_store_n(&ptr_have, 0, __ATOMIC_RELEASE);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_WHEEL: // notches, + away from the player (a flipped wheel reports the other sign)
|
||||
if (captured) {
|
||||
// Captured, or released over the focused window: a game menu with the pointer takes it (input.c)
|
||||
if (captured || (focused && __atomic_load_n(&ptr_have, __ATOMIC_ACQUIRE))) {
|
||||
float y = e->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -e->wheel.y : e->wheel.y;
|
||||
plat_add32(&mouse_wheel, (int32_t)(y * 120));
|
||||
}
|
||||
|
||||
+45
-4
@@ -84,7 +84,8 @@ uint32_t input_key_char(int 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 mouse_travel; // raw counts moved in total, captured or not (ikb_mouse_travel)
|
||||
static volatile LONG mouse_wheel; // wheel turned while captured, in WHEEL_DELTA units (ikb_wheel_take)
|
||||
static volatile LONG mouse_wheel; // wheel turned while captured or over the window, in WHEEL_DELTA units
|
||||
// (ikb_wheel_take)
|
||||
static volatile LONG cur_captured; // cursor hidden and confined to the client area
|
||||
static volatile LONG cur_active; // WM_ACTIVATEAPP: the window's application is active
|
||||
// Bits: CUR_REL, Esc or activation by a click on the title bar or border: until a client click; CUR_ESC, set with CUR_REL
|
||||
@@ -121,6 +122,39 @@ static void cursor_update(HWND h) {
|
||||
ReleaseSRWLockExclusive(&cur_lock);
|
||||
}
|
||||
|
||||
// The pointer shown over the client area while the cursor is not captured (cursor_art.c), 32 pixels at 96 DPI and
|
||||
// larger with the window's DPI; made again when the DPI changes. Window thread. NULL when Windows refuses it: the
|
||||
// window class's arrow stays.
|
||||
static HCURSOR art_cursor(HWND h) {
|
||||
static HCURSOR cur;
|
||||
static UINT made_dpi;
|
||||
UINT dpi = GetDpiForWindow(h);
|
||||
if (!dpi) dpi = USER_DEFAULT_SCREEN_DPI;
|
||||
if (cur && dpi == made_dpi) return cur;
|
||||
int size = MulDiv(32, (int)dpi, USER_DEFAULT_SCREEN_DPI), hot;
|
||||
size = size < 32 ? 32 : size > 128 ? 128 : size;
|
||||
BITMAPV5HEADER bh = {.bV5Size = sizeof bh, .bV5Width = size, .bV5Height = -size, .bV5Planes = 1, .bV5BitCount = 32,
|
||||
.bV5Compression = BI_BITFIELDS, .bV5RedMask = 0xff0000, .bV5GreenMask = 0xff00,
|
||||
.bV5BlueMask = 0xff, .bV5AlphaMask = 0xff000000u};
|
||||
void *bits = NULL;
|
||||
HDC dc = GetDC(NULL);
|
||||
HBITMAP color = CreateDIBSection(dc, (BITMAPINFO *)&bh, DIB_RGB_COLORS, &bits, NULL, 0);
|
||||
ReleaseDC(NULL, dc);
|
||||
HBITMAP mask = CreateBitmap(size, size, 1, 1, NULL);
|
||||
HCURSOR made = NULL;
|
||||
if (color && mask && bits) {
|
||||
cursor_art(bits, size, &hot);
|
||||
ICONINFO ii = {.fIcon = FALSE, .xHotspot = (DWORD)hot, .yHotspot = (DWORD)hot, .hbmMask = mask,
|
||||
.hbmColor = color};
|
||||
made = (HCURSOR)CreateIconIndirect(&ii);
|
||||
}
|
||||
if (color) DeleteObject(color);
|
||||
if (mask) DeleteObject(mask);
|
||||
if (!made) return cur; // the old size, or NULL
|
||||
cur = made, made_dpi = dpi; // the old one may still be on screen: kept (a DPI change is rare)
|
||||
return cur;
|
||||
}
|
||||
|
||||
int input_cursor_released(void) { return (cur_rel & CUR_REL) != 0; }
|
||||
|
||||
void input_cursor_suspend(int on) {
|
||||
@@ -148,13 +182,20 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
InterlockedAdd(&mouse_dy, y);
|
||||
}
|
||||
}
|
||||
// The wheel comes in the same message (usButtonData, signed, + away from the player)
|
||||
if (cur_captured && ri.header.dwType == RIM_TYPEMOUSE && (ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL))
|
||||
// The wheel comes in the same message (usButtonData, signed, + away from the player). It counts while the
|
||||
// cursor is captured, or released over the client area: a game menu with the pointer (menu_cursor.c) takes it
|
||||
// as steps of its focus. input.c drops the notches where nothing takes them.
|
||||
float px, py;
|
||||
if (ri.header.dwType == RIM_TYPEMOUSE && (ri.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) &&
|
||||
(cur_captured || ikb_pointer(&px, &py)))
|
||||
InterlockedAdd(&mouse_wheel, (SHORT)ri.data.mouse.usButtonData);
|
||||
break; // DefWindowProc must see WM_INPUT for cleanup
|
||||
}
|
||||
case WM_SETCURSOR:
|
||||
if (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; }
|
||||
if (LOWORD(l) == HTCLIENT) {
|
||||
HCURSOR c = cur_captured ? NULL : art_cursor(h);
|
||||
if (cur_captured || c) { SetCursor(c); *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; }
|
||||
|
||||
@@ -13,10 +13,16 @@ void ikb_pointer_set(float nx, float ny); // moves the pointer there (the wind
|
||||
int ikb_captured(void); // the cursor is captured for the mouse camera
|
||||
void ikb_mouse_take(int32_t *dx, int32_t *dy); // raw mouse motion since the last call, in counts
|
||||
uint32_t ikb_mouse_travel(void); // raw counts the mouse moved in total (|dx| + |dy|), captured or not
|
||||
int32_t ikb_wheel_take(void); // whole wheel notches turned while captured since the last call (+ away
|
||||
// from the player); a high-resolution wheel's part of a notch is kept
|
||||
int32_t ikb_wheel_take(void); // whole wheel notches turned since the last call while the cursor was
|
||||
// captured or over the focused window (+ away from the player); a
|
||||
// high-resolution wheel's part of a notch is kept
|
||||
void ikb_cursor_update(void); // what input_cursor_allowed says may have changed
|
||||
void ikb_menu_closed(void); // the menu closed: a capture that Esc gave up comes back
|
||||
|
||||
// ---- shared by the back ends
|
||||
// cursor_art.c: the pointer's image at size x size pixels (0xAARRGGBB, straight alpha, rows from the top) and its
|
||||
// hotspot (*hot, the same in x and y). Pure.
|
||||
void cursor_art(uint32_t *argb, int size, int *hot);
|
||||
|
||||
// ---- what input.c provides the back end
|
||||
int input_cursor_allowed(void); // no text entry or menu open, the mouse camera on, input not disabled
|
||||
+50
-8
@@ -58,6 +58,10 @@ enum { DI_PROJ = 0x10, DI_VIEW = 0x50, LYT_ROOT = 0x18, LYT_SIZE = 0x28, LYT_NAM
|
||||
// nn::ui2d::Pane
|
||||
enum { PANE_PARENT = 0x18, PANE_SIZE = 0x50, PANE_FLAG = 0x58, PANE_ALPHA = 0x59, PANE_BASE = 0x5b, PANE_MTX = 0x70 };
|
||||
|
||||
// How far the pointer moves, in layout units (1280 x 720 across the picture: 1.5 window pixels at 1080p, 3 at 4K),
|
||||
// before it takes back a focus that the wheel, the keys or the pad moved away from it (menu_cursor_poll)
|
||||
#define DEAD_ZONE 6.0f
|
||||
|
||||
static uint64_t main_lo, main_hi;
|
||||
|
||||
static int ok_at(uint64_t p, uint64_t n) {
|
||||
@@ -175,19 +179,23 @@ static void layout_name(uint64_t scr, char *out, size_t n) {
|
||||
// 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).
|
||||
// The dialogue window (DIALOGUE_SCREEN) has no focus box either: the scan remembers its screen for dialogue_shown.
|
||||
// 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 };
|
||||
#define DIALOGUE_SCREEN "MessageDialog_00" // the box a character's lines and the game's messages are shown in
|
||||
#define DIALOGUE_GAP_MS 500 // how long after the box closed a click is still the dialogue's
|
||||
static uint64_t dialogue_scr; // game thread only
|
||||
static int map_open(void) {
|
||||
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 = *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;
|
||||
@@ -200,6 +208,8 @@ static int map_open(void) {
|
||||
map |= !strcmp(nm, "AppMap_00");
|
||||
bg |= !strcmp(nm, "AppMenuBG_00");
|
||||
if (!strcmp(nm, DIALOGUE_SCREEN)) dialogue_scr = scr;
|
||||
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;
|
||||
if (len < sizeof list - 64) len += (size_t)snprintf(list + len, sizeof list - len, "%s%s", len ? " " : "", nm);
|
||||
@@ -207,6 +217,7 @@ static int map_open(void) {
|
||||
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;
|
||||
}
|
||||
// The dialogue window is open. Read at every pad read from the screen the last scan found open, so a click follows the
|
||||
@@ -307,10 +318,16 @@ static int gameplay_screen(const char *nm) {
|
||||
static volatile int32_t g_pointer; // a menu has the pointer: input_cursor_allowed releases the capture
|
||||
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_dialogue; // a dialogue box is on screen and TOTK_DIALOGUE_CLICK is on: left B, right A
|
||||
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_dialogue(void) { return __atomic_load_n(&g_dialogue, __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;
|
||||
@@ -351,9 +368,10 @@ static void log_screen(const Focus *f, const char *nm, int n, float lw, float lh
|
||||
|
||||
// Once per pad read on the game thread: the pointer's hover and clicks, as pad buttons (A, B) for this read
|
||||
void menu_cursor_poll(uint64_t *buttons) {
|
||||
static int inited, pending_a, held_l, held_r;
|
||||
static int inited, pending_a, held_l, held_r, anchored;
|
||||
static uint64_t pending_node, pending_until, hold_until, hold_bit, menu_seen;
|
||||
static float last_px = -1, last_py = -1;
|
||||
static uint64_t ptr_node, last_focus; // the item the pointer last pointed at, the focus at the last read
|
||||
static float last_px = -1, last_py = -1, anchor_px, anchor_py;
|
||||
if (!inited) {
|
||||
inited = 1;
|
||||
main_lo = MOD_MAIN_BASE, main_hi = MOD_MAIN_BASE + MAIN_SIZE;
|
||||
@@ -364,13 +382,16 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
set_pointer(0);
|
||||
__atomic_store_n(&g_map, 0, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&g_dialogue, 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;
|
||||
}
|
||||
// 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, dialogue_logged;
|
||||
if (!map_at || now - map_at >= 100) map_at = now, map = map_open();
|
||||
static int map, map_logged, dialogue_logged, strip, camera;
|
||||
if (!map_at || now - map_at >= 100) map_at = now, map = map_open(&strip, &camera);
|
||||
// Between two lines of a conversation the game closes the box and opens it again, so a click made in that gap still
|
||||
// counts as dialogue for DIALOGUE_GAP_MS after the box was last open. The first clicks after a conversation fall
|
||||
// in it too and are B or A, as they are for a player who taps the button through the last line.
|
||||
@@ -391,7 +412,16 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
dialogue_logged = 1, rt_log("menu_cursor: a dialogue box is open (" DIALOGUE_SCREEN "): left click is B, "
|
||||
"right click A (TOTK_DIALOGUE_CLICK=1)");
|
||||
__atomic_store_n(&g_dialogue, dialogue, __ATOMIC_RELAXED);
|
||||
if (!cursor) { set_pointer(0); __atomic_store_n(&g_map, 0, __ATOMIC_RELAXED); return; }
|
||||
if (!cursor) {
|
||||
set_pointer(0);
|
||||
__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;
|
||||
}
|
||||
__atomic_store_n(&g_strip, strip, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&g_camera, camera, __ATOMIC_RELAXED);
|
||||
Focus f = focus_now();
|
||||
char nm[48] = "";
|
||||
if (f.screen) layout_name(f.screen, nm, sizeof nm);
|
||||
@@ -399,6 +429,7 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
__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.
|
||||
// Moving the mouse (or a key) makes keyboard and mouse the last device and the pointer comes.
|
||||
__atomic_store_n(&g_menu, f.screen && !gameplay_screen(nm) && !map, __ATOMIC_RELAXED);
|
||||
int menu = f.screen && !gameplay_screen(nm) && ikb_foreground() && input_kbm_last();
|
||||
if (menu) menu_seen = now;
|
||||
// A menu's focus gap (a tab switch, a popup opening: no focus box for a frame or two) keeps the pointer where it
|
||||
@@ -413,7 +444,7 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
return;
|
||||
}
|
||||
if (gap) return; // a click's focus request waits for the next screen
|
||||
if (!menu) { pending_a = 0; last_px = last_py = -1; return; }
|
||||
if (!menu) { pending_a = 0, anchored = 0, ptr_node = last_focus = 0; last_px = last_py = -1; return; }
|
||||
if (pending_a) { // the focus asked for by a click: A once it is there
|
||||
if (rd64(f.control + CTL_ACTIVE) == pending_node) {
|
||||
pending_a = 0, hold_until = now + 60, hold_bit = 1ull << B_A;
|
||||
@@ -427,11 +458,21 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
if (click_r) { hold_until = now + 60, hold_bit = 1ull << B_B; *buttons |= hold_bit; return; }
|
||||
float px, py;
|
||||
if (!picture_pos(&px, &py)) return;
|
||||
// The focus moved to another item than the pointer's (the scroll wheel, the keys, the pad): the pointer takes it
|
||||
// back only after it has left a dead zone of DEAD_ZONE layout units around where it was then, so a hand resting on
|
||||
// the mouse does not undo a scroll. A click still acts at once.
|
||||
if (f.node != last_focus) {
|
||||
if (f.node != ptr_node) anchored = 1, anchor_px = px, anchor_py = py;
|
||||
last_focus = f.node;
|
||||
}
|
||||
int moved = fabsf(px - last_px) > 0.001f || fabsf(py - last_py) > 0.001f;
|
||||
if (!moved && !click_l) return;
|
||||
last_px = px, last_py = py;
|
||||
float lw, lh;
|
||||
layout_size(f.screen, &lw, &lh);
|
||||
if (anchored && !click_l && fabsf(px - anchor_px) * lw < DEAD_ZONE && fabsf(py - anchor_py) * lh < DEAD_ZONE)
|
||||
return;
|
||||
anchored = 0;
|
||||
Xf xf = screen_xf(f.screen);
|
||||
Pt p = {(px - 0.5f) * lw, (0.5f - py) * lh, px * 2 - 1, 1 - py * 2, NULL};
|
||||
if (xf.ok && !xf_plain(&xf, lw, lh)) p.t = &xf;
|
||||
@@ -440,6 +481,7 @@ void menu_cursor_poll(uint64_t *buttons) {
|
||||
log_screen(&f, nm, n, lw, lh, p.t, n && stale_hit_panes(n, btn, lw, lh, p.t));
|
||||
uint64_t at = n ? node_at(n, node, btn, &p, lw, lh) : 0;
|
||||
if (!at) return;
|
||||
ptr_node = at;
|
||||
if (at != f.node) move_focus(&f, at);
|
||||
if (click_l) {
|
||||
if (at == f.node) { hold_until = now + 60, hold_bit = 1ull << B_A; *buttons |= hold_bit; }
|
||||
|
||||
Reference in new issue
Block a user