mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 06:20:48 +00:00
iKeyhandler repariert
This commit is contained in:
parent
21378405a0
commit
e2517990b7
2 changed files with 136 additions and 55 deletions
|
@ -26,7 +26,7 @@ key up events are sent even if in console mode
|
|||
*/
|
||||
|
||||
|
||||
#define MAXCMDLINE 256
|
||||
#define MAXCMDLINE 512
|
||||
char key_lines[32][MAXCMDLINE];
|
||||
int key_linepos;
|
||||
int shift_down=false;
|
||||
|
@ -91,12 +91,6 @@ keyname_t keynames[] =
|
|||
{"MOUSE4", K_MOUSE4},
|
||||
{"MOUSE5", K_MOUSE5},
|
||||
|
||||
|
||||
{"JOY1", K_JOY1},
|
||||
{"JOY2", K_JOY2},
|
||||
{"JOY3", K_JOY3},
|
||||
{"JOY4", K_JOY4},
|
||||
|
||||
{"AUX1", K_AUX1},
|
||||
{"AUX2", K_AUX2},
|
||||
{"AUX3", K_AUX3},
|
||||
|
@ -179,7 +173,7 @@ void CompleteCommand (void)
|
|||
{
|
||||
key_lines[edit_line][1] = '/';
|
||||
strcpy (key_lines[edit_line]+2, cmd);
|
||||
key_linepos = strlen(cmd)+2;
|
||||
key_linepos = (int)strlen(cmd)+2;
|
||||
key_lines[edit_line][key_linepos] = ' ';
|
||||
key_linepos++;
|
||||
key_lines[edit_line][key_linepos] = 0;
|
||||
|
@ -256,9 +250,9 @@ void Key_Console (int key)
|
|||
|
||||
strtok( cbd, "\n\r\b" );
|
||||
|
||||
i = strlen( cbd );
|
||||
if ( i + key_linepos >= MAXCMDLINE)
|
||||
i= MAXCMDLINE - key_linepos;
|
||||
i = (int)strlen( cbd );
|
||||
if ( i + key_linepos >= MAXCMDLINE - 1)
|
||||
i= MAXCMDLINE - key_linepos - 1;
|
||||
|
||||
if ( i > 0 )
|
||||
{
|
||||
|
@ -306,13 +300,36 @@ void Key_Console (int key)
|
|||
return;
|
||||
}
|
||||
|
||||
if ( ( key == K_BACKSPACE ) || ( key == K_LEFTARROW ) || ( key == K_KP_LEFTARROW ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
|
||||
if ( key == K_LEFTARROW )
|
||||
{
|
||||
if (key_linepos > 1)
|
||||
key_linepos--;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_RIGHTARROW)
|
||||
{
|
||||
if (key_lines[edit_line][key_linepos])
|
||||
key_linepos++;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( key == K_BACKSPACE ) || ( ( key == 'h' ) && ( keydown[K_CTRL] ) ) )
|
||||
{
|
||||
if (key_linepos > 1)
|
||||
{
|
||||
memmove (key_lines[edit_line] + key_linepos-1, key_lines[edit_line] + key_linepos, sizeof(key_lines[edit_line])-key_linepos);
|
||||
key_linepos--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ( key == K_DEL )
|
||||
{
|
||||
memmove (key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1, sizeof(key_lines[edit_line])-key_linepos-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( key == K_UPARROW ) || ( key == K_KP_UPARROW ) ||
|
||||
( ( key == 'p' ) && keydown[K_CTRL] ) )
|
||||
{
|
||||
|
@ -324,7 +341,7 @@ void Key_Console (int key)
|
|||
if (history_line == edit_line)
|
||||
history_line = (edit_line+1)&31;
|
||||
strcpy(key_lines[edit_line], key_lines[history_line]);
|
||||
key_linepos = strlen(key_lines[edit_line]);
|
||||
key_linepos = (int)strlen(key_lines[edit_line]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -346,7 +363,7 @@ void Key_Console (int key)
|
|||
else
|
||||
{
|
||||
strcpy(key_lines[edit_line], key_lines[history_line]);
|
||||
key_linepos = strlen(key_lines[edit_line]);
|
||||
key_linepos = (int)strlen(key_lines[edit_line]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -367,13 +384,19 @@ void Key_Console (int key)
|
|||
|
||||
if (key == K_HOME || key == K_KP_HOME )
|
||||
{
|
||||
con.display = con.current - con.totallines + 10;
|
||||
if (keydown[K_CTRL])
|
||||
con.display = con.current - con.totallines + 10;
|
||||
else
|
||||
key_linepos = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_END || key == K_KP_END )
|
||||
{
|
||||
con.display = con.current;
|
||||
if (keydown[K_CTRL])
|
||||
con.display = con.current;
|
||||
else
|
||||
key_linepos = (int)strlen(key_lines[edit_line]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -382,11 +405,24 @@ void Key_Console (int key)
|
|||
|
||||
if (key_linepos < MAXCMDLINE-1)
|
||||
{
|
||||
int last;
|
||||
int length;
|
||||
|
||||
length = strlen(key_lines[edit_line]);
|
||||
|
||||
if (length >= MAXCMDLINE-1)
|
||||
return;
|
||||
|
||||
last = key_lines[edit_line][key_linepos];
|
||||
|
||||
memmove (key_lines[edit_line] + key_linepos+1, key_lines[edit_line] + key_linepos, length - key_linepos);
|
||||
|
||||
key_lines[edit_line][key_linepos] = key;
|
||||
key_linepos++;
|
||||
key_lines[edit_line][key_linepos] = 0;
|
||||
}
|
||||
|
||||
if (!last)
|
||||
key_lines[edit_line][key_linepos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -394,9 +430,11 @@ void Key_Console (int key)
|
|||
qboolean chat_team;
|
||||
char chat_buffer[MAXCMDLINE];
|
||||
int chat_bufferlen = 0;
|
||||
int chat_cursorpos = 0;
|
||||
|
||||
void Key_Message (int key)
|
||||
{
|
||||
char last;
|
||||
|
||||
if ( key == K_ENTER || key == K_KP_ENTER )
|
||||
{
|
||||
|
@ -410,35 +448,85 @@ void Key_Message (int key)
|
|||
cls.key_dest = key_game;
|
||||
chat_bufferlen = 0;
|
||||
chat_buffer[0] = 0;
|
||||
chat_cursorpos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_ESCAPE)
|
||||
{
|
||||
cls.key_dest = key_game;
|
||||
chat_cursorpos = 0;
|
||||
chat_bufferlen = 0;
|
||||
chat_buffer[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_BACKSPACE)
|
||||
{
|
||||
if (chat_cursorpos)
|
||||
{
|
||||
memmove (chat_buffer + chat_cursorpos - 1, chat_buffer + chat_cursorpos, chat_bufferlen - chat_cursorpos + 1);
|
||||
chat_cursorpos--;
|
||||
chat_bufferlen--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_DEL)
|
||||
{
|
||||
if (chat_bufferlen && chat_cursorpos != chat_bufferlen)
|
||||
{
|
||||
memmove (chat_buffer + chat_cursorpos, chat_buffer + chat_cursorpos + 1, chat_bufferlen - chat_cursorpos + 1);
|
||||
chat_bufferlen--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_LEFTARROW)
|
||||
{
|
||||
if (chat_cursorpos > 0)
|
||||
chat_cursorpos--;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_HOME)
|
||||
{
|
||||
chat_cursorpos = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_END)
|
||||
{
|
||||
chat_cursorpos = chat_bufferlen;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == K_RIGHTARROW)
|
||||
{
|
||||
if (chat_buffer[chat_cursorpos])
|
||||
chat_cursorpos++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (key < 32 || key > 127)
|
||||
return; // non printable
|
||||
|
||||
if (key == K_BACKSPACE)
|
||||
{
|
||||
if (chat_bufferlen)
|
||||
{
|
||||
chat_bufferlen--;
|
||||
chat_buffer[chat_bufferlen] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (chat_bufferlen == sizeof(chat_buffer)-1)
|
||||
return; // all full
|
||||
|
||||
chat_buffer[chat_bufferlen++] = key;
|
||||
chat_buffer[chat_bufferlen] = 0;
|
||||
memmove (chat_buffer + chat_cursorpos + 1, chat_buffer + chat_cursorpos, chat_bufferlen - chat_cursorpos + 1);
|
||||
|
||||
last = chat_buffer[chat_cursorpos];
|
||||
|
||||
chat_buffer[chat_cursorpos] = key;
|
||||
|
||||
chat_bufferlen++;
|
||||
chat_cursorpos++;
|
||||
|
||||
if (!last)
|
||||
{
|
||||
chat_buffer[chat_cursorpos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -464,7 +552,7 @@ int Key_StringToKeynum (char *str)
|
|||
|
||||
for (kn=keynames ; kn->name ; kn++)
|
||||
{
|
||||
if (!Q_strcasecmp(str,kn->name))
|
||||
if (!Q_stricmp(str,kn->name))
|
||||
return kn->keynum;
|
||||
}
|
||||
return -1;
|
||||
|
@ -482,14 +570,13 @@ FIXME: handle quote special (general escape sequence?)
|
|||
char *Key_KeynumToString (int keynum)
|
||||
{
|
||||
keyname_t *kn;
|
||||
static char tinystr[2];
|
||||
static char tinystr[2] = {0};
|
||||
|
||||
if (keynum == -1)
|
||||
return "<KEY NOT FOUND>";
|
||||
if (keynum > 32 && keynum < 127)
|
||||
{ // printable ascii
|
||||
tinystr[0] = keynum;
|
||||
tinystr[1] = 0;
|
||||
return tinystr;
|
||||
}
|
||||
|
||||
|
@ -514,14 +601,14 @@ void Key_SetBinding (int keynum, char *binding)
|
|||
if (keynum == -1)
|
||||
return;
|
||||
|
||||
// free old bindings
|
||||
// free old bindings
|
||||
if (keybindings[keynum])
|
||||
{
|
||||
Z_Free (keybindings[keynum]);
|
||||
keybindings[keynum] = NULL;
|
||||
}
|
||||
|
||||
// allocate memory for new binding
|
||||
// allocate memory for new binding
|
||||
l = strlen (binding);
|
||||
new = Z_Malloc (l+1);
|
||||
strcpy (new, binding);
|
||||
|
@ -597,7 +684,7 @@ void Key_Bind_f (void)
|
|||
return;
|
||||
}
|
||||
|
||||
// copy the rest of the command line
|
||||
// copy the rest of the command line
|
||||
cmd[0] = 0; // start out with a null string
|
||||
for (i=2 ; i< c ; i++)
|
||||
{
|
||||
|
@ -658,9 +745,9 @@ void Key_Init (void)
|
|||
}
|
||||
key_linepos = 1;
|
||||
|
||||
//
|
||||
// init ascii characters in console mode
|
||||
//
|
||||
//
|
||||
// init ascii characters in console mode
|
||||
//
|
||||
for (i=32 ; i<128 ; i++)
|
||||
consolekeys[i] = true;
|
||||
consolekeys[K_ENTER] = true;
|
||||
|
@ -694,6 +781,7 @@ void Key_Init (void)
|
|||
|
||||
consolekeys['`'] = false;
|
||||
consolekeys['~'] = false;
|
||||
consolekeys['^'] = false;
|
||||
|
||||
for (i=0 ; i<K_LAST ; i++)
|
||||
keyshift[i] = i;
|
||||
|
@ -725,9 +813,9 @@ void Key_Init (void)
|
|||
for (i=0 ; i<12 ; i++)
|
||||
menubound[K_F1+i] = true;
|
||||
|
||||
//
|
||||
// register our functions
|
||||
//
|
||||
//
|
||||
// register our functions
|
||||
//
|
||||
Cmd_AddCommand ("bind",Key_Bind_f);
|
||||
Cmd_AddCommand ("unbind",Key_Unbind_f);
|
||||
Cmd_AddCommand ("unbindall",Key_Unbindall_f);
|
||||
|
@ -759,7 +847,7 @@ void Key_Event (int key, qboolean down, unsigned time)
|
|||
if (down)
|
||||
{
|
||||
key_repeats[key]++;
|
||||
if (key != K_BACKSPACE
|
||||
if (cls.key_dest != key_console && key != K_BACKSPACE && key != K_DEL && key != K_LEFTARROW && key != K_RIGHTARROW
|
||||
&& key != K_PAUSE
|
||||
&& key != K_PGUP
|
||||
&& key != K_KP_PGUP
|
||||
|
@ -780,7 +868,7 @@ void Key_Event (int key, qboolean down, unsigned time)
|
|||
shift_down = down;
|
||||
|
||||
// console key is hardcoded, so the user can never unbind it
|
||||
if (key == '^' || key == '~')
|
||||
if (key == '^' || key == '~' || key == '`')
|
||||
{
|
||||
if (!down)
|
||||
return;
|
||||
|
@ -863,9 +951,9 @@ void Key_Event (int key, qboolean down, unsigned time)
|
|||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// if not a consolekey, send to the interpreter no matter what mode is
|
||||
//
|
||||
//
|
||||
// if not a consolekey, send to the interpreter no matter what mode is
|
||||
//
|
||||
if ( (cls.key_dest == key_menu && menubound[key])
|
||||
|| (cls.key_dest == key_console && !consolekeys[key])
|
||||
|| (cls.key_dest == key_game && ( cls.state == ca_active || !consolekeys[key] ) ) )
|
||||
|
|
|
@ -82,14 +82,6 @@ enum QKEYS {
|
|||
K_MOUSE4 = 241,
|
||||
K_MOUSE5 = 242,
|
||||
|
||||
//
|
||||
// joystick buttons
|
||||
//
|
||||
K_JOY1 = 203,
|
||||
K_JOY2 = 204,
|
||||
K_JOY3 = 205,
|
||||
K_JOY4 = 206,
|
||||
|
||||
//
|
||||
// aux keys are for multi-buttoned joysticks to generate so they can use
|
||||
// the normal binding process
|
||||
|
@ -141,6 +133,7 @@ extern int key_repeats[K_LAST];
|
|||
extern int anykeydown;
|
||||
extern char chat_buffer[];
|
||||
extern int chat_bufferlen;
|
||||
extern int chat_cursorpos;
|
||||
extern qboolean chat_team;
|
||||
|
||||
void Key_Event (int key, qboolean down, unsigned time);
|
||||
|
|
Loading…
Reference in a new issue