X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=keys.c;h=8dffbe90b6a692b587c027c4bc728f7ecfcb8a6c;hb=1d2c0289d043ec7b49e0ff78685e0fd3db806e02;hp=ffaabf8e9bf1d527ad6b247ab757f45a1f8224d1;hpb=2c3544a2e8fc2215253728fea9c53b43e57d46bb;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index ffaabf8e..8dffbe90 100644 --- a/keys.c +++ b/keys.c @@ -414,15 +414,15 @@ Key_Console (int key, char ascii) if (key == K_PGUP || key == K_KP_PGUP || key == K_MWHEELUP) { - con_backscroll += ((int) vid.conheight >> 5); - if (con_backscroll > con_totallines - (vid.conheight>>3) - 1) - con_backscroll = con_totallines - (vid.conheight>>3) - 1; + con_backscroll += ((int) vid_conheight.integer >> 5); + if (con_backscroll > con_totallines - (vid_conheight.integer>>3) - 1) + con_backscroll = con_totallines - (vid_conheight.integer>>3) - 1; return; } if (key == K_PGDN || key == K_KP_PGDN || key == K_MWHEELDOWN) { - con_backscroll -= ((int) vid.conheight >> 5); + con_backscroll -= ((int) vid_conheight.integer >> 5); if (con_backscroll < 0) con_backscroll = 0; return; @@ -430,7 +430,7 @@ Key_Console (int key, char ascii) if (key == K_HOME || key == K_KP_HOME) { - con_backscroll = con_totallines - (vid.conheight>>3) - 1; + con_backscroll = con_totallines - (vid_conheight.integer>>3) - 1; return; } @@ -446,27 +446,17 @@ Key_Console (int key, char ascii) if (key_linepos < MAX_INPUTLINE-1) { - int i; - - if (key_insert) // check insert mode + int len; + len = strlen(&key_lines[edit_line][key_linepos]); + // check insert mode, or always insert if at end of line + if (key_insert || len == 0) { - // can't do strcpy to move string to right - i = strlen(key_lines[edit_line]) - 1; - - if (i == 254) - i--; - - for (; i >= key_linepos; i--) - key_lines[edit_line][i + 1] = key_lines[edit_line][i]; + // can't use strcpy to move string to right + len++; + memmove(&key_lines[edit_line][key_linepos + 1], &key_lines[edit_line][key_linepos], len); } - - // only null terminate if at the end - i = key_lines[edit_line][key_linepos]; key_lines[edit_line][key_linepos] = ascii; key_linepos++; - - if (!i) - key_lines[edit_line][key_linepos] = 0; } } @@ -843,6 +833,116 @@ Should NOT be called during an interrupt! void Key_Event (int key, char ascii, qboolean down) { +#if 1 +#define USERPLAYING() ( !key_consoleactive && key_dest == key_game && (cls.state == ca_connected && cls.signon == SIGNONS) ) + const char *bind; + static qboolean shift_down = false; + + // get key binding + bind = keybindings[ key_bmap ][ key ]; + if( !bind ) { + bind = keybindings[ key_bmap2 ][ key ]; + } + + // set key state + keydown[ key ] = down; + + // update key repeats + if( down ) { + key_repeats[ key ]++; + if( key_repeats[ key ] > 1 ) { + if( (key_consoleactive && !consolekeys[key]) || USERPLAYING() ) + return; // ignore most autorepeats + } + } else { + key_repeats[ key ] = 0; + } + + if( key == K_SHIFT ) { + shift_down = down; + } + + if( !down ) { + if( bind && bind[ 0 ] == '+') { + Cbuf_AddText( va( "-%s %i\n", bind + 1, key) ); + } + } else { + // handle ESCAPE specially, so unbinding wont help + if( key == K_ESCAPE ) { + // shift-escape is a safety measure for users who cant toggle the console otherwise + if( shift_down ) { + Con_ToggleConsole_f(); + return; + } + switch( key_dest ) { + case key_message: + Key_Message( key, ascii ); + break; + case key_menu: + MR_Keydown( key, ascii ); + break; + case key_game: + if (COM_CheckParm ("-demolooponly")) + { + CL_Disconnect (); + return; + } + MR_ToggleMenu_f(); + break; + default: + Sys_Error( "Bad key_dest" ); + } + return; + } + + if( !(key_consoleactive && consolekeys[ key ]) && bind && !strncmp( bind, "toggleconsole", strlen( "toggleconsole" ) ) ) { + Cbuf_AddText( bind ); + Cbuf_AddText( "\n" ); + if( ascii != STRING_COLOR_TAG ) { + return; + } + } else { + // during demo playback, all keys ingame bring up the main menu + if( cls.demoplayback && !key_consoleactive && key_dest == key_game ) { + if (!COM_CheckParm ("-demolooponly")) + MR_ToggleMenu_f (); + return; + } + + // menu bind/function keys or normal binds + if( (key_dest == key_menu && menubound[key]) || USERPLAYING() ) { + if( bind ) { + if( bind[0] == '+' ) { // button commands add keynum as a parm + Cbuf_AddText( va( "%s %i\n", bind, key ) ); + } else { + Cbuf_AddText( bind ); + Cbuf_AddText( "\n" ); + } + } + return; + } + } + + // either console or game state key functions + if( key_consoleactive ) { + Key_Console( key, ascii ); + } else { + switch (key_dest) { + case key_message: + Key_Message( key, ascii ); + break; + case key_menu: + MR_Keydown( key, ascii ); + break; + case key_game: + // unbound key + break; + default: + Sys_Error( "Bad key_dest" ); + } + } + } +#else const char *kb; char cmd[1024]; @@ -877,6 +977,12 @@ Key_Event (int key, char ascii, qboolean down) if (key == K_ESCAPE) { if (!down) return; + // ctrl-escape is a safety measure + if (ctrl_down) + { + Con_ToggleConsole_f (); + return; + } switch (key_dest) { case key_message: Key_Message (key, ascii); @@ -980,6 +1086,7 @@ Key_Event (int key, char ascii, qboolean down) Sys_Error ("Bad key_dest"); } } +#endif } /*