diff --git a/lang/Czech.ini b/lang/Czech.ini index 33f515085..98bcb8701 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -107,6 +107,7 @@ DEADZONE = "Deadzone" RUMBLE_STRENGTH = "Síla vibrace" CHAT = "Chat" +CHAT_COMMAND = "Chat (Příkaz)" PLAYERS = "Hráči" D_UP = "D-Pad nahoru" D_DOWN = "D-Pad dolů" diff --git a/lang/Dutch.ini b/lang/Dutch.ini index 40cdb3602..825a8feb6 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -107,6 +107,7 @@ DEADZONE = "Doode-zone" RUMBLE_STRENGTH = "Rommel Kracht" CHAT = "Chat" +CHAT_COMMAND = "Chat (Commando)" PLAYERS = "Spelers" D_UP = "D Omhoog" D_DOWN = "D Naar Beneden" diff --git a/lang/English.ini b/lang/English.ini index 4a835249b..9ae85f73b 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -107,6 +107,7 @@ DEADZONE = "Deadzone" RUMBLE_STRENGTH = "Rumble Strength" CHAT = "Chat" +CHAT_COMMAND = "Chat (Command)" PLAYERS = "Players" D_UP = "D-Up" D_DOWN = "D-Down" diff --git a/lang/French.ini b/lang/French.ini index 404597073..b1ae398b6 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -107,6 +107,7 @@ DEADZONE = "Zone Morte" RUMBLE_STRENGTH = "Vibrations" CHAT = "Chat" +CHAT_COMMAND = "Chat (Commande)" PLAYERS = "Joueurs" D_UP = "D Haut" D_DOWN = "D Bas" diff --git a/lang/German.ini b/lang/German.ini index f12fe5ed6..c2a8eb998 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -107,6 +107,7 @@ DEADZONE = "Tote Zone" RUMBLE_STRENGTH = "Vibration-Stärke" CHAT = "Chat" +CHAT_COMMAND = "Chat (Befehl)" PLAYERS = "Spieler" D_UP = "D-Hoch" D_DOWN = "D-Unten" diff --git a/lang/Italian.ini b/lang/Italian.ini index 2cdd7f201..55d7a4d43 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -105,6 +105,7 @@ GAMEPAD = "Controller" DEADZONE = "Zona Morta" RUMBLE_STRENGTH = "Intesità Vibrazione" CHAT = "Chat" +CHAT_COMMAND = "Chat (Comando)" PLAYERS = "Giocatori" D_UP = "D Su" D_DOWN = "D Giù" diff --git a/lang/Japanese.ini b/lang/Japanese.ini index 439ded225..7f06356a9 100644 --- a/lang/Japanese.ini +++ b/lang/Japanese.ini @@ -108,6 +108,7 @@ DEADZONE = "デッドゾーン" RUMBLE_STRENGTH = "振動の強さ" CHAT = "チャット" +CHAT_COMMAND = "チャット(コマンド)" PLAYERS = "プレイヤーリストの表示" D_UP = "十字キー 上" D_DOWN = "十字キー 下" diff --git a/lang/Polish.ini b/lang/Polish.ini index 698550388..8bad911f6 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -107,6 +107,7 @@ DEADZONE = "Martwa Strefa" RUMBLE_STRENGTH = "Siła Wibracji" CHAT = "Czat" +CHAT_COMMAND = "Czat (Komenda)" PLAYERS = "Gracze" D_UP = "Kierunek w Górę" D_DOWN = "Kierunek w Dół" diff --git a/lang/Portuguese.ini b/lang/Portuguese.ini index 6dba6e874..15db94c24 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -107,6 +107,7 @@ DEADZONE = "Zona morta" RUMBLE_STRENGTH = "Força de vibração" CHAT = "Chat" +CHAT_COMMAND = "Chat (Comando)" PLAYERS = "Jogadores" D_UP = "D-Cima" D_DOWN = "D-Baixo" diff --git a/lang/Russian.ini b/lang/Russian.ini index a4277a0dc..babf6ac03 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -106,6 +106,7 @@ DEADZONE = "Mёртвая зона" RUMBLE_STRENGTH = "Вибрация" CHAT = "Чат" +CHAT_COMMAND = "Чат (Команда)" PLAYERS = "Игроки" D_UP = "Крестовина вверх" D_DOWN = "Крестовина вниз" diff --git a/lang/Spanish.ini b/lang/Spanish.ini index 967bd71bc..5d2ae2d4f 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -107,6 +107,7 @@ DEADZONE = "Zona muerta" RUMBLE_STRENGTH = "Intensidad de vibración" CHAT = "Chat" +CHAT_COMMAND = "Chat (Comando)" PLAYERS = "Jugadores" D_UP = "Cruz Arriba" D_DOWN = "Cruz Abajo" diff --git a/src/pc/configfile.c b/src/pc/configfile.c index f2267a7db..220a7d693 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -4,6 +4,9 @@ #include #include #include +#ifdef _WIN32 +#include +#endif #include #include "platform.h" @@ -114,6 +117,7 @@ unsigned int configKeyStickDown[MAX_BINDS] = { 0x001F, VK_INVALID, VK unsigned int configKeyStickLeft[MAX_BINDS] = { 0x001E, VK_INVALID, VK_INVALID }; unsigned int configKeyStickRight[MAX_BINDS] = { 0x0020, VK_INVALID, VK_INVALID }; unsigned int configKeyChat[MAX_BINDS] = { 0x001C, VK_INVALID, VK_INVALID }; +unsigned int configKeyChatCommand[MAX_BINDS] = { VK_INVALID, VK_INVALID, VK_INVALID }; unsigned int configKeyPlayerList[MAX_BINDS] = { 0x000F, 0x1004, VK_INVALID }; unsigned int configKeyDUp[MAX_BINDS] = { 0x0147, 0x100b, VK_INVALID }; unsigned int configKeyDDown[MAX_BINDS] = { 0x014f, 0x100c, VK_INVALID }; @@ -257,6 +261,7 @@ static const struct ConfigOption options[] = { {.name = "key_stickleft", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickLeft}, {.name = "key_stickright", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStickRight}, {.name = "key_chat", .type = CONFIG_TYPE_BIND, .uintValue = configKeyChat}, + {.name = "key_chat_command", .type = CONFIG_TYPE_BIND, .uintValue = configKeyChatCommand}, {.name = "key_playerlist", .type = CONFIG_TYPE_BIND, .uintValue = configKeyPlayerList}, {.name = "key_dup", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDUp}, {.name = "key_ddown", .type = CONFIG_TYPE_BIND, .uintValue = configKeyDDown}, @@ -666,6 +671,23 @@ static void configfile_load_internal(const char *filename, bool* error) { if (file == NULL) { // Create a new config file and save defaults printf("Config file '%s' not found. Creating it.\n", filename); + // set sensible default for chat command key depending on keyboard layout + if (configKeyChatCommand[0] == VK_INVALID && configKeyChatCommand[1] == VK_INVALID && configKeyChatCommand[2] == VK_INVALID) { +#ifdef _WIN32 + HKL hkl = GetKeyboardLayout(0); + LANGID lang = LOWORD(hkl); + switch (PRIMARYLANGID(lang)) { + case LANG_GERMAN: + configKeyChatCommand[0] = 0x002B; // '#' on QWERTZ (OEM_5 position) + break; + default: + configKeyChatCommand[0] = 0x0035; // '/' on US QWERTY + break; + } +#else + configKeyChatCommand[0] = 0x0035; // '/' default on non-Windows +#endif + } configfile_save(filename); return; } @@ -777,6 +799,23 @@ NEXT_OPTION: } fs_close(file); + // If user has no chat command bind yet, set a default based on layout + if (configKeyChatCommand[0] == VK_INVALID && configKeyChatCommand[1] == VK_INVALID && configKeyChatCommand[2] == VK_INVALID) { +#ifdef _WIN32 + HKL hkl = GetKeyboardLayout(0); + LANGID lang = LOWORD(hkl); + switch (PRIMARYLANGID(lang)) { + case LANG_GERMAN: + configKeyChatCommand[0] = 0x002B; // '#' + break; + default: + configKeyChatCommand[0] = 0x0035; // '/' + break; + } +#else + configKeyChatCommand[0] = 0x0035; +#endif + } if (configFramerateMode < 0 || configFramerateMode > RRM_MAX) { configFramerateMode = 0; } if (configFrameLimit < 30) { configFrameLimit = 30; } diff --git a/src/pc/configfile.h b/src/pc/configfile.h index d537970e4..755fe6ba9 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -80,6 +80,7 @@ extern unsigned int configKeyStickDown[MAX_BINDS]; extern unsigned int configKeyStickLeft[MAX_BINDS]; extern unsigned int configKeyStickRight[MAX_BINDS]; extern unsigned int configKeyChat[MAX_BINDS]; +extern unsigned int configKeyChatCommand[MAX_BINDS]; extern unsigned int configKeyPlayerList[MAX_BINDS]; extern unsigned int configKeyDUp[MAX_BINDS]; extern unsigned int configKeyDDown[MAX_BINDS]; diff --git a/src/pc/djui/djui_chat_box.c b/src/pc/djui/djui_chat_box.c index cd019f2a9..01710083f 100644 --- a/src/pc/djui/djui_chat_box.c +++ b/src/pc/djui/djui_chat_box.c @@ -542,6 +542,19 @@ void djui_chat_box_toggle(void) { gDjuiChatBox->chatFlow->base.y.value = gDjuiChatBox->chatContainer->base.elem.height - gDjuiChatBox->chatFlow->base.height.value; } +void djui_chat_box_open_with_text(const char* text) { + if (gDjuiChatBox == NULL) { return; } + if (!gDjuiChatBoxFocus) { + sDjuiChatBoxClearText = false; + gDjuiChatBoxFocus = true; + djui_chat_box_set_focus_style(); + } + if (gDjuiChatBox->chatInput != NULL && text != NULL) { + djui_inputbox_set_text(gDjuiChatBox->chatInput, (char*)text); + djui_inputbox_move_cursor_to_end(gDjuiChatBox->chatInput); + } +} + struct DjuiChatBox* djui_chat_box_create(void) { if (gDjuiChatBox != NULL) { djui_base_destroy(&gDjuiChatBox->base); diff --git a/src/pc/djui/djui_chat_box.h b/src/pc/djui/djui_chat_box.h index 1c5a7d150..a37005c67 100644 --- a/src/pc/djui/djui_chat_box.h +++ b/src/pc/djui/djui_chat_box.h @@ -14,4 +14,5 @@ extern struct DjuiChatBox* gDjuiChatBox; extern bool gDjuiChatBoxFocus; void djui_chat_box_toggle(void); +void djui_chat_box_open_with_text(const char* text); struct DjuiChatBox* djui_chat_box_create(void); diff --git a/src/pc/djui/djui_interactable.c b/src/pc/djui/djui_interactable.c index 288844e86..79137aeb3 100644 --- a/src/pc/djui/djui_interactable.c +++ b/src/pc/djui/djui_interactable.c @@ -211,16 +211,23 @@ bool djui_interactable_on_key_down(int scancode) { } } - if (gDjuiChatBox != NULL && !gDjuiChatBoxFocus) { + if (gDjuiChatBox != NULL) { bool pressChat = false; + bool pressChatCommand = false; for (int i = 0; i < MAX_BINDS; i++) { if (scancode == (int)configKeyChat[i]) { pressChat = true; } + if (scancode == (int)configKeyChatCommand[i]) { pressChatCommand = true; } } - if (pressChat && !gDjuiConsoleFocus) { + if (pressChat && !gDjuiConsoleFocus && !gDjuiChatBoxFocus) { djui_chat_box_toggle(); return true; } + + if (pressChatCommand && !gDjuiConsoleFocus) { + djui_chat_box_open_with_text("/"); + return true; + } } if ((gDjuiPlayerList != NULL || gDjuiModList != NULL)) { diff --git a/src/pc/djui/djui_panel_controls_extra.c b/src/pc/djui/djui_panel_controls_extra.c index e4727b45f..9669dea17 100644 --- a/src/pc/djui/djui_panel_controls_extra.c +++ b/src/pc/djui/djui_panel_controls_extra.c @@ -15,18 +15,19 @@ void djui_panel_controls_extra_create(struct DjuiBase* caller) { djui_base_set_color(&bindBody->base, 0, 0, 0, 0); djui_flow_layout_set_margin(bindBody, 1); { - djui_bind_create(&bindBody->base, DLANG(CONTROLS, CHAT), configKeyChat); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, PLAYERS), configKeyPlayerList); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_UP), configKeyDUp); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_DOWN), configKeyDDown); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_LEFT), configKeyDLeft); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_RIGHT), configKeyDRight); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, X), configKeyX); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, Y), configKeyY); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, CONSOLE), configKeyConsole); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, PREV), configKeyPrevPage); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, NEXT), configKeyNextPage); - djui_bind_create(&bindBody->base, DLANG(CONTROLS, DISCONNECT), configKeyDisconnect); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, CHAT), configKeyChat); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, CHAT_COMMAND), configKeyChatCommand); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, PLAYERS), configKeyPlayerList); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_UP), configKeyDUp); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_DOWN), configKeyDDown); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_LEFT), configKeyDLeft); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, D_RIGHT), configKeyDRight); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, X), configKeyX); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, Y), configKeyY); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, CONSOLE), configKeyConsole); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, PREV), configKeyPrevPage); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, NEXT), configKeyNextPage); + djui_bind_create(&bindBody->base, DLANG(CONTROLS, DISCONNECT), configKeyDisconnect); } djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);