Add IMT_DEMO for demo playback bindings.

This will allow special key bindings for use during demo playback without
interfering with normal keys.
This commit is contained in:
Bill Currie 2011-12-10 14:21:12 +09:00
parent 14d8e8669f
commit 81a16c925b
2 changed files with 43 additions and 12 deletions

View file

@ -369,6 +369,7 @@ typedef enum {
typedef enum {
IMT_CONSOLE,
IMT_DEMO,
IMT_MOD,
IMT_0,
IMT_1,
@ -393,6 +394,7 @@ typedef enum {
// key_none should, preferably, be last
typedef enum {
key_game,
key_demo,
key_console,
key_message,
key_menu,

View file

@ -76,6 +76,7 @@ typedef struct {
imtname_t imtnames[] = {
{"IMT_CONSOLE", IMT_CONSOLE},
{"IMT_DEMO", IMT_DEMO},
{"IMT_MOD", IMT_MOD},
{"IMT_0", IMT_0},
{"IMT_1", IMT_1},
@ -409,6 +410,23 @@ keyname_t keynames[] = {
};
static void
process_binding (knum_t key, const char *kb)
{
char cmd[1024];
if (kb[0] == '+') {
if (keydown[key])
snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key);
else
snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key);
} else {
if (!keydown[key])
return;
snprintf (cmd, sizeof (cmd), "%s\n", kb);
}
Cbuf_AddText (cbuf, cmd);
}
/*
Key_Game
@ -418,7 +436,6 @@ static qboolean
Key_Game (knum_t key, short unicode)
{
const char *kb;
char cmd[1024];
kb = Key_GetBinding (game_target, key);
if (!kb && (game_target > IMT_0))
@ -436,20 +453,29 @@ Key_Game (knum_t key, short unicode)
if (keydown[key] > 1)
return true;
if (kb[0] == '+') {
if (keydown[key])
snprintf (cmd, sizeof (cmd), "%s %d\n", kb, key);
else
snprintf (cmd, sizeof (cmd), "-%s %d\n", kb + 1, key);
} else {
if (!keydown[key])
return true;
snprintf (cmd, sizeof (cmd), "%s\n", kb);
}
Cbuf_AddText (cbuf, cmd);
process_binding (key, kb);
return true;
}
/*
Key_Demo
Interactive line editing and console scrollback
*/
static void
Key_Demo (knum_t key, short unicode)
{
const char *kb;
// escape is un-bindable
if (keydown[key] == 1 && key && Key_Game (key, unicode))
return;
kb = Key_GetBinding (IMT_DEMO, key);
if (kb)
process_binding (key, kb);
}
/*
Key_Console
@ -851,6 +877,9 @@ Key_Event (knum_t key, short unicode, qboolean down)
case key_game:
Key_Game (key, unicode);
break;
case key_demo:
Key_Demo (key, unicode);
break;
case key_message:
case key_menu:
case key_console: