]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
- fix a bug in Quake menu when in_bindmap was not "0 0"
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 4 Jul 2010 19:48:53 +0000 (19:48 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 4 Jul 2010 19:48:53 +0000 (19:48 +0000)
- key bind editing QC builtins: add an optional second argument of the bindmap number to query

From: Rudolf Polzer <divverent@alientrap.org>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10270 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
keys.c
keys.h
menu.c
mvm_cmds.c
prvm_cmds.c

index cd2588ed7d814bfce50049a78fc33ecfb34d8aa1..bcbcdb54d7e08cd47f68c8322de6a9a13dd4a32b 100644 (file)
@@ -4325,7 +4325,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)
@@ -4505,7 +4505,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 5339881f2070001662c561932dc0fad544bcdeda..981e2f24d7bf71d75e04167ac6185dd2fce3a77b 100644 (file)
--- 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 c270282b1e75cca6b1ba82ce7ff0c5c768032a28..cd95805e921e0bdd6c2b818302f9c4646a4adcca 100644 (file)
--- 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 444fc0c57a610e0ac2f6156ebeaf1b21f097aa51..c9e8d1fa4801a28e58be71c3ffeada3166ac2ce0 100644 (file)
--- 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]);
index 49873b134757495a6787637c4c6fa8fd74a4d544..3bb9a651a9770f04682382ed32376e12438f411a 100644 (file)
@@ -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)
index 380d81e551c6c5b393039317e311d17541c2a7d3..2ddf0afbdffeebbd257fcb91c48bce879bb5ee9f 100644 (file)
@@ -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