From 42dcd49b08554411f024b8e4bbca670a78186ea5 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 4 Jul 2010 19:48:53 +0000 Subject: [PATCH] - fix a bug in Quake menu when in_bindmap was not "0 0" - key bind editing QC builtins: add an optional second argument of the bindmap number to query From: Rudolf Polzer git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10270 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=ae7512c307941f96c1ec6506a63bbf48a1e1069f --- clvm_cmds.c | 4 ++-- keys.c | 40 ++++++++++++++++++++++++++++++++++++---- keys.h | 3 +++ menu.c | 29 ++--------------------------- mvm_cmds.c | 4 ++-- prvm_cmds.c | 27 ++++++++++++++++++--------- 6 files changed, 63 insertions(+), 44 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 8614a121..9e138d14 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -4327,7 +4327,7 @@ VM_centerprint, // #338 void(string s, ...) centerprint (EXT_CSQC) VM_print, // #339 void(string s, ...) print (EXT_CSQC, DP_SV_PRINT) VM_keynumtostring, // #340 string(float keynum) keynumtostring (EXT_CSQC) VM_stringtokeynum, // #341 float(string keyname) stringtokeynum (EXT_CSQC) -VM_getkeybind, // #342 string(float keynum) getkeybind (EXT_CSQC) +VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC) VM_CL_setcursormode, // #343 void(float usecursor) setcursormode (EXT_CSQC) VM_CL_getmousepos, // #344 vector() getmousepos (EXT_CSQC) VM_CL_getinputstate, // #345 float(float framenum) getinputstate (EXT_CSQC) @@ -4507,7 +4507,7 @@ VM_buf_cvarlist, // #517 void(float buf, string prefix, string antiprefix) VM_cvar_description, // #518 float(string name) cvar_description = #518; (DP_QC_CVAR_DESCRIPTION) VM_gettime, // #519 float(float timer) gettime = #519; (DP_QC_GETTIME) VM_keynumtostring, // #520 string keynumtostring(float keynum) -VM_findkeysforcommand, // #521 string findkeysforcommand(string command) +VM_findkeysforcommand, // #521 string findkeysforcommand(string command[, float bindmap]) VM_CL_InitParticleSpawner, // #522 void(float max_themes) initparticlespawner (DP_CSQC_SPAWNPARTICLE) VM_CL_ResetParticle, // #523 void() resetparticle (DP_CSQC_SPAWNPARTICLE) VM_CL_ParticleTheme, // #524 void(float theme) particletheme (DP_CSQC_SPAWNPARTICLE) diff --git a/keys.c b/keys.c index 5339881f..981e2f24 100644 --- a/keys.c +++ b/keys.c @@ -1383,17 +1383,49 @@ Key_Shutdown (void) Key_History_Shutdown(); } -const char *Key_GetBind (int key) +const char *Key_GetBind (int key, int bindmap) { const char *bind; if (key < 0 || key >= MAX_KEYS) return NULL; - bind = keybindings[key_bmap][key]; - if (!bind) - bind = keybindings[key_bmap2][key]; + if(bindmap >= 0) + { + bind = keybindings[bindmap][key]; + } + else + { + bind = keybindings[key_bmap][key]; + if (!bind) + bind = keybindings[key_bmap2][key]; + } return bind; } +void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bindmap) +{ + int count; + int j; + char *b; + + for (j = 0;j < numkeys;j++) + keys[j] = -1; + + count = 0; + + for (j = 0; j < MAX_KEYS; ++j) + { + b = Key_GetBind(j, bindmap); + if (!b) + continue; + if (!strcmp (b, command) ) + { + keys[count++] = j; + if (count == numkeys) + break; + } + } +} + qboolean CL_VM_InputEvent (qboolean down, int key, int ascii); /* diff --git a/keys.h b/keys.h index c270282b..cd95805e 100644 --- a/keys.h +++ b/keys.h @@ -349,5 +349,8 @@ void Key_SetBinding (int keynum, int bindmap, const char *binding); void Key_EventQueue_Block(void); void Key_EventQueue_Unblock(void); +const char *Key_GetBind (int key, int bindmap); +void Key_FindKeysForCommand (const char *command, int *keys, int numkeys, int bindmap); + #endif // __KEYS_H diff --git a/menu.c b/menu.c index 444fc0c5..c9e8d1fa 100644 --- a/menu.c +++ b/menu.c @@ -2525,31 +2525,6 @@ void M_Menu_Keys_f (void) #define NUMKEYS 5 -void M_FindKeysForCommand (const char *command, int *keys) -{ - int count; - int j; - char *b; - - for (j = 0;j < NUMKEYS;j++) - keys[j] = -1; - - count = 0; - - for (j = 0; j < (int)sizeof (keybindings[0]) / (int)sizeof (keybindings[0][0]); j++) - { - b = keybindings[0][j]; - if (!b) - continue; - if (!strcmp (b, command) ) - { - keys[count++] = j; - if (count == NUMKEYS) - break; - } - } -} - static void M_UnbindCommand (char *command) { int j; @@ -2599,7 +2574,7 @@ static void M_Keys_Draw (void) else M_Print(16, y, bindnames[i][1]); - M_FindKeysForCommand (bindnames[i][0], keys); + Key_FindKeysForCommand (bindnames[i][0], keys, NUMKEYS, 0); // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer if (keys[0] == -1) @@ -2680,7 +2655,7 @@ static void M_Keys_Key (int k, int ascii) break; case K_ENTER: // go into bind mode - M_FindKeysForCommand (bindnames[keys_cursor][0], keys); + Key_FindKeysForCommand (bindnames[keys_cursor][0], keys, NUMKEYS, 0); S_LocalSound ("sound/misc/menu2.wav"); if (keys[NUMKEYS - 1] != -1) M_UnbindCommand (bindnames[keys_cursor][0]); diff --git a/mvm_cmds.c b/mvm_cmds.c index 49873b13..3bb9a651 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1119,7 +1119,7 @@ NULL, // #338 NULL, // #339 NULL, // #340 NULL, // #341 -VM_getkeybind, // #342 string(float keynum) getkeybind (EXT_CSQC) +VM_getkeybind, // #342 string(float keynum[, float bindmap]) getkeybind (EXT_CSQC) NULL, // #343 NULL, // #344 NULL, // #345 @@ -1387,7 +1387,7 @@ VM_writetofile, // #606 void writetofile(float fhandle, entity ent) VM_isfunction, // #607 float isfunction(string function_name) VM_M_getresolution, // #608 vector getresolution(float number, [float forfullscreen]) VM_keynumtostring, // #609 string keynumtostring(float keynum) -VM_findkeysforcommand, // #610 string findkeysforcommand(string command) +VM_findkeysforcommand, // #610 string findkeysforcommand(string command[, float bindmap]) VM_M_getserverliststat, // #611 float gethostcachevalue(float type) VM_M_getserverliststring, // #612 string gethostcachestring(float type, float hostnr) VM_parseentitydata, // #613 void parseentitydata(entity ent, string data) diff --git a/prvm_cmds.c b/prvm_cmds.c index 3976608f..e1c44f04 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3907,26 +3907,30 @@ string findkeysforcommand(string command) the returned string is an altstring ========= */ -#define NUMKEYS 5 // TODO: merge the constant in keys.c with this one somewhen - +#define FKFC_NUMKEYS 5 void M_FindKeysForCommand(const char *command, int *keys); void VM_findkeysforcommand(void) { const char *cmd; char ret[VM_STRINGTEMP_LENGTH]; - int keys[NUMKEYS]; + int keys[FKFC_NUMKEYS]; int i; + int bindmap; - VM_SAFEPARMCOUNT(1, VM_findkeysforcommand); + VM_SAFEPARMCOUNTRANGE(1, 2, VM_findkeysforcommand); cmd = PRVM_G_STRING(OFS_PARM0); + if(prog->argc == 2) + bindmap = bound(0, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1); + else + bindmap = -1; VM_CheckEmptyString(cmd); - M_FindKeysForCommand(cmd, keys); + Key_FindKeysForCommand(cmd, keys, FKFC_NUMKEYS, bindmap); ret[0] = 0; - for(i = 0; i < NUMKEYS; i++) + for(i = 0; i < FKFC_NUMKEYS; i++) strlcat(ret, va(" \'%i\'", keys[i]), sizeof(ret)); PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(ret); @@ -3953,11 +3957,16 @@ VM_getkeybind string getkeybind(float key) ========= */ -const char *Key_GetBind (int key); void VM_getkeybind (void) { - VM_SAFEPARMCOUNT(1, VM_CL_getkeybind); - PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0))); + int bindmap; + VM_SAFEPARMCOUNTRANGE(1, 2, VM_CL_getkeybind); + if(prog->argc == 2) + bindmap = bound(0, PRVM_G_FLOAT(OFS_PARM1), MAX_BINDMAPS-1); + else + bindmap = -1; + + PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(Key_GetBind((int)PRVM_G_FLOAT(OFS_PARM0), bindmap)); } // CL_Video interface functions -- 2.39.2