mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
Merge branch 'original'
This commit is contained in:
@@ -24,6 +24,7 @@ GNU General Public License for more details.
|
||||
typedef struct
|
||||
{
|
||||
qboolean down;
|
||||
qboolean gamedown;
|
||||
int repeats; // if > 1, it is autorepeating
|
||||
const char *binding;
|
||||
} enginekey_t;
|
||||
@@ -269,16 +270,27 @@ const char *Key_GetBinding( int keynum )
|
||||
Key_GetKey
|
||||
===================
|
||||
*/
|
||||
int Key_GetKey( const char *binding )
|
||||
int Key_GetKey( const char *pBinding )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( !binding ) return -1;
|
||||
if( !pBinding ) return -1;
|
||||
|
||||
for( i = 0; i < 256; i++ )
|
||||
{
|
||||
if( keys[i].binding && !Q_stricmp( binding, keys[i].binding ))
|
||||
return i;
|
||||
if( !keys[i].binding )
|
||||
continue;
|
||||
|
||||
if( *keys[i].binding == '+' )
|
||||
{
|
||||
if( !Q_strnicmp( keys[i].binding + 1, pBinding, Q_strlen( pBinding )))
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !Q_strnicmp( keys[i].binding, pBinding, Q_strlen( pBinding )))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -463,18 +475,17 @@ void Key_Init( void )
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_AddKeyUpCommands
|
||||
Key_AddKeyCommands
|
||||
===================
|
||||
*/
|
||||
void Key_AddKeyUpCommands( int key, const char *kb )
|
||||
void Key_AddKeyCommands( int key, const char *kb, qboolean down )
|
||||
{
|
||||
int i;
|
||||
char button[1024], *buttonPtr;
|
||||
char button[1024];
|
||||
char *buttonPtr;
|
||||
char cmd[1024];
|
||||
qboolean keyevent;
|
||||
int i;
|
||||
|
||||
if( !kb ) return;
|
||||
keyevent = false;
|
||||
buttonPtr = button;
|
||||
|
||||
for( i = 0; ; i++ )
|
||||
@@ -485,18 +496,15 @@ void Key_AddKeyUpCommands( int key, const char *kb )
|
||||
if( button[0] == '+' )
|
||||
{
|
||||
// button commands add keynum as a parm
|
||||
Q_sprintf( cmd, "-%s %i\n", button+1, key );
|
||||
if( down ) Q_sprintf( cmd, "%s %i\n", button, key );
|
||||
else Q_sprintf( cmd, "-%s %i\n", button + 1, key );
|
||||
Cbuf_AddText( cmd );
|
||||
keyevent = true;
|
||||
}
|
||||
else
|
||||
else if( down )
|
||||
{
|
||||
if( keyevent )
|
||||
{
|
||||
// down-only command
|
||||
Cbuf_AddText( button );
|
||||
Cbuf_AddText( "\n" );
|
||||
}
|
||||
// down-only command
|
||||
Cbuf_AddText( button );
|
||||
Cbuf_AddText( "\n" );
|
||||
}
|
||||
|
||||
buttonPtr = button;
|
||||
@@ -509,6 +517,29 @@ void Key_AddKeyUpCommands( int key, const char *kb )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_IsAllowedAutoRepeat
|
||||
|
||||
List of keys that allows auto-repeat
|
||||
===================
|
||||
*/
|
||||
qboolean Key_IsAllowedAutoRepeat( int key )
|
||||
{
|
||||
switch( key )
|
||||
{
|
||||
case K_BACKSPACE:
|
||||
case K_PAUSE:
|
||||
case K_PGUP:
|
||||
case K_KP_PGUP:
|
||||
case K_PGDN:
|
||||
case K_KP_PGDN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Key_Event
|
||||
@@ -519,30 +550,58 @@ Called by the system for both key up and key down events
|
||||
void Key_Event( int key, int down )
|
||||
{
|
||||
const char *kb;
|
||||
char cmd[1024];
|
||||
|
||||
// key was pressed before engine was run
|
||||
if( !keys[key].down && !down )
|
||||
return;
|
||||
|
||||
// update auto-repeat status and BUTTON_ANY status
|
||||
kb = keys[key].binding;
|
||||
keys[key].down = down;
|
||||
|
||||
#ifdef HACKS_RELATED_HLMODS
|
||||
if(( cls.key_dest == key_game ) && ( cls.state == ca_cinematic ) && ( key != K_ESCAPE || !down ))
|
||||
{
|
||||
// only escape passed when cinematic is playing
|
||||
// HLFX 0.6 bug: crash in vgui3.dll while press +attack during movie playback
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// distribute the key down event to the apropriate handler
|
||||
if( cls.key_dest == key_game && ( down || keys[key].gamedown ))
|
||||
{
|
||||
if( !clgame.dllFuncs.pfnKey_Event( down, key, keys[key].binding ))
|
||||
{
|
||||
if( keys[key].repeats == 0 && down )
|
||||
{
|
||||
keys[key].gamedown = true;
|
||||
}
|
||||
|
||||
if( !down )
|
||||
{
|
||||
keys[key].gamedown = false;
|
||||
keys[key].repeats = 0;
|
||||
}
|
||||
return; // handled in client.dll
|
||||
}
|
||||
}
|
||||
|
||||
// update auto-repeat status
|
||||
if( down )
|
||||
{
|
||||
keys[key].repeats++;
|
||||
|
||||
if( key != K_BACKSPACE && key != K_PAUSE && keys[key].repeats > 1 )
|
||||
if( !Key_IsAllowedAutoRepeat( key ) && keys[key].repeats > 1 )
|
||||
{
|
||||
if( cls.key_dest == key_game )
|
||||
{
|
||||
// ignore most autorepeats
|
||||
return;
|
||||
}
|
||||
// ignore most autorepeats
|
||||
return;
|
||||
}
|
||||
|
||||
if( key >= 200 && !kb )
|
||||
Con_Printf( "%s is unbound.\n", Key_KeynumToString( key ));
|
||||
}
|
||||
else
|
||||
{
|
||||
keys[key].gamedown = false;
|
||||
keys[key].repeats = 0;
|
||||
}
|
||||
|
||||
@@ -565,13 +624,13 @@ void Key_Event( int key, int down )
|
||||
switch( cls.key_dest )
|
||||
{
|
||||
case key_game:
|
||||
if( gl_showtextures->value )
|
||||
if( CVAR_TO_BOOL( gl_showtextures ))
|
||||
{
|
||||
// close texture atlas
|
||||
Cvar_SetValue( "r_showtextures", 0.0f );
|
||||
return;
|
||||
}
|
||||
if( host.mouse_visible && cls.state != ca_cinematic )
|
||||
else if( host.mouse_visible && cls.state != ca_cinematic )
|
||||
{
|
||||
clgame.dllFuncs.pfnKey_Event( down, key, keys[key].binding );
|
||||
return; // handled in client.dll
|
||||
@@ -588,9 +647,7 @@ void Key_Event( int key, int down )
|
||||
case key_menu:
|
||||
UI_KeyEvent( key, true );
|
||||
return;
|
||||
default:
|
||||
MsgDev( D_ERROR, "Key_Event: bad cls.key_dest\n" );
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,72 +675,14 @@ void Key_Event( int key, int down )
|
||||
// an action started before a mode switch.
|
||||
if( !down )
|
||||
{
|
||||
kb = keys[key].binding;
|
||||
|
||||
if( cls.key_dest == key_game && ( key != K_ESCAPE ))
|
||||
clgame.dllFuncs.pfnKey_Event( down, key, kb );
|
||||
|
||||
Key_AddKeyUpCommands( key, kb );
|
||||
Key_AddKeyCommands( key, kb, down );
|
||||
return;
|
||||
}
|
||||
|
||||
// distribute the key down event to the apropriate handler
|
||||
if( cls.key_dest == key_game )
|
||||
{
|
||||
if( cls.state == ca_cinematic && ( key != K_ESCAPE || !down ))
|
||||
{
|
||||
// only escape passed when cinematic is playing
|
||||
// HLFX 0.6 bug: crash in vgui3.dll while press +attack during movie playback
|
||||
return;
|
||||
}
|
||||
|
||||
// send the bound action
|
||||
kb = keys[key].binding;
|
||||
|
||||
if( !clgame.dllFuncs.pfnKey_Event( down, key, keys[key].binding ))
|
||||
{
|
||||
// handled in client.dll
|
||||
}
|
||||
else if( kb != NULL )
|
||||
{
|
||||
if( kb[0] == '+' )
|
||||
{
|
||||
int i;
|
||||
char button[1024], *buttonPtr;
|
||||
|
||||
for( i = 0, buttonPtr = button; ; i++ )
|
||||
{
|
||||
if( kb[i] == ';' || !kb[i] )
|
||||
{
|
||||
*buttonPtr = '\0';
|
||||
if( button[0] == '+' )
|
||||
{
|
||||
Q_sprintf( cmd, "%s %i\n", button, key );
|
||||
Cbuf_AddText( cmd );
|
||||
}
|
||||
else
|
||||
{
|
||||
// down-only command
|
||||
Cbuf_AddText( button );
|
||||
Cbuf_AddText( "\n" );
|
||||
}
|
||||
|
||||
buttonPtr = button;
|
||||
while (( kb[i] <= ' ' || kb[i] == ';' ) && kb[i] != 0 )
|
||||
i++;
|
||||
}
|
||||
|
||||
*buttonPtr++ = kb[i];
|
||||
if( !kb[i] ) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// down-only command
|
||||
Cbuf_AddText( kb );
|
||||
Cbuf_AddText( "\n" );
|
||||
}
|
||||
}
|
||||
Key_AddKeyCommands( key, kb, down );
|
||||
}
|
||||
else if( cls.key_dest == key_console )
|
||||
{
|
||||
@@ -774,6 +773,7 @@ void Key_ClearStates( void )
|
||||
|
||||
keys[i].down = 0;
|
||||
keys[i].repeats = 0;
|
||||
keys[i].gamedown = 0;
|
||||
}
|
||||
|
||||
if( clgame.hInstance )
|
||||
|
||||
Reference in New Issue
Block a user