void CheckKeyValues( KeyValues *pKeyValues, CUtlVector<VTFInfo_t> &vtf ) { for ( KeyValues *pSubKey = pKeyValues->GetFirstValue(); pSubKey; pSubKey = pSubKey->GetNextValue() ) { if ( pSubKey->GetDataType() != KeyValues::TYPE_STRING ) continue; if ( IsTexture( pSubKey->GetString() ) ) { int nLen = Q_strlen( pSubKey->GetString() ) + 1; char *pTemp = (char*)_alloca( nLen ); memcpy( pTemp, pSubKey->GetString(), nLen ); Q_FixSlashes( pTemp ); int nCount = vtf.Count(); for ( int i = 0; i < nCount; ++i ) { if ( Q_stricmp( vtf[i].m_VTFName, pTemp ) ) continue; vtf[i].m_bFoundInVMT = true; break; } } } for ( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { CheckKeyValues( pSubKey, vtf ); } }
bool CMapAdd::RunPlayerInit( const char *mapaddMap, const char *szLabel) { if(AllocPooledString(mapaddMap) == AllocPooledString("") || !mapaddMap) return false; //Failed to load! if(!szLabel) szLabel = "Init"; //FileHandle_t fh = filesystem->Open(szMapadd,"r","MOD"); // Open the mapadd data file, and abort if we can't KeyValues *pMapAdd = new KeyValues( "MapAdd" ); if(pMapAdd->LoadFromFile( filesystem, mapaddMap, "MOD" )) { KeyValues *pMapAdd2 = pMapAdd->FindKey(szLabel); if(pMapAdd2) { KeyValues *pMapAddEnt = pMapAdd2->GetFirstTrueSubKey(); while (pMapAddEnt) { HandlePlayerEntity(pMapAddEnt, false); pMapAddEnt = pMapAddEnt->GetNextTrueSubKey(); //Got to keep this! } } } pMapAdd->deleteThis(); return true; }
static cell_t smn_KvGotoNextKey(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError herr; HandleSecurity sec; KeyValueStack *pStk; sec.pOwner = NULL; sec.pIdentity = g_pCoreIdent; if ((herr=handlesys->ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr); } KeyValues *pSubKey = pStk->pCurRoot.front(); if (params[2]) { pSubKey = pSubKey->GetNextTrueSubKey(); } else { pSubKey = pSubKey->GetNextKey(); } if (!pSubKey) { return 0; } pStk->pCurRoot.pop(); pStk->pCurRoot.push(pSubKey); return 1; }
/** * @brief Scans the KeyValues tree for a key with the name name. */ class KeyValues* CRPG_FileVar::scan_kvtree(class KeyValues *kv, char *name) { KeyValues *subkey; for(subkey = kv; subkey != NULL; subkey = subkey->GetNextTrueSubKey()) { if(CRPG::istrcmp((char*)subkey->GetName(), name)) return subkey; } return NULL; }
//----------------------------------------------------------------------------- // Scan material + all subsections for key //----------------------------------------------------------------------------- static bool DoesMaterialHaveKey( KeyValues *pKeyValues, const char *pKeyName ) { if ( pKeyValues->GetString( pKeyName, NULL ) != NULL ) return true; for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { if ( DoesMaterialHaveKey( pSubKey, pKeyName ) ) return true; } return false; }
//----------------------------------------------------------------------------- // Scan material + all subsections for key //----------------------------------------------------------------------------- static float MaterialFloatKeyValue( KeyValues *pKeyValues, const char *pKeyName, float flDefault ) { float flValue = pKeyValues->GetFloat( pKeyName, flDefault ); if ( flValue != flDefault ) return flValue; for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { float flValue = MaterialFloatKeyValue( pSubKey, pKeyName, flDefault ); if ( flValue != flDefault ) return flValue; } return flDefault; }
//----------------------------------------------------------------------------- // Scan material + all subsections for key/value pair //----------------------------------------------------------------------------- static bool DoesMaterialHaveKeyValuePair( KeyValues *pKeyValues, const char *pKeyName, const char *pSearchValue ) { const char *pVal; pVal = pKeyValues->GetString( pKeyName, NULL ); if ( pVal != NULL && ( Q_stricmp( pSearchValue, pVal ) == 0 ) ) return true; for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { if ( DoesMaterialHaveKeyValuePair( pSubKey, pKeyName, pSearchValue ) ) return true; } return false; }
void CASWJukeboxPlaylist::LoadPlaylistKV() { KeyValues *pKV = new KeyValues( "playlist" ); if( pKV->LoadFromFile( filesystem, sz_PlaylistFilename ) ) { // If the load succeeded, create the playlist for( KeyValues *sub = pKV->GetFirstSubKey(); sub != NULL; sub = sub->GetNextTrueSubKey() ) { const char *szTrackName = sub->GetString("TrackName"); const char *szHexName = sub->GetString("HexName"); const char *szAlbum = sub->GetString("Album"); const char *szArtist = sub->GetString("Artist"); const char *szGenre = sub->GetString("Genre"); AddMusicToPlaylist( szTrackName, szHexName, szAlbum, szArtist, szGenre ); } } }
void CreateMaterialPatchRecursive( KeyValues *pOriginalKeyValues, KeyValues *pPatchKeyValues, int nKeys, const MaterialPatchInfo_t *pInfo ) { int i; for( i = 0; i < nKeys; i++ ) { const char *pVal = pOriginalKeyValues->GetString( pInfo[i].m_pKey, NULL ); if( !pVal ) continue; if( pInfo[i].m_pRequiredOriginalValue && Q_stricmp( pVal, pInfo[i].m_pRequiredOriginalValue ) != 0 ) continue; pPatchKeyValues->SetString( pInfo[i].m_pKey, pInfo[i].m_pValue ); } KeyValues *pScan; for( pScan = pOriginalKeyValues->GetFirstTrueSubKey(); pScan; pScan = pScan->GetNextTrueSubKey() ) { CreateMaterialPatchRecursive( pScan, pPatchKeyValues->FindKey( pScan->GetName(), true ), nKeys, pInfo ); } }
void ReadCheatCommandsFromFile( char *pchFileName ) { KeyValues *pCheatCodeKeys = new KeyValues( "cheat_codes" ); pCheatCodeKeys->LoadFromFile( g_pFullFileSystem, pchFileName, NULL ); KeyValues *pKey = NULL; for ( pKey = pCheatCodeKeys->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() ) { int iCheat = s_CheatCodeCommands.AddToTail(); CheatCodeData_t *pNewCheatCode = &(s_CheatCodeCommands[ iCheat ]); Q_strncpy( pNewCheatCode->szName, pKey->GetName(), CHEAT_NAME_MAX_LEN ); // Get the name pNewCheatCode->bDevOnly = ( pKey->GetInt( "dev", 0 ) != 0 ); // Get developer only flag pNewCheatCode->iCodeLength = 0; // Start at zero code elements Q_strncpy( pNewCheatCode->szCommand, pKey->GetString( "command", "echo \"Cheat code has no command!\"" ), CHEAT_COMMAND_MAX_LEN ); KeyValues *pSubKey = NULL; for ( pSubKey = pKey->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey() ) { const char *pchType = pSubKey->GetName(); if ( Q_strcmp( pchType, "code" ) == 0 ) { AssertMsg( ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN ), "Cheat code elements exceeded max!" ); pNewCheatCode->pButtonCodes[ pNewCheatCode->iCodeLength ] = g_pInputSystem->StringToButtonCode( pSubKey->GetString() ); ++pNewCheatCode->iCodeLength; } } if ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN ) { // If it's activation is a subsequence of another cheat, the longer cheat can't be activated! DevWarning( "Cheat code \"%s\" has less than %i code elements!", pKey->GetName(), CHEAT_NAME_MAX_LEN ); } } }
void CGECreateServer::PopulateControls( void ) { // Only populate on first load if ( !m_bFirstLoad ) return; // Populate the map list ComboBox *maplist = dynamic_cast<ComboBox*>( FindChildByName("MapList") ); if ( maplist ) { // Clear the list first maplist->DeleteAllItems(); FileFindHandle_t findHandle; // note: FileFINDHandle char file[32]; maplist->AddItem( "#SERVER_RANDOM_MAP", new KeyValues(RANDOM_VALUE) ); const char *pFilename = filesystem->FindFirstEx( "maps\\*.bsp", "MOD", &findHandle ); while ( pFilename ) { if ( stricmp(pFilename, "ge_transition.bsp") ) //They don't need to pick our dinky crash avoidance map. { // Add the map to the list Q_FileBase(pFilename, file, 32); maplist->AddItem(file, new KeyValues(file)); } pFilename = filesystem->FindNext( findHandle ); } filesystem->FindClose( findHandle ); maplist->SetNumberOfEditLines( 10 ); maplist->SetEditable( false ); maplist->GetMenu()->ForceCalculateWidth(); maplist->ActivateItemByRow( 0 ); } // Populate the weapon list ComboBox *weaponlist = dynamic_cast<ComboBox*>( FindChildByName("WeaponList") ); if ( weaponlist ) { weaponlist->DeleteAllItems(); // TAKEN DIRECTLY FROM ge_loadoutmanager.cpp // Parsing individually allows us to overwrite the default sets with custom ones // Multiple custom sets can be defined as needed (can even make sets per gameplay) if ( !GELoadoutParser.HasBeenParsed() ) { GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_default.X"); GELoadoutParser.SetHasBeenParsed( false ); GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_custom*.X"); } // Random loadout weaponlist->AddItem( "#SERVER_RANDOM_SET", new KeyValues("random_loadout") ); FOR_EACH_DICT( m_WeaponSets, idx ) { if (Q_strstr(m_WeaponSets.GetElementName(idx), "_mhide")) continue; int id = weaponlist->AddItem( m_WeaponSets.GetElementName(idx), NULL ); weaponlist->GetMenu()->SetItemEnabled( id, false ); for ( int k=m_WeaponSets[idx]->First(); k != m_WeaponSets[idx]->InvalidIndex(); k = m_WeaponSets[idx]->Next(k) ) weaponlist->AddItem( m_WeaponSets[idx]->Element(k), new KeyValues(m_WeaponSets[idx]->GetElementName(k)) ); } weaponlist->SetEditable( false ); weaponlist->SetNumberOfEditLines( 15 ); weaponlist->GetMenu()->ForceCalculateWidth(); weaponlist->ActivateItemByRow( 0 ); } // Populate the scenario list ComboBox *scenariolist = dynamic_cast<ComboBox*>( FindChildByName("ScenarioList") ); if ( scenariolist ) { // Clear the list first scenariolist->DeleteAllItems(); FileFindHandle_t findHandle; // note: FileFINDHandle char file[32]; scenariolist->AddItem( "#SERVER_RANDOM_SCENARIO", new KeyValues(RANDOM_VALUE) ); const char *pFilename = filesystem->FindFirstEx( PYDIR, "MOD", &findHandle ); while ( pFilename ) { // Add the scenario to the list if not __init__ if ( !Q_stristr( pFilename, "__init__") ) { Q_FileBase( pFilename, file, 32 ); scenariolist->AddItem( file, new KeyValues(file) ); } pFilename = filesystem->FindNext( findHandle ); } filesystem->FindClose( findHandle ); scenariolist->SetEditable( false ); scenariolist->SetNumberOfEditLines( 10 ); scenariolist->GetMenu()->ForceCalculateWidth(); scenariolist->ActivateItemByRow( 0 ); } // Populate the bot difficulty list ComboBox *botdifflist = dynamic_cast<ComboBox*>( FindChildByName("BotLevel") ); if ( botdifflist && botdifflist->GetItemCount() == 0 ) { // Hard coded items (sorry!) botdifflist->AddItem( "#BOT_LEVEL_EASY", new KeyValues("1") ); botdifflist->AddItem( "#BOT_LEVEL_MED", new KeyValues("3") ); botdifflist->AddItem( "#BOT_LEVEL_HARD", new KeyValues("6") ); botdifflist->AddItem( "#BOT_LEVEL_UBER", new KeyValues("9") ); // Admin botdifflist->SetEditable( false ); botdifflist->SetNumberOfEditLines( 4 ); botdifflist->GetMenu()->ForceCalculateWidth(); botdifflist->ActivateItemByRow( 0 ); } // Populate the turbo mode list ComboBox *turbolist = dynamic_cast<ComboBox*>( FindChildByName("TurboMode") ); if ( turbolist && turbolist->GetItemCount() == 0 ) { // Hard coded items (sorry!) turbolist->AddItem( "#TURBO_MODE_NORM", new KeyValues("1.000000") ); turbolist->AddItem( "#TURBO_MODE_FAST", new KeyValues("1.500000") ); turbolist->AddItem( "#TURBO_MODE_LIGHT", new KeyValues("1.850000") ); // Admin turbolist->SetEditable( false ); turbolist->SetNumberOfEditLines( 3 ); turbolist->GetMenu()->ForceCalculateWidth(); turbolist->ActivateItemByRow( 0 ); } // Load the default/saved values from our command map for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() ) { // Get our value (or default) const char *value = (m_kvCmdValues->FindKey( kv->GetName() )) ? m_kvCmdValues->GetString( kv->GetName() ) : NULL; if ( !value ) value = kv->GetString( "default", "" ); if ( !Q_stricmp(kv->GetString("type"), "CHOICE") ) { ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; // Search through all our items to find a matching value for ( int i=0; i < panel->GetItemCount(); i++ ) { int id = panel->GetItemIDFromRow( i ); KeyValues* userdata = panel->GetItemUserData( id ); if ( userdata && !Q_stricmp(value, userdata->GetName()) ) { panel->ActivateItem( id ); break; } } } else if ( !Q_stricmp(kv->GetString("type"), "TEXT") ) { TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; panel->SetText( value ); } else if ( !Q_stricmp(kv->GetString("type"), "BOOL") ) { CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) ); if ( !panel ) continue; if ( !Q_stricmp(value, "1") ) panel->SetSelected( true ); else panel->SetSelected( false ); } } m_bFirstLoad = false; }
void CGECreateServer::OnCommand( const char *command ) { if ( !Q_stricmp(command, "play") ) { CUtlVector<char*> commands; // Pull the values from our controls and apply them to commands and save off the choices for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() ) { KeyValues *kv_value = m_kvCmdValues->FindKey( kv->GetName(), true ); char *cmd = new char[128]; try { if ( !Q_stricmp(kv->GetString("type"), "CHOICE") ) { ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) ); const char *cmd_value = panel->GetActiveItemUserData()->GetName(); kv_value->SetStringValue( cmd_value ); if ( !Q_stricmp(cmd_value, RANDOM_VALUE) ) { int idx = GERandom<int>( panel->GetItemCount()-1 ) + 1; idx = panel->GetItemIDFromRow( idx ); cmd_value = panel->GetItemUserData( idx )->GetName(); } Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value ); commands.AddToTail( cmd ); } else if ( !Q_stricmp(kv->GetString("type"), "TEXT") ) { char cmd_value[64]; TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) ); panel->GetText( cmd_value, 64 ); // We don't allow blank values... use default instead if ( !cmd_value[0] ) Q_strncpy( cmd_value, kv->GetString("default",""), 64 ); kv_value->SetStringValue( cmd_value ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value ); commands.AddToTail( cmd ); } else if ( !Q_stricmp(kv->GetString("type"), "BOOL") ) { CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) ); if ( panel->IsSelected() ) { kv_value->SetStringValue( "1" ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("on_val","1") ); } else { kv_value->SetStringValue( "0" ); Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("off_val","0") ); } commands.AddToTail( cmd ); } else { delete [] cmd; } } catch (...) { delete [] cmd; } } // Apply the commands for ( int i=0; i < commands.Count(); i++ ) engine->ClientCmd_Unrestricted( commands[i] ); // Save our last used settings to our custom file m_kvCmdValues->SaveToFile( filesystem, COMMAND_MAP_VAL, "MOD" ); // Cleanup commands.PurgeAndDeleteElements(); } SetVisible( false ); }
//========================================================= //========================================================= bool C_GameInstructor::ReadSaveData() { // for external playtests, don't ever read in persisted instructor state, always start fresh if ( CommandLine()->FindParm( "-playtest" ) ) return true; if ( m_bHasLoadedSaveData ) return true; // Always reset state first in case storage device // was declined or ends up in faulty state ResetDisplaysAndSuccesses(); m_bHasLoadedSaveData = true; #ifdef _X360 DevMsg( "Read Game Instructor for splitscreen slot %d\n", m_nSplitScreenSlot ); if ( m_nSplitScreenSlot < 0 ) return false; if ( m_nSplitScreenSlot >= (int) XBX_GetNumGameUsers() ) return false; int iController = XBX_GetUserId( m_nSplitScreenSlot ); if ( iController < 0 || XBX_GetUserIsGuest( iController ) ) { // Can't read data for guests return false; } DWORD nStorageDevice = XBX_GetStorageDeviceId( iController ); if ( !XBX_DescribeStorageDevice( nStorageDevice ) ) return false; #endif char szFilename[_MAX_PATH]; #ifdef _X360 if ( IsX360() ) { XBX_MakeStorageContainerRoot( iController, XBX_USER_SETTINGS_CONTAINER_DRIVE, szFilename, sizeof( szFilename ) ); int nLen = strlen( szFilename ); Q_snprintf( szFilename + nLen, sizeof( szFilename ) - nLen, ":\\game_instructor_counts.txt" ); } else #endif { Q_snprintf( szFilename, sizeof( szFilename ), "save/game_instructor_counts.txt" ); } KeyValues *data = new KeyValues( "Game Instructor Counts" ); KeyValues::AutoDelete autoDelete(data); if ( data->LoadFromFile( g_pFullFileSystem, szFilename, NULL ) ) { int nVersion = 0; for ( KeyValues *pKey = data->GetFirstSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() ) { CBaseLesson *pLesson = GetLesson_Internal( pKey->GetName() ); if ( pLesson ) { pLesson->SetDisplayCount( pKey->GetInt( "display", 0 ) ); pLesson->SetSuccessCount( pKey->GetInt( "success", 0 ) ); if ( Q_strcmp( pKey->GetName(), "version number" ) == 0 ) { nVersion = pLesson->GetSuccessCount(); } } } CBaseLesson *pLessonVersionNumber = GetLesson_Internal( "version number" ); if ( pLessonVersionNumber && !pLessonVersionNumber->IsLearned() ) { ResetDisplaysAndSuccesses(); pLessonVersionNumber->SetSuccessCount( pLessonVersionNumber->GetSuccessLimit() ); m_bDirtySaveData = true; } return true; } // Couldn't read from the file return false; }
static bool MaterialVectorKeyValue( KeyValues *pKeyValues, const char *pKeyName, int nDefaultDim, float *pDefault, int *pDim, float *pVector ) { int nDim; float retVal[4]; KeyValues *pValue = pKeyValues->FindKey( pKeyName ); if ( pValue ) { switch( pValue->GetDataType() ) { case KeyValues::TYPE_INT: { int nInt = pValue->GetInt(); for ( int i = 0; i < 4; ++i ) { retVal[i] = nInt; } if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) { *pDim = nDefaultDim; memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); return true; } } break; case KeyValues::TYPE_FLOAT: { float flFloat = pValue->GetFloat(); for ( int i = 0; i < 4; ++i ) { retVal[i] = flFloat; } if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) { *pDim = nDefaultDim; memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); return true; } } break; case KeyValues::TYPE_STRING: { nDim = ParseVectorFromKeyValueString( pValue, "", retVal ); if ( !AsVectorsEqual( nDefaultDim, pDefault, nDim, retVal ) ) { *pDim = nDim; memcpy( pVector, retVal, nDim * sizeof(float) ); return true; } } break; } } for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { if ( MaterialVectorKeyValue( pSubKey, pKeyName, nDefaultDim, pDefault, &nDim, retVal ) ) { *pDim = nDim; memcpy( pVector, retVal, nDim * sizeof(float) ); return true; } } *pDim = nDefaultDim; memcpy( pVector, pDefault, nDefaultDim * sizeof(float) ); return false; }
void CWeapons::LoadWeapons(const char *szWeaponListName, WeaponsData_t *pDefault) { if ((szWeaponListName != NULL) && (szWeaponListName[0] != 0)) { KeyValues *kv = new KeyValues("Weapons"); char szFilename[1024]; CBotGlobals::BuildFileName(szFilename, "weapons", BOT_CONFIG_FOLDER, "ini", false); if (kv) { if (kv->LoadFromFile(filesystem, szFilename, NULL)) { kv = kv->FindKey(szWeaponListName); if (kv) { kv = kv->GetFirstSubKey(); if (0) kv = kv->GetFirstTrueSubKey(); while (kv != NULL) { WeaponsData_t newWeapon; memset(&newWeapon, 0, sizeof(WeaponsData_t)); const char *szKeyName = kv->GetName(); char lowered[64]; strncpy(lowered, szKeyName, 63); lowered[63] = 0; __strlow(lowered); newWeapon.szWeaponName = CStrings::GetString(lowered); newWeapon.iId = kv->GetInt("id"); newWeapon.iSlot = kv->GetInt("slot"); newWeapon.minPrimDist = kv->GetFloat("minPrimDist"); newWeapon.maxPrimDist = kv->GetFloat("maxPrimDist"); newWeapon.m_fProjSpeed = kv->GetFloat("m_fProjSpeed"); newWeapon.m_iAmmoIndex = kv->GetInt("m_iAmmoIndex"); newWeapon.m_iPreference = kv->GetInt("m_iPreference"); KeyValues *flags = kv->FindKey("flags"); if (flags) { int i = 0; while (szWeaponFlags[i][0] != '\0') { if (flags->FindKey(szWeaponFlags[i]) && (flags->GetInt(szWeaponFlags[i]) == 1)) newWeapon.m_iFlags |= (1 << i); i++; } } AddWeapon(new CWeapon(&newWeapon)); kv = kv->GetNextTrueSubKey(); } } } kv->deleteThis(); } } if (pDefault != NULL) { // No weapons from INI file then add default if (m_theWeapons.size() == 0) { while (pDefault->szWeaponName[0] != '\0') { AddWeapon(new CWeapon(pDefault)); pDefault++; } } } }
void GameModes::ApplySettings( KeyValues *pInResourceData ) { BaseClass::ApplySettings( pInResourceData ); vgui::HScheme hScheme = vgui::scheme()->GetScheme( "SwarmScheme" ); vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( hScheme ); if ( !pScheme ) return; const char *pImageName = pInResourceData->GetString( "borderimage", "" ); m_nBorderImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nBorderImageId == -1 ) { m_nBorderImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nBorderImageId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "leftarrow", "" ); m_nLeftArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nLeftArrowId == -1 ) { m_nLeftArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nLeftArrowId, pImageName, true, false ); } pImageName = pInResourceData->GetString( "rightarrow", "" ); m_nRightArrowId = vgui::surface()->DrawGetTextureId( pImageName ); if ( m_nRightArrowId == -1 ) { m_nRightArrowId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( m_nRightArrowId, pImageName, true, false ); } m_nPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picoffsetx", 0 ) ); m_nPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picwidth", 0 ) ); m_nPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picheight", 0 ) ); m_nMenuTitleX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlex", 0 ) ); m_nMenuTitleY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitley", 0 ) ); m_nMenuTitleWide = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlewide", 0 ) ); m_nMenuTitleTall = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitletall", 0 ) ); m_nSubPics = pInResourceData->GetInt( "subpics", 0 ); m_nSubPicGap = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicgap", 0 ) ); m_nSubPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsetx", 0 ) ); m_nSubPicOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsety", 0 ) ); m_nSubPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicwidth", 0 ) ); m_nSubPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicheight", 0 ) ); m_bHideLabels = !!vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "hidelabels", 0 ) ); m_nArrowWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowwidth", 0 ) ); m_nArrowHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowheight", 0 ) ); m_nArrowOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowoffsety", 0 ) ); m_nRightArrowOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "rightarrowoffsetx", 0 ) ); m_hNameFont = pScheme->GetFont( pInResourceData->GetString( "subpicnamefont", "" ), true ); m_nNameFontHeight = vgui::surface()->GetFontTall( m_hNameFont ); const char *pNavUp = pInResourceData->GetString( "navUp", "" ); const char *pNavDown = pInResourceData->GetString( "navDown", "" ); int wideAtOpen = pInResourceData->GetInt( "wideatopen", 0 ); // need to reset due to video mode change, alt+tab, etc m_GameModeInfos.Purge(); // find all modes for ( KeyValues *pModeKey = pInResourceData->GetFirstTrueSubKey(); pModeKey; pModeKey = pModeKey->GetNextTrueSubKey() ) { pImageName = pModeKey->GetString( "image", "" ); int nImageId = vgui::surface()->DrawGetTextureId( pImageName ); if ( nImageId == -1 ) { nImageId = vgui::surface()->CreateNewTextureID(); vgui::surface()->DrawSetTextureFile( nImageId, pImageName, true, false ); } int iIndex = m_GameModeInfos.AddToTail(); m_GameModeInfos[iIndex].m_NameId = pModeKey->GetString( "id", "" ); m_GameModeInfos[iIndex].m_NameText = pModeKey->GetString( "name", "" ); m_GameModeInfos[iIndex].m_CommandText = pModeKey->GetString( "command", "" ); m_GameModeInfos[iIndex].m_TitleText = pModeKey->GetString( "menutitle", "" ); m_GameModeInfos[iIndex].m_HintText = pModeKey->GetString( "menuhint", "" ); m_GameModeInfos[iIndex].m_HintTextDisabled = pModeKey->GetString( "menuhintdisabled", "" ); m_GameModeInfos[iIndex].m_nImageId = nImageId; m_GameModeInfos[iIndex].m_bEnabled = pModeKey->GetBool( "enabled", true ); m_GameModeInfos[iIndex].m_pHybridButton = new BaseModHybridButton( this, m_GameModeInfos[iIndex].m_NameId, m_GameModeInfos[iIndex].m_TitleText, this->GetParent(), m_GameModeInfos[iIndex].m_CommandText ); KeyValues *pKV = new KeyValues( "BtnGameMode" ); int buttonX = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleX ); int buttonY = vgui::scheme()->GetProportionalNormalizedValue( m_nPicHeight + m_nMenuTitleY ); int buttonW = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleWide ); int buttonH = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleTall ); pKV->SetInt( "xpos", buttonX ); pKV->SetInt( "ypos", buttonY ); pKV->SetInt( "wide", buttonW ); pKV->SetInt( "tall", buttonH ); pKV->SetInt( "autoResize", 1 ); pKV->SetInt( "pinCorner", 0 ); pKV->SetInt( "visible", 0 ); pKV->SetInt( "enabled", m_GameModeInfos[iIndex].m_bEnabled ); pKV->SetInt( "tabPosition", 0 ); if ( IsX360() ) { pKV->SetString( "navUp", pNavUp ); pKV->SetString( "navDown", pNavDown ); } pKV->SetString( "tooltiptext", m_GameModeInfos[iIndex].m_HintText ); pKV->SetString( "disabled_tooltiptext", m_GameModeInfos[iIndex].m_HintTextDisabled ); pKV->SetString( "style", "GameModeButton" ); pKV->SetInt( "ActivationType", 1 ); pKV->SetString( "EnableCondition", pModeKey->GetString( "EnableCondition", "" ) ); pKV->SetInt( "wideatopen", wideAtOpen ); m_GameModeInfos[iIndex].m_pHybridButton->ApplySettings( pKV ); pKV->deleteThis(); } m_nMenuTitleActualTall = m_nMenuTitleTall; if ( m_GameModeInfos.Count() ) { // get the real size m_nMenuTitleActualTall = m_GameModeInfos[0].m_pHybridButton->GetTall(); // fixup the number of subpics to what we actually have // one active plus any subpics can only show the modes with no repeat m_nSubPics = MIN( m_nSubPics, m_GameModeInfos.Count() - 1 ); } else { m_nSubPics = 0; } // exact size fixup width to get hardware clipping on rhs int panelWidth, panelHeight; GetSize( panelWidth, panelHeight ); panelWidth = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX + ( m_nSubPics + 1 ) * m_nSubPicWidth + m_nSubPics * m_nSubPicGap; panelHeight = m_nPicHeight + m_nMenuTitleY + ( m_nMenuTitleActualTall - m_nMenuTitleTall )/2 + m_nMenuTitleTall; SetSize( panelWidth, panelHeight ); // calc the arrow position for drawing and hit testing m_nSubPicX = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX; m_nSubPicY = ( m_nPicHeight + m_nMenuTitleY + m_nMenuTitleTall - m_nSubPicHeight )/2 + m_nSubPicOffsetY; m_nLeftArrowX = m_nPicOffsetX - m_nSubPicGap - m_nArrowWidth; m_nLeftArrowY = m_nSubPicY + m_nSubPicHeight - m_nArrowHeight + m_nArrowOffsetY; if ( m_nRightArrowOffsetX ) { m_nRightArrowX = m_nPicOffsetX + m_nPicWidth + m_nSubPicGap + m_nRightArrowOffsetX; } else { m_nRightArrowX = m_nSubPicX + m_nSubPics * ( m_nSubPicWidth + m_nSubPicGap ); } m_nRightArrowY = m_nLeftArrowY; // try to put back our last known game mode // this is to solve the navigation to children when the navigation has been lost // or alt+tab, video mode resize m_nActive = 0; if ( !g_CurrentModeIdSave.IsEmpty() ) { m_nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() ); if ( m_nActive == -1 ) { // no longer available g_CurrentModeIdSave = NULL; m_nActive = 0; } } SetActiveGameMode( m_nActive, true ); }
//============================================================================= void InGameChapterSelect::ApplySchemeSettings(vgui::IScheme *pScheme) { BaseClass::ApplySchemeSettings(pScheme); SetPaintBackgroundEnabled( true ); // Determine current game settings KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); char const *szGameMode = pGameSettings->GetString( "game/mode", "campaign" ); if ( !GameModeIsSingleChapter( szGameMode ) ) pGameSettings->SetInt( "game/chapter", 1 ); // Get mission and campaign info KeyValues *pInfoMission = NULL; KeyValues *pInfoChapter = g_pMatchExtSwarm->GetMapInfo( pGameSettings, &pInfoMission ); // Check if this is a custom mission? if ( pInfoMission && !pInfoMission->GetBool( "builtin" ) ) pInfoChapter = pInfoMission = NULL; // trigger to use another builtin mission if ( !pInfoMission || !pInfoChapter ) { KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions(); for ( pInfoMission = pAllMissions ? pAllMissions->GetFirstTrueSubKey() : NULL; pInfoMission; pInfoMission = pInfoMission->GetNextTrueSubKey() ) { if ( !pInfoMission->GetBool( "builtin" ) ) continue; pInfoChapter = pInfoMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) ); if ( pInfoChapter ) break; } } Assert( pInfoMission && pInfoChapter ); // set the dropdowns DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) ); DropDownMenu *pChapterDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpChapter" ) ); if( pMissionDropDown && pChapterDropDown ) //missions change what the available campaigns are, we should listen on that flyout as well { pMissionDropDown->SetFlyout( CFmtStr( "FlmMission%s", szGameMode ) ); if ( pInfoMission && pInfoChapter ) { pMissionDropDown->SetCurrentSelection( CFmtStr( "cmd_campaign_%s", pInfoMission->GetString( "name" ) ) ); Q_strncpy( m_chCampaign, pInfoMission->GetString( "name" ), ARRAYSIZE( m_chCampaign ) ); // Set this after setting the mission dropdown, as that will default the chapter to the first in the campaign pChapterDropDown->SetCurrentSelection( CFmtStr( "#L4D360UI_Chapter_%d", pInfoChapter->GetInt( "chapter" ) ) ); m_nChapter = pInfoChapter->GetInt( "chapter" ); } FlyoutMenu *flyout = pMissionDropDown->GetCurrentFlyout(); if( flyout ) { flyout->CloseMenu( NULL ); } flyout = pChapterDropDown->GetCurrentFlyout(); if( flyout ) { flyout->CloseMenu( NULL ); } if ( m_ActiveControl ) { m_ActiveControl->NavigateFrom( ); } pMissionDropDown->NavigateTo(); m_ActiveControl = pMissionDropDown; // Chapters are directly selectable only in some game modes pChapterDropDown->SetEnabled( GameModeIsSingleChapter( szGameMode ) ); } SetPaintBackgroundEnabled( true ); SetupAsDialogStyle(); }
//============================================================================= void CustomCampaigns::Activate() { BaseClass::Activate(); // // Show reminder to download legacy data (if necessary) // if ( GetLegacyData::CheckAndSeeIfShouldShow() ) { CBaseModPanel::GetSingleton().OpenWindow( WT_GETLEGACYDATA, this, false ); } m_ActiveControl = m_GplCustomCampaigns; m_GplCustomCampaigns->RemoveAllPanelItems(); // Build a list of campaigns KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions(); if ( !pAllMissions ) return; char const *szGameMode = m_pDataSettings->GetString( "game/mode", "campaign" ); for ( KeyValues *pMission = pAllMissions->GetFirstTrueSubKey(); pMission; pMission = pMission->GetNextTrueSubKey() ) { // Skip builtin missions if ( pMission->GetInt( "builtin" ) ) continue; m_hasAddonCampaign = true; // Check this campaign has chapters for this mode KeyValues *pFirstChapter = pMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) ); if ( !pFirstChapter ) { m_SomeAddonNoSupport = true; continue; } CustomCampaignListItem* panelItem = m_GplCustomCampaigns->AddPanelItem<CustomCampaignListItem>( "CustomCampaignListItem" ); panelItem->SetParent( m_GplCustomCampaigns ); panelItem->SetCustomCampaignName( pMission->GetString( "displaytitle" ) ); panelItem->SetCampaignContext( pMission->GetString( "name" ) ); } }
//----------------------------------------------------------------------------- // Main entry point for the unserialization //----------------------------------------------------------------------------- CDmElement* CImportActBusy::UnserializeFromKeyValues( KeyValues *pKeyValues ) { // Create the main element CDmElement *pElement = CreateDmElement( "DmElement", "ActBusyList", NULL ); if ( !pElement ) return NULL; // Each act busy list needs to have an editortype associated with it so it displays nicely in editors pElement->SetValue( "editorType", "actBusyList" ); // All actbusy keys are elements of a single element array attribute 'children' CDmAttribute *pChildren = pElement->AddAttribute( "children", AT_ELEMENT_ARRAY ); if ( !pChildren ) return NULL; // Under the root are all the actbusy keys for ( KeyValues *pActBusyKey = pKeyValues->GetFirstTrueSubKey(); pActBusyKey != NULL; pActBusyKey = pActBusyKey->GetNextTrueSubKey() ) { if ( !UnserializeActBusyKey( pChildren, pActBusyKey ) ) { Warning( "Error importing actbusy element %s\n", pActBusyKey->GetName() ); return NULL; } } // Resolve all element references recursively RecursivelyResolveElement( pElement ); return pElement; }
bool CMapAdd::RunLabel( const char *mapaddMap, const char *szLabel) { if(AllocPooledString(mapaddMap) == AllocPooledString("") || !mapaddMap || !szLabel || AllocPooledString(szLabel) == AllocPooledString("")) return false; //Failed to load! //FileHandle_t fh = filesystem->Open(szMapadd,"r","MOD"); // Open the mapadd data file, and abort if we can't KeyValues *pMapAdd = new KeyValues( "MapAdd" ); if(pMapAdd->LoadFromFile( filesystem, mapaddMap, "MOD" )) { KeyValues *pMapAdd2 = pMapAdd->FindKey(szLabel); if(pMapAdd2) { KeyValues *pMapAddEnt = pMapAdd2->GetFirstTrueSubKey(); while (pMapAddEnt) { if(!HandlePlayerEntity(pMapAddEnt, false) && !HandleRemoveEnitity( pMapAddEnt ) && !HandleSMODEntity(pMapAddEnt) && !HandleSpecialEnitity(pMapAddEnt)) { Vector SpawnVector = Vector(0,0,0); QAngle SpawnAngle = QAngle(0,0,0); SpawnVector.x = pMapAddEnt->GetFloat("x", SpawnVector.x); SpawnVector.y = pMapAddEnt->GetFloat("y", SpawnVector.y); SpawnVector.z = pMapAddEnt->GetFloat("z", SpawnVector.z); SpawnAngle[PITCH] = pMapAddEnt->GetFloat("pitch", SpawnAngle[PITCH]); SpawnAngle[YAW] = pMapAddEnt->GetFloat("yaw", SpawnAngle[YAW]); SpawnAngle[ROLL] = pMapAddEnt->GetFloat("roll", SpawnAngle[ROLL]); CBaseEntity *createEnt = CBaseEntity::CreateNoSpawn(pMapAddEnt->GetName(),SpawnVector,SpawnAngle); KeyValues *pEntKeyValues = pMapAddEnt->FindKey("KeyValues"); if(pEntKeyValues && createEnt) { Msg("keyvalue for %s Found!\n",pMapAddEnt->GetName()); KeyValues *pEntKeyValuesAdd = pEntKeyValues->GetFirstValue(); while(pEntKeyValuesAdd && createEnt) { if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("model")) { PrecacheModel(pEntKeyValuesAdd->GetString("")); createEnt->SetModel(pEntKeyValuesAdd->GetString("")); } /* else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("name")) { createEnt->SetName(AllocPooledString(pEntKeyValuesAdd->GetString(""))); } else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("spawnflags")) { createEnt->AddSpawnFlags(pEntKeyValuesAdd->GetInt()); }*/ else { createEnt->KeyValue(pEntKeyValuesAdd->GetName(),pEntKeyValuesAdd->GetString("")); } pEntKeyValuesAdd = pEntKeyValuesAdd->GetNextValue(); } } //createEnt->Activate();//Is this a good idea? Not sure! //createEnt->Spawn(); DispatchSpawn( createEnt ); //I derped } pMapAddEnt = pMapAddEnt->GetNextTrueSubKey(); //Got to keep this! } } } pMapAdd->deleteThis(); return true; }