void Restore( IRestore *pRestore, bool createPlayers ) { CAchievementMgr *pAchievementMgr = dynamic_cast<CAchievementMgr *>( engine->GetAchievementMgr() ); if ( !pAchievementMgr ) return; if ( m_fDoLoad ) { pAchievementMgr->PreRestoreSavedGame(); pRestore->StartBlock(); // read # of achievements int nSavedAchievements = pRestore->ReadShort(); while ( nSavedAchievements-- ) { // read achievement ID int iAchievementID = pRestore->ReadShort(); // find the corresponding achievement object // We only save games in SP games so the assumption of SINGLE_PLAYER_SLOT is valid CBaseAchievement *pAchievement = pAchievementMgr->GetAchievementByID( iAchievementID, SINGLE_PLAYER_SLOT ); Assert( pAchievement ); // It's a bug if we don't understand this achievement if ( pAchievement ) { // read achievement data pRestore->ReadAll( pAchievement, pAchievement->GetDataDescMap() ); } else { // if we don't recognize the achievement for some reason, read and discard the data and keep going CBaseAchievement ignored; pRestore->ReadAll( &ignored, ignored.GetDataDescMap() ); } } pRestore->EndBlock(); pAchievementMgr->PostRestoreSavedGame(); } }
void MedalStatLine::ApplySchemeSettings( vgui::IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); LoadControlSettings( "resource/UI/MedalStatLine.res" ); if ( m_nMedalIndex != -1 ) { //int nMedalImage = m_nMedalIndex; bool bCheckSingleplayerTooltip = false; // if ( nMedalImage >= 44 && nMedalImage <= 51 ) // speedrun // { // nMedalImage = 44; // bCheckSingleplayerTooltip = true; // } if ( ASWGameRules() ) { int nAchievementIndex = GetAchievementIndexForMedal( m_nMedalIndex ); if ( nAchievementIndex != -1 ) { CAchievementMgr *pAchievementMgr = dynamic_cast<CAchievementMgr *>( engine->GetAchievementMgr() ); if ( pAchievementMgr ) { CBaseAchievement *pAch = pAchievementMgr->GetAchievementByID( nAchievementIndex, 0 ); if ( pAch ) { char buffer[128]; Q_snprintf( buffer, sizeof(buffer), "achievements/%s", pAch->GetName() ); m_pIcon->SetImage(buffer); } } } } //m_pIcon->SetImage( VarArgs( "swarm/medals/medal%d", nMedalImage ) ); Q_snprintf( m_szMedalName, sizeof( m_szMedalName ), "#asw_medal%d", m_nMedalIndex ); m_pTitle->SetText( m_szMedalName ); if ( bCheckSingleplayerTooltip && ASWGameResource() && ASWGameResource()->IsOfflineGame() ) { Q_snprintf( m_szMedalDescription, sizeof( m_szMedalDescription ), "#asw_medaltt%dsp", m_nMedalIndex ); } else { Q_snprintf( m_szMedalDescription, sizeof( m_szMedalDescription ), "#asw_medaltt%d", m_nMedalIndex ); } m_pDescription->SetText( m_szMedalDescription ); m_pCounter->SetText( VarArgs( "+%d", GetXPForMedal( m_nMedalIndex ) ) ); m_nXP = GetXPForMedal( m_nMedalIndex ); } else if ( m_nAchievementIndex != -1 ) { CAchievementMgr *pAchievementMgr = dynamic_cast<CAchievementMgr *>( engine->GetAchievementMgr() ); if ( !pAchievementMgr ) return; CBaseAchievement *pAchievement = pAchievementMgr->GetAchievementByID ( m_nAchievementIndex, 0 ); if ( pAchievement) { m_pIcon->SetImage( pAchievement->GetIconPath() ); Q_snprintf( m_szMedalName, sizeof( m_szMedalName ), "#%s_NAME", pAchievement->GetName() ); m_pTitle->SetText( m_szMedalName ); Q_snprintf( m_szMedalDescription, sizeof( m_szMedalDescription ), "#%s_DESC", pAchievement->GetName() ); m_pDescription->SetText( m_szMedalDescription ); m_pCounter->SetText( VarArgs( "+%d", GetXPForMedal( -m_nAchievementIndex ) ) ); m_nXP = GetXPForMedal( -m_nAchievementIndex ); } } }