]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - keys.c
only send prydoncursor related buttons, if cl_prydoncursor is 1
[xonotic/darkplaces.git] / keys.c
diff --git a/keys.c b/keys.c
index 6a7eaf20ac961951738a04816df47625943605a5..18765a167e2c0c6c050dd6e915502c858ac1d654 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1085,14 +1085,16 @@ Key_KeynumToString (int keynum)
 }
 
 
-void
+qboolean
 Key_SetBinding (int keynum, int bindmap, const char *binding)
 {
        char *newbinding;
        size_t l;
 
        if (keynum == -1 || keynum >= MAX_KEYS)
-               return;
+               return false;
+       if ((bindmap < 0) || (bindmap >= MAX_BINDMAPS))
+               return false;
 
 // free old bindings
        if (keybindings[bindmap][keynum]) {
@@ -1100,13 +1102,35 @@ Key_SetBinding (int keynum, int bindmap, const char *binding)
                keybindings[bindmap][keynum] = NULL;
        }
        if(!binding[0]) // make "" binds be removed --blub
-               return;
+               return true;
 // allocate memory for new binding
        l = strlen (binding);
        newbinding = (char *)Z_Malloc (l + 1);
        memcpy (newbinding, binding, l + 1);
        newbinding[l] = 0;
        keybindings[bindmap][keynum] = newbinding;
+       return true;
+}
+
+void Key_GetBindMap(int *fg, int *bg)
+{
+       if(fg)
+               *fg = key_bmap;
+       if(bg)
+               *bg = key_bmap2;
+}
+
+qboolean Key_SetBindMap(int fg, int bg)
+{
+       if(fg >= MAX_BINDMAPS)
+               return false;
+       if(bg >= MAX_BINDMAPS)
+               return false;
+       if(fg >= 0)
+               key_bmap = fg;
+       if(bg >= 0)
+               key_bmap2 = bg;
+       return true;
 }
 
 static void
@@ -1121,7 +1145,7 @@ Key_In_Unbind_f (void)
        }
 
        m = strtol(Cmd_Argv (1), &errchar, 0);
-       if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
+       if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
                Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
                return;
        }
@@ -1132,7 +1156,8 @@ Key_In_Unbind_f (void)
                return;
        }
 
-       Key_SetBinding (b, m, "");
+       if(!Key_SetBinding (b, m, ""))
+               Con_Printf("Key_SetBinding failed for unknown reason\n");
 }
 
 static void
@@ -1150,7 +1175,7 @@ Key_In_Bind_f (void)
        }
 
        m = strtol(Cmd_Argv (1), &errchar, 0);
-       if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
+       if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
                Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
                return;
        }
@@ -1176,7 +1201,8 @@ Key_In_Bind_f (void)
                        strlcat (cmd, " ", sizeof (cmd));
        }
 
-       Key_SetBinding (b, m, cmd);
+       if(!Key_SetBinding (b, m, cmd))
+               Con_Printf("Key_SetBinding failed for unknown reason\n");
 }
 
 static void
@@ -1193,13 +1219,13 @@ Key_In_Bindmap_f (void)
        }
 
        m1 = strtol(Cmd_Argv (1), &errchar, 0);
-       if ((m1 < 0) || (m1 >= 8) || (errchar && *errchar)) {
+       if ((m1 < 0) || (m1 >= MAX_BINDMAPS) || (errchar && *errchar)) {
                Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
                return;
        }
 
        m2 = strtol(Cmd_Argv (2), &errchar, 0);
-       if ((m2 < 0) || (m2 >= 8) || (errchar && *errchar)) {
+       if ((m2 < 0) || (m2 >= MAX_BINDMAPS) || (errchar && *errchar)) {
                Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(2));
                return;
        }
@@ -1224,7 +1250,8 @@ Key_Unbind_f (void)
                return;
        }
 
-       Key_SetBinding (b, 0, "");
+       if(!Key_SetBinding (b, 0, ""))
+               Con_Printf("Key_SetBinding failed for unknown reason\n");
 }
 
 static void
@@ -1232,7 +1259,7 @@ Key_Unbindall_f (void)
 {
        int         i, j;
 
-       for (j = 0; j < 8; j++)
+       for (j = 0; j < MAX_BINDMAPS; j++)
                for (i = 0; i < (int)(sizeof(keybindings[0])/sizeof(keybindings[0][0])); i++)
                        if (keybindings[j][i])
                                Key_SetBinding (i, j, "");
@@ -1268,7 +1295,7 @@ Key_In_BindList_f (void)
        if(Cmd_Argc() >= 2)
        {
                m = strtol(Cmd_Argv(1), &errchar, 0);
-               if ((m < 0) || (m >= 8) || (errchar && *errchar)) {
+               if ((m < 0) || (m >= MAX_BINDMAPS) || (errchar && *errchar)) {
                        Con_Printf("%s isn't a valid bindmap\n", Cmd_Argv(1));
                        return;
                }
@@ -1320,7 +1347,8 @@ Key_Bind_f (void)
                        strlcat (cmd, " ", sizeof (cmd));
        }
 
-       Key_SetBinding (b, 0, cmd);
+       if(!Key_SetBinding (b, 0, cmd))
+               Con_Printf("Key_SetBinding failed for unknown reason\n");
 }
 
 /*
@@ -1383,17 +1411,54 @@ 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 >= MAX_BINDMAPS)
+               return NULL;
+       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;
+       const char      *b;
+
+       for (j = 0;j < numkeys;j++)
+               keys[j] = -1;
+
+       if(bindmap >= MAX_BINDMAPS)
+               return;
+
+       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);
 
 /*
@@ -1405,6 +1470,44 @@ Should NOT be called during an interrupt!
 static char tbl_keyascii[MAX_KEYS];
 static keydest_t tbl_keydest[MAX_KEYS];
 
+typedef struct eventqueueitem_s
+{
+       int key;
+       int ascii;
+       qboolean down;
+}
+eventqueueitem_t;
+static int events_blocked = 0;
+static eventqueueitem_t eventqueue[32];
+static unsigned eventqueue_idx = 0;
+
+static void Key_EventQueue_Add(int key, int ascii, qboolean down)
+{
+       if(eventqueue_idx < sizeof(eventqueue) / sizeof(*eventqueue))
+       {
+               eventqueue[eventqueue_idx].key = key;
+               eventqueue[eventqueue_idx].ascii = ascii;
+               eventqueue[eventqueue_idx].down = down;
+               ++eventqueue_idx;
+       }
+}
+
+void Key_EventQueue_Block(void)
+{
+       // block key events until call to Unblock
+       events_blocked = true;
+}
+
+void Key_EventQueue_Unblock(void)
+{
+       // unblocks key events again
+       unsigned i;
+       events_blocked = false;
+       for(i = 0; i < eventqueue_idx; ++i)
+               Key_Event(eventqueue[i].key, eventqueue[i].ascii, eventqueue[i].down);
+       eventqueue_idx = 0;
+}
+
 void
 Key_Event (int key, int ascii, qboolean down)
 {
@@ -1415,6 +1518,12 @@ Key_Event (int key, int ascii, qboolean down)
        if (key < 0 || key >= MAX_KEYS)
                return;
 
+       if(events_blocked)
+       {
+               Key_EventQueue_Add(key, ascii, down);
+               return;
+       }
+
        // get key binding
        bind = keybindings[key_bmap][key];
        if (!bind)
@@ -1492,7 +1601,7 @@ Key_Event (int key, int ascii, qboolean down)
                                        if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
                                        {
                                                key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
-                                               MR_ToggleMenu(-1);
+                                               MR_ToggleMenu(1);
                                        }
                                        else
                                                Con_ToggleConsole_f();
@@ -1513,7 +1622,7 @@ Key_Event (int key, int ascii, qboolean down)
                                // 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(-1);
+                                       MR_ToggleMenu(1);
                                break;
 
                        default:
@@ -1523,8 +1632,9 @@ Key_Event (int key, int ascii, qboolean down)
        }
 
        // send function keydowns to interpreter no matter what mode is (unless the menu has specifically grabbed the keyboard, for rebinding keys)
+       // VorteX: Omnicide does bind F* keys
        if (keydest != key_menu_grabbed)
-       if (key >= K_F1 && key <= K_F12)
+       if (key >= K_F1 && key <= K_F12 && gamemode != GAME_BLOODOMNICIDE)
        {
                if (bind)
                {