mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 06:20:48 +00:00
Fix duplicate menu key keyboard entries
Fixes a bug where duplicate keyboard entries would occur in menu fields when using the keypad keys with num-lock on. Adds `IN_NumpadIsOn` function returning the state of the numpad key.
This commit is contained in:
parent
ef456964e3
commit
089a1cd53f
4 changed files with 48 additions and 45 deletions
|
@ -276,6 +276,7 @@ extern int chat_bufferlen;
|
|||
extern int chat_cursorpos;
|
||||
extern qboolean chat_team;
|
||||
|
||||
qboolean IN_NumpadIsOn();
|
||||
void Char_Event(int key);
|
||||
void Key_Event(int key, qboolean down, qboolean special);
|
||||
void Key_Init(void);
|
||||
|
|
|
@ -537,6 +537,18 @@ IN_TranslateGamepadBtnToQ2Key(int btn)
|
|||
static void IN_Controller_Init(qboolean notify_user);
|
||||
static void IN_Controller_Shutdown(qboolean notify_user);
|
||||
|
||||
qboolean IN_NumpadIsOn()
|
||||
{
|
||||
SDL_Keymod mod = SDL_GetModState();
|
||||
|
||||
if ((mod & KMOD_NUM) == KMOD_NUM)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
|
|
|
@ -242,23 +242,27 @@ Key_GetMenuKey(int key)
|
|||
switch (key)
|
||||
{
|
||||
case K_KP_UPARROW:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_UPARROW:
|
||||
case K_DPAD_UP:
|
||||
return K_UPARROW;
|
||||
|
||||
case K_TAB:
|
||||
case K_KP_DOWNARROW:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_DOWNARROW:
|
||||
case K_DPAD_DOWN:
|
||||
return K_DOWNARROW;
|
||||
|
||||
case K_KP_LEFTARROW:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_LEFTARROW:
|
||||
case K_DPAD_LEFT:
|
||||
case K_SHOULDER_LEFT:
|
||||
return K_LEFTARROW;
|
||||
|
||||
case K_KP_RIGHTARROW:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_RIGHTARROW:
|
||||
case K_DPAD_RIGHT:
|
||||
case K_SHOULDER_RIGHT:
|
||||
|
@ -283,12 +287,18 @@ Key_GetMenuKey(int key)
|
|||
case K_BACKSPACE:
|
||||
case K_DEL:
|
||||
case K_KP_DEL:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_BTN_Y:
|
||||
return K_BACKSPACE;
|
||||
case K_KP_INS:
|
||||
if (IN_NumpadIsOn() == true) { break; }
|
||||
case K_INS:
|
||||
return K_INS;
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
const char *
|
||||
Default_MenuKey(menuframework_s *m, int key)
|
||||
{
|
||||
|
|
|
@ -223,49 +223,29 @@ extern int keydown[];
|
|||
qboolean
|
||||
Field_Key(menufield_s *f, int key)
|
||||
{
|
||||
/*
|
||||
* Ignore keypad in field to prevent duplicate
|
||||
* entries through key presses processed as a
|
||||
* normal char event and additionally as key
|
||||
* event.
|
||||
*/
|
||||
switch (key)
|
||||
{
|
||||
case K_KP_SLASH:
|
||||
key = '/';
|
||||
break;
|
||||
case K_KP_MINUS:
|
||||
key = '-';
|
||||
break;
|
||||
case K_KP_PLUS:
|
||||
key = '+';
|
||||
break;
|
||||
case K_KP_HOME:
|
||||
key = '7';
|
||||
break;
|
||||
case K_KP_UPARROW:
|
||||
key = '8';
|
||||
break;
|
||||
case K_KP_PGUP:
|
||||
key = '9';
|
||||
break;
|
||||
case K_KP_LEFTARROW:
|
||||
key = '4';
|
||||
break;
|
||||
case K_KP_5:
|
||||
key = '5';
|
||||
break;
|
||||
case K_KP_RIGHTARROW:
|
||||
key = '6';
|
||||
break;
|
||||
case K_KP_END:
|
||||
key = '1';
|
||||
break;
|
||||
case K_KP_DOWNARROW:
|
||||
key = '2';
|
||||
break;
|
||||
case K_KP_PGDN:
|
||||
key = '3';
|
||||
break;
|
||||
case K_KP_INS:
|
||||
key = '0';
|
||||
break;
|
||||
case K_KP_DEL:
|
||||
key = '.';
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue