void InputMapper::SaveMappingsToDisk() { IniFile ini; ini.ReadFile( KEYMAPS_PATH ); const Game* pGame = GAMESTATE->GetCurrentGame(); // erase the key so that we overwrite everything for this game ini.DeleteKey( pGame->m_szName ); // iterate over our input map and write all mappings to the ini file FOREACH_GameController( i ) { for( int j=0; j<pGame->m_iButtonsPerController; j++ ) { GameInput GameI( i, (GameButton)j ); CString sNameString = GameI.toString( pGame ); vector<CString> asValues; for( int button = 0; button < NUM_GAME_TO_DEVICE_SLOTS; ++button ) asValues.push_back( m_GItoDI[i][j][button].toString() ); while( asValues.size() && asValues.back() == "" ) asValues.erase( asValues.begin()+asValues.size()-1 ); CString sValueString = join( ",", asValues ); ini.SetValue( pGame->m_szName, sNameString, sValueString ); } } ini.WriteFile( KEYMAPS_PATH ); }
void InputMapper::SaveMappingsToDisk() { IniFile ini; ini.ReadFile( KEYMAPS_PATH ); // erase the key so that we overwrite everything for this game ini.DeleteKey( GAMESTATE->GetCurrentGame()->m_szName ); // iterate over our input map and write all mappings to the ini file for( int i=0; i<MAX_GAME_CONTROLLERS; i++ ) { for( int j=0; j<MAX_GAME_BUTTONS; j++ ) { CString sNameString, sValueString; GameInput GameI( (GameController)i, (GameButton)j ); sNameString = GameI.toString(); sValueString = ssprintf( "%s,%s,%s", m_GItoDI[i][j][0].toString().c_str(), m_GItoDI[i][j][1].toString().c_str(), m_GItoDI[i][j][2].toString().c_str() ); ini.SetValue( GAMESTATE->GetCurrentGame()->m_szName, sNameString, sValueString ); } } ini.WriteFile( KEYMAPS_PATH ); }
void InputMapper::UpdateTempDItoGI() { // clear out m_tempDItoGI for( int d=0; d<NUM_INPUT_DEVICES; d++ ) { for( int b=0; b<NUM_DEVICE_BUTTONS[d]; b++ ) { m_tempDItoGI[d][b].MakeInvalid(); } } // repopulate m_tempDItoGI for( int n=0; n<MAX_GAME_CONTROLLERS; n++ ) { for( int b=0; b<MAX_GAME_BUTTONS; b++ ) { for( int s=0; s<NUM_GAME_TO_DEVICE_SLOTS; s++ ) { GameInput GameI( (GameController)n, (GameButton)b ); DeviceInput DeviceI = m_GItoDI[n][b][s]; if( DeviceI.IsValid() ) m_tempDItoGI[DeviceI.device][DeviceI.button] = GameI; } } } }
void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped() { // Clear default mappings. Default mappings are in the third slot. FOREACH_ENUM( GameController, i ) FOREACH_ENUM( GameButton, j) ClearFromInputMap( GameInput(i, j), 2 ); vector<AutoMappingEntry> aMaps; aMaps.reserve( 32 ); FOREACH_CONST( AutoMappingEntry, g_DefaultKeyMappings.m_vMaps, iter ) aMaps.push_back( *iter ); FOREACH_CONST( AutoMappingEntry, m_pInputScheme->m_pAutoMappings->m_vMaps, iter ) aMaps.push_back( *iter ); /* There may be duplicate GAME_BUTTON maps. Process the list backwards, * so game-specific mappings override g_DefaultKeyMappings. */ std::reverse( aMaps.begin(), aMaps.end() ); FOREACH( AutoMappingEntry, aMaps, m ) { DeviceButton key = m->m_deviceButton; DeviceInput DeviceI( DEVICE_KEYBOARD, key ); GameInput GameI( m->m_bSecondController ? GameController_2 : GameController_1, m->m_gb ); if( !IsMapped(DeviceI) ) // if this key isn't already being used by another user-made mapping { if( !GameI.IsValid() ) ClearFromInputMap( DeviceI ); else SetInputMap( DeviceI, GameI, 2 ); } }
void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped() { // Clear default mappings. Default mappings are in the third slot. for( int i=0; i<MAX_GAME_CONTROLLERS; i++ ) for( int j=0; j<MAX_GAME_BUTTONS; j++ ) ClearFromInputMap( GameInput((GameController)i,(GameButton)j), 2 ); const Game* pGame = GAMESTATE->GetCurrentGame(); for( int c=0; c<MAX_GAME_CONTROLLERS; c++ ) { for( int b=0; b<pGame->m_iButtonsPerController; b++ ) { int key = pGame->m_iDefaultKeyboardKey[c][b]; if( key == NO_DEFAULT_KEY ) continue; DeviceInput DeviceI( DEVICE_KEYBOARD, key ); GameInput GameI( (GameController)c, (GameButton)b ); if( !IsMapped(DeviceI) ) // if this key isn't already being used by another user-made mapping SetInputMap( DeviceI, GameI, 2 ); } } }