}
-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]) {
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
}
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;
}
return;
}
- Key_SetBinding (b, m, "");
+ if(!Key_SetBinding (b, m, ""))
+ Con_Printf("Key_SetBinding failed for unknown reason\n");
}
static 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;
}
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
}
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;
}
return;
}
- Key_SetBinding (b, 0, "");
+ if(!Key_SetBinding (b, 0, ""))
+ Con_Printf("Key_SetBinding failed for unknown reason\n");
}
static 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, "");
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;
}
strlcat (cmd, " ", sizeof (cmd));
}
- Key_SetBinding (b, 0, cmd);
+ if(!Key_SetBinding (b, 0, cmd))
+ Con_Printf("Key_SetBinding failed for unknown reason\n");
}
/*
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);
/*
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)
{
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)
if(key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
{
key_consoleactive &= ~KEY_CONSOLEACTIVE_USER;
- MR_ToggleMenu(-1);
+ MR_ToggleMenu(1);
}
else
Con_ToggleConsole_f();
// 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:
}
// 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)
{