Keyboard presses (and thus keybindings) will now report the turf the mouse was over when a player presses or releases a key (#90480)

## About The Pull Request

Semi WIP cus I need to probably make an issue report for lummox, but
apart from that ready for review

Uses the new mouse-pos so we can combine it with screen size and size to
estimate very accurately the mouse position in turf terms. In future
also will need to add a way to continously poll the users mouse pos but
this alone is very useful

## Why It's Good For The Game

This isnt used yet, but the benefits are pretty damn obvious (hitting E
and dashing towards where your mouse??? 1990s features?????)

## Changelog
🆑
refactor: Added the possibility for keybindings to report the turf they
clicked on.
/🆑

---------

Co-authored-by: TiviPlus <572233640+TiviPlus@users.noreply.com>
This commit is contained in:
TiviPlus
2025-05-22 21:17:28 -04:00
committed by Roxy
co-authored by TiviPlus
parent dcd41131dd
commit 78bc9dba91
15 changed files with 144 additions and 67 deletions
+13 -6
View File
@@ -1,6 +1,6 @@
// Clients aren't datums so we have to define these procs indpendently.
// These verbs are called for all key press and release events
/client/verb/keyDown(_key as text)
/client/verb/keyDown(_key as text, mousepos_x as num, mousepos_y as num, sizex as num, sizey as num)
set instant = TRUE
set hidden = TRUE
@@ -43,7 +43,7 @@
return
if(length(keys_held) >= HELD_KEY_BUFFER_LENGTH && !keys_held[_key])
keyUp(keys_held[1]) //We are going over the number of possible held keys, so let's remove the first one.
keyUp(keys_held[1], mousepos_x, mousepos_y, sizex, sizey) //We are going over the number of possible held keys, so let's remove the first one.
//the time a key was pressed isn't actually used anywhere (as of 2019-9-10) but this allows easier access usage/checking
keys_held[_key] = world.time
@@ -68,25 +68,31 @@
key_combos_held[_key] = full_key
else
full_key = _key
var/list/click_data = get_loc_from_mousepos(mousepos_x, mousepos_y, sizex, sizey, src)
var/turf/test = click_data[1]
test.add_atom_colour(COLOR_RED, ADMIN_COLOUR_PRIORITY)
var/keycount = 0
for(var/kb_name in prefs.key_bindings_by_key[full_key])
keycount++
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.can_use(src) && kb.down(src) && keycount >= MAX_COMMANDS_PER_KEY)
if(kb.can_use(src) && kb.down(src, click_data[1]) && keycount >= MAX_COMMANDS_PER_KEY)
break
holder?.key_down(_key, src, full_key)
mob.focus?.key_down(_key, src, full_key)
mob.update_mouse_pointer()
/client/verb/keyUp(_key as text)
/client/verb/keyUp(_key as text, mousepos_x as num, mousepos_y as num, sizex as num, sizey as num)
set instant = TRUE
set hidden = TRUE
var/key_combo = key_combos_held[_key]
if(key_combo)
key_combos_held -= _key
keyUp(key_combo)
keyUp(key_combo, mousepos_x, mousepos_y, sizex, sizey)
if(!keys_held[_key])
return
@@ -99,11 +105,12 @@
if(!movement_locked && !(next_move_dir_add & movement))
next_move_dir_sub |= movement
var/list/click_data = get_loc_from_mousepos(mousepos_x, mousepos_y, sizex, sizey, src)
// We don't do full key for release, because for mod keys you
// can hold different keys and releasing any should be handled by the key binding specifically
for (var/kb_name in prefs.key_bindings_by_key[_key])
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
if(kb.can_use(src) && kb.up(src))
if(kb.can_use(src) && kb.up(src, click_data[1]))
break
holder?.key_up(_key, src)
mob.focus?.key_up(_key, src)