From bc93603b98d5c47ce60d8ae5205e4b250028026c Mon Sep 17 00:00:00 2001 From: Serge K Lebedev Date: Fri, 5 May 2023 00:03:36 +0600 Subject: [PATCH] Tweak: moved cyrillic fix to modules (#18) * moved to module * oops * removed extra * fixed looc and whisper * abc Cyrillic key fixes (#3) * fix: communication hotkeys * Feat: add ability to setup keybinds on russian keylayout --------- feat: Cyrillic names (#20) Co-authored-by: Vallat --- code/__HELPERS/text.dm | 4 +-- .../cyrillic_key_fixes/code/client_procs.dm | 22 ++++++++++++ .../cyrillic_key_fixes/code/communication.dm | 35 ++++++++++++++++++ .../cyrillic_key_fixes/code/keybindings.dm | 36 +++++++++++++++++++ .../modules/cyrillic_key_fixes/code/text.dm | 12 +++++++ tgstation.dme | 4 +++ 6 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 modular_ss220/modules/cyrillic_key_fixes/code/client_procs.dm create mode 100644 modular_ss220/modules/cyrillic_key_fixes/code/communication.dm create mode 100644 modular_ss220/modules/cyrillic_key_fixes/code/keybindings.dm create mode 100644 modular_ss220/modules/cyrillic_key_fixes/code/text.dm diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index 5102a592e20d351..7fe5bd2f95f84d1 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -178,12 +178,12 @@ switch(text2ascii(char)) // A .. Z - if(65 to 90) //Uppercase Letters + if(65 to 90, 1040 to 1071, 1025) //Uppercase Letters //SS220 EDIT CHANGE number_of_alphanumeric++ last_char_group = LETTERS_DETECTED // a .. z - if(97 to 122) //Lowercase Letters + if(97 to 122, 1072 to 1103, 1105) //Lowercase Letters //SS220 EDIT CHANGE if(last_char_group == NO_CHARS_DETECTED || last_char_group == SPACES_DETECTED || cap_after_symbols && last_char_group == SYMBOLS_DETECTED) //start of a word char = uppertext(char) number_of_alphanumeric++ diff --git a/modular_ss220/modules/cyrillic_key_fixes/code/client_procs.dm b/modular_ss220/modules/cyrillic_key_fixes/code/client_procs.dm new file mode 100644 index 000000000000000..f19145e9a3c3ac0 --- /dev/null +++ b/modular_ss220/modules/cyrillic_key_fixes/code/client_procs.dm @@ -0,0 +1,22 @@ +/client/update_special_keybinds(datum/preferences/direct_prefs) + var/datum/preferences/D = prefs || direct_prefs + if(!D?.key_bindings) + return + movement_keys = list() + for(var/kb_name in D.key_bindings) + for(var/key in D.key_bindings[kb_name]) + switch(kb_name) + if("North") + movement_keys[key] = NORTH + if("East") + movement_keys[key] = EAST + if("West") + movement_keys[key] = WEST + if("South") + movement_keys[key] = SOUTH + if(ADMIN_CHANNEL) + if(holder) + var/asay = tgui_say_create_open_command(ADMIN_CHANNEL) + winset(src, "default-[REF(key)]", "parent=default;name=[key];command=[asay]") + else + winset(src, "default-[REF(key)]", "parent=default;name=[key];command=") diff --git a/modular_ss220/modules/cyrillic_key_fixes/code/communication.dm b/modular_ss220/modules/cyrillic_key_fixes/code/communication.dm new file mode 100644 index 000000000000000..7f49034b3bbcff1 --- /dev/null +++ b/modular_ss220/modules/cyrillic_key_fixes/code/communication.dm @@ -0,0 +1,35 @@ +/datum/keybinding/client/communication/say/down(client/user) + . = ..() + if(.) + return + winset(user, null, "command=[user.tgui_say_create_open_command(SAY_CHANNEL)]") + return TRUE + + +/datum/keybinding/client/communication/ooc/down(client/user) + . = ..() + if(.) + return + winset(user, null, "command=[user.tgui_say_create_open_command(OOC_CHANNEL)]") + return TRUE + +/datum/keybinding/client/communication/me/down(client/user) + . = ..() + if(.) + return + winset(user, null, "command=[user.tgui_say_create_open_command(ME_CHANNEL)]") + return TRUE + +/datum/keybinding/client/communication/looc/down(client/user) + . = ..() + if(.) + return + winset(user, null, "command=looc") + return TRUE + +/datum/keybinding/client/communication/whisper/down(client/user) + . = ..() + if(.) + return + winset(user, null, "command=whisper") + return TRUE diff --git a/modular_ss220/modules/cyrillic_key_fixes/code/keybindings.dm b/modular_ss220/modules/cyrillic_key_fixes/code/keybindings.dm new file mode 100644 index 000000000000000..2e9b721be847c48 --- /dev/null +++ b/modular_ss220/modules/cyrillic_key_fixes/code/keybindings.dm @@ -0,0 +1,36 @@ +#define MAX_HOTKEY_SLOTS 3 + + +/datum/preference_middleware/keybindings/set_keybindings(list/params) + var/keybind_name = params["keybind_name"] + + if (isnull(GLOB.keybindings_by_name[keybind_name])) + return FALSE + + var/list/raw_hotkeys = params["hotkeys"] + if (!istype(raw_hotkeys)) + return FALSE + + if (raw_hotkeys.len > MAX_HOTKEY_SLOTS) + return FALSE + + // There's no optimal, easy way to check if something is an array + // and not an object in BYOND, so just sanitize it to make sure. + var/list/hotkeys = list() + for (var/hotkey in raw_hotkeys) + if (!istext(hotkey)) + return FALSE + + // Fairly arbitrary number, it's just so you don't save enormous fake keybinds. + if (length(hotkey) > 100) + return FALSE + + hotkeys += convert_ru_key_to_en_key(hotkey) + + preferences.key_bindings[keybind_name] = hotkeys + preferences.key_bindings_by_key = preferences.get_key_bindings_by_key(preferences.key_bindings) + + return TRUE + + +#undef MAX_HOTKEY_SLOTS diff --git a/modular_ss220/modules/cyrillic_key_fixes/code/text.dm b/modular_ss220/modules/cyrillic_key_fixes/code/text.dm new file mode 100644 index 000000000000000..a3ec83c04659090 --- /dev/null +++ b/modular_ss220/modules/cyrillic_key_fixes/code/text.dm @@ -0,0 +1,12 @@ +GLOBAL_LIST_INIT(ru_key_to_en_key, list( + "й" = "q", "ц" = "w", "у" = "e", "к" = "r", "е" = "t", "н" = "y", "г" = "u", "ш" = "i", "щ" = "o", "з" = "p", "х" = "\[", "ъ" = "]", + "ф" = "a", "ы" = "s", "в" = "d", "а" = "f", "п" = "g", "р" = "h", "о" = "j", "л" = "k", "д" = "l", "ж" = ";", "э" = "'", + "я" = "z", "ч" = "x", "с" = "c", "м" = "v", "и" = "b", "т" = "n", "ь" = "m", "б" = ",", "ю" = "." +)) + +/proc/convert_ru_key_to_en_key(var/_key) + var/new_key = lowertext(_key) + new_key = GLOB.ru_key_to_en_key[new_key] + if(!new_key) + return _key + return uppertext(new_key) diff --git a/tgstation.dme b/tgstation.dme index acd59f44805f560..792fd9fa903c6da 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -8494,4 +8494,8 @@ #include "modular_nova\modules\xenos_nova_redo\code\xeno_types\sentinel.dm" #include "modular_nova\modules\xenos_nova_redo\code\xeno_types\spitter.dm" #include "modular_nova\modules\xenos_nova_redo\code\xeno_types\warrior.dm" +#include "modular_ss220\modules\cyrillic_key_fixes\code\client_procs.dm" +#include "modular_ss220\modules\cyrillic_key_fixes\code\communication.dm" +#include "modular_ss220\modules\cyrillic_key_fixes\code\keybindings.dm" +#include "modular_ss220\modules\cyrillic_key_fixes\code\text.dm" // END_INCLUDE