//============================================================================= void FoundPublicGames::OnCommand( const char *command ) { if( V_strcmp( command, "CreateGame" ) == 0 ) { if ( !CanCreateGame() ) { CBaseModPanel::GetSingleton().PlayUISound( UISOUND_INVALID ); return; } KeyValues *pSettings = KeyValues::FromString( "settings", " system { " " network LIVE " " access friends " " } " " game { " " mode = " " campaign = " " mission = " " } " " options { " " action create " " } " ); KeyValues::AutoDelete autodelete( pSettings ); char const *szGameMode = "campaign"; pSettings->SetString( "game/mode", szGameMode ); pSettings->SetString( "game/campaign", "jacob" ); pSettings->SetString( "game/mission", "asi-jac1-landingbay_01" ); if ( !CUIGameData::Get()->SignedInToLive() ) { pSettings->SetString( "system/network", "lan" ); pSettings->SetString( "system/access", "public" ); } if ( StringHasPrefix( szGameMode, "team" ) ) { pSettings->SetString( "system/netflag", "teamlobby" ); } else if ( !Q_stricmp( "custommatch", m_pDataSettings->GetString( "options/action", "" ) ) ) { pSettings->SetString( "system/access", "public" ); } // TCR: We need to respect the default difficulty pSettings->SetString( "game/difficulty", GameModeGetDefaultDifficulty( szGameMode ) ); CBaseModPanel::GetSingleton().PlayUISound( UISOUND_ACCEPT ); CBaseModPanel::GetSingleton().CloseAllWindows(); CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, NULL, true, pSettings ); } else if ( !Q_stricmp( command, "StartCustomMatchSearch" ) ) { if ( CheckAndDisplayErrorIfNotLoggedIn() || CUIGameData::Get()->CheckAndDisplayErrorIfNotSignedInToLive( this ) ) { CBaseModPanel::GetSingleton().PlayUISound( UISOUND_DENY ); return; } KeyValues *pSettings = NULL; bool bDefaultSettings = true; if ( FoundGameListItem* gameListItem = static_cast<FoundGameListItem*>( m_GplGames->GetSelectedPanelItem() ) ) { pSettings = gameListItem->GetFullInfo().mpGameDetails; } if ( !pSettings ) { pSettings = new KeyValues( "settings" ); } else { pSettings = pSettings->MakeCopy(); bDefaultSettings = false; } // Take ownership of allocated/copied keyvalues KeyValues::AutoDelete autodelete( pSettings ); char const *szGameMode = m_pDataSettings->GetString( "game/mode", "campaign" ); pSettings->SetString( "system/network", "LIVE" ); pSettings->SetString( "system/access", "public" ); pSettings->SetString( "game/mode", szGameMode ); pSettings->SetString( "options/action", "custommatch" ); // TCR: We need to respect the default difficulty if ( bDefaultSettings && GameModeHasDifficulty( szGameMode ) ) pSettings->SetString( "game/difficulty", GameModeGetDefaultDifficulty( szGameMode ) ); CBaseModPanel::GetSingleton().PlayUISound( UISOUND_ACCEPT ); CBaseModPanel::GetSingleton().CloseAllWindows(); CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, NULL, true, pSettings ); } else if ( char const *filterDifficulty = StringAfterPrefix( command, "filter_difficulty_" ) ) { ui_public_lobby_filter_difficulty2.SetValue( filterDifficulty ); StartSearching(); } else if ( char const *filterOnslaught = StringAfterPrefix( command, "filter_onslaught_" ) ) { ui_public_lobby_filter_onslaught.SetValue( filterOnslaught ); StartSearching(); } else if ( char const *filterCampaign = StringAfterPrefix( command, "filter_campaign_" ) ) { ui_public_lobby_filter_campaign.SetValue( filterCampaign ); StartSearching(); } else if ( char const *filterGamestatus = StringAfterPrefix( command, "filter_status_" ) ) { ui_public_lobby_filter_status.SetValue( filterGamestatus ); StartSearching(); } else if ( !Q_stricmp( command, "InstallSupport" ) ) { // install the add-on support package #ifdef IS_WINDOWS_PC // App ID for the legacy addon data is 564 ShellExecute ( 0, "open", "steam://install/564", NULL, 0, SW_SHOW ); #endif } else { BaseClass::OnCommand( command ); } }
//----------------------------------------------------------------------------- // Purpose: Checks to see if any text has changed //----------------------------------------------------------------------------- void BuildModeDialog::OnTextChanged( Panel *panel ) { if (panel == m_pFileSelectionCombo) { // reload file if it's changed char newFile[512]; m_pFileSelectionCombo->GetText(newFile, sizeof(newFile)); if (stricmp(newFile, m_pBuildGroup->GetResourceName()) != 0) { // file has changed, reload SetActiveControl(NULL); m_pBuildGroup->ChangeControlSettingsFile(newFile); } return; } if (panel == m_pAddNewControlCombo) { char buf[40]; m_pAddNewControlCombo->GetText(buf, 40); if (stricmp(buf, "None") != 0) { OnNewControl(buf); // reset box back to None m_pAddNewControlCombo->ActivateItemByRow( 0 ); } } if ( panel == m_pEditableChildren ) { KeyValues *kv = m_pEditableChildren->GetActiveItemUserData(); if ( kv ) { EditablePanel *ep = reinterpret_cast< EditablePanel * >( kv->GetPtr( "ptr" ) ); if ( ep ) { ep->ActivateBuildMode(); } } } if ( panel == m_pEditableParents ) { KeyValues *kv = m_pEditableParents->GetActiveItemUserData(); if ( kv ) { EditablePanel *ep = reinterpret_cast< EditablePanel * >( kv->GetPtr( "ptr" ) ); if ( ep ) { ep->ActivateBuildMode(); } } } if (m_pCurrentPanel && m_pCurrentPanel->IsBuildModeEditable()) { m_pApplyButton->SetEnabled(true); } if (_autoUpdate) { ApplyDataToControls(); } }
//----------------------------------------------------------------------------- // Purpose: Applies the current settings to the build controls //----------------------------------------------------------------------------- void BuildModeDialog::ApplyDataToControls() { // don't apply if the panel is not editable if ( !m_pCurrentPanel->IsBuildModeEditable()) { UpdateControlData( m_pCurrentPanel ); return; // return success, since we are behaving as expected. } char fieldName[512]; if (m_pPanelList->m_PanelList[0].m_EditPanel) { m_pPanelList->m_PanelList[0].m_EditPanel->GetText(fieldName, sizeof(fieldName)); } else { m_pPanelList->m_PanelList[0].m_EditButton->GetText(fieldName, sizeof(fieldName)); } // check to see if any buildgroup panels have this name Panel *panel = m_pBuildGroup->FieldNameTaken(fieldName); if (panel) { if (panel != m_pCurrentPanel)// make sure name is taken by some other panel not this one { char messageString[255]; Q_snprintf(messageString, sizeof( messageString ), "Fieldname is not unique: %s\nRename it and try again.", fieldName); MessageBox *errorBox = new MessageBox("Cannot Apply", messageString); errorBox->DoModal(); UpdateControlData(m_pCurrentPanel); m_pApplyButton->SetEnabled(false); return; } } // create a section to store settings // m_pPanelList->m_pResourceData->getSection( m_pCurrentPanel->GetName(), true ); KeyValues *dat = new KeyValues( m_pCurrentPanel->GetName() ); // loop through the textedit filling in settings for ( int i = 0; i < m_pPanelList->m_PanelList.Count(); i++ ) { const char *name = m_pPanelList->m_PanelList[i].m_szName; char buf[512]; if (m_pPanelList->m_PanelList[i].m_EditPanel) { m_pPanelList->m_PanelList[i].m_EditPanel->GetText(buf, sizeof(buf)); } else { m_pPanelList->m_PanelList[i].m_EditButton->GetText(buf, sizeof(buf)); } switch (m_pPanelList->m_PanelList[i].m_iType) { case TYPE_CORNER: case TYPE_AUTORESIZE: // the integer value is assumed to be the first part of the string for these items dat->SetInt(name, atoi(buf)); break; default: dat->SetString(name, buf); break; } } // dat is built, hand it back to the control m_pCurrentPanel->ApplySettings( dat ); if ( m_pBuildGroup->GetContextPanel() ) { m_pBuildGroup->GetContextPanel()->Repaint(); } m_pApplyButton->SetEnabled(false); m_pSaveButton->SetEnabled(true); }
bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show) { KeyValues *SubKey = NULL; int count = 0; cell_t players[] = {client}; #if SOURCE_ENGINE == SE_DOTA CUserMsg_VGUIMenu *pMsg; if ((pMsg = (CUserMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL) { return false; } #elif SOURCE_ENGINE == SE_CSGO CCSUsrMsg_VGUIMenu *pMsg; if ((pMsg = (CCSUsrMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL) { return false; } #else bf_write *pBitBuf = NULL; if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL) { return false; } #endif if (data) { SubKey = data->GetFirstSubKey(); while (SubKey) { count++; SubKey = SubKey->GetNextKey(); } SubKey = data->GetFirstSubKey(); } #if SOURCE_ENGINE == SE_DOTA pMsg->set_name(name); pMsg->set_show(show); while (SubKey) { CUserMsg_VGUIMenu_Keys *key = pMsg->add_keys(); key->set_name(SubKey->GetName()); key->set_value(SubKey->GetString()); SubKey = SubKey->GetNextKey(); } #elif SOURCE_ENGINE == SE_CSGO pMsg->set_name(name); pMsg->set_show(show); while (SubKey) { CCSUsrMsg_VGUIMenu_Subkey *key = pMsg->add_subkeys(); key->set_name(SubKey->GetName()); key->set_str(SubKey->GetString()); SubKey = SubKey->GetNextKey(); } #else pBitBuf->WriteString(name); pBitBuf->WriteByte((show) ? 1 : 0); pBitBuf->WriteByte(count); while (SubKey) { pBitBuf->WriteString(SubKey->GetName()); pBitBuf->WriteString(SubKey->GetString()); SubKey = SubKey->GetNextKey(); } #endif g_UserMsgs.EndMessage(); return true; }
void CLeaderboardsStats::OnPlayerStats(KeyValues* kv) { KeyValues *pData = kv->FindKey("data"); KeyValues *pErr = kv->FindKey("error"); if (pData) { // int mtotal = -1; // MOM_TODO // int grank = -1; // MOM_TODO // int gtotal = -1; // MOM_TODO KeyValues *pMapRank = pData->FindKey("mapRank"); if (pMapRank) { int iMapRank = pMapRank->GetInt("rank", -1); if (iMapRank == -1) pMapRank->SetWString("mRank", g_pVGuiLocalize->Find("MOM_NotApplicable")); else pMapRank->SetInt("mRank", iMapRank); const auto iRankXP = pMapRank->GetInt("rankXP", -1); if (iRankXP == -1) pMapRank->SetWString("rankXP", g_pVGuiLocalize->Find("MOM_NotApplicable")); else pMapRank->SetInt("rankXP", iRankXP); pMapRank->SetWString("time", g_pVGuiLocalize->Find("MOM_NotApplicable")); KeyValues *pRun = pMapRank->FindKey("run"); if (pRun) { float seconds = pRun->GetFloat("time"); if (seconds > 0.0f) { char sPersonalBestTime[BUFSIZETIME]; MomUtil::FormatTime(seconds, sPersonalBestTime); pMapRank->SetString("time", sPersonalBestTime); } } } KeyValues *pUserStats = pData->FindKey("stats"); if (pUserStats) { // MOM_TODO: fill in these // grank = static_cast<int>(pExperience->GetFloat("rank")); // gtotal = static_cast<int>(pExperience->GetFloat("total")); m_pPlayerLevel->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_Level"), pUserStats)); m_pPlayerCosXP->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_CosXP"), pUserStats)); m_pMapsCompleted->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_MapsCompleted"), pUserStats)); m_pRunsSubmitted->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_RunsSubmitted"), pUserStats)); m_pTotalJumps->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_TotalJumps"), pUserStats)); m_pTotalStrafes->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_TotalStrafes"), pUserStats)); } m_pPlayerMapRank->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_MapRank"), pMapRank)); m_pPlayerRankXP->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_RankXP"), pMapRank)); m_pPlayerPersonalBest->SetText(CConstructLocalizedString(g_pVGuiLocalize->Find("MOM_PersonalBestTime"), pMapRank)); /*if (grank > -1 && gtotal > -1) { char p_sGlobalRank[BUFSIZELOCL]; char p_sLocalized[BUFSIZELOCL]; LOCALIZE_TOKEN(p_wcGlobalRank, "MOM_GlobalRank", p_sGlobalRank); Q_snprintf(p_sLocalized, BUFSIZELOCL, "%s: %i/%i", p_sGlobalRank, grank, gtotal); m_pPlayerGlobalRank->SetText(p_sLocalized); }*/ } else if (pErr) { // MOM_TODO: Handle errors } }
//============================================================================= void CustomCampaigns::OnItemSelected( const char* panelName ) { CustomCampaignListItem *pSelectedItem = static_cast< CustomCampaignListItem * >( m_GplCustomCampaigns->GetSelectedPanelItem() ); if ( !pSelectedItem ) return; KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions(); if ( !pAllMissions ) return; char const *szGameMode = m_pDataSettings->GetString( "game/mode", "campaign" ); KeyValues *pMission = pAllMissions->FindKey( pSelectedItem->GetCampaignContext() ); KeyValues *pFirstChapter = pAllMissions->FindKey( CFmtStr( "%s/modes/%s/1", pSelectedItem->GetCampaignContext(), szGameMode ) ); if ( !pFirstChapter || !pMission ) return; const char *missionImage = pFirstChapter->GetString( "image" ); const char *missionDesc = pMission->GetString( "description" ); const char *campaignAuthor = pMission->GetString( "author" ); const char *campaignWebsite = pMission->GetString( "website" ); wchar_t finalString[MAX_PATH] = L""; wchar_t convertedString[MAX_PATH] = L""; if( m_lblAuthor ) { if ( campaignAuthor ) { const wchar_t * authorFormat = g_pVGuiLocalize->Find( "#L4D360UI_CustomCampaign_Author" ); g_pVGuiLocalize->ConvertANSIToUnicode( campaignAuthor, convertedString, sizeof( convertedString ) ); if ( authorFormat ) { g_pVGuiLocalize->ConstructString( finalString, sizeof( finalString ), authorFormat, 1, convertedString ); m_lblAuthor->SetText( finalString ); } m_lblAuthor->SetVisible( true ); } else { m_lblAuthor->SetVisible( false ); } } if( m_lblWebsite ) { if ( campaignWebsite ) { const wchar_t * websiteFormat = g_pVGuiLocalize->Find( "#L4D360UI_CustomCampaign_Website" ); g_pVGuiLocalize->ConvertANSIToUnicode( campaignWebsite, convertedString, sizeof( convertedString ) ); if ( websiteFormat ) { g_pVGuiLocalize->ConstructString( finalString, sizeof( finalString ), websiteFormat, 1, convertedString ); m_lblWebsite->SetText( finalString ); } m_lblWebsite->SetVisible( true ); } else { m_lblWebsite->SetVisible( false ); } } if( m_lblDescription ) { if ( missionDesc ) { m_lblDescription->SetText( missionDesc ); m_lblDescription->SetVisible( true ); } else { m_lblDescription->SetVisible( false ); } } if ( m_imgLevelImage ) { m_imgLevelImage->SetVisible( true ); if( missionImage ) { m_imgLevelImage->SetImage( missionImage ); } else { m_imgLevelImage->SetImage( "swarm/MissionPics/addonMissionPic" ); } } }
void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { // Okay, we tried at least once to look this up... bParsedScript = true; // Classname Q_strncpy( szClassName, szWeaponName, MAX_WEAPON_STRING ); // Printable name Q_strncpy( szPrintName, pKeyValuesData->GetString( "printname", WEAPON_PRINTNAME_MISSING ), MAX_WEAPON_STRING ); // View model & world model Q_strncpy( szViewModel, pKeyValuesData->GetString( "viewmodel" ), MAX_WEAPON_STRING ); Q_strncpy( szWorldModel, pKeyValuesData->GetString( "playermodel" ), MAX_WEAPON_STRING ); Q_strncpy( szAnimationPrefix, pKeyValuesData->GetString( "anim_prefix" ), MAX_WEAPON_PREFIX ); Q_strncpy( szWeaponType, pKeyValuesData->GetString("weapon_type"), MAX_WEAPON_STRING ); iSlot = pKeyValuesData->GetInt( "bucket", 0 ); iPosition = pKeyValuesData->GetInt( "bucket_position", 0 ); // Use the console (X360) buckets if hud_fastswitch is set to 2. #ifdef CLIENT_DLL if ( hud_fastswitch.GetInt() == 2 ) #else if ( IsX360() ) #endif { iSlot = pKeyValuesData->GetInt( "bucket_360", iSlot ); iPosition = pKeyValuesData->GetInt( "bucket_position_360", iPosition ); } iMaxClip1 = pKeyValuesData->GetInt( "clip_size", WEAPON_NOCLIP ); // Max primary clips gun can hold (assume they don't use clips by default) iMaxClip2 = pKeyValuesData->GetInt( "clip2_size", WEAPON_NOCLIP ); // Max secondary clips gun can hold (assume they don't use clips by default) iDefaultClip1 = pKeyValuesData->GetInt( "default_clip", iMaxClip1 ); // amount of primary ammo placed in the primary clip when it's picked up iDefaultClip2 = pKeyValuesData->GetInt( "default_clip2", iMaxClip2 ); // amount of secondary ammo placed in the secondary clip when it's picked up iWeight = pKeyValuesData->GetInt( "weight", 0 ); iRumbleEffect = pKeyValuesData->GetInt( "rumble", -1 ); // LAME old way to specify item flags. // Weapon scripts should use the flag names. iFlags = pKeyValuesData->GetInt( "item_flags", ITEM_FLAG_LIMITINWORLD ); for ( int i=0; i < ARRAYSIZE( g_ItemFlags ); i++ ) { int iVal = pKeyValuesData->GetInt( g_ItemFlags[i].m_pFlagName, -1 ); if ( iVal == 0 ) { iFlags &= ~g_ItemFlags[i].m_iFlagValue; } else if ( iVal == 1 ) { iFlags |= g_ItemFlags[i].m_iFlagValue; } } bShowUsageHint = ( pKeyValuesData->GetInt( "showusagehint", 0 ) != 0 ) ? true : false; bAutoSwitchTo = ( pKeyValuesData->GetInt( "autoswitchto", 1 ) != 0 ) ? true : false; bAutoSwitchFrom = ( pKeyValuesData->GetInt( "autoswitchfrom", 1 ) != 0 ) ? true : false; m_bBuiltRightHanded = ( pKeyValuesData->GetInt( "BuiltRightHanded", 1 ) != 0 ) ? true : false; m_bAllowFlipping = ( pKeyValuesData->GetInt( "AllowFlipping", 1 ) != 0 ) ? true : false; m_bMeleeWeapon = ( pKeyValuesData->GetInt( "MeleeWeapon", 0 ) != 0 ) ? true : false; m_bUseMagStyleReloads = (pKeyValuesData->GetInt("MagazineStyledReloads", 0) != 0) ? true : false; m_bUseMuzzleSmoke = (pKeyValuesData->GetInt("UseMuzzleSmoke", 0) != 0) ? true : false; m_bUseIronsight = (pKeyValuesData->GetInt("useironsights", 1) != 0) ? true : false; m_bLowerWeapon = (pKeyValuesData->GetInt("LowerWeapon", 1) != 0) ? true : false; m_bUseIronsightCrosshair = (pKeyValuesData->GetInt("useironsightcrosshair", 1) != 0) ? true : false; #if defined(_DEBUG) && defined(HL2_CLIENT_DLL) // make sure two weapons aren't in the same slot & position if ( iSlot >= MAX_WEAPON_SLOTS || iPosition >= MAX_WEAPON_POSITIONS ) { Warning( "Invalid weapon slot or position [slot %d/%d max], pos[%d/%d max]\n", iSlot, MAX_WEAPON_SLOTS - 1, iPosition, MAX_WEAPON_POSITIONS - 1 ); } else { if (g_bUsedWeaponSlots[iSlot][iPosition]) { Warning( "Duplicately assigned weapon slots in selection hud: %s (%d, %d)\n", szPrintName, iSlot, iPosition ); } g_bUsedWeaponSlots[iSlot][iPosition] = true; } #endif // Primary ammo used cAmmoType = pKeyValuesData->GetString("primary_ammo", "None"); if (strcmp("None", cAmmoType) == 0) Q_strncpy( szAmmo1, "", sizeof( szAmmo1 ) ); else Q_strncpy(szAmmo1, cAmmoType, sizeof(szAmmo1)); iAmmoType = GetAmmoDef()->Index( szAmmo1 ); // Secondary ammo used cAmmo2Type = pKeyValuesData->GetString("secondary_ammo", "None"); if (strcmp("None", cAmmo2Type) == 0) Q_strncpy( szAmmo2, "", sizeof( szAmmo2 ) ); else Q_strncpy(szAmmo2, cAmmo2Type, sizeof(szAmmo2)); iAmmo2Type = GetAmmoDef()->Index( szAmmo2 ); //ironsights KeyValues *pSights = pKeyValuesData->FindKey("IronSight"); if (pSights) { vecIronsightPosOffset.x = pSights->GetFloat("forward", 0.0f); vecIronsightPosOffset.y = pSights->GetFloat("right", 0.0f); vecIronsightPosOffset.z = pSights->GetFloat("up", 0.0f); angIronsightAngOffset[PITCH] = pSights->GetFloat("pitch", 0.0f); angIronsightAngOffset[YAW] = pSights->GetFloat("yaw", 0.0f); angIronsightAngOffset[ROLL] = pSights->GetFloat("roll", 0.0f); flIronsightFOVOffset = pSights->GetFloat("fov", 0.0f); } else { //m_bUseIronsight = false; vecIronsightPosOffset = vec3_origin; angIronsightAngOffset.Init(); } //Adjust KeyValues *pAdjust = pKeyValuesData->FindKey("Adjust"); if (pAdjust) { vecAdjustPosOffset.x = pAdjust->GetFloat("forward", 0.0f); vecAdjustPosOffset.y = pAdjust->GetFloat("right", 0.0f); vecAdjustPosOffset.z = pAdjust->GetFloat("up", 0.0f); angAdjustAngOffset[PITCH] = pAdjust->GetFloat("pitch", 0.0f); angAdjustAngOffset[YAW] = pAdjust->GetFloat("yaw", 0.0f); angAdjustAngOffset[ROLL] = pAdjust->GetFloat("roll", 0.0f); } else { vecAdjustPosOffset = vec3_origin; angAdjustAngOffset.Init(); } KeyValues *pWeaponSpec = pKeyValuesData->FindKey("WeaponSpec"); if (pWeaponSpec) { KeyValues *pWeaponOptions = pWeaponSpec->FindKey("WeaponOptions"); if (pWeaponOptions) { m_sWeaponOptions = true; m_sCanReloadSingly = (pWeaponOptions->GetInt("CanReloadSingly", 1) != 0) ? true : false; m_sDualWeapons = (pWeaponOptions->GetInt("DualWeapons", 1) != 0) ? true : false; m_sCustomMelee = (pWeaponOptions->GetInt("IsMelee", 1) != 0) ? true : false; m_sCustomMeleeSecondary = (pWeaponOptions->GetInt("SecondaryCanMelee", 1) != 0) ? true : false; } else { m_sWeaponOptions = false; } KeyValues *pPrimaryFire = pWeaponSpec->FindKey("PrimaryFire"); if (pPrimaryFire) { m_sHasPrimaryFire = true; m_sPrimaryFireRate = pPrimaryFire->GetFloat("FireRate", 1.0f); m_sPrimaryIronsightFireRate = pPrimaryFire->GetFloat("IronsightFireRate", m_sPrimaryFireRate); m_sPrimaryZoomFireRate = pPrimaryFire->GetFloat("ZoomFireRate", m_sPrimaryFireRate); m_sPrimaryInfiniteAmmoEnabled = (pPrimaryFire->GetInt("InfiniteAmmo", 1) != 0) ? true : false; m_sPrimaryMinRange = pPrimaryFire->GetInt("MinRange", 0); m_sPrimaryMinRange = pPrimaryFire->GetInt("MaxRange", 0); m_sCanPrimaryFireUnderwater = (pPrimaryFire->GetInt("CanFireUnderwater", 1) != 0) ? true : false; m_sFireBothOnPrimary = (pWeaponOptions->GetInt("FireBothGuns", 1) != 0) ? true : false; KeyValues *pBullet1 = pPrimaryFire->FindKey("Bullet"); if (pBullet1) { m_sPrimaryBulletEnabled = true; m_sPrimaryDamage = pBullet1->GetFloat("Damage", 0); m_sPrimaryShotCount = pBullet1->GetInt("ShotCount", 0); KeyValues *pSpread1 = pBullet1->FindKey("Spread"); if (pSpread1) { m_vPrimarySpread.x = sin((pSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimarySpread.y = sin((pSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimarySpread.z = sin((pSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimarySpread.x = 0.0f; m_vPrimarySpread.y = 0.0f; m_vPrimarySpread.z = 0.0f; } KeyValues *pIronsightSpread1 = pBullet1->FindKey("IronsightSpread"); if (pIronsightSpread1) { m_vPrimaryIronsightSpread.x = sin((pIronsightSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimaryIronsightSpread.y = sin((pIronsightSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimaryIronsightSpread.z = sin((pIronsightSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimaryIronsightSpread.x = m_vPrimarySpread.x; m_vPrimaryIronsightSpread.y = m_vPrimarySpread.y; m_vPrimaryIronsightSpread.z = m_vPrimarySpread.z; } KeyValues *pZoomSpread1 = pBullet1->FindKey("ZoomSpread"); if (pZoomSpread1) { m_vPrimaryZoomSpread.x = sin((pZoomSpread1->GetFloat("x", 0.0f) / 2.0f)); m_vPrimaryZoomSpread.y = sin((pZoomSpread1->GetFloat("y", 0.0f) / 2.0f)); m_vPrimaryZoomSpread.z = sin((pZoomSpread1->GetFloat("z", 0.0f) / 2.0f)); } else { m_vPrimaryZoomSpread.x = m_vPrimarySpread.x; m_vPrimaryZoomSpread.y = m_vPrimarySpread.y; m_vPrimaryZoomSpread.z = m_vPrimarySpread.z; } } else { m_sPrimaryDamage = 0.0f; m_sPrimaryShotCount = 0; m_sPrimaryBulletEnabled = false; } KeyValues *pMissle1 = pPrimaryFire->FindKey("Missle"); if (pMissle1) //No params yet, but setting this will enable missles { m_sPrimaryMissleEnabled = true; m_sPrimaryHasRecoilRPGMissle = (pMissle1->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sPrimaryMissleEnabled = false; } KeyValues *pSMGGrenade1 = pPrimaryFire->FindKey("SMGGrenade"); if (pSMGGrenade1) //No params yet, but setting this will enable missles { m_sPrimarySMGGrenadeEnabled = true; m_sSMGGrenadePrimaryDamage = pSMGGrenade1->GetFloat("Damage", 0); m_sPrimaryHasRecoilSMGGrenade = (pSMGGrenade1->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sPrimarySMGGrenadeEnabled = false; m_sSMGGrenadePrimaryDamage = 0.0; } KeyValues *pAR2EnergyBall1 = pPrimaryFire->FindKey("AR2EnergyBall"); if (pAR2EnergyBall1) //No params yet, but setting this will enable missles { m_sPrimaryAR2EnergyBallEnabled = true; m_sPrimaryCombineBallRadius = pAR2EnergyBall1->GetFloat("Radius", 0); m_sPrimaryCombineBallMass = pAR2EnergyBall1->GetFloat("Mass", 0); m_sPrimaryCombineBallDuration = pAR2EnergyBall1->GetFloat("Duration", 0); } else { m_sPrimaryAR2EnergyBallEnabled = false; m_sPrimaryCombineBallRadius = 0.0; m_sPrimaryCombineBallMass = 0.0; m_sPrimaryCombineBallDuration = 0.0; } KeyValues *pRecoil1 = pPrimaryFire->FindKey("Recoil"); if (pRecoil1) //No params yet, but setting this will enable missles { m_sPrimaryRecoilEasyDampen = pRecoil1->GetFloat("EasyDampen", 0); m_sPrimaryRecoilDegrees = pRecoil1->GetFloat("Degrees", 0); m_sPrimaryRecoilSeconds = pRecoil1->GetFloat("Seconds", 0); } else { m_sPrimaryRecoilEasyDampen = 0.0; m_sPrimaryRecoilDegrees = 0.0; m_sPrimaryRecoilSeconds = 0.0; } } else { m_sHasPrimaryFire = false; } KeyValues *pSecondaryFire = pWeaponSpec->FindKey("SecondaryFire"); if (pSecondaryFire) { m_sHasSecondaryFire = true; m_sSecondaryFireRate = pSecondaryFire->GetFloat("FireRate", 1.0f); m_sSecondaryIronsightFireRate = pSecondaryFire->GetFloat("IronsightFireRate", m_sSecondaryFireRate); m_sSecondaryZoomFireRate = pSecondaryFire->GetFloat("ZoomFireRate", m_sSecondaryFireRate); m_sUsePrimaryAmmo = (pSecondaryFire->GetInt("UsePrimaryAmmo", 0) != 0) ? true : false; m_sSecondaryInfiniteAmmoEnabled = (pSecondaryFire->GetInt("InfiniteAmmo", 1) != 0) ? true : false; m_sSecondaryMinRange = pSecondaryFire->GetInt("MinRange", 0); m_sSecondaryMinRange = pSecondaryFire->GetInt("MaxRange", 0); m_sCanSecondaryFireUnderwater = (pSecondaryFire->GetInt("CanFireUnderwater", 1) != 0) ? true : false; m_sFireBothOnSecondary = (pWeaponOptions->GetInt("FireBothGuns", 1) != 0) ? true : false; KeyValues *pBullet2 = pSecondaryFire->FindKey("Bullet"); if (pBullet2) { m_sSecondaryBulletEnabled = true; m_sSecondaryDamage = pBullet2->GetFloat("Damage", 0); m_sSecondaryShotCount = pBullet2->GetInt("ShotCount", 0); KeyValues *pSpread2 = pBullet2->FindKey("Spread"); if (pSpread2) { m_vSecondarySpread.x = sin(pSpread2->GetFloat("x", 0.0f) / 2.0f); m_vSecondarySpread.y = sin(pSpread2->GetFloat("y", 0.0f) / 2.0f); m_vSecondarySpread.z = sin(pSpread2->GetFloat("z", 0.0f) / 2.0f); } else { m_vSecondarySpread.x = 0.0f; m_vSecondarySpread.y = 0.0f; m_vSecondarySpread.z = 0.0f; } KeyValues *pIronsightSpread2 = pBullet2->FindKey("IronsightSpread"); if (pIronsightSpread2) { m_vSecondaryIronsightSpread.x = sin((pIronsightSpread2->GetFloat("x", 0.0f) / 2.0f)); m_vSecondaryIronsightSpread.y = sin((pIronsightSpread2->GetFloat("y", 0.0f) / 2.0f)); m_vSecondaryIronsightSpread.z = sin((pIronsightSpread2->GetFloat("z", 0.0f) / 2.0f)); } else { m_vSecondaryIronsightSpread.x = m_vSecondarySpread.x; m_vSecondaryIronsightSpread.y = m_vSecondarySpread.y; m_vSecondaryIronsightSpread.z = m_vSecondarySpread.z; } KeyValues *pZoomSpread2 = pBullet2->FindKey("ZoomSpread"); if (pZoomSpread2) { m_vSecondaryZoomSpread.x = sin((pZoomSpread2->GetFloat("x", 0.0f) / 2.0f)); m_vSecondaryZoomSpread.y = sin((pZoomSpread2->GetFloat("y", 0.0f) / 2.0f)); m_vSecondaryZoomSpread.z = sin((pZoomSpread2->GetFloat("z", 0.0f) / 2.0f)); } else { m_vSecondaryZoomSpread.x = m_vSecondarySpread.x; m_vSecondaryZoomSpread.y = m_vSecondarySpread.y; m_vSecondaryZoomSpread.z = m_vSecondarySpread.z; } } else { m_sSecondaryDamage = 0.0f; m_sSecondaryShotCount = 0; m_sSecondaryBulletEnabled = false; } KeyValues *pMissle2 = pSecondaryFire->FindKey("Missle"); if (pMissle2) //No params yet, but setting this will enable missles { m_sSecondaryMissleEnabled = true; m_sSecondaryHasRecoilRPGMissle = (pMissle2->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sSecondaryMissleEnabled = false; } KeyValues *pSMGGrenade2 = pSecondaryFire->FindKey("SMGGrenade"); if (pSMGGrenade2) //No params yet, but setting this will enable missles { m_sSecondarySMGGrenadeEnabled = true; m_sSMGGrenadeSecondaryDamage = pSMGGrenade2->GetFloat("Damage", 0); m_sSecondaryHasRecoilSMGGrenade = (pSMGGrenade2->GetInt("UseRecoil", 1) != 0) ? true : false; } else { m_sSecondarySMGGrenadeEnabled = false; m_sSMGGrenadeSecondaryDamage = 0.0; } KeyValues *pAR2EnergyBall2 = pSecondaryFire->FindKey("AR2EnergyBall"); if (pAR2EnergyBall2) //No params yet, but setting this will enable missles { m_sSecondaryAR2EnergyBallEnabled = true; m_sSecondaryCombineBallRadius = pAR2EnergyBall2->GetFloat("Radius", 0); m_sSecondaryCombineBallMass = pAR2EnergyBall2->GetFloat("Mass", 0); m_sSecondaryCombineBallDuration = pAR2EnergyBall2->GetFloat("Duration", 0); } else { m_sSecondaryAR2EnergyBallEnabled = false; m_sSecondaryCombineBallRadius = 0.0; m_sSecondaryCombineBallMass = 0.0; m_sSecondaryCombineBallDuration = 0.0; } KeyValues *pRecoil2 = pSecondaryFire->FindKey("Recoil"); if (pRecoil2) //No params yet, but setting this will enable missles { m_sSecondaryRecoilEasyDampen = pRecoil2->GetFloat("EasyDampen", 0); m_sSecondaryRecoilDegrees = pRecoil2->GetFloat("Degrees", 0); m_sSecondaryRecoilSeconds = pRecoil2->GetFloat("Seconds", 0); } else { m_sSecondaryRecoilEasyDampen = 0.0; m_sSecondaryRecoilDegrees = 0.0; m_sSecondaryRecoilSeconds = 0.0; } } else { m_sHasSecondaryFire = false; } KeyValues *pMeleeOptions = pWeaponSpec->FindKey("Melee"); if (pMeleeOptions) { m_sHasMeleeOptions = true; m_sMeleeDamage = pMeleeOptions->GetFloat("Damage", 0); m_sMeleeRange = pMeleeOptions->GetFloat("Range", 0); KeyValues *pRecoilM = pMeleeOptions->FindKey("Kick"); if (pRecoilM) //No params yet, but setting this will enable missles { m_sMeleeKickEasyDampen = pRecoilM->GetFloat("EasyDampen", 0); m_sMeleeKickDegrees = pRecoilM->GetFloat("Degrees", 0); m_sMeleeKickSeconds = pRecoilM->GetFloat("Seconds", 0); } else { m_sMeleeKickEasyDampen = 0.0; m_sMeleeKickDegrees = 0.0; m_sMeleeKickSeconds = 0.0; } } else { m_sHasMeleeOptions = false; } KeyValues *pZoom = pWeaponSpec->FindKey("Zoom"); if (pZoom) { m_sUsesZoom = true; m_sUseZoomOnPrimaryFire = (pZoom->GetInt("UseOnPrimaryFire", 1) != 0) ? true : false; m_sUsesZoomSound = (pZoom->GetInt("UsesSound", 1) != 0) ? true : false; m_sUsesZoomColor = (pZoom->GetInt("UsesColor", 1) != 0) ? true : false; KeyValues *pZoomColor = pZoom->FindKey("ZoomColor"); { if (pZoomColor) { m_sZoomColorRed = pZoomColor->GetInt("Red", 0); m_sZoomColorGreen = pZoomColor->GetInt("Green", 0); m_sZoomColorBlue = pZoomColor->GetInt("Blue", 0); m_sZoomColorAlpha = pZoomColor->GetInt("Alpha", 0); } } } else { m_sUsesZoom = false; } KeyValues *pCustomization = pWeaponSpec->FindKey("Customization"); if (pCustomization) { m_sUsesCustomization = true; m_sWeaponSkin = pCustomization->GetInt("Skin", 0); KeyValues *pBodygroup1 = pWeaponSpec->FindKey("Bodygroup1"); { if (pBodygroup1) { m_sBodygroup1 = pBodygroup1->GetInt("Bodygroup", 0); m_sSubgroup1 = pBodygroup1->GetInt("Subgroup", 0); } } KeyValues *pBodygroup2 = pWeaponSpec->FindKey("Bodygroup2"); { if (pBodygroup2) { m_sBodygroup2 = pBodygroup2->GetInt("Bodygroup", 0); m_sSubgroup2 = pBodygroup2->GetInt("Subgroup", 0); } } KeyValues *pBodygroup3 = pWeaponSpec->FindKey("Bodygroup3"); { if (pBodygroup3) { m_sBodygroup3 = pBodygroup3->GetInt("Bodygroup", 0); m_sSubgroup3 = pBodygroup3->GetInt("Subgroup", 0); } } KeyValues *pBodygroup4 = pWeaponSpec->FindKey("Bodygroup4"); { if (pBodygroup4) { m_sBodygroup4 = pBodygroup4->GetInt("Bodygroup", 0); m_sSubgroup4 = pBodygroup4->GetInt("Subgroup", 0); } } KeyValues *pBodygroup5 = pWeaponSpec->FindKey("Bodygroup5"); { if (pBodygroup5) { m_sBodygroup5 = pBodygroup5->GetInt("Bodygroup", 0); m_sSubgroup5 = pBodygroup5->GetInt("Subgroup", 0); } } KeyValues *pBodygroup6 = pWeaponSpec->FindKey("Bodygroup6"); { if (pBodygroup6) { m_sBodygroup6 = pBodygroup6->GetInt("Bodygroup", 0); m_sSubgroup6 = pBodygroup6->GetInt("Subgroup", 0); } } } else { m_sUsesCustomization = false; } } // Now read the weapon sounds memset( aShootSounds, 0, sizeof( aShootSounds ) ); KeyValues *pSoundData = pKeyValuesData->FindKey( "SoundData" ); if ( pSoundData ) { for ( int i = EMPTY; i < NUM_SHOOT_SOUND_TYPES; i++ ) { const char *soundname = pSoundData->GetString( pWeaponSoundCategories[i] ); if ( soundname && soundname[0] ) { Q_strncpy( aShootSounds[i], soundname, MAX_WEAPON_STRING ); } } } }
bool CEngineSprite::Init( const char *pName ) { m_hAVIMaterial = AVIMATERIAL_INVALID; m_hBIKMaterial = BIKMATERIAL_INVALID; m_width = m_height = m_numFrames = 1; const char *pExt = Q_GetFileExtension( pName ); bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" ); #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) bool bIsBIK = pExt && !Q_stricmp( pExt, "bik" ); #endif if ( bIsAVI && IsPC() ) { m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" ); if ( m_hAVIMaterial == AVIMATERIAL_INVALID ) return false; IMaterial *pMaterial = avi->GetMaterial( m_hAVIMaterial ); avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height ); m_numFrames = avi->GetFrameCount( m_hAVIMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 ) else if ( bIsBIK ) { m_hBIKMaterial = bik->CreateMaterial( pName, pName, "GAME" ); if ( m_hBIKMaterial == BIKMATERIAL_INVALID ) return false; IMaterial *pMaterial = bik->GetMaterial( m_hBIKMaterial ); bik->GetFrameSize( m_hBIKMaterial, &m_width, &m_height ); m_numFrames = bik->GetFrameCount( m_hBIKMaterial ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } #endif else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = NULL; } KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { continue; } // strip possible materials/ Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName + ( bIsUNC ? 0 : 10 ), i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[i]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
bool CMapLayout::SaveMapLayout( const char *filename ) { KeyValues *pLayoutKeys = new KeyValues( "Layout" ); if ( m_pGenerationOptions ) { pLayoutKeys->AddSubKey( m_pGenerationOptions->MakeCopy() ); } KeyValues *pMiscKeys = new KeyValues( "mapmisc" ); pMiscKeys->SetInt( "PlayerStartX", m_iPlayerStartTileX ); pMiscKeys->SetInt( "PlayerStartY", m_iPlayerStartTileY ); pLayoutKeys->AddSubKey( pMiscKeys ); // save out each room int iRooms = m_PlacedRooms.Count(); for (int i=0;i<iRooms;i++) { CRoom *pRoom = m_PlacedRooms[i]; if (!pRoom) continue; pLayoutKeys->AddSubKey( pRoom->GetKeyValuesCopy() ); } // save out logical rooms iRooms = m_LogicalRooms.Count(); for (int i=0;i<iRooms;i++) { KeyValues *pRoomKeys = new KeyValues( "logical_room" ); if ( m_LogicalRooms[i]->m_pLevelTheme ) { pRoomKeys->SetString( "theme", m_LogicalRooms[i]->m_pLevelTheme->m_szName ); } pRoomKeys->SetString( "template", m_LogicalRooms[i]->GetFullName() ); pLayoutKeys->AddSubKey( pRoomKeys ); } for ( int i = 0; i < m_InstanceSpawns.Count(); ++ i ) { KeyValues *pNewInstanceSpawn = new KeyValues( "instance_spawn" ); m_InstanceSpawns[i].SaveToKeyValues( pNewInstanceSpawn ); pLayoutKeys->AddSubKey( pNewInstanceSpawn ); } for ( int i = 0; i < m_Encounters.Count(); ++ i ) { KeyValues *pEncounterKeys = new KeyValues( "npc_encounter" ); m_Encounters[i]->SaveToKeyValues( pEncounterKeys ); pLayoutKeys->AddSubKey( pEncounterKeys ); } CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER ); for ( KeyValues *pKey = pLayoutKeys->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() ) { pKey->RecursiveSaveToFile( buf, 0 ); } pLayoutKeys->deleteThis(); if ( !g_pFullFileSystem->WriteFile( filename, "GAME", buf ) ) { Log_Warning( LOG_TilegenLayoutSystem, "Failed to SaveToFile %s\n", filename ); return false; } return true; }
void CASWMissionChooserNPCs::InitFixedSpawns( CLayoutSystem *pLayoutSystem, CMapLayout *pLayout ) { // init the spawn set for this mission KeyValues *pGenerationOptions = pLayout->GetGenerationOptions(); if ( !pGenerationOptions ) { Warning( "Error placed fixed alien spawns, no generation options in this layout." ); return; } bool bChosenSpawnSet = false; const char *szNamedSpawnSet = pGenerationOptions->GetString( "AlienSpawnSet" ); if ( szNamedSpawnSet && szNamedSpawnSet[0] ) { bChosenSpawnSet = SpawnSelection()->SetCurrentSpawnSet( szNamedSpawnSet ); } if ( !bChosenSpawnSet ) { SpawnSelection()->SetCurrentSpawnSet( pGenerationOptions->GetInt( "Difficulty", 5 ) ); } // if we have any rooms with the alien encounter tag, then just use those for fixed spawn locations bool bAlienEncounterTag = false; int iRooms = pLayout->m_PlacedRooms.Count(); for ( int i = 0; i < iRooms; i++ ) { CRoom *pRoom = pLayout->m_PlacedRooms[i]; if ( pRoom && pRoom->m_pRoomTemplate && pRoom->m_pRoomTemplate->HasTag( "AlienEncounter" ) ) { bAlienEncounterTag = true; CASW_Encounter *pEncounter = new CASW_Encounter(); // pick a random spot in this room Vector vecWorldMins, vecWorldMaxs; pRoom->GetWorldBounds( &vecWorldMins, &vecWorldMaxs ); Vector vecPos = vecWorldMins + pLayoutSystem->GetRandomFloat( 0, 1 ) * ( vecWorldMaxs - vecWorldMins ); vecPos.z = 0; pEncounter->SetEncounterPosition( vecPos ); pEncounter->SetEncounterRadius( pLayoutSystem->GetRandomFloat( asw_encounter_radius_min.GetFloat(), asw_encounter_radius_max.GetFloat() ) ); // add spawn defs // TODO: more spawns in bigger rooms? or rooms with higher weights? int iSpawnsPerEncounter = pLayoutSystem->GetRandomInt( CurrentSpawnSet()->GetMinSpawnsPerEncounter(), CurrentSpawnSet()->GetMaxSpawnsPerEncounter() ); for ( int i = 0; i < iSpawnsPerEncounter; i++ ) { CASW_Spawn_Definition* pSpawnDef = CurrentSpawnSet()->GetSpawnDef( ASW_NPC_SPAWN_TYPE_FIXED ); if ( !pSpawnDef ) continue; pEncounter->AddSpawnDef( pSpawnDef ); } pLayout->m_Encounters.AddToTail( pEncounter ); } } if ( bAlienEncounterTag ) { pLayout->MarkEncounterRooms(); return; } // find area of the mission int iTotalArea = 0; for ( int i = 0; i < iRooms; i++ ) { CRoom *pRoom = pLayout->m_PlacedRooms[i]; iTotalArea += ( pRoom->m_pRoomTemplate->GetTilesX() * ASW_TILE_SIZE ) * ( pRoom->m_pRoomTemplate->GetTilesY() * ASW_TILE_SIZE ); } // decide how many encounters we want int iEncounters = pLayoutSystem->GetRandomInt( CurrentSpawnSet()->GetMinEncounters(), CurrentSpawnSet()->GetMaxEncounters() ); // distance between encounters //float flMinDistance = asw_encounters_distance_min.GetFloat(); // randomly pick rooms for the encounters to be in, using the room weights CUtlVector<CRoom*> candidates; float flTotalWeight = 0; for ( int i = 0; i < iRooms; i++ ) { CRoom *pRoom = pLayout->m_PlacedRooms[i]; if ( pRoom->GetSpawnWeight() > 0 && !pRoom->m_pRoomTemplate->IsEscapeRoom() && !pRoom->m_pRoomTemplate->IsStartRoom() && !pRoom->m_pRoomTemplate->IsBorderRoom() ) { flTotalWeight += pRoom->GetSpawnWeight(); candidates.AddToTail( pRoom ); } } for ( int e = 0; e < iEncounters; e++ ) { float flChosen = pLayoutSystem->GetRandomFloat( 0, flTotalWeight ); CRoom *pChosenRoom = NULL; for ( int i = 0; i < candidates.Count(); i++ ) { CRoom *pRoom = candidates[i]; flChosen -= pRoom->GetSpawnWeight(); if ( flChosen <= 0 ) { pChosenRoom = pRoom; break; } } if ( !pChosenRoom ) continue; CASW_Encounter *pEncounter = new CASW_Encounter(); // pick a random spot in this room Vector vecWorldMins, vecWorldMaxs; pChosenRoom->GetWorldBounds( &vecWorldMins, &vecWorldMaxs ); //Vector vecPos = vecWorldMins + pLayoutSystem->GetRandomFloat( 0, 1 ) * ( vecWorldMaxs - vecWorldMins ); Vector vecPos = ( vecWorldMins + vecWorldMaxs ) * 0.5f; // center of the room vecPos.z = 0; pEncounter->SetEncounterPosition( vecPos ); pEncounter->SetEncounterRadius( pLayoutSystem->GetRandomFloat( asw_encounter_radius_min.GetFloat(), asw_encounter_radius_max.GetFloat() ) ); // add spawn defs // TODO: more spawns in bigger rooms? or rooms with higher weights? int iSpawnsPerEncounter = pLayoutSystem->GetRandomInt( CurrentSpawnSet()->GetMinSpawnsPerEncounter(), CurrentSpawnSet()->GetMaxSpawnsPerEncounter() ); for ( int i = 0; i < iSpawnsPerEncounter; i++ ) { CASW_Spawn_Definition* pSpawnDef = CurrentSpawnSet()->GetSpawnDef( ASW_NPC_SPAWN_TYPE_FIXED ); if ( !pSpawnDef ) continue; pEncounter->AddSpawnDef( pSpawnDef ); } pLayout->m_Encounters.AddToTail( pEncounter ); } PushEncountersApart( pLayout ); pLayout->MarkEncounterRooms(); }
//----------------------------------------------------------------------------- // Purpose: Updates the player list //----------------------------------------------------------------------------- void CTFDeathMatchScoreBoardDialog::UpdatePlayerList() { int iSelectedPlayerIndex = GetLocalPlayerIndex(); // Save off which player we had selected SectionedListPanel *pList = GetSelectedPlayerList(); if ( pList ) { int itemID = pList->GetSelectedItem(); if ( itemID >= 0 ) { KeyValues *pInfo = pList->GetItemData( itemID ); if ( pInfo ) { iSelectedPlayerIndex = pInfo->GetInt( "playerIndex" ); } } } m_pPlayerListRed->RemoveAll(); C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>( g_PR ); if ( !tf_PR ) return; C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer(); if ( !pLocalPlayer ) return; int localteam = pLocalPlayer->GetTeamNumber(); bool bMadeSelection = false; for( int playerIndex = 1 ; playerIndex <= MAX_PLAYERS; playerIndex++ ) { if( g_PR->IsConnected( playerIndex ) ) { SectionedListPanel *pPlayerList = NULL; switch ( g_PR->GetTeam( playerIndex ) ) { case TF_TEAM_RED: pPlayerList = m_pPlayerListRed; break; } if ( null == pPlayerList ) continue; const char *szName = tf_PR->GetPlayerName(playerIndex); int score = tf_PR->GetTotalScore(playerIndex); int kills = tf_PR->GetPlayerScore(playerIndex); int deaths = tf_PR->GetDeaths(playerIndex); int streak = tf_PR->GetKillstreak(playerIndex); KeyValues *pKeyValues = new KeyValues( "data" ); pKeyValues->SetInt( "playerIndex", playerIndex ); pKeyValues->SetString( "name", szName ); pKeyValues->SetInt("score", score); pKeyValues->SetInt("kills", kills); pKeyValues->SetInt("deaths", deaths); pKeyValues->SetInt("streak", streak); // can only see class information if we're on the same team if ( !AreEnemyTeams( g_PR->GetTeam( playerIndex ), localteam ) && !( localteam == TEAM_UNASSIGNED ) ) { // class name if( g_PR->IsConnected( playerIndex ) ) { int iClass = tf_PR->GetPlayerClass( playerIndex ); if ( GetLocalPlayerIndex() == playerIndex && !tf_PR->IsAlive( playerIndex ) ) { // If this is local player and he is dead, show desired class (which he will spawn as) rather than current class. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer(); int iDesiredClass = pPlayer->m_Shared.GetDesiredPlayerClassIndex(); // use desired class unless it's random -- if random, his future class is not decided until moment of spawn if ( TF_CLASS_RANDOM != iDesiredClass ) { iClass = iDesiredClass; } } else { // for non-local players, show the current class iClass = tf_PR->GetPlayerClass( playerIndex ); } } } else { C_TFPlayer *pPlayerOther = ToTFPlayer( UTIL_PlayerByIndex( playerIndex ) ); if ( pPlayerOther && pPlayerOther->m_Shared.IsPlayerDominated( pLocalPlayer->entindex() ) ) { // if local player is dominated by this player, show a nemesis icon pKeyValues->SetInt( "nemesis", m_iImageNemesis ); } else if ( pLocalPlayer->m_Shared.IsPlayerDominated( playerIndex) ) { // if this player is dominated by the local player, show the domination icon pKeyValues->SetInt( "nemesis", m_iImageDominated ); } } // display whether player is alive or dead (all players see this for all other players on both teams) pKeyValues->SetInt( "status", tf_PR->IsAlive( playerIndex ) ? 0 : m_iImageDead ); if ( g_PR->GetPing( playerIndex ) < 1 ) { if ( g_PR->IsFakePlayer( playerIndex ) ) { pKeyValues->SetString( "ping", "#TF_Scoreboard_Bot" ); } else { pKeyValues->SetString( "ping", "" ); } } else { pKeyValues->SetInt( "ping", g_PR->GetPing( playerIndex ) ); } UpdatePlayerAvatar( playerIndex, pKeyValues ); int itemID = pPlayerList->AddItem( 0, pKeyValues ); Color clr = tf_PR->GetPlayerColor(playerIndex); pPlayerList->SetItemFgColor( itemID, clr ); if ( iSelectedPlayerIndex == playerIndex ) { bMadeSelection = true; pPlayerList->SetSelectedItem( itemID ); } pKeyValues->deleteThis(); } } // If we're on spectator, find a default selection if ( !bMadeSelection ) { if ( m_pPlayerListRed->GetItemCount() > 0 ) { m_pPlayerListRed->SetSelectedItem( 0 ); } } ResizeScoreboard(); }
void CASW_EquipmentList::LoadEquipmentList() { m_iNumRegular = 0; m_iNumExtra = 0; KeyValues *kv = new KeyValues("Equipment"); // load equipment if (kv->LoadFromFile(filesystem, "resource/Equipment.res")) { int iNumEquip = 0; KeyValues *pKeys = kv; while ( pKeys ) { for (KeyValues *details = pKeys->GetFirstSubKey(); details; details = details->GetNextKey()) { if ( FStrEq( details->GetName(), "Regular" ) ) { //Msg("adding regular equip %s\n", MAKE_STRING( details->GetString() )); CASW_EquipItem* equip = new CASW_EquipItem(); equip->m_EquipClass = MAKE_STRING( details->GetString() ); equip->m_iItemIndex = iNumEquip; equip->m_bSelectableInBriefing = true; m_Regular.AddToTail(equip); m_iNumRegular++; iNumEquip++; } else if ( FStrEq( details->GetName(), "Extra" ) ) { //Msg("adding extra equip %s\n", MAKE_STRING( details->GetString() )); CASW_EquipItem* equip = new CASW_EquipItem(); equip->m_EquipClass = MAKE_STRING( details->GetString() ); equip->m_iItemIndex = iNumEquip; equip->m_bSelectableInBriefing = true; m_Extra.AddToTail(equip); m_iNumExtra++; iNumEquip++; } // hidden equip else if ( FStrEq( details->GetName(), "RegularOther" ) ) { //Msg("adding regular equip %s\n", MAKE_STRING( details->GetString() )); CASW_EquipItem* equip = new CASW_EquipItem(); equip->m_EquipClass = MAKE_STRING( details->GetString() ); equip->m_iItemIndex = iNumEquip; equip->m_bSelectableInBriefing = true; m_Regular.AddToTail(equip); iNumEquip++; } else if ( FStrEq( details->GetName(), "ExtraOther" ) ) { //Msg("adding extra equip %s\n", MAKE_STRING( details->GetString() )); CASW_EquipItem* equip = new CASW_EquipItem(); equip->m_EquipClass = MAKE_STRING( details->GetString() ); equip->m_iItemIndex = iNumEquip; equip->m_bSelectableInBriefing = false; m_Extra.AddToTail(equip); iNumEquip++; } } pKeys = pKeys->GetNextKey(); } } }
//----------------------------------------------------------------------------- // Recording //----------------------------------------------------------------------------- static inline void RecordBloodSprite( const Vector &start, const Vector &direction, int r, int g, int b, int a, int nSprayModelIndex, int nDropModelIndex, int size ) { if ( !ToolsEnabled() ) return; if ( clienttools->IsInRecordingMode() ) { Color clr( r, g, b, a ); const model_t* pSprayModel = (nSprayModelIndex != 0) ? modelinfo->GetModel( nSprayModelIndex ) : NULL; const model_t* pDropModel = (nDropModelIndex != 0) ? modelinfo->GetModel( nDropModelIndex ) : NULL; const char *pSprayModelName = pSprayModel ? modelinfo->GetModelName( pSprayModel ) : ""; const char *pDropModelName = pDropModel ? modelinfo->GetModelName( pDropModel ) : ""; KeyValues *msg = new KeyValues( "TempEntity" ); msg->SetInt( "te", TE_BLOOD_SPRITE ); msg->SetString( "name", "TE_BloodSprite" ); msg->SetFloat( "time", gpGlobals->curtime ); msg->SetFloat( "originx", start.x ); msg->SetFloat( "originy", start.y ); msg->SetFloat( "originz", start.z ); msg->SetFloat( "directionx", direction.x ); msg->SetFloat( "directiony", direction.y ); msg->SetFloat( "directionz", direction.z ); msg->SetColor( "color", clr ); msg->SetString( "spraymodel", pSprayModelName ); msg->SetString( "dropmodel", pDropModelName ); msg->SetInt( "size", size ); ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg ); msg->deleteThis(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CEditorSystem::DoSelect( CHL2WarsPlayer *pPlayer ) { #ifndef CLIENT_DLL // Sync from client return; #endif // CLIENT_DLL Vector vPos = pPlayer->Weapon_ShootPosition(); const Vector &vMouseAim = pPlayer->GetMouseAim(); const Vector &vCamOffset = pPlayer->GetCameraOffset(); Vector vStartPos, vEndPos; vStartPos = vPos + vCamOffset; vEndPos = vStartPos + (vMouseAim * MAX_TRACE_LENGTH); //NDebugOverlay::Line( vStartPos, vEndPos, 0, 255, 0, true, 4.0f ); Ray_t pickerRay; pickerRay.Init( vStartPos, vEndPos ); CWarsFlora *pBest = NULL; float fBestDistance = 0; #ifdef CLIENT_DLL for( CBaseEntity *pEntity = ClientEntityList().FirstBaseEntity(); pEntity; pEntity = ClientEntityList().NextBaseEntity( pEntity ) ) #else for( CBaseEntity *pEntity = gEntList.FirstEnt(); pEntity != NULL; pEntity = gEntList.NextEnt( pEntity ) ) #endif // CLIENT_DLL { CWarsFlora *pFlora = dynamic_cast<CWarsFlora *>( pEntity ); if( pFlora ) { // Prefer testing against hitboxes // If no hitboxes available, use the bounding box trace_t trace; bool bTestedHitBoxes = pFlora->TestHitboxes( pickerRay, MASK_SOLID, trace ); if( bTestedHitBoxes ) { if( trace.DidHit() ) { float fDistance = trace.endpos.DistTo( vStartPos ); if( !pBest || fDistance < fBestDistance ) { pBest = pFlora; fBestDistance = fDistance; } } } else { CBaseTrace trace2; if ( IntersectRayWithBox( pickerRay, pFlora->GetAbsOrigin() + pFlora->CollisionProp()->OBBMins(), pFlora->GetAbsOrigin() + pFlora->CollisionProp()->OBBMaxs(), 0.5f, &trace2 ) ) { float fDistance = trace2.endpos.DistTo( vStartPos ); if( !pBest || fDistance < fBestDistance ) { pBest = pFlora; fBestDistance = fDistance; } } } } } if( pBest ) { if( !IsSelected( pBest ) ) { Select( pBest ); KeyValues *pOperation = new KeyValues( "data" ); pOperation->SetString("operation", "select"); KeyValues *pFloraKey = new KeyValues( "flora", "uuid", pBest->GetFloraUUID() ); pFloraKey->SetBool( "select", true ); pOperation->AddSubKey( pFloraKey ); warseditorstorage->QueueServerCommand( pOperation ); } else { Deselect( pBest ); KeyValues *pOperation = new KeyValues( "data" ); pOperation->SetString("operation", "select"); KeyValues *pFloraKey = new KeyValues( "flora", "uuid", pBest->GetFloraUUID() ); pFloraKey->SetBool( "select", false ); pOperation->AddSubKey( pFloraKey ); warseditorstorage->QueueServerCommand( pOperation ); } //NDebugOverlay::Box( pBest->GetAbsOrigin(), -Vector(8, 8, 8), Vector(8, 8, 8), 0, 255, 0, 255, 5.0f); } }
//----------------------------------------------------------------------------- // Purpose: This is called every time the DLL is loaded //----------------------------------------------------------------------------- void CHud::Init( void ) { HOOK_HUD_MESSAGE( gHUD, ResetHUD ); #if 1 HOOK_HUD_MESSAGE( gHUD, SendAudio ); #endif InitFonts(); // Create all the Hud elements CHudElementHelper::CreateAllElements(); gLCD.Init(); // Initialize all created elements for ( int i = 0; i < m_HudList.Size(); i++ ) { m_HudList[i]->Init(); } m_bHudTexturesLoaded = false; KeyValues *kv = new KeyValues( "layout" ); if ( kv ) { if ( kv->LoadFromFile( filesystem, "scripts/HudLayout.res" ) ) { int numelements = m_HudList.Size(); for ( int i = 0; i < numelements; i++ ) { CHudElement *element = m_HudList[i]; vgui::Panel *pPanel = dynamic_cast<vgui::Panel*>(element); if ( !pPanel ) { Msg( "Non-vgui hud element %s\n", m_HudList[i]->GetName() ); continue; } KeyValues *key = kv->FindKey( pPanel->GetName(), false ); if ( !key ) { Msg( "Hud element '%s' doesn't have an entry '%s' in scripts/HudLayout.res\n", m_HudList[i]->GetName(), pPanel->GetName() ); } // Note: When a panel is parented to the module root, it's "parent" is returned as NULL. if ( !element->IsParentedToClientDLLRootPanel() && !pPanel->GetParent() ) { DevMsg( "Hud element '%s'/'%s' doesn't have a parent\n", m_HudList[i]->GetName(), pPanel->GetName() ); } } } kv->deleteThis(); } if ( m_bHudTexturesLoaded ) return; m_bHudTexturesLoaded = true; CUtlDict< CHudTexture *, int > textureList; // check to see if we have sprites for this res; if not, step down LoadHudTextures( textureList, "scripts/hud_textures", NULL ); LoadHudTextures( textureList, "scripts/mod_textures", NULL ); int c = textureList.Count(); for ( int index = 0; index < c; index++ ) { CHudTexture* tex = textureList[ index ]; AddSearchableHudIconToList( *tex ); } FreeHudTextureList( textureList ); HudIcons().Init(); }
bool CMapLayout::LoadMapLayout(const char *filename) { // open our output layout file KeyValues *pLayoutKeys = new KeyValues( "LayoutKeys" ); if ( !pLayoutKeys->LoadFromFile( g_pFullFileSystem, filename, "GAME" ) ) { //Msg( "Failed to load map layout %s\n", filename ); pLayoutKeys->deleteThis(); return false; } while ( pLayoutKeys ) { if ( !Q_stricmp( pLayoutKeys->GetName(), "room" ) ) { if ( !CRoom::LoadRoomFromKeyValues( pLayoutKeys, this ) ) return false; } else if ( !Q_stricmp( pLayoutKeys->GetName(), "logical_room" ) ) { LoadLogicalRoom( pLayoutKeys ); } else if ( !Q_stricmp( pLayoutKeys->GetName(), "mapmisc" ) ) { m_iPlayerStartTileX = pLayoutKeys->GetInt( "PlayerStartX" ); m_iPlayerStartTileY = pLayoutKeys->GetInt( "PlayerStartY" ); } else if ( Q_stricmp( pLayoutKeys->GetName(), "mission_settings" ) == 0 ) { m_pGenerationOptions = pLayoutKeys->MakeCopy(); } else if ( Q_stricmp( pLayoutKeys->GetName(), "instance_spawn" ) == 0 ) { m_InstanceSpawns[m_InstanceSpawns.AddToTail()].LoadFromKeyValues( pLayoutKeys ); } else if ( Q_stricmp( pLayoutKeys->GetName(), "npc_encounter" ) == 0 ) { CASW_Encounter *pEncounter = new CASW_Encounter(); pEncounter->LoadFromKeyValues( pLayoutKeys ); m_Encounters.AddToTail( pEncounter ); } pLayoutKeys = pLayoutKeys->GetNextKey(); } MarkEncounterRooms(); SetCurrentFilename(filename); pLayoutKeys->deleteThis(); return true; }
void LoadHudTextures( CUtlDict< CHudTexture *, int >& list, const char *szFilenameWithoutExtension, const unsigned char *pICEKey ) { KeyValues *pTemp, *pTextureSection; KeyValues *pKeyValuesData = ReadEncryptedKVFile( filesystem, szFilenameWithoutExtension, pICEKey ); if ( pKeyValuesData ) { CUtlVector<HudTextureFileRef> hudTextureFileRefs; // By default, add a default entry mapping "file" to no prefix. This will allow earlier-version files // to work with no modification. hudTextureFileRefs.AddToTail( HudTextureFileRef( "file", "" ) ); // Read "*file"-to-prefix mapping. KeyValues *pTextureFileRefs = pKeyValuesData->FindKey( "TextureFileRefs" ); if ( pTextureFileRefs ) { pTemp = pTextureFileRefs->GetFirstSubKey(); while ( pTemp ) { hudTextureFileRefs.AddToTail( HudTextureFileRef( pTemp->GetName(), pTemp->GetString( "prefix", "" ) ) ); pTemp = pTemp->GetNextKey(); } } // Read our individual HUD texture data blocks. pTextureSection = pKeyValuesData->FindKey( "TextureData" ); if ( pTextureSection ) { // Read the sprite data pTemp = pTextureSection->GetFirstSubKey(); while ( pTemp ) { if ( pTemp->GetString( "font", NULL ) ) { CHudTexture *tex = new CHudTexture(); // Key Name is the sprite name Q_strncpy( tex->szShortName, pTemp->GetName(), sizeof( tex->szShortName ) ); // it's a font-based icon tex->bRenderUsingFont = true; tex->cCharacterInFont = *(pTemp->GetString("character", "")); Q_strncpy( tex->szTextureFile, pTemp->GetString( "font" ), sizeof( tex->szTextureFile ) ); list.Insert( tex->szShortName, tex ); } else { int iTexLeft = pTemp->GetInt( "x", 0 ), iTexTop = pTemp->GetInt( "y", 0 ), iTexRight = pTemp->GetInt( "width", 0 ) + iTexLeft, iTexBottom = pTemp->GetInt( "height", 0 ) + iTexTop; for ( int i = 0; i < hudTextureFileRefs.Size(); i++ ) { const char *cszFilename = pTemp->GetString( hudTextureFileRefs[i].m_fileKeySymbol, NULL ); if ( cszFilename ) { CHudTexture *tex = new CHudTexture(); tex->bRenderUsingFont = false; tex->rc.left = iTexLeft; tex->rc.top = iTexTop; tex->rc.right = iTexRight; tex->rc.bottom = iTexBottom; Q_strncpy( tex->szShortName, hudTextureFileRefs[i].m_cszHudTexturePrefix, sizeof( tex->szShortName ) ); Q_strncpy( tex->szShortName + hudTextureFileRefs[i].m_uiPrefixLength, pTemp->GetName(), sizeof( tex->szShortName ) - hudTextureFileRefs[i].m_uiPrefixLength ); Q_strncpy( tex->szTextureFile, cszFilename, sizeof( tex->szTextureFile ) ); list.Insert( tex->szShortName, tex ); } } } pTemp = pTemp->GetNextKey(); } } } // Failed for some reason. Delete the Key data and abort. pKeyValuesData->deleteThis(); }
//============================================================================= bool GenericPanelList::SelectPanelItem( unsigned short index, SEARCH_DIRECTION direction, bool scrollToItem, bool bAllowStealFocus ) { bool itemSelected = false; if( index < m_PanelItems.Count() ) { Panel* previousNav = m_CurrentSelectedItem; if( ( m_PanelItems[index] != 0 ) && ( m_PanelItems[index] != previousNav ) && ( m_PanelItems[index]->IsEnabled() ) ) { itemSelected = true; if ( m_CurrentSelectedItem ) { PostMessage( m_CurrentSelectedItem->GetVPanel(), new KeyValues("PanelUnSelected") ); } m_CurrentSelectedItem = m_PanelItems[index]; m_CurrentSelectedItem->SetVisible( true ); //mouse input could have set any panel item as navigated to. for( int i = 0; i != m_PanelItems.Count(); ++i ) { if( i != index ) m_PanelItems[i]->NavigateFrom(); } CBaseModPanel::GetSingletonPtr()->SafeNavigateTo( previousNav, m_CurrentSelectedItem, bAllowStealFocus ); if( scrollToItem ) { ScrollToPanelItem( index ); } int regionX, regionY, regionWide, regionTall; m_PnlItemRegion->GetBounds( regionX, regionY, regionWide, regionTall ); int x, y, wide, tall; m_CurrentSelectedItem->GetBounds( x, y, wide, tall ); if ( regionTall > 0 ) // can get called here before our bounds are init { if ( y < regionY ) { m_ScrVerticalScroll->SetValue( index * ( tall + m_PanelItemBorder ) ); } else if ( ( y + tall ) > ( regionY + regionTall ) ) { // scroll to regionTall pixels above the bottom of the selected panel m_ScrVerticalScroll->SetValue( MAX( ( index + 1 ) * ( tall + m_PanelItemBorder ) - regionTall, 0 ) ); } } CBaseModPanel::GetSingleton().PlayUISound( UISOUND_FOCUS ); PostMessage( m_CurrentSelectedItem->GetVPanel(), new KeyValues("PanelSelected") ); KeyValues *pKv = new KeyValues( "OnItemSelected", "panelName", GetName() ); pKv->SetInt( "index", index ); CallParentFunction( pKv ); } } return itemSelected; }
KeyValues* ReadEncryptedKVFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey, bool bForceReadEncryptedFile /*= false*/ ) { Assert( strchr( szFilenameWithoutExtension, '.' ) == NULL ); char szFullName[512]; const char *pSearchPath = "MOD"; if ( pICEKey == NULL ) { pSearchPath = "GAME"; } // Open the weapon data file, and abort if we can't KeyValues *pKV = new KeyValues( "WeaponDatafile" ); Q_snprintf(szFullName,sizeof(szFullName), "%s.txt", szFilenameWithoutExtension); if ( bForceReadEncryptedFile || !pKV->LoadFromFile( filesystem, szFullName, pSearchPath ) ) // try to load the normal .txt file first { #ifndef _XBOX if ( pICEKey ) { Q_snprintf(szFullName,sizeof(szFullName), "%s.ctx", szFilenameWithoutExtension); // fall back to the .ctx file FileHandle_t f = filesystem->Open( szFullName, "rb", pSearchPath ); if (!f) { pKV->deleteThis(); return NULL; } // load file into a null-terminated buffer int fileSize = filesystem->Size(f); char *buffer = (char*)MemAllocScratch(fileSize + 1); Assert(buffer); filesystem->Read(buffer, fileSize, f); // read into local buffer buffer[fileSize] = 0; // null terminate file as EOF filesystem->Close( f ); // close file after reading UTIL_DecodeICE( (unsigned char*)buffer, fileSize, pICEKey ); bool retOK = pKV->LoadFromBuffer( szFullName, buffer, filesystem ); MemFreeScratch(); if ( !retOK ) { pKV->deleteThis(); return NULL; } } else { pKV->deleteThis(); return NULL; } #else pKV->deleteThis(); return NULL; #endif } return pKV; }
void CKeyBindingHelpDialog::PopulateList() { m_pList->DeleteAllItems(); int i, j; CUtlVector< ListInfo_t > maps; vgui2::Panel *pPanel = m_hPanel; while ( pPanel->IsKeyBindingChainToParentAllowed() ) { PanelKeyBindingMap *map = pPanel->GetKBMap(); while ( map ) { int k; int c = maps.Count(); for ( k = 0; k < c; ++k ) { if ( maps[k].m_pMap == map ) break; } if ( k == c ) { int mapIndex = maps.AddToTail( ); maps[mapIndex].m_pMap = map; maps[mapIndex].m_pPanel = pPanel; } map = map->baseMap; } pPanel = pPanel->GetParent(); if ( !pPanel ) break; } CUtlRBTree< KeyValues *, int > sorted( 0, 0, BindingLessFunc ); // add header item int c = maps.Count(); for ( i = 0; i < c; ++i ) { PanelKeyBindingMap *m = maps[ i ].m_pMap; Panel *pMapPanel = maps[i].m_pPanel; Assert( m ); int bindings = m->boundkeys.Count(); for ( j = 0; j < bindings; ++j ) { BoundKey_t *kbMap = &m->boundkeys[ j ]; Assert( kbMap ); // Create a new: blank item KeyValues *item = new KeyValues( "Item" ); // Fill in data char loc[ 128 ]; Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname ); char ansi[ 256 ]; AnsiText( loc, ansi, sizeof( ansi ) ); item->SetString( "Action", ansi ); item->SetWString( "Binding", Panel::KeyCodeModifiersToDisplayString( (KeyCode)kbMap->keycode, kbMap->modifiers ) ); // Find the binding KeyBindingMap_t *bindingMap = pMapPanel->LookupBinding( kbMap->bindingname ); if ( bindingMap && bindingMap->helpstring ) { AnsiText( bindingMap->helpstring, ansi, sizeof( ansi ) ); item->SetString( "Description", ansi ); } item->SetPtr( "Item", kbMap ); sorted.Insert( item ); } // Now try and find any "unbound" keys... int mappings = m->entries.Count(); for ( j = 0; j < mappings; ++j ) { KeyBindingMap_t *kbMap = &m->entries[ j ]; // See if it's bound CUtlVector< BoundKey_t * > list; pMapPanel->LookupBoundKeys( kbMap->bindingname, list ); if ( list.Count() > 0 ) continue; // Not bound, add a placeholder entry // Create a new: blank item KeyValues *item = new KeyValues( "Item" ); // fill in data char loc[ 128 ]; Q_snprintf( loc, sizeof( loc ), "#%s", kbMap->bindingname ); char ansi[ 256 ]; AnsiText( loc, ansi, sizeof( ansi ) ); item->SetString( "Action", ansi ); item->SetWString( "Binding", L"" ); if ( kbMap->helpstring ) { AnsiText( kbMap->helpstring, ansi, sizeof( ansi ) ); item->SetString( "Description", ansi ); } item->SetPtr( "Unbound", kbMap ); sorted.Insert( item ); } } for ( j = sorted.FirstInorder() ; j != sorted.InvalidIndex(); j = sorted.NextInorder( j ) ) { KeyValues *item = sorted[ j ]; // Add to list m_pList->AddItem( item, 0, false, false ); item->deleteThis(); } sorted.RemoveAll(); }
static cell_t SQL_ConnectCustom(IPluginContext *pContext, const cell_t *params) { KeyValues *kv; HandleError err; kv = g_SourceMod.ReadKeyValuesHandle(params[1], &err, false); if (kv == NULL) { return pContext->ThrowNativeError("Invalid KeyValues handle %x (error: %d)", params[1], err); } DatabaseInfo info; info.database = kv->GetString("database", ""); info.driver = kv->GetString("driver", "default"); info.host = kv->GetString("host", ""); info.maxTimeout = kv->GetInt("timeout", 0); info.pass = kv->GetString("pass", ""); info.port = kv->GetInt("port", 0); info.user = kv->GetString("user", ""); IDBDriver *driver; if (info.driver[0] == '\0' || strcmp(info.driver, "default") == 0) { driver = g_DBMan.GetDefaultDriver(); } else { driver = g_DBMan.FindOrLoadDriver(info.driver); } if (driver == NULL) { char buffer[255]; UTIL_Format(buffer, sizeof(buffer), "Could not find driver \"%s\"", info.driver); pContext->StringToLocalUTF8(params[2], params[3], buffer, NULL); return BAD_HANDLE; } char *buffer; IDatabase *db; pContext->LocalToString(params[2], &buffer); db = driver->Connect(&info, params[4] ? true : false, buffer, params[3]); if (db == NULL) { return BAD_HANDLE; } Handle_t hndl = g_DBMan.CreateHandle(DBHandle_Database, db, pContext->GetIdentity()); if (!hndl) { db->Close(); return pContext->ThrowNativeError("Out of handles!"); } /* HACK! Add us to the dependency list */ CExtension *pExt = g_Extensions.GetExtensionFromIdent(driver->GetIdentity()); if (pExt) { g_Extensions.BindChildPlugin(pExt, g_PluginSys.GetPluginByCtx(pContext->GetContext())); } return hndl; }
void UploadOgsData( IReplayMovie *pMovie, bool bEnded = false, const char *pEndReason = NULL ) { static int s_nUploadCounter = 0; KeyValues* pKVData = new KeyValues( "TF2ReplayUploads" ); pKVData->SetInt( "UploadCounter", s_nUploadCounter++ ); pKVData->SetInt( "ReplayHandle", (int)pMovie->GetReplayHandle() ); const ReplayRenderSettings_t &RenderSettings = pMovie->GetRenderSettings(); CFmtStr fmtResolution( "%ix%i", RenderSettings.m_nWidth, RenderSettings.m_nHeight ); pKVData->SetString( "ResolutionID", fmtResolution.Access() ); pKVData->SetString( "CodecID", ReplayVideo_GetCodec( ReplayVideo_FindCodecPresetFromCodec( RenderSettings.m_Codec ) ).m_pName ); pKVData->SetInt( "MotionBlurQuality", RenderSettings.m_nMotionBlurQuality ); pKVData->SetInt( "RenderQuality", RenderSettings.m_nEncodingQuality ); pKVData->SetInt( "FPSUPF", RenderSettings.m_FPS.GetUnitsPerFrame() ); pKVData->SetInt( "FPSUPS", RenderSettings.m_FPS.GetUnitsPerSecond() ); if ( bEnded ) { pKVData->SetInt( "EndUploadTime", GetSteamWorksSGameStatsUploader().GetTimeSinceEpoch() ); pKVData->SetString( "EndUploadReasonID", pEndReason ); } else { pKVData->SetInt( "StartUploadTime", GetSteamWorksSGameStatsUploader().GetTimeSinceEpoch() ); } GetSteamWorksSGameStatsUploader().AddStatsForUpload( pKVData ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CHL2MPClientScoreBoardDialog::UpdatePlayerInfo() { m_iSectionId = 0; // 0'th row is a header int selectedRow = -1; int i; CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer || !g_PR ) return; // walk all the players and make sure they're in the scoreboard for ( i = 1; i <= gpGlobals->maxClients; i++ ) { bool shouldShow = g_PR->IsConnected( i ); if ( shouldShow ) { // add the player to the list KeyValues *playerData = new KeyValues("data"); GetPlayerScoreInfo( i, playerData ); int itemID = FindItemIDForPlayerIndex( i ); int sectionID = GetSectionFromTeamNumber( g_PR->GetTeam( i ) ); if (itemID == -1) { // add a new row itemID = m_pPlayerList->AddItem( sectionID, playerData ); } else { // modify the current row m_pPlayerList->ModifyItem( itemID, sectionID, playerData ); } if ( i == pPlayer->entindex() ) { selectedRow = itemID; // this is the local player, hilight this row } // set the row color based on the players team m_pPlayerList->SetItemFgColor( itemID, g_PR->GetTeamColor( g_PR->GetTeam( i ) ) ); playerData->deleteThis(); } else { // remove the player int itemID = FindItemIDForPlayerIndex( i ); if (itemID != -1) { m_pPlayerList->RemoveItem(itemID); } } } if ( selectedRow != -1 ) { m_pPlayerList->SetSelectedItem(selectedRow); } }
//----------------------------------------------------------------------------- // Purpose: accessor to the filter save data //----------------------------------------------------------------------------- KeyValues *CServerBrowserDialog::GetFilterSaveData(const char *filterSet) { KeyValues *filterList = m_pSavedData->FindKey("FilterList", true); return filterList->FindKey(filterSet, true); }
void C_SlideshowDisplay::BuildSlideShowImagesList( void ) { FileFindHandle_t matHandle; char szDirectory[_MAX_PATH]; char szMatFileName[_MAX_PATH] = {'\0'}; char szFileBuffer[ SLIDESHOW_LIST_BUFFER_MAX ]; char *pchCurrentLine = NULL; if ( IsX360() ) { Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/slides.txt", m_szSlideshowDirectory ); FileHandle_t fh = g_pFullFileSystem->Open( szDirectory, "rt" ); if ( !fh ) { DevWarning( "Couldn't read slideshow image file %s!", szDirectory ); return; } int iFileSize = MIN( g_pFullFileSystem->Size( fh ), SLIDESHOW_LIST_BUFFER_MAX ); int iBytesRead = g_pFullFileSystem->Read( szFileBuffer, iFileSize, fh ); g_pFullFileSystem->Close( fh ); // Ensure we don't write outside of our buffer if ( iBytesRead > iFileSize ) iBytesRead = iFileSize; szFileBuffer[ iBytesRead ] = '\0'; pchCurrentLine = szFileBuffer; // Seek to end of first line char *pchNextLine = pchCurrentLine; while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' ) ++pchNextLine; if ( *pchNextLine != '\0' ) { // Mark end of string *pchNextLine = '\0'; // Seek to start of next string ++pchNextLine; while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) ) ++pchNextLine; } Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) ); pchCurrentLine = pchNextLine; } else { Q_snprintf( szDirectory, sizeof( szDirectory ), "materials/vgui/%s/*.vmt", m_szSlideshowDirectory ); const char *pMatFileName = g_pFullFileSystem->FindFirst( szDirectory, &matHandle ); if ( pMatFileName ) Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) ); } int iSlideIndex = 0; while ( szMatFileName[ 0 ] ) { char szFileName[_MAX_PATH]; Q_snprintf( szFileName, sizeof( szFileName ), "vgui/%s/%s", m_szSlideshowDirectory, szMatFileName ); szFileName[ Q_strlen( szFileName ) - 4 ] = '\0'; int iMatIndex = ::GetMaterialIndex( szFileName ); // Get material keywords char szFullFileName[_MAX_PATH]; Q_snprintf( szFullFileName, sizeof( szFullFileName ), "materials/vgui/%s/%s", m_szSlideshowDirectory, szMatFileName ); KeyValues *pMaterialKeys = new KeyValues( "material" ); bool bLoaded = pMaterialKeys->LoadFromFile( g_pFullFileSystem, szFullFileName, NULL ); if ( bLoaded ) { char szKeywords[ 256 ]; Q_strcpy( szKeywords, pMaterialKeys->GetString( "%keywords", "" ) ); char *pchKeyword = szKeywords; while ( pchKeyword[ 0 ] != '\0' ) { char *pNextKeyword = pchKeyword; // Skip commas and spaces while ( pNextKeyword[ 0 ] != '\0' && pNextKeyword[ 0 ] != ',' ) ++pNextKeyword; if ( pNextKeyword[ 0 ] != '\0' ) { pNextKeyword[ 0 ] = '\0'; ++pNextKeyword; while ( pNextKeyword[ 0 ] != '\0' && ( pNextKeyword[ 0 ] == ',' || pNextKeyword[ 0 ] == ' ' ) ) ++pNextKeyword; } // Find the list with the current keyword int iList; for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList ) { if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword ) == 0 ) break; } if ( iList >= m_SlideMaterialLists.Count() ) { // Couldn't find the list, so create it iList = m_SlideMaterialLists.AddToTail( new SlideMaterialList_t ); Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, pchKeyword ); } // Add material index to this list m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex ); m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex ); pchKeyword = pNextKeyword; } } // Find the generic list int iList; for ( iList = 0; iList < m_SlideMaterialLists.Count(); ++iList ) { if ( Q_strcmp( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" ) == 0 ) break; } if ( iList >= m_SlideMaterialLists.Count() ) { // Couldn't find the generic list, so create it iList = m_SlideMaterialLists.AddToHead( new SlideMaterialList_t ); Q_strcpy( m_SlideMaterialLists[ iList ]->szSlideKeyword, "" ); } // Add material index to this list m_SlideMaterialLists[ iList ]->iSlideMaterials.AddToTail( iMatIndex ); m_SlideMaterialLists[ iList ]->iSlideIndex.AddToTail( iSlideIndex ); if ( IsX360() ) { // Seek to end of first line char *pchNextLine = pchCurrentLine; while ( *pchNextLine != '\0' && *pchNextLine != '\n' && *pchNextLine != ' ' ) ++pchNextLine; if ( *pchNextLine != '\0' ) { // Mark end of string *pchNextLine = '\0'; // Seek to start of next string ++pchNextLine; while ( *pchNextLine != '\0' && ( *pchNextLine == '\n' || *pchNextLine == ' ' ) ) ++pchNextLine; } Q_strncpy( szMatFileName, pchCurrentLine, sizeof(szMatFileName) ); pchCurrentLine = pchNextLine; } else { const char *pMatFileName = g_pFullFileSystem->FindNext( matHandle ); if ( pMatFileName ) Q_strncpy( szMatFileName, pMatFileName, sizeof(szMatFileName) ); else szMatFileName[ 0 ] = '\0'; } ++iSlideIndex; } if ( !IsX360() ) { g_pFullFileSystem->FindClose( matHandle ); } }
//----------------------------------------------------------------------------- // Purpose: Shared script resource of voice menu commands and hud strings //----------------------------------------------------------------------------- void CMultiplayRules::LoadVoiceCommandScript( void ) { KeyValues *pKV = new KeyValues( "VoiceCommands" ); if ( pKV->LoadFromFile( filesystem, "scripts/voicecommands.txt", "GAME" ) ) { for ( KeyValues *menu = pKV->GetFirstSubKey(); menu != NULL; menu = menu->GetNextKey() ) { int iMenuIndex = m_VoiceCommandMenus.AddToTail(); int iNumItems = 0; // for each subkey of this menu, add a menu item for ( KeyValues *menuitem = menu->GetFirstSubKey(); menuitem != NULL; menuitem = menuitem->GetNextKey() ) { iNumItems++; if ( iNumItems > 9 ) { Warning( "Trying to load more than 9 menu items in voicecommands.txt, extras ignored" ); continue; } VoiceCommandMenuItem_t item; #ifndef CLIENT_DLL int iConcept = GetMPConceptIndexFromString( menuitem->GetString( "concept", "" ) ); if ( iConcept == MP_CONCEPT_NONE ) { Warning( "Voicecommand script attempting to use unknown concept. Need to define new concepts in code. ( %s )\n", menuitem->GetString( "concept", "" ) ); } item.m_iConcept = iConcept; item.m_bShowSubtitle = ( menuitem->GetInt( "show_subtitle", 0 ) > 0 ); item.m_bDistanceBasedSubtitle = ( menuitem->GetInt( "distance_check_subtitle", 0 ) > 0 ); Q_strncpy( item.m_szGestureActivity, menuitem->GetString( "activity", "" ), sizeof( item.m_szGestureActivity ) ); #else Q_strncpy( item.m_szSubtitle, menuitem->GetString( "subtitle", "" ), MAX_VOICE_COMMAND_SUBTITLE ); Q_strncpy( item.m_szMenuLabel, menuitem->GetString( "menu_label", "" ), MAX_VOICE_COMMAND_SUBTITLE ); #endif m_VoiceCommandMenus.Element( iMenuIndex ).AddToTail( item ); } } } pKV->deleteThis(); }
//----------------------------------------------------------------------------- // Purpose: Creates the build mode editing controls //----------------------------------------------------------------------------- void BuildModeDialog::CreateControls() { int i; m_pPanelList = new PanelList; m_pPanelList->m_pResourceData = new KeyValues( "BuildDialog" ); m_pPanelList->m_pControls = new PanelListPanel(this, "BuildModeControls"); // file to edit combo box is first m_pFileSelectionCombo = new ComboBox(this, "FileSelectionCombo", 10, false); for ( i = 0; i < m_pBuildGroup->GetRegisteredControlSettingsFileCount(); i++) { m_pFileSelectionCombo->AddItem(m_pBuildGroup->GetRegisteredControlSettingsFileByIndex(i), NULL); } if (m_pFileSelectionCombo->GetItemCount() < 2) { m_pFileSelectionCombo->SetEnabled(false); } int buttonH = 18; // status info at top of dialog m_pStatusLabel = new Label(this, "StatusLabel", "[nothing currently selected]"); m_pStatusLabel->SetTextColorState(Label::CS_DULL); m_pStatusLabel->SetTall( buttonH ); m_pDivider = new Divider(this, "Divider"); // drop-down combo box for adding new controls m_pAddNewControlCombo = new ComboBox(this, NULL, 30, false); m_pAddNewControlCombo->SetSize(116, buttonH); m_pAddNewControlCombo->SetOpenDirection(Menu::DOWN); m_pEditableParents = new CBuildModeNavCombo( this, NULL, 15, false, true, m_pBuildGroup->GetContextPanel() ); m_pEditableParents->SetSize(116, buttonH); m_pEditableParents->SetOpenDirection(Menu::DOWN); m_pEditableChildren = new CBuildModeNavCombo( this, NULL, 15, false, false, m_pBuildGroup->GetContextPanel() ); m_pEditableChildren->SetSize(116, buttonH); m_pEditableChildren->SetOpenDirection(Menu::DOWN); m_pNextChild = new Button( this, "NextChild", "Next", this ); m_pNextChild->SetCommand( new KeyValues( "OnChangeChild", "direction", 1 ) ); m_pPrevChild = new Button( this, "PrevChild", "Prev", this ); m_pPrevChild->SetCommand( new KeyValues( "OnChangeChild", "direction", -1 ) ); // controls that can be added // this list comes from controls EditablePanel can create by name. int defaultItem = m_pAddNewControlCombo->AddItem("None", NULL); CUtlVector< char const * > names; CBuildFactoryHelper::GetFactoryNames( names ); // Sort the names CUtlRBTree< char const *, int > sorted( 0, 0, StringLessThan ); for ( i = 0; i < names.Count(); ++i ) { sorted.Insert( names[ i ] ); } for ( i = sorted.FirstInorder(); i != sorted.InvalidIndex(); i = sorted.NextInorder( i ) ) { m_pAddNewControlCombo->AddItem( sorted[ i ], NULL ); } m_pAddNewControlCombo->ActivateItem(defaultItem); m_pExitButton = new Button(this, "ExitButton", "&Exit"); m_pExitButton->SetSize(64, buttonH); m_pSaveButton = new Button(this, "SaveButton", "&Save"); m_pSaveButton->SetSize(64, buttonH); m_pApplyButton = new Button(this, "ApplyButton", "&Apply"); m_pApplyButton->SetSize(64, buttonH); m_pReloadLocalization = new Button( this, "Localization", "&Reload Localization" ); m_pReloadLocalization->SetSize( 100, buttonH ); m_pExitButton->SetCommand("Exit"); m_pSaveButton->SetCommand("Save"); m_pApplyButton->SetCommand("Apply"); m_pReloadLocalization->SetCommand( new KeyValues( "ReloadLocalization" ) ); m_pDeleteButton = new Button(this, "DeletePanelButton", "Delete"); m_pDeleteButton->SetSize(64, buttonH); m_pDeleteButton->SetCommand("DeletePanel"); m_pVarsButton = new MenuButton(this, "VarsButton", "Variables"); m_pVarsButton->SetSize(72, buttonH); m_pVarsButton->SetOpenDirection(Menu::UP); // iterate the vars KeyValues *vars = m_pBuildGroup->GetDialogVariables(); if (vars && vars->GetFirstSubKey()) { // create the menu m_pVarsButton->SetEnabled(true); Menu *menu = new Menu(m_pVarsButton, "VarsMenu"); // set all the variables to be copied to the clipboard when selected for (KeyValues *kv = vars->GetFirstSubKey(); kv != NULL; kv = kv->GetNextKey()) { char buf[32]; _snprintf(buf, sizeof(buf), "%%%s%%", kv->GetName()); menu->AddMenuItem(kv->GetName(), new KeyValues("SetClipboardText", "text", buf), this); } m_pVarsButton->SetMenu(menu); } else { // no variables m_pVarsButton->SetEnabled(false); } m_pApplyButton->SetTabPosition(1); m_pPanelList->m_pControls->SetTabPosition(2); m_pVarsButton->SetTabPosition(3); m_pDeleteButton->SetTabPosition(4); m_pAddNewControlCombo->SetTabPosition(5); m_pSaveButton->SetTabPosition(6); m_pExitButton->SetTabPosition(7); m_pEditableParents->SetTabPosition( 8 ); m_pEditableChildren->SetTabPosition( 9 ); m_pPrevChild->SetTabPosition( 10 ); m_pNextChild->SetTabPosition( 11 ); m_pReloadLocalization->SetTabPosition( 12 ); }
bool CEngineSprite::Init( const char *pName ) { m_VideoMaterial = NULL; for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[ i ] = NULL; } m_width = m_height = m_numFrames = 1; Assert( g_pVideo != NULL ); if ( g_pVideo != NULL && g_pVideo->LocateVideoSystemForPlayingFile( pName ) != VideoSystem::NONE ) { m_VideoMaterial = g_pVideo->CreateVideoMaterial( pName, pName, "GAME", VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS, VideoSystem::DETERMINE_FROM_FILE_EXTENSION, false ); if ( m_VideoMaterial == NULL ) return false; IMaterial *pMaterial = m_VideoMaterial->GetMaterial(); m_VideoMaterial->GetVideoImageSize( &m_width, &m_height ); m_numFrames = m_VideoMaterial->GetFrameCount(); for ( int i = 0; i < kRenderModeCount; ++i ) { m_material[i] = pMaterial; pMaterial->IncrementReferenceCount(); } } else { char pTemp[MAX_PATH]; char pMaterialName[MAX_PATH]; char pMaterialPath[MAX_PATH]; Q_StripExtension( pName, pTemp, sizeof(pTemp) ); Q_strlower( pTemp ); Q_FixSlashes( pTemp, '/' ); // Check to see if this is a UNC-specified material name bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/'; if ( !bIsUNC ) { Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) ); Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS ); } else { Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) ); } Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) ); Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) ); KeyValues *kv = new KeyValues( "vmt" ); if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) ) { Warning( "Unable to load sprite material %s!\n", pMaterialPath ); return false; } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) { m_material[i] = NULL; continue; } Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName, i ); KeyValues *pMaterialKV = kv->MakeCopy(); pMaterialKV->SetInt( "$spriteRenderMode", i ); m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV ); m_material[ i ]->IncrementReferenceCount(); } kv->deleteThis(); m_width = m_material[0]->GetMappingWidth(); m_height = m_material[0]->GetMappingHeight(); m_numFrames = m_material[0]->GetNumAnimationFrames(); } for ( int i = 0; i < kRenderModeCount; ++i ) { if ( i == kRenderNone || i == kRenderEnvironmental ) continue; if ( !m_material[i] ) return false; } IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache ); m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT; IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache ); Vector origin, originVarValue; if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) ) { origin[0] = -m_width * 0.5f; origin[1] = m_height * 0.5f; } else { originVar->GetVecValue( &originVarValue[0], 3 ); origin[0] = -m_width * originVarValue[0]; origin[1] = m_height * originVarValue[1]; } up = origin[1]; down = origin[1] - m_height; left = origin[0]; right = m_width + origin[0]; return true; }
//============================================================================= void InGameChapterSelect::OnCommand(const char *command) { if ( const char* szMissionItem = StringAfterPrefix( command, "cmd_campaign_" ) ) { if ( !Q_stricmp( szMissionItem, m_chCampaign ) ) return; // Setting to same mission Q_strncpy( m_chCampaign, szMissionItem, ARRAYSIZE( m_chCampaign ) ); // Determine current game settings KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); if ( !pGameSettings ) return; DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) ); if( pMissionDropDown ) //we should become a listener for events pertaining to the mission flyout { FlyoutMenu* missionFlyout = pMissionDropDown->GetCurrentFlyout(); if( missionFlyout ) { missionFlyout->SetListener( this ); if ( vgui::Button *pAddonBtn = missionFlyout->FindChildButtonByCommand( "cmd_addoncampaign" ) ) { pAddonBtn->SetEnabled( false ); } // Disable all other campaigns that cannot be used for a vote for ( int k = 0, kNum = missionFlyout->GetChildCount(); k < kNum; ++ k ) { Panel *child = missionFlyout->GetChild( k ); if ( BaseModHybridButton* button = dynamic_cast< BaseModHybridButton* >( child ) ) { if ( const char* commandValue = button->GetCommand()->GetString( "command", NULL ) ) { if ( char const *szMissionName = StringAfterPrefix( commandValue, "cmd_campaign_" ) ) { pGameSettings->SetString( "game/campaign", szMissionName ); pGameSettings->SetInt( "game/chapter", 1 ); if ( !g_pMatchExtSwarm->GetMapInfo( pGameSettings ) ) { button->SetEnabled( false ); } } } } } } } } else if ( char const *szChapterSelected = StringAfterPrefix( command, "#L4D360UI_Chapter_" ) ) { m_nChapter = atoi( szChapterSelected ); UpdateChapterImage( m_chCampaign, m_nChapter ); } else if ( !Q_stricmp( command, "Select" ) ) { KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL ); KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings ); if ( !GameModeIsSingleChapter( pGameSettings->GetString( "game/mode" ) ) ) m_nChapter = 1; pGameSettings->SetString( "game/campaign", m_chCampaign ); pGameSettings->SetInt( "game/chapter", m_nChapter ); char const *szVoteCommand = "ChangeChapter"; int iUser = GetGameUIActiveSplitScreenPlayerSlot(); GAMEUI_ACTIVE_SPLITSCREEN_PLAYER_GUARD( iUser ); Panel *pDrpChapter = FindChildByName( "DrpChapter" ); if ( !pDrpChapter || !pDrpChapter->IsEnabled() ) { szVoteCommand = "ChangeMission"; m_nChapter = 1; engine->ClientCmd( CFmtStr( "callvote %s %s;", szVoteCommand, m_chCampaign ) ); } else if ( KeyValues *pInfoMap = g_pMatchExtSwarm->GetMapInfo( pGameSettings ) ) { engine->ClientCmd( CFmtStr( "callvote %s %s;", szVoteCommand, pInfoMap->GetString( "map" ) ) ); } GameUI().AllowEngineHideGameUI(); engine->ClientCmd( "gameui_hide" ); Close(); } else if ( !Q_strcmp( command, "Cancel" ) ) { GameUI().AllowEngineHideGameUI(); engine->ClientCmd("gameui_hide"); Close(); } }
//============================================================================= void FoundPublicGames::AddServersToList( void ) { if ( !m_pSearchManager ) return; int numItems = m_pSearchManager->GetNumResults(); for ( int i = 0; i < numItems; ++ i ) { IMatchSearchResult *item = m_pSearchManager->GetResultByIndex( i ); KeyValues *pGameDetails = item->GetGameDetails(); if ( !pGameDetails ) continue; if ( !ShouldShowPublicGame( pGameDetails ) ) continue; FoundGameListItem::Info fi; fi.mInfoType = FoundGameListItem::FGT_PUBLICGAME; char const *szGameMode = pGameDetails->GetString( "game/mode", "campaign" ); bool bGameModeChapters = GameModeIsSingleChapter( szGameMode ); const char *szDisplayName = pGameDetails->GetString( "game/missioninfo/displaytitle" ); if ( !szDisplayName || !szDisplayName[0] ) { szDisplayName = "Unknown Mission"; } Q_strncpy( fi.Name, szDisplayName, sizeof( fi.Name ) ); fi.mIsJoinable = item->IsJoinable(); fi.mbInGame = true; fi.miPing = pGameDetails->GetInt( "server/ping", 0 ); fi.mPing = fi.GP_HIGH; if ( !Q_stricmp( "lan", pGameDetails->GetString( "system/network", "" ) ) ) fi.mPing = fi.GP_SYSTEMLINK; fi.mpGameDetails = pGameDetails->MakeCopy(); KeyValues::AutoDelete autodelete_fi_mpGameDetails( fi.mpGameDetails ); // Force the chapter to 1 in case there is no chapter specified int iChapter = fi.mpGameDetails->GetInt( "game/chapter", 0 ); if ( !iChapter ) { fi.mpGameDetails->SetInt( "game/chapter", 1 ); fi.mpGameDetails->SetBool( "UI/nochapter", 1 ); } if ( IsX360() ) { // For X360 titles do not transmit campaign display title, so client needs to resolve locally KeyValues *pMissionInfo = NULL; KeyValues *pChapterInfo = NULL; //GetMapInfoRespectingAnyChapter( fi.mpGameDetails, &pMissionInfo ); if ( pMissionInfo && pChapterInfo ) { if ( bGameModeChapters ) Q_strncpy( fi.Name, pChapterInfo->GetString( "displayname", "#L4D360UI_LevelName_Unknown" ), sizeof( fi.Name ) ); else Q_strncpy( fi.Name, pMissionInfo->GetString( "displaytitle", "#L4D360UI_CampaignName_Unknown" ), sizeof( fi.Name ) ); } else { Q_strncpy( fi.Name, "#L4D360UI_CampaignName_Unknown", sizeof( fi.Name ) ); fi.mbDLC = true; } } fi.mFriendXUID = item->GetOnlineId(); // Check if this is actually a non-joinable game if ( fi.IsDLC() ) { fi.mIsJoinable = false; } else if ( fi.IsDownloadable() ) { fi.mIsJoinable = false; } else if ( fi.mbInGame ) { char const *szHint = fi.GetNonJoinableShortHint(); if ( !*szHint ) { fi.mIsJoinable = true; fi.mpfnJoinGame = HandleJoinPublicGame; } else { fi.mIsJoinable = false; } } AddGameFromDetails( fi ); } }