diff --git a/code/__DEFINES/keybinding.dm b/code/__DEFINES/keybinding.dm index fde4dbdf268..9f9d22e2643 100644 --- a/code/__DEFINES/keybinding.dm +++ b/code/__DEFINES/keybinding.dm @@ -3,6 +3,7 @@ //General #define COMSIG_KB_ACTIVATED (1<<0) #define COMSIG_KB_EMOTE "keybinding_emote_down" +#define UNBOUND_KEY "Unbound" ///Signal sent when a keybind is deactivated #define DEACTIVATE_KEYBIND(A) "[A]_DEACTIVATED" diff --git a/code/_globalvars/lists/keybindings.dm b/code/_globalvars/lists/keybindings.dm index 90a7501f5e4..0730ff7d60c 100644 --- a/code/_globalvars/lists/keybindings.dm +++ b/code/_globalvars/lists/keybindings.dm @@ -14,7 +14,7 @@ // Hotkey if(LAZYLEN(instance.hotkey_keys)) for(var/bound_key in instance.hotkey_keys) - if (bound_key == "Unbound") + if (bound_key == UNBOUND_KEY) LAZYADD(GLOB.default_hotkeys[instance.name], list()) else LAZYADD(GLOB.default_hotkeys[instance.name], list(bound_key)) diff --git a/code/datums/keybinding/admin.dm b/code/datums/keybinding/admin.dm index 0e703d7e148..207610b4364 100644 --- a/code/datums/keybinding/admin.dm +++ b/code/datums/keybinding/admin.dm @@ -97,7 +97,7 @@ return TRUE /datum/keybinding/admin/deadmin - hotkey_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) name = "deadmin" full_name = "Deadmin" description = "Shed your admin powers" @@ -111,7 +111,7 @@ return TRUE /datum/keybinding/admin/readmin - hotkey_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) name = "readmin" full_name = "Readmin" description = "Regain your admin powers" diff --git a/code/datums/keybinding/emote.dm b/code/datums/keybinding/emote.dm index 71f9ba88135..38d48735631 100644 --- a/code/datums/keybinding/emote.dm +++ b/code/datums/keybinding/emote.dm @@ -5,8 +5,8 @@ var/emote_key /datum/keybinding/emote/proc/link_to_emote(datum/emote/faketype) - hotkey_keys = list("Unbound") - classic_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) + classic_keys = list(UNBOUND_KEY) emote_key = initial(faketype.key) name = initial(faketype.key) full_name = capitalize(initial(faketype.key)) diff --git a/code/datums/keybinding/living.dm b/code/datums/keybinding/living.dm index 1e3a682c97f..42eb96bf5da 100644 --- a/code/datums/keybinding/living.dm +++ b/code/datums/keybinding/living.dm @@ -152,7 +152,7 @@ return TRUE /datum/keybinding/living/toggle_move_intent_alternative - hotkey_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) name = "toggle_move_intent_alt" full_name = "press to cycle move intent" description = "Pressing this cycle to the opposite move intent, does not cycle back" diff --git a/code/datums/keybinding/mob.dm b/code/datums/keybinding/mob.dm index dc9b3756508..dd27763338b 100644 --- a/code/datums/keybinding/mob.dm +++ b/code/datums/keybinding/mob.dm @@ -21,7 +21,7 @@ return TRUE /datum/keybinding/mob/swap_hands - hotkey_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) name = "swap_hands" full_name = "Swap hands" description = "" @@ -166,7 +166,7 @@ keybind_signal = COMSIG_KB_MOB_TARGETCYCLEHEAD_DOWN /datum/keybinding/mob/target/head - hotkey_keys = list("Unbound") + hotkey_keys = list(UNBOUND_KEY) name = "target_head" full_name = "Target: Head" description = "Pressing this key targets the head. This will impact where you hit people, and can be used for surgery." diff --git a/code/modules/client/preferences/middleware/keybindings.dm b/code/modules/client/preferences/middleware/keybindings.dm index 07ec54d3cbc..5c1cddfa352 100644 --- a/code/modules/client/preferences/middleware/keybindings.dm +++ b/code/modules/client/preferences/middleware/keybindings.dm @@ -94,6 +94,7 @@ keybindings[keybinding.category][keybinding.name] = list( "name" = keybinding.full_name, "description" = keybinding.description, + "default" = keybinding.hotkey_keys, ) return keybindings diff --git a/code/modules/client/preferences/migrations/tgui_prefs_migration.dm b/code/modules/client/preferences/migrations/tgui_prefs_migration.dm index 2d852c96a02..50e9d5af526 100644 --- a/code/modules/client/preferences/migrations/tgui_prefs_migration.dm +++ b/code/modules/client/preferences/migrations/tgui_prefs_migration.dm @@ -15,11 +15,11 @@ /datum/preferences/proc/migrate_key_bindings() var/new_key_bindings = list() - for (var/unbound_hotkey in key_bindings["Unbound"]) + for (var/unbound_hotkey in key_bindings[UNBOUND_KEY]) new_key_bindings[unbound_hotkey] = list() for (var/hotkey in key_bindings) - if (hotkey == "Unbound") + if (hotkey == UNBOUND_KEY) continue for (var/keybind in key_bindings[hotkey]) diff --git a/code/modules/client/preferences_savefile.dm b/code/modules/client/preferences_savefile.dm index e0d376add9d..6dd20be22f5 100644 --- a/code/modules/client/preferences_savefile.dm +++ b/code/modules/client/preferences_savefile.dm @@ -184,14 +184,14 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car if(parent.hotkeys) for(var/hotkeytobind in kb.hotkey_keys) - if(hotkeytobind == "Unbound") + if(hotkeytobind == UNBOUND_KEY) addedbind = TRUE else if(!length(binds_by_key[hotkeytobind])) //Only bind to the key if nothing else is bound key_bindings[kb.name] |= hotkeytobind addedbind = TRUE else for(var/classickeytobind in kb.classic_keys) - if(classickeytobind == "Unbound") + if(classickeytobind == UNBOUND_KEY) addedbind = TRUE else if(!length(binds_by_key[classickeytobind])) //Only bind to the key if nothing else is bound key_bindings[kb.name] |= classickeytobind @@ -199,7 +199,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car if(!addedbind) notadded += kb - save_preferences() //Save the players pref so that new keys that were set to Unbound as default are permanently stored + save_preferences() //Save the players pref so that new keys that were set to UNBOUND_KEY as default are permanently stored if(length(notadded)) addtimer(CALLBACK(src, PROC_REF(announce_conflict), notadded), 5 SECONDS) diff --git a/tgui/packages/tgui/interfaces/PreferencesMenu/GamePreferences/KeybindingsPage.tsx b/tgui/packages/tgui/interfaces/PreferencesMenu/GamePreferences/KeybindingsPage.tsx index 619c368baf2..42dc60e768e 100644 --- a/tgui/packages/tgui/interfaces/PreferencesMenu/GamePreferences/KeybindingsPage.tsx +++ b/tgui/packages/tgui/interfaces/PreferencesMenu/GamePreferences/KeybindingsPage.tsx @@ -21,6 +21,7 @@ import { TabbedMenu } from './TabbedMenu'; type Keybinding = { name: string; description?: string; + default?: string[]; }; type Keybindings = Record>; @@ -121,6 +122,7 @@ class KeybindingButton extends Component<{ currentHotkey?: string; onClick?: () => void; typingHotkey?: string; + defaults?: string[]; }> { shouldComponentUpdate(nextProps) { return ( @@ -130,8 +132,9 @@ class KeybindingButton extends Component<{ } render() { - const { currentHotkey, onClick, typingHotkey } = this.props; + const { currentHotkey, onClick, typingHotkey, defaults } = this.props; + const keyText = typingHotkey || currentHotkey || 'Unbound'; const child = ( ); @@ -241,6 +250,7 @@ function getKeybindingNodes( currentHotkey={keys[key]} typingHotkey={getTypingHotkey(keybindingId, key)} onClick={getKeybindingOnClick(keybindingId, key)} + defaults={keybinding.default} /> ))}