mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-02-16 16:41:30 +00:00
Bound keys not saved in quotes fix, this caused problems with a binded semilicon
This commit is contained in:
parent
af1a000fb1
commit
ac7199d6e2
1 changed files with 58 additions and 45 deletions
103
source/keys.c
103
source/keys.c
|
@ -212,7 +212,8 @@ keyname_t keynames[] =
|
||||||
==============================================================================
|
==============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
qboolean CheckForCommand (void)
|
qboolean
|
||||||
|
CheckForCommand ( void )
|
||||||
{
|
{
|
||||||
char command[128];
|
char command[128];
|
||||||
char *cmd, *s;
|
char *cmd, *s;
|
||||||
|
@ -230,12 +231,13 @@ qboolean CheckForCommand (void)
|
||||||
cmd = Cmd_CompleteCommand (command);
|
cmd = Cmd_CompleteCommand (command);
|
||||||
if (!cmd || strcmp (cmd, command))
|
if (!cmd || strcmp (cmd, command))
|
||||||
cmd = Cvar_CompleteVariable (command);
|
cmd = Cvar_CompleteVariable (command);
|
||||||
if (!cmd || strcmp (cmd, command) )
|
if (!cmd || strcmp (cmd, command) )
|
||||||
return false; // just a chat message
|
return false; // just a chat message
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompleteCommand (void)
|
void
|
||||||
|
CompleteCommand ( void )
|
||||||
{
|
{
|
||||||
char *cmd, *s;
|
char *cmd, *s;
|
||||||
|
|
||||||
|
@ -265,7 +267,8 @@ Key_Console
|
||||||
Interactive line editing and console scrollback
|
Interactive line editing and console scrollback
|
||||||
====================
|
====================
|
||||||
*/
|
*/
|
||||||
void Key_Console (int key)
|
void
|
||||||
|
Key_Console ( int key )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -275,7 +278,7 @@ void Key_Console (int key)
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
case K_ENTER:
|
case K_ENTER:
|
||||||
// backslash text are commands
|
// backslash text are commands
|
||||||
if (key_lines[edit_line][1] == '/' && key_lines[edit_line][2] == '/')
|
if (key_lines[edit_line][1] == '/' && key_lines[edit_line][2] == '/')
|
||||||
goto no_lf;
|
goto no_lf;
|
||||||
|
@ -331,12 +334,12 @@ no_lf:
|
||||||
key_linepos++;
|
key_linepos++;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_LEFTARROW:
|
case K_LEFTARROW:
|
||||||
if (key_linepos > 1)
|
if (key_linepos > 1)
|
||||||
key_linepos--;
|
key_linepos--;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_UPARROW:
|
case K_UPARROW:
|
||||||
do {
|
do {
|
||||||
history_line = (history_line - 1) & 31;
|
history_line = (history_line - 1) & 31;
|
||||||
} while (history_line != edit_line
|
} while (history_line != edit_line
|
||||||
|
@ -347,7 +350,7 @@ no_lf:
|
||||||
key_linepos = strlen(key_lines[edit_line]);
|
key_linepos = strlen(key_lines[edit_line]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_DOWNARROW:
|
case K_DOWNARROW:
|
||||||
if (history_line == edit_line) return;
|
if (history_line == edit_line) return;
|
||||||
do {
|
do {
|
||||||
history_line = (history_line + 1) & 31;
|
history_line = (history_line + 1) & 31;
|
||||||
|
@ -364,20 +367,20 @@ no_lf:
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_MWHEELUP:
|
case K_MWHEELUP:
|
||||||
case K_PGUP:
|
case K_PGUP:
|
||||||
if (con->display - con->current + con->numlines > 2)
|
if (con->display - con->current + con->numlines > 2)
|
||||||
con->display -= 2;
|
con->display -= 2;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_MWHEELDOWN:
|
case K_MWHEELDOWN:
|
||||||
case K_PGDN:
|
case K_PGDN:
|
||||||
con->display += 2;
|
con->display += 2;
|
||||||
if (con->display > con->current)
|
if (con->display > con->current)
|
||||||
con->display = con->current;
|
con->display = con->current;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_HOME:
|
case K_HOME:
|
||||||
if (keydown[K_CTRL])
|
if (keydown[K_CTRL])
|
||||||
{
|
{
|
||||||
if (con->numlines > 10)
|
if (con->numlines > 10)
|
||||||
|
@ -387,7 +390,7 @@ no_lf:
|
||||||
key_linepos = 1;
|
key_linepos = 1;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case K_END:
|
case K_END:
|
||||||
if (keydown[K_CTRL])
|
if (keydown[K_CTRL])
|
||||||
con->display = con->current;
|
con->display = con->current;
|
||||||
else
|
else
|
||||||
|
@ -444,7 +447,8 @@ qboolean chat_team;
|
||||||
char chat_buffer[MAXCMDLINE];
|
char chat_buffer[MAXCMDLINE];
|
||||||
int chat_bufferlen = 0;
|
int chat_bufferlen = 0;
|
||||||
|
|
||||||
void Key_Message (int key)
|
void
|
||||||
|
Key_Message ( int key )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (key == K_ENTER)
|
if (key == K_ENTER)
|
||||||
|
@ -484,7 +488,7 @@ void Key_Message (int key)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat_bufferlen == sizeof(chat_buffer)-1)
|
if (chat_bufferlen == sizeof(chat_buffer)-1)
|
||||||
return; // all full
|
return; // all full
|
||||||
|
|
||||||
chat_buffer[chat_bufferlen++] = key;
|
chat_buffer[chat_bufferlen++] = key;
|
||||||
chat_buffer[chat_bufferlen] = 0;
|
chat_buffer[chat_bufferlen] = 0;
|
||||||
|
@ -502,10 +506,11 @@ the given string. Single ascii characters return themselves, while
|
||||||
the K_* names are matched up.
|
the K_* names are matched up.
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
int Key_StringToKeynum (char *str)
|
int
|
||||||
|
Key_StringToKeynum ( char *str )
|
||||||
{
|
{
|
||||||
keyname_t *kn;
|
keyname_t *kn;
|
||||||
|
|
||||||
if (!str || !str[0])
|
if (!str || !str[0])
|
||||||
return -1;
|
return -1;
|
||||||
if (!str[1])
|
if (!str[1])
|
||||||
|
@ -528,11 +533,12 @@ given keynum.
|
||||||
FIXME: handle quote special (general escape sequence?)
|
FIXME: handle quote special (general escape sequence?)
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
char *Key_KeynumToString (int keynum)
|
char *
|
||||||
|
Key_KeynumToString ( int keynum )
|
||||||
{
|
{
|
||||||
keyname_t *kn;
|
keyname_t *kn;
|
||||||
static char tinystr[2];
|
static char tinystr[2];
|
||||||
|
|
||||||
if (keynum == -1)
|
if (keynum == -1)
|
||||||
return "<KEY NOT FOUND>";
|
return "<KEY NOT FOUND>";
|
||||||
if (keynum > 32 && keynum < 127)
|
if (keynum > 32 && keynum < 127)
|
||||||
|
@ -541,7 +547,7 @@ char *Key_KeynumToString (int keynum)
|
||||||
tinystr[1] = 0;
|
tinystr[1] = 0;
|
||||||
return tinystr;
|
return tinystr;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (kn=keynames ; kn->name ; kn++)
|
for (kn=keynames ; kn->name ; kn++)
|
||||||
if (keynum == kn->keynum)
|
if (keynum == kn->keynum)
|
||||||
return kn->name;
|
return kn->name;
|
||||||
|
@ -555,11 +561,12 @@ char *Key_KeynumToString (int keynum)
|
||||||
Key_SetBinding
|
Key_SetBinding
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_SetBinding (int keynum, char *binding)
|
void
|
||||||
|
Key_SetBinding ( int keynum, char *binding )
|
||||||
{
|
{
|
||||||
char *new;
|
char *new;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
if (keynum == -1)
|
if (keynum == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -569,13 +576,13 @@ void Key_SetBinding (int keynum, char *binding)
|
||||||
free (keybindings[keynum]);
|
free (keybindings[keynum]);
|
||||||
keybindings[keynum] = NULL;
|
keybindings[keynum] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate memory for new binding
|
// allocate memory for new binding
|
||||||
l = strlen (binding);
|
l = strlen (binding);
|
||||||
new = malloc (l+1);
|
new = malloc (l+1);
|
||||||
strcpy (new, binding);
|
strcpy (new, binding);
|
||||||
new[l] = 0;
|
new[l] = 0;
|
||||||
keybindings[keynum] = new;
|
keybindings[keynum] = new;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -583,7 +590,8 @@ void Key_SetBinding (int keynum, char *binding)
|
||||||
Key_Unbind_f
|
Key_Unbind_f
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_Unbind_f (void)
|
void
|
||||||
|
Key_Unbind_f ( void )
|
||||||
{
|
{
|
||||||
int b;
|
int b;
|
||||||
|
|
||||||
|
@ -592,7 +600,7 @@ void Key_Unbind_f (void)
|
||||||
Con_Printf ("unbind <key> : remove commands from a key\n");
|
Con_Printf ("unbind <key> : remove commands from a key\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
b = Key_StringToKeynum (Cmd_Argv(1));
|
b = Key_StringToKeynum (Cmd_Argv(1));
|
||||||
if (b==-1)
|
if (b==-1)
|
||||||
{
|
{
|
||||||
|
@ -603,10 +611,11 @@ void Key_Unbind_f (void)
|
||||||
Key_SetBinding (b, "");
|
Key_SetBinding (b, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Key_Unbindall_f (void)
|
void
|
||||||
|
Key_Unbindall_f ( void )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0 ; i<256 ; i++)
|
for (i=0 ; i<256 ; i++)
|
||||||
if (keybindings[i])
|
if (keybindings[i])
|
||||||
Key_SetBinding (i, "");
|
Key_SetBinding (i, "");
|
||||||
|
@ -618,11 +627,12 @@ void Key_Unbindall_f (void)
|
||||||
Key_Bind_f
|
Key_Bind_f
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_Bind_f (void)
|
void
|
||||||
|
Key_Bind_f ( void )
|
||||||
{
|
{
|
||||||
int i, c, b;
|
int i, c, b;
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
|
|
||||||
c = Cmd_Argc();
|
c = Cmd_Argc();
|
||||||
|
|
||||||
if (c < 2)
|
if (c < 2)
|
||||||
|
@ -645,7 +655,7 @@ void Key_Bind_f (void)
|
||||||
Con_Printf ("\"%s\" is not bound\n", Cmd_Argv(1) );
|
Con_Printf ("\"%s\" is not bound\n", Cmd_Argv(1) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the rest of the command line
|
// copy the rest of the command line
|
||||||
cmd[0] = 0; // start out with a null string
|
cmd[0] = 0; // start out with a null string
|
||||||
for (i=2 ; i< c ; i++)
|
for (i=2 ; i< c ; i++)
|
||||||
|
@ -665,13 +675,14 @@ Key_WriteBindings
|
||||||
Writes lines containing "bind key value"
|
Writes lines containing "bind key value"
|
||||||
============
|
============
|
||||||
*/
|
*/
|
||||||
void Key_WriteBindings (FILE *f)
|
void
|
||||||
|
Key_WriteBindings ( FILE *f )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0 ; i<256 ; i++)
|
for (i=0 ; i<256 ; i++)
|
||||||
if (keybindings[i])
|
if (keybindings[i])
|
||||||
fprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
|
fprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]); // 1999-12-26 bound keys not saved in quotes fix by Maddes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -680,7 +691,8 @@ void Key_WriteBindings (FILE *f)
|
||||||
Key_Init
|
Key_Init
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_Init (void)
|
void
|
||||||
|
Key_Init ( void )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -690,7 +702,7 @@ void Key_Init (void)
|
||||||
key_lines[i][1] = 0;
|
key_lines[i][1] = 0;
|
||||||
}
|
}
|
||||||
key_linepos = 1;
|
key_linepos = 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// init ascii characters in console mode
|
// init ascii characters in console mode
|
||||||
//
|
//
|
||||||
|
@ -764,12 +776,13 @@ Called by the system between frames for both key up and key down events
|
||||||
Should NOT be called during an interrupt!
|
Should NOT be called during an interrupt!
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_Event (int key, qboolean down)
|
void
|
||||||
|
Key_Event ( int key, qboolean down )
|
||||||
{
|
{
|
||||||
char *kb;
|
char *kb;
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
|
|
||||||
// Con_Printf ("%i : %i\n", key, down); //@@@
|
// Con_Printf ("%i : %i\n", key, down); //@@@
|
||||||
|
|
||||||
keydown[key] = down;
|
keydown[key] = down;
|
||||||
|
|
||||||
|
@ -795,7 +808,7 @@ void Key_Event (int key, qboolean down)
|
||||||
|| (key_dest == key_game && cls.state == ca_active))
|
|| (key_dest == key_game && cls.state == ca_active))
|
||||||
return; // ignore most autorepeats
|
return; // ignore most autorepeats
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key >= 200 && !keybindings[key])
|
if (key >= 200 && !keybindings[key])
|
||||||
Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
|
Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) );
|
||||||
}
|
}
|
||||||
|
@ -860,7 +873,7 @@ void Key_Event (int key, qboolean down)
|
||||||
// during demo playback, most keys bring up the main menu
|
// during demo playback, most keys bring up the main menu
|
||||||
//
|
//
|
||||||
if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game
|
if (cls.demoplayback && down && consolekeys[key] && key_dest == key_game
|
||||||
&& key != K_CTRL && key != K_DEL && key != K_HOME && key != K_END && key != K_TAB)
|
&& key != K_CTRL && key != K_DEL && key != K_HOME && key != K_END && key != K_TAB)
|
||||||
{
|
{
|
||||||
M_ToggleMenu_f ();
|
M_ToggleMenu_f ();
|
||||||
return;
|
return;
|
||||||
|
@ -878,7 +891,7 @@ void Key_Event (int key, qboolean down)
|
||||||
{
|
{
|
||||||
if (kb[0] == '+')
|
if (kb[0] == '+')
|
||||||
{ // button commands add keynum as a parm
|
{ // button commands add keynum as a parm
|
||||||
snprintf (cmd, sizeof(cmd), "%s %i\n", kb, key);
|
snprintf (cmd, sizeof(cmd), "%s %i\n", kb, key);
|
||||||
Cbuf_AddText (cmd);
|
Cbuf_AddText (cmd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -919,7 +932,8 @@ void Key_Event (int key, qboolean down)
|
||||||
Key_ClearStates
|
Key_ClearStates
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void Key_ClearStates (void)
|
void
|
||||||
|
Key_ClearStates ( void )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -929,4 +943,3 @@ void Key_ClearStates (void)
|
||||||
key_repeats[i] = false;
|
key_repeats[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue