Skip to content

Commit

Permalink
Tweak: moved cyrillic fix to modules (#18)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and Dimach committed Jul 15, 2024
1 parent 6e59b4b commit bc93603
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
4 changes: 2 additions & 2 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
22 changes: 22 additions & 0 deletions modular_ss220/modules/cyrillic_key_fixes/code/client_procs.dm
Original file line number Diff line number Diff line change
@@ -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=")
35 changes: 35 additions & 0 deletions modular_ss220/modules/cyrillic_key_fixes/code/communication.dm
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions modular_ss220/modules/cyrillic_key_fixes/code/keybindings.dm
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions modular_ss220/modules/cyrillic_key_fixes/code/text.dm
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc93603

Please sign in to comment.