Ejemplo n.º 1
0
/*
============
idKeyInput::KeysFromBinding
returns the localized name of the key for the binding
============
*/
const char *idKeyInput::KeysFromBinding(const char *bind)
{
	int i;
	static char keyName[MAX_STRING_CHARS];

	keyName[0] = '\0';

	if (bind && *bind) {
		for (i = 0; i < MAX_KEYS; i++) {
			if (keys[i].binding.Icmp(bind) == 0) {
				if (keyName[0] != '\0') {
					idStr::Append(keyName, sizeof(keyName), common->GetLanguageDict()->GetString("#str_07183"));
				}

				idStr::Append(keyName, sizeof(keyName), KeyNumToString(i, true));
			}
		}
	}

	if (keyName[0] == '\0') {
		idStr::Copynz(keyName, common->GetLanguageDict()->GetString("#str_07133"), sizeof(keyName));
	}

	idStr::ToLower(keyName);
	return keyName;
}
Ejemplo n.º 2
0
/*
============
idKeyInput::WriteBindings

Writes lines containing "bind key value"
============
*/
void idKeyInput::WriteBindings( idFile *f ) {
    int		i;

    f->Printf( "unbindall\n" );

    for ( i = 0; i < MAX_KEYS; i++ ) {
        if ( keys[i].binding.Length() ) {
            const char *name = KeyNumToString( i, false );

            // handle the escape character nicely
            if ( !strcmp( name, "\\" ) ) {
                f->Printf( "bind \"\\\" \"%s\"\n", keys[i].binding.c_str() );
            } else {
                f->Printf( "bind \"%s\" \"%s\"\n", KeyNumToString( i, false ), keys[i].binding.c_str() );
            }
        }
    }
}
Ejemplo n.º 3
0
/*
============
idKeyInput::WriteBindings

Writes lines containing "bind key value"
============
*/
void idKeyInput::WriteBindings( idFile* f )
{
	f->Printf( "unbindall\n" );
	
	for( int i = 0; i < K_LAST_KEY; i++ )
	{
		if( keys[i].binding.Length() )
		{
			const char* name = KeyNumToString( ( keyNum_t )i );
			f->Printf( "bind \"%s\" \"%s\"\n", name, keys[i].binding.c_str() );
		}
	}
}
Ejemplo n.º 4
0
/*
========================
idKeyInput::LocalizedKeyName
========================
*/
const char* idKeyInput::LocalizedKeyName( keyNum_t keynum )
{
	// RB: FIXME
#if defined(_WIN32)
	if( keynum < K_JOY1 )
	{
		// On the PC, we want to turn the scan code in to a key label that matches the currently selected keyboard layout
		unsigned char keystate[256] = { 0 };
		WCHAR temp[5];
		
		int scancode = ( int )keynum;
		int vkey = MapVirtualKey( keynum, MAPVK_VSC_TO_VK_EX );
		int result = -1;
		while( result < 0 )
		{
			result = ToUnicode( vkey, scancode, keystate, temp, sizeof( temp ) / sizeof( temp[0] ), 0 );
		}
		if( result > 0 && temp[0] > ' ' && iswprint( temp[0] ) )
		{
			static idStr bindStr;
			bindStr.Empty();
			bindStr.AppendUTF8Char( temp[0] );
			return bindStr;
		}
	}
	
	// check for a key string
	for( keyname_t* kn = keynames; kn->name; kn++ )
	{
		if( keynum == kn->keynum )
		{
			return idLocalization::GetString( kn->strId );
		}
	}
	return "????";
#else
	return KeyNumToString( keynum );
#endif
	// RB end
}
Ejemplo n.º 5
0
/*
========================
idKeyInput::KeyBindingsFromBinding

return: bindings for keyboard mouse and gamepad
========================
*/
keyBindings_t idKeyInput::KeyBindingsFromBinding( const char* bind, bool firstOnly, bool localized )
{
	idStr keyboard;
	idStr mouse;
	idStr gamepad;
	
	if( bind && *bind )
	{
		for( int i = 0; i < K_LAST_KEY; i++ )
		{
			if( keys[i].binding.Icmp( bind ) == 0 )
			{
				if( i >= K_JOY1 && i <= K_JOY_DPAD_RIGHT )
				{
					const char* gamepadKey = "";
					if( localized )
					{
						gamepadKey = LocalizedKeyName( ( keyNum_t )i );
					}
					else
					{
						gamepadKey = KeyNumToString( ( keyNum_t )i );
					}
					if( idStr::Icmp( gamepadKey, "" ) != 0 )
					{
						if( !gamepad.IsEmpty() )
						{
							if( firstOnly )
							{
								continue;
							}
							gamepad.Append( ", " );
						}
						gamepad.Append( gamepadKey );
					}
				}
				else if( i >= K_MOUSE1 && i <= K_MWHEELUP )
				{
					const char* mouseKey = "";
					if( localized )
					{
						mouseKey = LocalizedKeyName( ( keyNum_t )i );
					}
					else
					{
						mouseKey = KeyNumToString( ( keyNum_t )i );
					}
					if( idStr::Icmp( mouseKey, "" ) != 0 )
					{
						if( !mouse.IsEmpty() )
						{
							if( firstOnly )
							{
								continue;
							}
							mouse.Append( ", " );
						}
						mouse.Append( mouseKey );
					}
				}
				else
				{
					const char* tmp = "";
					if( localized )
					{
						tmp = LocalizedKeyName( ( keyNum_t )i );
					}
					else
					{
						tmp = KeyNumToString( ( keyNum_t )i );
					}
					if( idStr::Icmp( tmp, "" ) != 0 && idStr::Icmp( tmp, keyboard ) != 0 )
					{
						if( !keyboard.IsEmpty() )
						{
							if( firstOnly )
							{
								continue;
							}
							keyboard.Append( ", " );
						}
						keyboard.Append( tmp );
					}
				}
			}
		}
	}
	
	keyBindings_t bindings;
	bindings.gamepad = gamepad;
	bindings.mouse = mouse;
	bindings.keyboard = keyboard;
	
	return bindings;
}