X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=keys.c;h=fce61a985fcffcb512d82d9af5ca54ef5f084488;hb=afbba9cc46d256b621f8d0e73dc10f4ea88be166;hp=8ccd5de0fdb3129585370788037f8e9f72af294d;hpb=68809d17b6e8920a745bf72b29a0b44f222e5462;p=xonotic%2Fdarkplaces.git diff --git a/keys.c b/keys.c index 8ccd5de0..fce61a98 100644 --- a/keys.c +++ b/keys.c @@ -233,7 +233,7 @@ Interactive line editing and console scrollback ==================== */ static void -Key_Console (int key, char ascii) +Key_Console (int key, int ascii) { // LordHavoc: copied most of this from Q2 to improve keyboard handling switch (key) @@ -523,19 +523,22 @@ Key_Console (int key, char ascii) //============================================================================ -qboolean chat_team; +int chat_mode; char chat_buffer[MAX_INPUTLINE]; unsigned int chat_bufferlen = 0; extern int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos); static void -Key_Message (int key, char ascii) +Key_Message (int key, int ascii) { if (key == K_ENTER || ascii == 10 || ascii == 13) { - Cmd_ForwardStringToServer(va("%s %s", chat_team ? "say_team" : "say ", chat_buffer)); + if(chat_mode < 0) + Cmd_ExecuteString(chat_buffer, src_command); // not Cbuf_AddText to allow semiclons in args; however, this allows no variables then. Use aliases! + else + Cmd_ForwardStringToServer(va("%s %s", chat_mode ? "say_team" : "say ", chat_buffer)); key_dest = key_game; chat_bufferlen = 0; @@ -543,6 +546,8 @@ Key_Message (int key, char ascii) return; } + // TODO add support for arrow keys and simple editing + if (key == K_ESCAPE) { key_dest = key_game; chat_bufferlen = 0; @@ -900,7 +905,7 @@ static char tbl_keyascii[MAX_KEYS]; static keydest_t tbl_keydest[MAX_KEYS]; void -Key_Event (int key, char ascii, qboolean down) +Key_Event (int key, int ascii, qboolean down) { const char *bind; qboolean q; @@ -960,89 +965,111 @@ Key_Event (int key, char ascii, qboolean down) // ignore key repeats on escape if (keydown[key] > 1) return; + // escape does these things: // key_consoleactive - close console // key_message - abort messagemode // key_menu - go to parent menu (or key_game) // key_game - open menu + // in all modes shift-escape toggles console - if (((key_consoleactive & KEY_CONSOLEACTIVE_USER) || keydown[K_SHIFT]) && down) + if (keydown[K_SHIFT]) { - Con_ToggleConsole_f (); - tbl_keydest[key] = key_void; // ignore the release + if(down) + { + Con_ToggleConsole_f (); + tbl_keydest[key] = key_void; // esc release should go nowhere (especially not to key_menu or key_game) + } return; } -#if 0 + switch (keydest) { + case key_console: + if(down) + { + if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED) + { + key_consoleactive &= ~KEY_CONSOLEACTIVE_USER; + MR_ToggleMenu_f (); + } + else + Con_ToggleConsole_f(); + } + break; + case key_message: if (down) - Key_Message (key, ascii); + Key_Message (key, ascii); // that'll close the message input break; + case key_menu: case key_menu_grabbed: MR_KeyEvent (key, ascii, down); break; + case key_game: // csqc has priority over toggle menu if it wants to (e.g. handling escape for UI stuff in-game.. :sick:) q = CL_VM_InputEvent(down, key, ascii); if (!q && down) MR_ToggleMenu_f (); break; + default: Con_Printf ("Key_Event: Bad key_dest\n"); } return; -#endif } // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys) if (keydest != key_menu_grabbed) - if (key >= K_F1 && key <= K_F12 && down) + if (key >= K_F1 && key <= K_F12) { - // ignore key repeats on F1-F12 binds - if (keydown[key] > 1) - return; if (bind) { - // button commands add keynum as a parm - if (bind[0] == '+') - Cbuf_AddText (va("%s %i\n", bind, key)); - else + if(keydown[key] == 1 && down) { - Cbuf_AddText (bind); - Cbuf_AddText ("\n"); - } + // button commands add keynum as a parm + if (bind[0] == '+') + Cbuf_AddText (va("%s %i\n", bind, key)); + else + { + Cbuf_AddText (bind); + Cbuf_AddText ("\n"); + } + } else if(bind[0] == '+' && !down && keydown[key] == 0) + Cbuf_AddText(va("-%s %i\n", bind + 1, key)); } return; } -#if 0 - // ignore binds (other than the above escape/F1-F12 keys) while in console - if (key_consoleactive && down) -#else - // respond to toggleconsole binds while in console unless the pressed key - // happens to be the color prefix character (such as on German keyboards) - if (keydest == key_console && key_consoleactive && (!con_closeontoggleconsole.integer || !bind || strncmp(bind, "toggleconsole", strlen("toggleconsole")) || ascii == STRING_COLOR_TAG)) -#endif + // send input to console if it wants it + if (keydest == key_console) { - if(down) - Key_Console (key, ascii); + if (!down) + return; + // con_closeontoggleconsole enables toggleconsole keys to close the + // console, as long as they are not the color prefix character + // (special exemption for german keyboard layouts) + if (con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && (key_consoleactive & KEY_CONSOLEACTIVE_USER) && ascii != STRING_COLOR_TAG) + { + Con_ToggleConsole_f (); + return; + } + Key_Console (key, ascii); return; } - - // FIXME: actually the up-bind should only be called if the button was actually pressed while key_dest == key_game [12/17/2007 Black] - // especially CL_VM_InputEvent should be able to prevent it from being called (to intercept the binds) - // key up events only generate commands if the game key binding is a button - // command (leading + sign). These will occur even in console mode, to - // keep the character from continuing an action started before a console - // switch. Button commands include the kenum as a parameter, so multiple - // downs can be matched with ups - /* - if (!down && bind && bind[0] == '+') - Cbuf_AddText(va("-%s %i\n", bind + 1, key)); - */ + // handle toggleconsole in menu too + if (keydest == key_menu) + { + if (down && con_closeontoggleconsole.integer && bind && !strncmp(bind, "toggleconsole", strlen("toggleconsole")) && ascii != STRING_COLOR_TAG) + { + Con_ToggleConsole_f (); + tbl_keydest[key] = key_void; // key release should go nowhere (especially not to key_menu or key_game) + return; + } + } // ignore binds while a video is played, let the video system handle the key event if (cl_videoplaying) @@ -1081,11 +1108,6 @@ Key_Event (int key, char ascii, qboolean down) Cbuf_AddText(va("-%s %i\n", bind + 1, key)); } break; - case key_console: - // This happens for example when pressing shift in the console - // closing the console, and then releasing shift. - // Con_Printf("Key_Event: Console key ignored\n"); - break; default: Con_Printf ("Key_Event: Bad key_dest\n"); }