From 82bd4a19672f80855acaaa8262e1a853d90eaf54 Mon Sep 17 00:00:00 2001 From: Jaime Ita Passos Date: Wed, 25 Nov 2020 23:15:52 -0300 Subject: [PATCH] Fixes --- src/m_menu.c | 51 +++++++++++++++++++++++++----- src/sdl/i_video.c | 79 +++++++++++++++++++---------------------------- 2 files changed, 75 insertions(+), 55 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 76505e746..0ed2595cf 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3110,8 +3110,13 @@ static boolean M_ChangeStringCvar(INT32 choice) char buf[MAXSTRINGLENGTH]; size_t len; - if (shiftdown && choice >= 32 && choice <= 127) - choice = shiftxform[choice]; +#ifdef TEXTINPUTEVENTS + if (!cv_keyboardlocale.value) +#endif + { + if (shiftdown && choice >= 32 && choice <= 127) + choice = shiftxform[choice]; + } switch (choice) { @@ -3194,10 +3199,29 @@ static void Command_Manual_f(void) boolean M_TextInput(void) { - // Of course return false if the menus are down... + menuitem_t *item = &(currentMenu->menuitems[itemOn]); + + // Return false if the menus are not active. if (!menuactive) return false; - return ((currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_KEYHANDLER); + + if (item->itemaction) + { + if ((item->status & IT_TYPE) == IT_KEYHANDLER) + { + void (*action)(INT32 choice) = item->itemaction; + if (action == M_HandleAddons) + return true; + else if (action == M_HandleSetupMultiPlayer) + return (itemOn == 0); + else if (action == M_HandleConnectIP) + return true; + } + else if ((item->status & IT_TYPE) == IT_CVAR) + return ((item->status & IT_CVARTYPE) == IT_CV_STRING); + } + + return false; } // @@ -3427,8 +3451,14 @@ boolean M_Responder(event_t *ev) // Handle menuitems which need a specific key handling if (routine && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_KEYHANDLER) { - if (shiftdown && ch >= 32 && ch <= 127) - ch = shiftxform[ch]; +#ifdef TEXTINPUTEVENTS + if (!(cv_keyboardlocale.value && M_TextInput())) +#endif + { + if (shiftdown && ch >= 32 && ch <= 127) + ch = shiftxform[ch]; + } + routine(ch); return true; } @@ -6608,8 +6638,13 @@ static void M_AddonExec(INT32 ch) #define len menusearch[0] static boolean M_ChangeStringAddons(INT32 choice) { - if (shiftdown && choice >= 32 && choice <= 127) - choice = shiftxform[choice]; +#ifdef TEXTINPUTEVENTS + if (!cv_keyboardlocale.value) +#endif + { + if (shiftdown && choice >= 32 && choice <= 127) + choice = shiftxform[choice]; + } switch (choice) { diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f31d592c6..420cc513f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -277,19 +277,17 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Keysym keysym, Uint32 type) SDL_Scancode scancode = keysym.scancode; SDL_Keycode keycode = keysym.sym; - boolean useqwerty = true; - boolean uselocale = (!!cv_usekeycodes.value); + boolean intextfield = (CON_AcceptInput() || M_TextInput() || HU_ChatActive()); + boolean usekeycodes = (!!cv_usekeycodes.value); + boolean forceqwerty = (!!cv_forceqwerty.value); -#ifdef TEXTINPUTEVENTS - if (cv_keyboardlocale.value) - uselocale = true; -#else - if (cv_usekeycodes.value == 2 - && !(CON_AcceptInput() || M_TextInput() || HU_ChatActive())) - uselocale = false; -#endif + // Only use keycodes in text fields + if (cv_usekeycodes.value == 2 && !intextfield) + { + usekeycodes = false; + } - if (uselocale) + if (usekeycodes) { // Lactozilla: Use keycodes instead of scancodes, so that non-US keyboards can work. switch (keycode) @@ -335,29 +333,14 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Keysym keysym, Uint32 type) return KEY_F1 + (keycode - SDLK_F1); } - // Send key up events to avoid stuck movement keys - if (type != SDL_KEYUP && (!ctrldown)) - { #ifdef TEXTINPUTEVENTS - if (cv_keyboardlocale.value) - { - // console input - if (CON_AcceptInput()) - return 0; - // menu text input - if (M_TextInput()) - return 0; - // chat input - if (HU_ChatActive()) - return 0; - } -#else - if (CON_AcceptInput() // console input - || M_TextInput() // menu text input - || HU_ChatActive()) // chat input - useqwerty = (cv_forceqwerty.value); -#endif + // Don't send key events if a text field is active. + // Send key up events to avoid stuck movement keys. + if (type != SDL_KEYUP && (!ctrldown) && cv_keyboardlocale.value && intextfield) + { + return 0; } +#endif switch (keycode) { @@ -411,23 +394,35 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Keysym keysym, Uint32 type) default: break; } - if (useqwerty) + if (forceqwerty) { if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) + { return scancode - SDL_SCANCODE_A + 'a'; + } else if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) + { return scancode - SDL_SCANCODE_1 + '1'; + } else if (scancode == SDL_SCANCODE_0) + { return '0'; + } } else { if (keycode >= SDLK_a && keycode <= SDLK_z) + { return keycode - SDLK_a + 'a'; + } else if (keycode >= SDLK_1 && keycode <= SDLK_9) + { return keycode - SDLK_1 + '1'; + } else if (keycode == SDLK_0) + { return '0'; + } } } else @@ -477,21 +472,11 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Keysym keysym, Uint32 type) } #ifdef TEXTINPUTEVENTS - // Send key up events to avoid stuck movement keys - if (type != SDL_KEYUP && (!ctrldown)) + // Don't send key events if a text field is active. + // Send key up events to avoid stuck movement keys. + if (type != SDL_KEYUP && (!ctrldown) && cv_keyboardlocale.value && intextfield) { - if (cv_keyboardlocale.value) - { - // console input - if (CON_AcceptInput()) - return 0; - // menu text input - if (M_TextInput()) - return 0; - // chat input - if (HU_ChatActive()) - return 0; - } + return 0; } #endif