Organization, some fixes

This commit is contained in:
Jaime Ita Passos 2020-11-25 16:02:57 -03:00
parent 4302b10e2b
commit f484cb0d76
7 changed files with 108 additions and 79 deletions

View file

@ -1259,26 +1259,31 @@ boolean CON_Responder(event_t *ev)
return true; return true;
} }
// allow people to use keypad in console (good for typing IP addresses) - Calum #ifdef HAVE_TEXTINPUT
if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) if (!cv_textinput.value)
#endif
{ {
char keypad_translation[] = {'7','8','9','-', // allow people to use keypad in console (good for typing IP addresses) - Calum
'4','5','6','+', if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL)
'1','2','3', {
'0','.'}; char keypad_translation[] = {'7','8','9','-',
'4','5','6','+',
'1','2','3',
'0','.'};
key = keypad_translation[key - KEY_KEYPAD7]; key = keypad_translation[key - KEY_KEYPAD7];
} }
else if (key == KEY_KPADSLASH) else if (key == KEY_KPADSLASH)
key = '/'; key = '/';
if (key >= 'a' && key <= 'z') if (key >= 'a' && key <= 'z')
{ {
if (capslock ^ shiftdown) if (capslock ^ shiftdown)
key = shiftxform[key];
}
else if (shiftdown)
key = shiftxform[key]; key = shiftxform[key];
} }
else if (shiftdown)
key = shiftxform[key];
// enter a char into the command prompt // enter a char into the command prompt
if (key < 32 || key > 127) if (key < 32 || key > 127)

View file

@ -817,6 +817,22 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_joyscale); CV_RegisterVar(&cv_joyscale);
CV_RegisterVar(&cv_joyscale2); CV_RegisterVar(&cv_joyscale2);
// * cv_textinput allows "text input" events from SDL,
// so that console and chat is guaranteed to use
// the player's keyboard locale reliably
// * When disabled, the game will fallback to using
// keycode events, still following the player's locale
// * If cv_keyboardlocale is disabled, input will default
// to using the US keyboard layout
// * cv_forceqwerty forces a QWERTY layout, but only
// if text input events are disabled
#ifdef HAVE_TEXTINPUT
CV_RegisterVar (&cv_textinput);
#endif
CV_RegisterVar (&cv_keyboardlocale);
CV_RegisterVar (&cv_forceqwerty);
// Analog Control // Analog Control
CV_RegisterVar(&cv_analog[0]); CV_RegisterVar(&cv_analog[0]);
CV_RegisterVar(&cv_analog[1]); CV_RegisterVar(&cv_analog[1]);

View file

@ -629,7 +629,7 @@ extern const char *compdate, *comptime, *comprevision, *compbranch;
#define SECTORSPECIALSAFTERTHINK #define SECTORSPECIALSAFTERTHINK
/// Text input events /// Text input events
//#define HAVE_TEXTINPUT #define HAVE_TEXTINPUT
/// Sprite rotation /// Sprite rotation
#define ROTSPRITE #define ROTSPRITE

View file

@ -19,6 +19,18 @@
#include "d_net.h" #include "d_net.h"
#include "console.h" #include "console.h"
static CV_PossibleValue_t keyboardlocale_cons_t[] = {
{0, "Off"},
{1, "On"},
{2, "Only in text fields"},
{0, NULL}};
#ifdef HAVE_TEXTINPUT
consvar_t cv_textinput = CVAR_INIT ("textinput", "On", CV_SAVE, CV_OnOff, NULL);
#endif
consvar_t cv_keyboardlocale = CVAR_INIT ("keyboardlocale", "Off", CV_SAVE, keyboardlocale_cons_t, NULL);
consvar_t cv_forceqwerty = CVAR_INIT ("forceqwerty", "Off", CV_SAVE, CV_OnOff, NULL);
#define MAXMOUSESENSITIVITY 100 // sensitivity steps #define MAXMOUSESENSITIVITY 100 // sensitivity steps
static CV_PossibleValue_t mousesens_cons_t[] = {{1, "MIN"}, {MAXMOUSESENSITIVITY, "MAX"}, {0, NULL}}; static CV_PossibleValue_t mousesens_cons_t[] = {{1, "MIN"}, {MAXMOUSESENSITIVITY, "MAX"}, {0, NULL}};

View file

@ -111,6 +111,12 @@ typedef enum
num_gamecontrolschemes num_gamecontrolschemes
} gamecontrolschemes_e; } gamecontrolschemes_e;
#ifdef HAVE_TEXTINPUT
extern consvar_t cv_textinput;
#endif
extern consvar_t cv_keyboardlocale;
extern consvar_t cv_forceqwerty;
// mouse values are used once // mouse values are used once
extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens, cv_mouseysens;
extern consvar_t cv_mousesens2, cv_mouseysens2; extern consvar_t cv_mousesens2, cv_mouseysens2;

View file

@ -1167,17 +1167,22 @@ boolean HU_Responder(event_t *ev)
c = (INT32)ev->data1; c = (INT32)ev->data1;
// I know this looks very messy but this works. If it ain't broke, don't fix it! #ifdef HAVE_TEXTINPUT
// shift LETTERS to uppercase if we have capslock or are holding shift if (!cv_textinput.value)
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) #endif
{ {
if (shiftdown ^ capslock) // I know this looks very messy but this works. If it ain't broke, don't fix it!
c = shiftxform[c]; // shift LETTERS to uppercase if we have capslock or are holding shift
} if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
else // if we're holding shift we should still shift non letter symbols {
{ if (shiftdown ^ capslock)
if (shiftdown) c = shiftxform[c];
c = shiftxform[c]; }
else // if we're holding shift we should still shift non letter symbols
{
if (shiftdown)
c = shiftxform[c];
}
} }
// pasting. pasting is cool. chat is a bit limited, though :( // pasting. pasting is cool. chat is a bit limited, though :(

View file

@ -107,13 +107,6 @@ static consvar_t cv_alwaysgrabmouse = CVAR_INIT ("alwaysgrabmouse", "Off", CV_SA
UINT8 graphics_started = 0; // Is used in console.c and screen.c UINT8 graphics_started = 0; // Is used in console.c and screen.c
// Lactozilla: keyboard input
#ifdef HAVE_TEXTINPUT
consvar_t cv_textinput = {"textinput", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
#endif
consvar_t cv_keyboardlocale = {"keyboardlocale", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_forceqwerty = {"forceqwerty", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
// To disable fullscreen at startup; is set in VID_PrepareModeList // To disable fullscreen at startup; is set in VID_PrepareModeList
boolean allow_fullscreen = false; boolean allow_fullscreen = false;
static SDL_bool disable_fullscreen = SDL_FALSE; static SDL_bool disable_fullscreen = SDL_FALSE;
@ -279,16 +272,26 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen, SDL_bool
} }
} }
static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type) static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Keysym keysym, Uint32 type)
{ {
boolean useqwerty = true; SDL_Scancode scancode = keysym.scancode;
if (cv_keyboardlocale.value) SDL_Keycode keycode = keysym.sym;
{
SDL_Keycode keycode = SDL_GetKeyFromScancode(code);
// Lactozilla boolean useqwerty = true;
// Use keycodes instead of scancodes, boolean uselocale = (!!cv_keyboardlocale.value);
// so that non-US keyboards can work! Wow!
#ifdef HAVE_TEXTINPUT
if (cv_textinput.value)
uselocale = true;
#else
if (cv_keyboardlocale.value == 2
&& !(CON_AcceptInput() || M_TextInput() || HU_ChatActive()))
uselocale = false;
#endif
if (uselocale)
{
// Lactozilla: Use keycodes instead of scancodes, so that non-US keyboards can work.
switch (keycode) switch (keycode)
{ {
// F11 and F12 are separated from the rest of the function keys // F11 and F12 are separated from the rest of the function keys
@ -332,13 +335,13 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
return KEY_F1 + (keycode - SDLK_F1); return KEY_F1 + (keycode - SDLK_F1);
} }
// Do send keyup events to avoid stuck movement keys // Send key up events to avoid stuck movement keys
if (type != SDL_KEYUP && (!ctrldown)) if (type != SDL_KEYUP && (!ctrldown))
{ {
#ifdef HAVE_TEXTINPUT #ifdef HAVE_TEXTINPUT
if (cv_textinput.value) if (cv_textinput.value)
{ {
// Lactozilla: console input // console input
if (CON_AcceptInput()) if (CON_AcceptInput())
return 0; return 0;
// menu text input // menu text input
@ -405,17 +408,16 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
case SDLK_QUOTEDBL: return '"'; case SDLK_QUOTEDBL: return '"';
case SDLK_RIGHTPAREN: return ')'; case SDLK_RIGHTPAREN: return ')';
case SDLK_UNDERSCORE: return '_'; case SDLK_UNDERSCORE: return '_';
default: break; default: break;
} }
// Tested by installing a French keymap
if (useqwerty) if (useqwerty)
{ {
if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z)
return code - SDL_SCANCODE_A + 'a'; return scancode - SDL_SCANCODE_A + 'a';
else if (code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) else if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9)
return code - SDL_SCANCODE_1 + '1'; return scancode - SDL_SCANCODE_1 + '1';
else if (code == SDL_SCANCODE_0) else if (scancode == SDL_SCANCODE_0)
return '0'; return '0';
} }
else else
@ -430,7 +432,7 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
} }
else else
{ {
switch (code) switch (scancode)
{ {
// F11 and F12 are separated from the rest of the function keys // F11 and F12 are separated from the rest of the function keys
case SDL_SCANCODE_F11: return KEY_F11; case SDL_SCANCODE_F11: return KEY_F11;
@ -469,18 +471,18 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
default: break; default: break;
} }
if (code >= SDL_SCANCODE_F1 && code <= SDL_SCANCODE_F10) if (scancode >= SDL_SCANCODE_F1 && scancode <= SDL_SCANCODE_F10)
{ {
return KEY_F1 + (code - SDL_SCANCODE_F1); return KEY_F1 + (scancode - SDL_SCANCODE_F1);
} }
#ifdef HAVE_TEXTINPUT #ifdef HAVE_TEXTINPUT
// Do send keyup events to avoid stuck movement keys // Send key up events to avoid stuck movement keys
if (type != SDL_KEYUP && (!ctrldown)) if (type != SDL_KEYUP && (!ctrldown))
{ {
if (cv_textinput.value) if (cv_textinput.value)
{ {
// Lactozilla: console input // console input
if (CON_AcceptInput()) if (CON_AcceptInput())
return 0; return 0;
// menu text input // menu text input
@ -493,7 +495,7 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
} }
#endif #endif
switch (code) switch (scancode)
{ {
case SDL_SCANCODE_KP_0: return KEY_KEYPAD0; case SDL_SCANCODE_KP_0: return KEY_KEYPAD0;
case SDL_SCANCODE_KP_1: return KEY_KEYPAD1; case SDL_SCANCODE_KP_1: return KEY_KEYPAD1;
@ -529,17 +531,16 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code, Uint32 type)
default: break; default: break;
} }
// cv_forceqwerty assumed on if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z)
if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z)
{ {
// get lowercase ASCII // get lowercase ASCII
return code - SDL_SCANCODE_A + 'a'; return scancode - SDL_SCANCODE_A + 'a';
} }
if (code >= SDL_SCANCODE_1 && code <= SDL_SCANCODE_9) if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9)
{ {
return code - SDL_SCANCODE_1 + '1'; return scancode - SDL_SCANCODE_1 + '1';
} }
else if (code == SDL_SCANCODE_0) else if (scancode == SDL_SCANCODE_0)
{ {
return '0'; return '0';
} }
@ -837,7 +838,7 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
{ {
return; return;
} }
event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode, type); event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym, type);
if (event.data1) D_PostEvent(&event); if (event.data1) D_PostEvent(&event);
} }
@ -1937,22 +1938,6 @@ void I_StartupGraphics(void)
disable_mouse = M_CheckParm("-nomouse"); disable_mouse = M_CheckParm("-nomouse");
disable_fullscreen = M_CheckParm("-win") ? 1 : 0; disable_fullscreen = M_CheckParm("-win") ? 1 : 0;
// * cv_textinput allows "text input" events from SDL,
// so that console and chat is guaranteed to use
// the player's keyboard locale reliably
// * When disabled, the game will fallback to using
// keycode events, still following the player's locale
// * If cv_keyboardlocale is disabled, input will default
// to using the US keyboard layout
// * cv_forceqwerty forces a QWERTY layout, but only
// if text input events are disabled
#ifdef HAVE_TEXTINPUT
CV_RegisterVar (&cv_textinput);
#endif
CV_RegisterVar (&cv_keyboardlocale);
CV_RegisterVar (&cv_forceqwerty);
keyboard_started = true; keyboard_started = true;
#if !defined(HAVE_TTF) #if !defined(HAVE_TTF)