Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions code/modules/client/tgui_macro.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)
"classic" = kb.classic_keys,
))

/proc/keybind_to_keyboardMap(keybind, list/mods)
var/list/tempList = list()
for(var/i in mods)
tempList += GLOB._kbMap[i]
if(GLOB._kbMap[keybind])
tempList += GLOB._kbMap[keybind]
else
tempList += keybind
return tempList.Join("+")

/datum/tgui_macro
var/client/owner
var/datum/preferences/prefs
Expand Down Expand Up @@ -66,12 +76,6 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)

var/old_key = params["old_key"]

var/mods = sortList(params["key_mods"]).Join("+")

var/full_key = params["key"]
if(mods)
full_key = "[mods]+[full_key]"

if(!params["key"])
if(kbinds[old_key])
kbinds[old_key] -= kb_name
Expand All @@ -82,17 +86,7 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)
prefs.save_preferences()
return

var/list/tempList = list()
for(var/i in splittext(full_key, "+"))
if(full_key == "+")
i = "+" //we split by + so empty means input was +
tempList += GLOB._kbMap[i]
break
if(GLOB._kbMap[i])
tempList += GLOB._kbMap[i]
else
tempList += i
full_key = tempList.Join("+")
var/full_key = keybind_to_keyboardMap(params["key"], params["key_mods"])

if(kb_name in kbinds[full_key]) //We pressed the same key combination that was already bound here, so let's remove to re-add and re-sort.
kbinds[full_key] -= kb_name
Expand Down Expand Up @@ -139,10 +133,9 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)
var/keybind_type = params["keybind_type"]
if(!(keybind_type in list(KEYBIND_TYPE_SAY, KEYBIND_TYPE_ME, KEYBIND_TYPE_PICKSAY)))
return TRUE

var/keybind = params["keybind"]
var/keybind = keybind_to_keyboardMap(params["key"], params["key_mods"])
if(!keybind)
return TRUE
keybind = params["keybind"]

var/contents = params["contents"]

Expand All @@ -168,9 +161,6 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)
contents = jointext(contents, ", ")
contents = strip_html(contents, MAX_MESSAGE_LEN)

for(var/i in GLOB._kbMap)
keybind = replacetext(keybind, i, GLOB._kbMap[i])

var/when_human = sanitize_integer(params["when_human"], FALSE, TRUE, TRUE)
var/when_xeno = sanitize_integer(params["when_xeno"], FALSE, TRUE, TRUE)
var/when_yautja = sanitize_integer(params["when_yautja"], FALSE, TRUE, TRUE)
Expand Down
8 changes: 8 additions & 0 deletions tgui/packages/tgui/interfaces/KeyBinds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Data = {

type CustomKeybind = {
keybinding?: string;
key?: string;
key_mods?: string;
type?: string;
contents?: string | string[];
when_xeno?: boolean;
Expand Down Expand Up @@ -503,12 +505,16 @@ const CustomKeybinds = (props: {
return {
...keybind,
keybinding: kb,
key: keys[0],
key_mods: mods,
};
}

return {
...pending,
keybinding: kb,
key: keys[0],
key_mods: mods,
};
});
}}
Expand Down Expand Up @@ -631,6 +637,8 @@ const CustomKeybinds = (props: {
act('set_custom_keybinds', {
index: index + 1,
keybind: pendingKeybind.keybinding,
key: pendingKeybind.key,
key_mods: pendingKeybind.key_mods,
keybind_type: pendingKeybind.type?.toLowerCase(),
contents: pendingKeybind.contents,
when_xeno: pendingKeybind.when_xeno ?? false,
Expand Down