Example #1
0
//-----------------------------------------------------------------------------
// Purpose: Sets the text from the message
//-----------------------------------------------------------------------------
void Label::OnSetText(KeyValues *params)
{
	KeyValues *pkvText = params->FindKey("text", false);
	if (!pkvText)
		return;

	if (pkvText->GetDataType() == KeyValues::TYPE_STRING)
	{
		SetText(pkvText->GetString());
	}
	else if (pkvText->GetDataType() == KeyValues::TYPE_WSTRING)
	{
		SetText(pkvText->GetWString());
	}
}
Example #2
0
//=============================================================================
void Addons::Activate()
{
	BaseClass::Activate();

	m_GplAddons->RemoveAllPanelItems();
	m_addonInfoList.RemoveAll();
	m_pAddonList ? m_pAddonList->deleteThis() : NULL;

	//
	// Get the list of addons
	//

	// Load particular info for each addon
	if ( LoadAddonListFile( m_pAddonList ) )
	{
		for ( KeyValues *pCur = m_pAddonList->GetFirstValue(); pCur; pCur = pCur->GetNextValue() )
		{
			char szAddonDirName[60];
			bool bIsVPK = true;

			// If the entry in the list is a .vpk then 
			if ( V_stristr( pCur->GetName(), ".vpk" ) )
			{
				V_StripExtension( pCur->GetName(), szAddonDirName, sizeof( szAddonDirName ) );
				ExtractAddonMetadata( szAddonDirName );
			}
			else
			{
				bIsVPK = false;
				V_strncpy( szAddonDirName, pCur->GetName(), sizeof( szAddonDirName ) );
			}

			Addons::AddonInfo addonInfo;

			// Copy info to the AddonInfo struct
			KeyValues *pAddonInfo;

			if ( LoadAddonInfoFile( pAddonInfo, szAddonDirName, bIsVPK ) )
			{
				// Convert JPEG image to VTF, if necessary
				GetAddonImage( pCur->GetName(), addonInfo.szImageName, sizeof( addonInfo.szImageName ), bIsVPK  );

				// Copy values from particular keys
				V_strncpy( addonInfo.szDirectory, pCur->GetName(), sizeof( addonInfo.szDirectory ) ); 

				V_wcsncpy( addonInfo.szName, pAddonInfo->GetWString( "addontitle", g_pVGuiLocalize->Find( "#L4D360UI_Addon_None_Specified" ) ), sizeof( addonInfo.szName ) );
				V_wcsncpy( addonInfo.szAuthor, pAddonInfo->GetWString( "addonauthor", g_pVGuiLocalize->Find( "#L4D360UI_Addon_None_Specified" ) ), sizeof( addonInfo.szAuthor ) );
				V_wcsncpy( addonInfo.szDescription, pAddonInfo->GetWString( "addonDescription", g_pVGuiLocalize->Find( "#L4D360UI_Addon_None_Specified" ) ), sizeof( addonInfo.szDescription ) );
				addonInfo.bEnabled = pCur->GetInt() != 0;

				// Generate the types string based on the value of keys
				bool bCampaign = false, bMaps = false, bSkin = false, bWeapon = false, bBoss = false, bCommon = false, bSurvivor = false, bSound = false, bMusic = false, bScript = false, bProp = false;

				bCampaign = pAddonInfo->GetInt( "addonContent_Campaign" ) != 0;
				bMaps = ( pAddonInfo->GetInt( "addonContent_Map" ) != 0 ) && !bCampaign;
				bSkin = pAddonInfo->GetInt( "addonContent_Skin" ) != 0;
				bWeapon = pAddonInfo->GetInt( "addonContent_weapon" ) != 0;
				bBoss = pAddonInfo->GetInt( "addonContent_BossInfected" ) != 0;
				bCommon = pAddonInfo->GetInt( "addonContent_CommonInfected" ) != 0;
				bSurvivor = pAddonInfo->GetInt( "addonContent_Survivor" ) != 0;
				bSound = pAddonInfo->GetInt( "addonContent_Sound" ) != 0;
				bScript = pAddonInfo->GetInt( "addonContent_Script" ) != 0;
				bMusic = pAddonInfo->GetInt( "addonContent_Music" ) != 0;
				bProp = pAddonInfo->GetInt( "addonContent_prop" ) != 0;

				// Make the addon types string based on the flags
				addonInfo.szTypes[0] = NULL;
				bCampaign ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Campaign" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bMaps ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Map" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bSkin ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Skin" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bWeapon ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Weapon" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bBoss ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Boss" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bCommon ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Common" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bSurvivor ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Survivor" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bSound ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Sound" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bScript ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Script" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bMusic ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Music" ), sizeof( addonInfo.szTypes ) ) : NULL;
				bProp ? wcsncat( addonInfo.szTypes, g_pVGuiLocalize->Find( "#L4D360UI_Addon_Type_Props" ), sizeof( addonInfo.szTypes ) ) : NULL;

				// Remove trailing ','
				if ( wcslen( addonInfo.szTypes ) )
				{
					wchar_t *pwcComma = wcsrchr( addonInfo.szTypes, ',' );
					if ( pwcComma )
					{
						*pwcComma = NULL;
					}
				}
			}

			m_addonInfoList.AddToTail( addonInfo );

			// Get rid of the temp files
			if ( bIsVPK )
			{
				char tempFilename[MAX_PATH];
				char modPath[MAX_PATH];
				
				GetPrimaryModDirectory( modPath, MAX_PATH );
				V_snprintf( tempFilename, sizeof( tempFilename ), "%s%s%c%s", modPath, ADDONS_DIRNAME, CORRECT_PATH_SEPARATOR, ADDONINFO_FILENAME );
				g_pFullFileSystem->RemoveFile( tempFilename );
				V_snprintf( tempFilename, sizeof( tempFilename ), "%s%s%c%s", modPath, ADDONS_DIRNAME, CORRECT_PATH_SEPARATOR, ADDONJPEG_FILENAME );
				g_pFullFileSystem->RemoveFile( tempFilename );
			}
		}
	}

	//
	// Add the addons to the list panel 
	//
	FOR_EACH_VEC( m_addonInfoList, i )
	{
		AddonListItem* panelItem = m_GplAddons->AddPanelItem<AddonListItem>( "AddonListItem" );

		panelItem->SetParent( m_GplAddons );
		panelItem->SetAddonName( m_addonInfoList[i].szName );
		panelItem->SetAddonType( m_addonInfoList[i].szTypes );
		panelItem->SetAddonEnabled( m_addonInfoList[i].bEnabled );
	}