Skip to content

Commit cae0abc

Browse files
authored
all the niceness (#1152)
1 parent 3f04d6b commit cae0abc

File tree

13 files changed

+96
-22
lines changed

13 files changed

+96
-22
lines changed

code/__DEFINES/keybinding.dm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#define COMSIG_KB_ACTIVATED (1<<0)
55
#define COMSIG_KB_EMOTE "keybinding_emote_down"
66

7+
//Rawkeys
8+
#define COMSIG_KB_RAW_CTRL "keybinding_raw_ctrl"
9+
#define COMSIG_KB_RAW_SHIFT "keybinding_raw_shift"
10+
711
//Admin
812
#define COMSIG_KB_ADMIN_ASAY_DOWN "keybinding_admin_asay_down"
913
#define COMSIG_KB_ADMIN_DSAY_DOWN "keybinding_admin_dsay_down"
@@ -50,7 +54,6 @@
5054
#define COMSIG_KB_LIVING_TOGGLE_COMBAT_DOWN "keybinding_living_toggle_combat_down"
5155
#define COMSIG_KB_LIVING_ENABLE_COMBAT_DOWN "keybinding_living_enable_combat_down"
5256
#define COMSIG_KB_LIVING_DISABLE_COMBAT_DOWN "keybinding_living_disable_combat_down"
53-
5457
//Mob
5558
#define COMSIG_KB_MOB_FACENORTH_DOWN "keybinding_mob_facenorth_down"
5659
#define COMSIG_KB_MOB_FACEEAST_DOWN "keybinding_mob_faceeast_down"

code/_globalvars/lists/client.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
GLOBAL_LIST_EMPTY(default_hotkeys)
22
GLOBAL_LIST_EMPTY(keybindings_by_name)
3+
GLOBAL_LIST_EMPTY(raw_keybindings_by_key)

code/_globalvars/lists/keybindings.dm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
/// Adds an instanced keybinding to the global tracker
1111
/proc/add_keybinding(datum/keybinding/instance)
12+
if(istype(instance, /datum/keybinding/rawkey))
13+
for(var/key in instance.hotkey_keys)
14+
GLOB.raw_keybindings_by_key[key] = instance
15+
return
16+
1217
GLOB.keybindings_by_name[instance.name] = instance
1318

1419
// Hotkey

code/_onclick/hud/screen_objects.dm

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
/atom/movable/screen/combattoggle
395395
name = "toggle combat mode"
396396
icon = 'icons/hud/screen_midnight.dmi'
397-
icon_state = "combat_off"
397+
icon_state = "help"
398398
screen_loc = ui_combat_toggle
399399

400400
/atom/movable/screen/combattoggle/Initialize(mapload)
@@ -405,6 +405,7 @@
405405
. = ..()
406406
if(.)
407407
return FALSE
408+
408409
if(isliving(usr))
409410
var/mob/living/owner = usr
410411
owner.set_combat_mode(!owner.combat_mode, FALSE)
@@ -414,7 +415,11 @@
414415
var/mob/living/user = hud?.mymob
415416
if(!istype(user) || !user.client)
416417
return ..()
417-
icon_state = user.combat_mode ? "combat" : "combat_off" //Treats the combat_mode
418+
419+
if(user.client.keys_held["Ctrl"])
420+
icon_state = "grab"
421+
else
422+
icon_state = user.combat_mode ? "harm" : "help" //Treats the combat_mode
418423
return ..()
419424

420425
//Version of the combat toggle with the flashy overlay

code/controllers/subsystem/input.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ VERB_MANAGER_SUBSYSTEM_DEF(input)
4242
// This is for when macro sets are eventualy datumized
4343
/datum/controller/subsystem/verb_manager/input/proc/setup_default_macro_sets()
4444
macro_set = list(
45-
// These could probably just be put in the skin. I actually don't understand WHY they aren't just in the skin. Besides the use of defines for Tab.
45+
// These could probably just be put in the skin. I actually don't understand WHY they aren't just in the skin. Besides the use of defines for Tab.
4646
"Back" = "\".winset \\\"input.text=\\\"\\\"\\\"\"",
4747
"Tab" = "\".winset \\\"input.focus=true?map.focus=true input.background-color=[COLOR_INPUT_DISABLED]:input.focus=true input.background-color=[COLOR_INPUT_ENABLED]\\\"\"",
4848
"Escape" = "Reset-Held-Keys",

code/datums/keybinding/rawkey.dm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Rawkeys are magic keybindings that are bound directly to a key instead of having an associated action, like "move up"
3+
* Rawkeys are NOT in GLOB.keybindings_by_name
4+
* NOTE: Legacy mode users will NOT fire rawkeys for printable keys. Do remember this if you are for some reason making
5+
* a rawkey associated with a printable key.
6+
*/
7+
/datum/keybinding/rawkey/ctrl
8+
hotkey_keys = list("Ctrl")
9+
name = "CTRL"
10+
keybind_signal = COMSIG_KB_RAW_CTRL
11+
12+
/datum/keybinding/rawkey/ctrl/up(client/user)
13+
. = ..()
14+
if(.)
15+
return
16+
17+
if(isliving(user.mob))
18+
var/mob/living/user_mob = user.mob
19+
user_mob.hud_used?.action_intent?.update_appearance()
20+
21+
/datum/keybinding/rawkey/ctrl/down(client/user)
22+
. = ..()
23+
if(.)
24+
return
25+
26+
if(isliving(user.mob))
27+
var/mob/living/user_mob = user.mob
28+
user_mob.hud_used?.action_intent?.update_appearance()
29+
30+
/datum/keybinding/rawkey/shift
31+
hotkey_keys = list("Shift")
32+
name = "Shift"
33+
keybind_signal = COMSIG_KB_RAW_CTRL
34+
35+
/datum/keybinding/rawkey/shift/up(client/user)
36+
. = ..()
37+
if(.)
38+
return
39+
40+
user.mob.update_mouse_pointer()
41+
42+
/datum/keybinding/rawkey/shift/down(client/user)
43+
. = ..()
44+
if(.)
45+
return
46+
47+
user.mob.update_mouse_pointer()
48+

code/modules/client/preferences/middleware/keybindings.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
/datum/preference_middleware/keybindings/proc/set_keybindings(list/params)
4646
var/keybind_name = params["keybind_name"]
4747

48-
if (isnull(GLOB.keybindings_by_name[keybind_name]))
48+
var/datum/keybinding/keybind_datum = GLOB.keybindings_by_name[keybind_name]
49+
if (isnull(keybind_datum))
4950
return FALSE
5051

5152
var/list/raw_hotkeys = params["hotkeys"]

code/modules/client/preferences_savefile.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
181181
fcopy(S, bacpath) //byond helpfully lets you use a savefile for the first arg.
182182
update_preferences(needs_update, S) //needs_update = savefile_version if we need an update (positive integer)
183183

184-
check_keybindings() // this apparently fails every time and overwrites any unloaded prefs with the default values, so don't load anything after this line or it won't actually save
185-
key_bindings_by_key = get_key_bindings_by_key(key_bindings)
186-
187184
//Sanitize
188185
lastchangelog = sanitize_text(lastchangelog, initial(lastchangelog))
189186
default_slot = sanitize_integer(default_slot, 1, max_save_slots, initial(default_slot))
190187
toggles = sanitize_integer(toggles, 0, SHORT_REAL_LIMIT-1, initial(toggles))
191188
key_bindings = sanitize_keybindings(key_bindings)
192189
favorite_outfits = SANITIZE_LIST(favorite_outfits)
193190

191+
check_keybindings() // this apparently fails every time and overwrites any unloaded prefs with the default values, so don't load anything after this line or it won't actually save
192+
key_bindings_by_key = get_key_bindings_by_key(key_bindings)
193+
194194
if(needs_update >= 0) //save the updated version
195195
var/old_default_slot = default_slot
196196
var/old_max_save_slots = max_save_slots

code/modules/keybindings/bindings_client.dm

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
if(!movement_locked && !(next_move_dir_sub & movement))
5151
next_move_dir_add |= movement
5252

53+
// Raw keys are handled first
54+
var/datum/keybinding/rawkey/raw_keybind = GLOB.raw_keybindings_by_key[_key]
55+
if(raw_keybind)
56+
raw_keybind.down(src)
57+
5358
// Client-level keybindings are ones anyone should be able to do at any time
5459
// Things like taking screenshots, hitting tab, and adminhelps.
5560
var/AltMod = keys_held["Alt"] ? "Alt" : ""
@@ -74,8 +79,6 @@
7479

7580
holder?.key_down(_key, src)
7681
mob.focus?.key_down(_key, src)
77-
if(ShiftMod)
78-
mob.update_mouse_pointer()
7982

8083

8184
/client/verb/keyUp(_key as text)
@@ -90,27 +93,28 @@
9093
if(!keys_held[_key])
9194
return
9295

93-
var/update_pointer = FALSE
94-
if(keys_held["Shift"])
95-
update_pointer = TRUE
96-
9796
keys_held -= _key
9897

99-
if(update_pointer == TRUE)
100-
mob.update_mouse_pointer()
101-
10298
var/movement = movement_keys[_key]
10399
if(movement)
104100
calculate_move_dir()
105101
if(!movement_locked && !(next_move_dir_add & movement))
106102
next_move_dir_sub |= movement
107103

104+
// Raw keys are handled first
105+
var/datum/keybinding/rawkey/raw_keybind = GLOB.raw_keybindings_by_key[_key]
106+
if(raw_keybind)
107+
raw_keybind.up(src)
108+
108109
// We don't do full key for release, because for mod keys you
109110
// can hold different keys and releasing any should be handled by the key binding specifically
111+
var/keycount = 0
110112
for (var/kb_name in prefs.key_bindings_by_key[_key])
113+
keycount++
111114
var/datum/keybinding/kb = GLOB.keybindings_by_name[kb_name]
112-
if(kb.can_use(src) && kb.up(src))
115+
if(kb.can_use(src) && kb.up(src) && keycount >= MAX_COMMANDS_PER_KEY)
113116
break
117+
114118
holder?.key_up(_key, src)
115119
mob.focus?.key_up(_key, src)
116120

code/modules/mob/living/carbon/carbon.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@
131131
throw_mode = THROW_MODE_DISABLED
132132
if(hud_used)
133133
hud_used.throw_icon.icon_state = "act_throw_off"
134+
update_mouse_pointer()
134135

135136

136137
/mob/living/carbon/proc/throw_mode_on(mode = THROW_MODE_TOGGLE)
137138
throw_mode = mode
138139
if(hud_used)
139140
hud_used.throw_icon.icon_state = "act_throw_on"
141+
update_mouse_pointer()
140142

141143
/mob/proc/throw_item(atom/target)
142144
SEND_SIGNAL(src, COMSIG_MOB_THROW, target)

0 commit comments

Comments
 (0)