mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-23 12:21:07 +00:00
Implement support for native keyboard layout
This commit is contained in:
parent
2c689bae52
commit
95d7a486ee
5 changed files with 60 additions and 27 deletions
|
@ -924,7 +924,7 @@ boolean CON_Responder(event_t *ev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// let go keyup events, don't eat them
|
// let go keyup events, don't eat them
|
||||||
if (ev->type != ev_keydown && ev->type != ev_console)
|
if (ev->type != ev_keydown && ev->type != ev_text && ev->type != ev_console)
|
||||||
{
|
{
|
||||||
if (ev->key == gamecontrol[GC_CONSOLE][0] || ev->key == gamecontrol[GC_CONSOLE][1])
|
if (ev->key == gamecontrol[GC_CONSOLE][0] || ev->key == gamecontrol[GC_CONSOLE][1])
|
||||||
consdown = false;
|
consdown = false;
|
||||||
|
@ -951,7 +951,7 @@ boolean CON_Responder(event_t *ev)
|
||||||
// check other keys only if console prompt is active
|
// check other keys only if console prompt is active
|
||||||
if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check!!
|
if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check!!
|
||||||
{
|
{
|
||||||
if (! menuactive && bindtable[key])
|
if (!menuactive && bindtable[key])
|
||||||
{
|
{
|
||||||
COM_BufAddText(bindtable[key]);
|
COM_BufAddText(bindtable[key]);
|
||||||
COM_BufAddText("\n");
|
COM_BufAddText("\n");
|
||||||
|
@ -968,6 +968,12 @@ boolean CON_Responder(event_t *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev->type == ev_text)
|
||||||
|
{
|
||||||
|
CON_InputAddChar(key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Always eat ctrl/shift/alt if console open, so the menu doesn't get ideas
|
// Always eat ctrl/shift/alt if console open, so the menu doesn't get ideas
|
||||||
if (key == KEY_LSHIFT || key == KEY_RSHIFT
|
if (key == KEY_LSHIFT || key == KEY_RSHIFT
|
||||||
|| key == KEY_LCTRL || key == KEY_RCTRL
|
|| key == KEY_LCTRL || key == KEY_RCTRL
|
||||||
|
@ -1304,21 +1310,12 @@ boolean CON_Responder(event_t *ev)
|
||||||
else if (key == KEY_KPADSLASH)
|
else if (key == KEY_KPADSLASH)
|
||||||
key = '/';
|
key = '/';
|
||||||
|
|
||||||
if (key >= 'a' && key <= 'z')
|
|
||||||
{
|
|
||||||
if (capslock ^ shiftdown)
|
|
||||||
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)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (input_sel != input_cur)
|
if (input_sel != input_cur)
|
||||||
CON_InputDelSelection();
|
CON_InputDelSelection();
|
||||||
CON_InputAddChar(key);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ typedef enum
|
||||||
{
|
{
|
||||||
ev_keydown,
|
ev_keydown,
|
||||||
ev_keyup,
|
ev_keyup,
|
||||||
|
ev_text,
|
||||||
ev_console,
|
ev_console,
|
||||||
ev_mouse,
|
ev_mouse,
|
||||||
ev_joystick,
|
ev_joystick,
|
||||||
|
|
|
@ -190,19 +190,19 @@ void D_ProcessEvents(void)
|
||||||
ev = &events[eventtail];
|
ev = &events[eventtail];
|
||||||
|
|
||||||
// Set mouse buttons early in case event is eaten later
|
// Set mouse buttons early in case event is eaten later
|
||||||
if (ev->type == ev_keydown || ev->type == ev_keyup)
|
if (ev->type == ev_keydown || ev->type == ev_keyup || ev->type == ev_text)
|
||||||
{
|
{
|
||||||
// Mouse buttons
|
// Mouse buttons
|
||||||
if ((UINT32)(ev->key - KEY_MOUSE1) < MOUSEBUTTONS)
|
if ((UINT32)(ev->key - KEY_MOUSE1) < MOUSEBUTTONS)
|
||||||
{
|
{
|
||||||
if (ev->type == ev_keydown)
|
if (ev->type == ev_keydown || ev->type == ev_text)
|
||||||
mouse.buttons |= 1 << (ev->key - KEY_MOUSE1);
|
mouse.buttons |= 1 << (ev->key - KEY_MOUSE1);
|
||||||
else
|
else
|
||||||
mouse.buttons &= ~(1 << (ev->key - KEY_MOUSE1));
|
mouse.buttons &= ~(1 << (ev->key - KEY_MOUSE1));
|
||||||
}
|
}
|
||||||
else if ((UINT32)(ev->key - KEY_2MOUSE1) < MOUSEBUTTONS)
|
else if ((UINT32)(ev->key - KEY_2MOUSE1) < MOUSEBUTTONS)
|
||||||
{
|
{
|
||||||
if (ev->type == ev_keydown)
|
if (ev->type == ev_keydown || ev->type == ev_text)
|
||||||
mouse2.buttons |= 1 << (ev->key - KEY_2MOUSE1);
|
mouse2.buttons |= 1 << (ev->key - KEY_2MOUSE1);
|
||||||
else
|
else
|
||||||
mouse2.buttons &= ~(1 << (ev->key - KEY_2MOUSE1));
|
mouse2.buttons &= ~(1 << (ev->key - KEY_2MOUSE1));
|
||||||
|
|
|
@ -77,6 +77,7 @@ patch_t *nto_font[NT_FONTSIZE];
|
||||||
|
|
||||||
static player_t *plr;
|
static player_t *plr;
|
||||||
boolean chat_on; // entering a chat message?
|
boolean chat_on; // entering a chat message?
|
||||||
|
boolean chat_on_first_event; // blocker for first chat input event
|
||||||
static char w_chat[HU_MAXMSGLEN + 1];
|
static char w_chat[HU_MAXMSGLEN + 1];
|
||||||
static size_t c_input = 0; // let's try to make the chat input less shitty.
|
static size_t c_input = 0; // let's try to make the chat input less shitty.
|
||||||
static boolean headsupactive = false;
|
static boolean headsupactive = false;
|
||||||
|
@ -1047,7 +1048,7 @@ boolean HU_Responder(event_t *ev)
|
||||||
INT32 c=0;
|
INT32 c=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ev->type != ev_keydown)
|
if (ev->type != ev_keydown && ev->type != ev_text)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// only KeyDown events now...
|
// only KeyDown events now...
|
||||||
|
@ -1077,11 +1078,15 @@ boolean HU_Responder(event_t *ev)
|
||||||
|
|
||||||
if (!chat_on)
|
if (!chat_on)
|
||||||
{
|
{
|
||||||
|
if (ev->type == ev_text)
|
||||||
|
return false;
|
||||||
|
|
||||||
// enter chat mode
|
// enter chat mode
|
||||||
if ((ev->key == gamecontrol[GC_TALKKEY][0] || ev->key == gamecontrol[GC_TALKKEY][1])
|
if ((ev->key == gamecontrol[GC_TALKKEY][0] || ev->key == gamecontrol[GC_TALKKEY][1])
|
||||||
&& netgame && !OLD_MUTE) // check for old chat mute, still let the players open the chat incase they want to scroll otherwise.
|
&& netgame && !OLD_MUTE) // check for old chat mute, still let the players open the chat incase they want to scroll otherwise.
|
||||||
{
|
{
|
||||||
chat_on = true;
|
chat_on = true;
|
||||||
|
chat_on_first_event = false;
|
||||||
w_chat[0] = 0;
|
w_chat[0] = 0;
|
||||||
teamtalk = false;
|
teamtalk = false;
|
||||||
chat_scrollmedown = true;
|
chat_scrollmedown = true;
|
||||||
|
@ -1092,6 +1097,7 @@ boolean HU_Responder(event_t *ev)
|
||||||
&& netgame && !OLD_MUTE)
|
&& netgame && !OLD_MUTE)
|
||||||
{
|
{
|
||||||
chat_on = true;
|
chat_on = true;
|
||||||
|
chat_on_first_event = false;
|
||||||
w_chat[0] = 0;
|
w_chat[0] = 0;
|
||||||
teamtalk = G_GametypeHasTeams(); // Don't teamtalk if we don't have teams.
|
teamtalk = G_GametypeHasTeams(); // Don't teamtalk if we don't have teams.
|
||||||
chat_scrollmedown = true;
|
chat_scrollmedown = true;
|
||||||
|
@ -1101,6 +1107,31 @@ boolean HU_Responder(event_t *ev)
|
||||||
}
|
}
|
||||||
else // if chat_on
|
else // if chat_on
|
||||||
{
|
{
|
||||||
|
if (!chat_on_first_event)
|
||||||
|
{
|
||||||
|
// since the text event is sent immediately after the keydown event,
|
||||||
|
// we need to make sure that nothing is displayed once the chat
|
||||||
|
// opens, otherwise a 't' would be outputted.
|
||||||
|
chat_on_first_event = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev->type == ev_text)
|
||||||
|
{
|
||||||
|
if ((c < HU_FONTSTART || c > HU_FONTEND || !hu_font[c-HU_FONTSTART])
|
||||||
|
&& c != ' ') // Allow spaces, of course
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
memmove(&w_chat[c_input + 1], &w_chat[c_input], strlen(w_chat) - c_input + 1);
|
||||||
|
w_chat[c_input] = c;
|
||||||
|
c_input++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore modifier keys
|
// Ignore modifier keys
|
||||||
// Note that we do this here so users can still set
|
// Note that we do this here so users can still set
|
||||||
|
@ -1110,8 +1141,6 @@ boolean HU_Responder(event_t *ev)
|
||||||
|| ev->key == KEY_LALT || ev->key == KEY_RALT)
|
|| ev->key == KEY_LALT || ev->key == KEY_RALT)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
c = (INT32)ev->key;
|
|
||||||
|
|
||||||
// I know this looks very messy but this works. If it ain't broke, don't fix it!
|
// I know this looks very messy but this works. If it ain't broke, don't fix it!
|
||||||
// shift LETTERS to uppercase if we have capslock or are holding shift
|
// shift LETTERS to uppercase if we have capslock or are holding shift
|
||||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||||
|
@ -1194,16 +1223,6 @@ boolean HU_Responder(event_t *ev)
|
||||||
else
|
else
|
||||||
c_input++;
|
c_input++;
|
||||||
}
|
}
|
||||||
else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font[c-HU_FONTSTART])
|
|
||||||
|| c == ' ') // Allow spaces, of course
|
|
||||||
{
|
|
||||||
if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
memmove(&w_chat[c_input + 1], &w_chat[c_input], strlen(w_chat) - c_input + 1);
|
|
||||||
w_chat[c_input] = c;
|
|
||||||
c_input++;
|
|
||||||
}
|
|
||||||
else if (c == KEY_BACKSPACE)
|
else if (c == KEY_BACKSPACE)
|
||||||
{
|
{
|
||||||
if (CHAT_MUTE || c_input <= 0)
|
if (CHAT_MUTE || c_input <= 0)
|
||||||
|
|
|
@ -686,6 +686,19 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
|
||||||
if (event.key) D_PostEvent(&event);
|
if (event.key) D_PostEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Impl_HandleTextEvent(SDL_TextInputEvent evt)
|
||||||
|
{
|
||||||
|
event_t event;
|
||||||
|
event.type = ev_text;
|
||||||
|
if (evt.text[1] != '\0')
|
||||||
|
{
|
||||||
|
// limit ourselves to ASCII for now, we can add UTF-8 support later
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.key = evt.text[0];
|
||||||
|
D_PostEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
|
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
|
||||||
{
|
{
|
||||||
static boolean firstmove = true;
|
static boolean firstmove = true;
|
||||||
|
@ -934,6 +947,9 @@ void I_GetEvent(void)
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
Impl_HandleKeyboardEvent(evt.key, evt.type);
|
Impl_HandleKeyboardEvent(evt.key, evt.type);
|
||||||
break;
|
break;
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
Impl_HandleTextEvent(evt.text);
|
||||||
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
//if (!mouseMotionOnce)
|
//if (!mouseMotionOnce)
|
||||||
Impl_HandleMouseMotionEvent(evt.motion);
|
Impl_HandleMouseMotionEvent(evt.motion);
|
||||||
|
|
Loading…
Reference in a new issue