//-----------------------------------------------------------------------------
// Purpose: Parse this prop's data from the model, if it has a keyvalues section.
//			Returns true only if this prop is using a model that has a prop_data section that's invalid.
//-----------------------------------------------------------------------------
int C_PhysPropClientside::ParsePropData( void )
{
	KeyValues *modelKeyValues = new KeyValues("");
	if ( !modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
	{
		modelKeyValues->deleteThis();
		return PARSE_FAILED_NO_DATA;
	}

	// Do we have a props section?
	KeyValues *pkvPropData = modelKeyValues->FindKey("prop_data");
	if ( !pkvPropData )
	{
		modelKeyValues->deleteThis();
		return PARSE_FAILED_NO_DATA;
	}

	int iResult = g_PropDataSystem.ParsePropFromKV( this, pkvPropData, modelKeyValues );
	modelKeyValues->deleteThis();
	return iResult;
}
void HintEventFn_BuildObject( CHintData *pData, C_HintEvent_Base *pEvent )
{
	if ( pEvent->GetType() == HINTEVENT_OBJECT_BUILT_BY_LOCAL_PLAYER )
	{
		C_BaseObject *pObj = ((C_HintEvent_ObjectBuiltByLocalPlayer*)pEvent)->m_pObject;
		
		if ( pObj->GetType() == pData->m_ObjectType )
		{
			// Ok, they just built the object that any hints of this type are referring to, so disable 
			// all further hints of this type.
			KeyValues *pkvStats = GetHintDisplayStats();
			if ( pkvStats )
			{
				KeyValues *pkvStatSection = pkvStats->FindKey( pData->name, true );
				if ( pkvStatSection )
				{
					pkvStatSection->SetString( "times_shown", VarArgs( "%i", 100 ) );
				}
			}
		}
	}
}
const char* CASW_Mission_Chooser_Source_Local::GetCampaignSaveIntroMap(const char *szSaveName)
{
	// check the save file exists
	char stripped[MAX_PATH];
	V_StripExtension( szSaveName, stripped, MAX_PATH );
	char tempfile[MAX_PATH];
	Q_snprintf( tempfile, sizeof( tempfile ), "save/%s.campaignsave", stripped );
	if (!g_pFullFileSystem->FileExists(tempfile))
		return NULL;

	KeyValues *pSaveKeyValues = new KeyValues( szSaveName );
	KeyValues::AutoDelete saveKeyValuesAutoDelete( pSaveKeyValues );
	const char* pszCampaign = NULL;
	if (pSaveKeyValues->LoadFromFile(g_pFullFileSystem, tempfile))
		pszCampaign = pSaveKeyValues->GetString("CampaignName");

	if (!pszCampaign)
		return NULL;

	// now read in the campaign txt and find the intro map name
	KeyValues *pCampaignKeyValues = GetCampaignDetails( pszCampaign );
	if (pCampaignKeyValues)
	{
		KeyValues *pMission = pCampaignKeyValues->FindKey("MISSION");
		Assert(pMission);
		if (pMission)
		{
			pMission = pMission->GetNextKey();
			Assert(pMission && !Q_stricmp(pMission->GetName(), "MISSION"));
			if (pMission && !Q_stricmp(pMission->GetName(), "MISSION"))
			{
				Assert(pMission->GetString("MapName", NULL));
				return pMission->GetString("MapName", NULL);
			}
		}
	}

	return NULL;
}
示例#4
0
//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
bool CNPC_Furniture::CreateVPhysics( void )
{
#ifndef HL2_DLL
	return false;
#endif

	KeyValues *modelKeyValues = new KeyValues("");
	if ( modelKeyValues->LoadFromBuffer( modelinfo->GetModelName( GetModel() ), modelinfo->GetModelKeyValueText( GetModel() ) ) )
	{
		// Do we have a bone follower section?
		KeyValues *pkvBoneFollowers = modelKeyValues->FindKey("bone_followers");
		if ( pkvBoneFollowers )
		{
			// Create our bone manager if we don't have one already
			if ( !m_pBoneFollowerManager )
			{
				m_pBoneFollowerManager = new CBoneFollowerManager();
			}

			// Loop through the list and create the bone followers
			KeyValues *pBone = pkvBoneFollowers->GetFirstSubKey();
			while ( pBone )
			{
				// Add it to the list
				const char *pBoneName = pBone->GetString();
				m_pBoneFollowerManager->AddBoneFollower( this, pBoneName );

				pBone = pBone->GetNextKey();
			}

			modelKeyValues->deleteThis();
			return true;
		}

		modelKeyValues->deleteThis();
	}

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: debug helper, spits out a human readable keyvalues version of the various configs
//-----------------------------------------------------------------------------
void OutputKeyValuesVersion( CVCProjConvert & proj )
{
	KeyValues *kv = new KeyValues( "project" );
	for ( int projIndex = 0; projIndex < proj.GetNumConfigurations(); projIndex++ )
	{
		CVCProjConvert::CConfiguration & config = proj.GetConfiguration(projIndex);
		KeyValues *configKv = kv->FindKey( config.GetName().String(), true );
		int fileCount = 0;
		for( int fileIndex = 0; fileIndex < config.GetNumFileNames(); fileIndex++ )
		{
			if ( config.GetFileType(fileIndex) == CVCProjConvert::CConfiguration::FILE_SOURCE ) 
			{
				char num[20];
				Q_snprintf( num, sizeof(num), "%i", fileCount );
				fileCount++;
				configKv->SetString( num, config.GetFileName(fileIndex) );
			}
		}
	}
	kv->SaveToFile( g_pFileSystem, "files.vdf" );
	kv->deleteThis();
}
示例#6
0
isstaticprop_ret IsStaticProp( studiohdr_t* pHdr )
{
	if (!(pHdr->flags & STUDIOHDR_FLAGS_STATIC_PROP))
		return RET_FAIL_NOT_MARKED_STATIC_PROP;

	// If it's got a propdata section in the model's keyvalues, it's not allowed to be a prop_static
	KeyValues *modelKeyValues = new KeyValues(pHdr->pszName());
	if ( StudioKeyValues( pHdr, modelKeyValues ) )
	{
		KeyValues *sub = modelKeyValues->FindKey("prop_data");
		if ( sub )
		{
			if ( !(sub->GetInt( "allowstatic", 0 )) )
			{
				modelKeyValues->deleteThis();
				return RET_FAIL_DYNAMIC;
			}
		}
	}
	modelKeyValues->deleteThis();

	return RET_VALID;
}
bool C_MountManager::LoadMountsFromKeyValues(std::string filename)
{
	unsigned int mountCount = 0;
	KeyValues* pKv = new KeyValues("mounts");
	if (pKv->LoadFromFile(g_pFullFileSystem, filename.c_str(), "MOD"))
	{
		for (KeyValues *pMountKv = pKv->GetFirstSubKey(); pMountKv; pMountKv = pMountKv->GetNextKey())
		{
			C_Mount* pMount = new C_Mount();

			std::string id = pMountKv->GetString("id");
			std::string title = pMountKv->GetString("title");
			std::string base = pMountKv->GetString("base");
			std::vector<std::string> paths;
			for (KeyValues *sub = pMountKv->FindKey("paths", true)->GetFirstSubKey(); sub; sub = sub->GetNextKey())
				paths.push_back(sub->GetString());

			pMount->Init(id, title, base, paths);

			//		if (pKv->GetBool("active"))
			//	{
			if (pMount->Activate())
				mountCount++;

			m_mounts[id] = pMount;
			//		}
		}
	}

	pKv->deleteThis();

	std::string num = VarArgs("%u", mountCount);
	C_AwesomiumBrowserInstance* pHudBrowserInstance = g_pAnarchyManager->GetAwesomiumBrowserManager()->FindAwesomiumBrowserInstance("hud");
	pHudBrowserInstance->AddHudLoadingMessage("progress", "", "Mounting Source Engine Games", "mounts", "0", num, num);

	return false;
}
示例#8
0
static cell_t smn_KvDeleteKey(IPluginContext *pContext, const cell_t *params)
{
	Handle_t hndl = static_cast<Handle_t>(params[1]);
	HandleError herr;
	HandleSecurity sec;
	KeyValueStack *pStk;

	sec.pOwner = NULL;
	sec.pIdentity = g_pCoreIdent;

	if ((herr=handlesys->ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
	}

	if (pStk->pCurRoot.size() < 2)
	{
		return 0;
	}

	char *keyName;
	pContext->LocalToString(params[2], &keyName);

	KeyValues *pRoot = pStk->pCurRoot.front();
	KeyValues *pValues = pRoot->FindKey(keyName);
	if (!pValues)
	{
		return 0;
	}

	pRoot->RemoveSubKey(pValues);
	pValues->deleteThis();

	return 1;
}
//-----------------------------------------------------------------------------
// Purpose: sets up the game menu from the keyvalues
//			the game menu is hierarchial, so this is recursive
//-----------------------------------------------------------------------------
vgui::Menu *CGameMenuButton::RecursiveLoadGameMenu(KeyValues *datafile)
{
	Menu *menu = new vgui::Menu(this, datafile->GetName());

	// loop through all the data adding items to the menu
	for (KeyValues *dat = datafile->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey())
	{
		const char *label = dat->GetString("label", "<unknown>");
		const char *cmd = dat->GetString("command", NULL);
		const char *name = dat->GetString("name", label);

		KeyValues *subkeys = dat->FindKey("SubMenu", false);
		Menu *submenu = NULL;
		if (subkeys)
		{
			// it's a hierarchial menu
			submenu = RecursiveLoadGameMenu(subkeys);
		}

		menu->AddCascadingMenuItem(name, label, cmd, this, submenu);
	}

	return menu;
}
示例#10
0
//=============================================================================
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" );
		}
	}
}
示例#11
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : scale - 
//			attachmentIndex - 
//			bOneFrame - 
//-----------------------------------------------------------------------------
void FX_MuzzleEffectAttached( 
	float scale, 
	ClientEntityHandle_t hEntity, 
	int attachmentIndex, 
	unsigned char *pFlashColor,
	bool bOneFrame )
{
	VPROF_BUDGET( "FX_MuzzleEffect", VPROF_BUDGETGROUP_PARTICLE_RENDERING );

	// If the material isn't available, let's not do anything.
	if ( g_Mat_SMG_Muzzleflash[0] == NULL )
	{
		return;
	}
	
	CSmartPtr<CLocalSpaceEmitter> pSimple = CLocalSpaceEmitter::Create( "MuzzleFlash", hEntity, attachmentIndex );
	Assert( pSimple );
	if ( pSimple == NULL )
		return;
	
	// Lock our bounding box
	pSimple->GetBinding().SetBBox( -( Vector( 16, 16, 16 ) * scale ), ( Vector( 16, 16, 16 ) * scale ) );
	
	SimpleParticle *pParticle;
	Vector			forward(1,0,0), offset;

	float flScale = random->RandomFloat( scale-0.25f, scale+0.25f );

	if ( flScale < 0.5f )
	{
		flScale = 0.5f;
	}
	else if ( flScale > 8.0f )
	{
		flScale = 8.0f;
	}

	//
	// Flash
	//

	int i;
	for ( i = 1; i < 9; i++ )
	{
		offset = (forward * (i*2.0f*scale));

		pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), g_Mat_SMG_Muzzleflash[random->RandomInt(0,3)], offset );
			
		if ( pParticle == NULL )
			return;

		pParticle->m_flLifetime		= 0.0f;
		pParticle->m_flDieTime		= bOneFrame ? 0.0001f : 0.1f;

		pParticle->m_vecVelocity.Init();

		if ( !pFlashColor )
		{
			pParticle->m_uchColor[0]	= 255;
			pParticle->m_uchColor[1]	= 255;
			pParticle->m_uchColor[2]	= 255;
		}
		else
		{
			pParticle->m_uchColor[0]	= pFlashColor[0];
			pParticle->m_uchColor[1]	= pFlashColor[1];
			pParticle->m_uchColor[2]	= pFlashColor[2];
		}

		pParticle->m_uchStartAlpha	= 255;
		pParticle->m_uchEndAlpha	= 128;

		pParticle->m_uchStartSize	= (random->RandomFloat( 6.0f, 9.0f ) * (12-(i))/9) * flScale;
		pParticle->m_uchEndSize		= pParticle->m_uchStartSize;
		pParticle->m_flRoll			= random->RandomInt( 0, 360 );
		pParticle->m_flRollDelta	= 0.0f;
	}


	if ( !ToolsEnabled() )
		return;

	if ( !clienttools->IsInRecordingMode() )
		return;

	C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( hEntity );
	if ( pEnt )
	{
		pEnt->RecordToolMessage();
	}

	// NOTE: Particle system destruction message will be sent by the particle effect itself.
	int nId = pSimple->AllocateToolParticleEffectId();

	KeyValues *msg = new KeyValues( "OldParticleSystem_Create" );
	msg->SetString( "name", "FX_MuzzleEffectAttached" );
	msg->SetInt( "id", nId );
	msg->SetFloat( "time", gpGlobals->curtime );

	KeyValues *pEmitter = msg->FindKey( "DmeSpriteEmitter", true );
	pEmitter->SetInt( "count", 9 );
	pEmitter->SetFloat( "duration", 0 );
	pEmitter->SetString( "material", "effects/muzzleflash2" ); // FIXME - create DmeMultiMaterialSpriteEmitter to support the 4 materials of muzzleflash
	pEmitter->SetInt( "active", true );

	KeyValues *pInitializers = pEmitter->FindKey( "initializers", true );

	KeyValues *pPosition = pInitializers->FindKey( "DmeLinearAttachedPositionInitializer", true );
	pPosition->SetPtr( "entindex", (void*)pEnt->entindex() );
	pPosition->SetInt( "attachmentIndex", attachmentIndex );
	pPosition->SetFloat( "linearOffsetX", 2.0f * scale );

	// TODO - create a DmeConstantLifetimeInitializer
	KeyValues *pLifetime = pInitializers->FindKey( "DmeRandomLifetimeInitializer", true );
	pLifetime->SetFloat( "minLifetime", bOneFrame ? 1.0f / 24.0f : 0.1f );
	pLifetime->SetFloat( "maxLifetime", bOneFrame ? 1.0f / 24.0f : 0.1f );

	KeyValues *pVelocity = pInitializers->FindKey( "DmeConstantVelocityInitializer", true );
	pVelocity->SetFloat( "velocityX", 0.0f );
	pVelocity->SetFloat( "velocityY", 0.0f );
	pVelocity->SetFloat( "velocityZ", 0.0f );

	KeyValues *pRoll = pInitializers->FindKey( "DmeRandomRollInitializer", true );
	pRoll->SetFloat( "minRoll", 0.0f );
	pRoll->SetFloat( "maxRoll", 360.0f );

	// TODO - create a DmeConstantRollSpeedInitializer
	KeyValues *pRollSpeed = pInitializers->FindKey( "DmeRandomRollSpeedInitializer", true );
	pRollSpeed->SetFloat( "minRollSpeed", 0.0f );
	pRollSpeed->SetFloat( "maxRollSpeed", 0.0f );

	// TODO - create a DmeConstantColorInitializer
	KeyValues *pColor = pInitializers->FindKey( "DmeRandomInterpolatedColorInitializer", true );
	Color color( pFlashColor ? pFlashColor[ 0 ] : 255, pFlashColor ? pFlashColor[ 1 ] : 255, pFlashColor ? pFlashColor[ 2 ] : 255, 255 );
	pColor->SetColor( "color1", color );
	pColor->SetColor( "color2", color );

	// TODO - create a DmeConstantAlphaInitializer
	KeyValues *pAlpha = pInitializers->FindKey( "DmeRandomAlphaInitializer", true );
	pAlpha->SetInt( "minStartAlpha", 255 );
	pAlpha->SetInt( "maxStartAlpha", 255 );
	pAlpha->SetInt( "minEndAlpha", 128 );
	pAlpha->SetInt( "maxEndAlpha", 128 );

	// size = rand(6..9) * indexed(12/9..4/9) * flScale = rand(6..9) * ( 4f + f * i )
	KeyValues *pSize = pInitializers->FindKey( "DmeMuzzleFlashSizeInitializer", true );
	float f = flScale / 9.0f;
	pSize->SetFloat( "indexedBase", 4.0f * f );
	pSize->SetFloat( "indexedDelta", f );
	pSize->SetFloat( "minRandomFactor", 6.0f );
	pSize->SetFloat( "maxRandomFactor", 9.0f );

/*
	KeyValues *pUpdaters = pEmitter->FindKey( "updaters", true );

	pUpdaters->FindKey( "DmePositionVelocityUpdater", true );
	pUpdaters->FindKey( "DmeRollUpdater", true );
	pUpdaters->FindKey( "DmeAlphaLinearUpdater", true );
	pUpdaters->FindKey( "DmeSizeUpdater", true );
*/
	ToolFramework_PostToolMessage( HTOOLHANDLE_INVALID, msg );
	msg->deleteThis();
}
//Logic from CASW_Random_Missions::BuildAndLaunchRandomLevel
void MOD_Level_Builder::BuildMapFromLayoutFile( const char *szMissionRuleFile, const char *szOutputLayoutFile, const char *szThemeName, bool bCompileLevel)
{
	if (IsBuildingLevel())
	{
		Msg("mod_level_builder is already building a level!\n");
		return;
	}
	
	Msg("Building Map.  MR File: [%s], Layout File: [%s], Theme: [%s]\n\n", 
		szMissionRuleFile, szOutputLayoutFile, szThemeName);

	/*Code taken from TileGenDialog.cpp*/
	KeyValues *pGenerationOptions = new KeyValues("EmptyOptions");
	pGenerationOptions->Clear();
	pGenerationOptions->LoadFromFile(g_pFullFileSystem, szMissionRuleFile, GAME_DIRECTORY);	

	CLayoutSystem *pLayoutSystem = new CLayoutSystem();

	CTilegenMissionPreprocessor *pMissionPreprocessor = new CTilegenMissionPreprocessor();

	CASW_KeyValuesDatabase *pRulesDatabase = new CASW_KeyValuesDatabase();
	pRulesDatabase->LoadFiles( "tilegen/rules/" );
	for ( int i = 0; i < pRulesDatabase->GetFileCount(); ++ i )
	{
		pMissionPreprocessor->ParseAndStripRules( pRulesDatabase->GetFile( i ) );
	}
	
	if (pMissionPreprocessor->SubstituteRules(pGenerationOptions) )
	{
		KeyValues *pMissionSettings = pGenerationOptions->FindKey( "mission_settings" ); 

		if ( pMissionSettings == NULL )
		{
			Warning("Mission is missing a Global Options Block!\n");
			return;
		}

		// Copy the filename key over
		pMissionSettings->SetString( "Filename", pGenerationOptions->GetString( "Filename", "invalid_filename" ) );
					
		AddListeners( pLayoutSystem );
		if ( !pLayoutSystem->LoadFromKeyValues( pGenerationOptions ) )
		{
			Warning("Failed to load mission from pre-processed key-values.");			
			return;
		}		

		int safteyCounter = 0;
		CMapLayout *pMapLayout = NULL;
		while (pMapLayout == NULL)
		{
			pMapLayout = GenerateMapLayout(pLayoutSystem, pMissionSettings);
			safteyCounter++;
			if (safteyCounter > 10)
			{
				Warning("MOD_Level_Builder failed generating a layout from layout file [%s]", szMissionRuleFile);
				return;
			}				
		}
			
		

		char* fullPath = (char*)malloc(sizeof(char)*1024);
		strcat(fullPath, g_gamedir);
		strcat(fullPath, szOutputLayoutFile);

		Q_strcpy(pMapLayout->m_szFilename, fullPath);	

		Msg("Saving layout file to [%s]", fullPath);
		if (!pMapLayout->SaveMapLayout( fullPath ))
		{
			Warning("Failed to save Layout file to [%s]", fullPath);
			return;
		}

		if (bCompileLevel)
			CompileLevel(szOutputLayoutFile);
	}
	else
	{
		Warning("Failed Initializting Mission Preprocessor\n");
		return;
	}		
}
void CGECreateServer::PopulateControls( void )
{
	// Only populate on first load
	if ( !m_bFirstLoad )
		return;

	// Populate the map list
	ComboBox *maplist = dynamic_cast<ComboBox*>( FindChildByName("MapList") );
	if ( maplist )
	{
		// Clear the list first
		maplist->DeleteAllItems();
		
		FileFindHandle_t findHandle; // note: FileFINDHandle
		char file[32];

		maplist->AddItem( "#SERVER_RANDOM_MAP", new KeyValues(RANDOM_VALUE) );
		const char *pFilename = filesystem->FindFirstEx( "maps\\*.bsp", "MOD", &findHandle );
		while ( pFilename )
		{
			if ( stricmp(pFilename, "ge_transition.bsp") ) //They don't need to pick our dinky crash avoidance map.
			{
				// Add the map to the list
				Q_FileBase(pFilename, file, 32);
				maplist->AddItem(file, new KeyValues(file));
			}

			pFilename = filesystem->FindNext( findHandle );
		}

		filesystem->FindClose( findHandle );
		maplist->SetNumberOfEditLines( 10 );
		maplist->SetEditable( false );
		maplist->GetMenu()->ForceCalculateWidth();
		maplist->ActivateItemByRow( 0 );
	}

	// Populate the weapon list
	ComboBox *weaponlist = dynamic_cast<ComboBox*>( FindChildByName("WeaponList") );
	if ( weaponlist )
	{
		weaponlist->DeleteAllItems();

		// TAKEN DIRECTLY FROM ge_loadoutmanager.cpp
		// Parsing individually allows us to overwrite the default sets with custom ones
		// Multiple custom sets can be defined as needed (can even make sets per gameplay)
		if ( !GELoadoutParser.HasBeenParsed() )
		{
			GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_default.X");
			GELoadoutParser.SetHasBeenParsed( false );
			GELoadoutParser.InitParser("scripts/loadouts/weapon_sets_custom*.X");
		}

		// Random loadout
		weaponlist->AddItem( "#SERVER_RANDOM_SET", new KeyValues("random_loadout") );
	
		FOR_EACH_DICT( m_WeaponSets, idx )
		{
			if (Q_strstr(m_WeaponSets.GetElementName(idx), "_mhide"))
				continue;

			int id = weaponlist->AddItem( m_WeaponSets.GetElementName(idx), NULL );
			weaponlist->GetMenu()->SetItemEnabled( id, false );

			for ( int k=m_WeaponSets[idx]->First(); k != m_WeaponSets[idx]->InvalidIndex(); k = m_WeaponSets[idx]->Next(k) )
				weaponlist->AddItem( m_WeaponSets[idx]->Element(k), new KeyValues(m_WeaponSets[idx]->GetElementName(k)) );
		}

		weaponlist->SetEditable( false );
		weaponlist->SetNumberOfEditLines( 15 );
		weaponlist->GetMenu()->ForceCalculateWidth();
		weaponlist->ActivateItemByRow( 0 );
	}

	// Populate the scenario list
	ComboBox *scenariolist = dynamic_cast<ComboBox*>( FindChildByName("ScenarioList") );
	if ( scenariolist )
	{
		// Clear the list first
		scenariolist->DeleteAllItems();

		FileFindHandle_t findHandle; // note: FileFINDHandle
		char file[32];

		scenariolist->AddItem( "#SERVER_RANDOM_SCENARIO", new KeyValues(RANDOM_VALUE) );
		const char *pFilename = filesystem->FindFirstEx( PYDIR, "MOD", &findHandle );
		while ( pFilename )
		{
			// Add the scenario to the list if not __init__
			if ( !Q_stristr( pFilename, "__init__") )
			{
				Q_FileBase( pFilename, file, 32 );
				scenariolist->AddItem( file, new KeyValues(file) );
			}

			pFilename = filesystem->FindNext( findHandle );
		}

		filesystem->FindClose( findHandle );
		scenariolist->SetEditable( false );
		scenariolist->SetNumberOfEditLines( 10 );
		scenariolist->GetMenu()->ForceCalculateWidth();
		scenariolist->ActivateItemByRow( 0 );
	}

	// Populate the bot difficulty list
	ComboBox *botdifflist = dynamic_cast<ComboBox*>( FindChildByName("BotLevel") );
	if ( botdifflist && botdifflist->GetItemCount() == 0 )
	{
		// Hard coded items (sorry!)
		botdifflist->AddItem( "#BOT_LEVEL_EASY", new KeyValues("1") );
		botdifflist->AddItem( "#BOT_LEVEL_MED", new KeyValues("3") );
		botdifflist->AddItem( "#BOT_LEVEL_HARD", new KeyValues("6") );
		botdifflist->AddItem( "#BOT_LEVEL_UBER", new KeyValues("9") );

		// Admin
		botdifflist->SetEditable( false );
		botdifflist->SetNumberOfEditLines( 4 );
		botdifflist->GetMenu()->ForceCalculateWidth();
		botdifflist->ActivateItemByRow( 0 );
	}

	// Populate the turbo mode list
	ComboBox *turbolist = dynamic_cast<ComboBox*>( FindChildByName("TurboMode") );
	if ( turbolist && turbolist->GetItemCount() == 0 )
	{
		// Hard coded items (sorry!)
		turbolist->AddItem( "#TURBO_MODE_NORM", new KeyValues("1.000000") );
		turbolist->AddItem( "#TURBO_MODE_FAST", new KeyValues("1.500000") );
		turbolist->AddItem( "#TURBO_MODE_LIGHT", new KeyValues("1.850000") );
		
		// Admin
		turbolist->SetEditable( false );
		turbolist->SetNumberOfEditLines( 3 );
		turbolist->GetMenu()->ForceCalculateWidth();
		turbolist->ActivateItemByRow( 0 );
	}

	// Load the default/saved values from our command map
	for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() )
	{
		// Get our value (or default)
		const char *value = (m_kvCmdValues->FindKey( kv->GetName() )) ? m_kvCmdValues->GetString( kv->GetName() ) : NULL;
		if ( !value )
			value = kv->GetString( "default", "" );

		if ( !Q_stricmp(kv->GetString("type"), "CHOICE") )
		{
			ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) );
			if ( !panel )
				continue;

			// Search through all our items to find a matching value
			for ( int i=0; i < panel->GetItemCount(); i++ )
			{
				int id = panel->GetItemIDFromRow( i );
				KeyValues* userdata = panel->GetItemUserData( id );
				
				if ( userdata && !Q_stricmp(value, userdata->GetName()) )
				{
					panel->ActivateItem( id );
					break;
				}
			}
		}
		else if ( !Q_stricmp(kv->GetString("type"), "TEXT") )
		{
			TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) );
			if ( !panel )
				continue;

			panel->SetText( value );
		}
		else if ( !Q_stricmp(kv->GetString("type"), "BOOL") )
		{
			CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) );
			if ( !panel )
				continue;

			if ( !Q_stricmp(value, "1") )
				panel->SetSelected( true );
			else
				panel->SetSelected( false );
		}
	}

	m_bFirstLoad = false;
}
void CGECreateServer::OnCommand( const char *command )
{
	if ( !Q_stricmp(command, "play") )
	{
		CUtlVector<char*> commands;

		// Pull the values from our controls and apply them to commands and save off the choices
		for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() )
		{
			KeyValues *kv_value = m_kvCmdValues->FindKey( kv->GetName(), true );
			char *cmd = new char[128];

			try {
				if ( !Q_stricmp(kv->GetString("type"), "CHOICE") )
				{
					ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) );

					const char *cmd_value = panel->GetActiveItemUserData()->GetName();
					kv_value->SetStringValue( cmd_value );

					if ( !Q_stricmp(cmd_value, RANDOM_VALUE) )
					{
						int idx = GERandom<int>( panel->GetItemCount()-1 ) + 1;
						idx = panel->GetItemIDFromRow( idx );
						cmd_value = panel->GetItemUserData( idx )->GetName();
					}

					Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value );
					commands.AddToTail( cmd );
				}
				else if ( !Q_stricmp(kv->GetString("type"), "TEXT") )
				{
					char cmd_value[64];
					TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) );
					panel->GetText( cmd_value, 64 );

					// We don't allow blank values... use default instead
					if ( !cmd_value[0] )
						Q_strncpy( cmd_value, kv->GetString("default",""), 64 );

					kv_value->SetStringValue( cmd_value );

					Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value );
					commands.AddToTail( cmd );
				}
				else if ( !Q_stricmp(kv->GetString("type"), "BOOL") )
				{
					CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) );
					
					if ( panel->IsSelected() ) {
						kv_value->SetStringValue( "1" );
						Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("on_val","1") );
					} else {
						kv_value->SetStringValue( "0" );
						Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("off_val","0") );
					}
				
					commands.AddToTail( cmd );
				}
				else
				{
					delete [] cmd;
				}
			} catch (...) {
				delete [] cmd;
			}
		}

		// Apply the commands
		for ( int i=0; i < commands.Count(); i++ )
			engine->ClientCmd_Unrestricted( commands[i] );
		
		// Save our last used settings to our custom file
		m_kvCmdValues->SaveToFile( filesystem, COMMAND_MAP_VAL, "MOD" );

		// Cleanup
		commands.PurgeAndDeleteElements();
	}

	SetVisible( false );
}
//---------------------------------------------------------------------
// Purpose: Center the dialog on the screen
//---------------------------------------------------------------------
void CSessionLobbyDialog::PerformLayout()
{
	BaseClass::PerformLayout();

	if ( !m_pDialogKeys )
		return;

	// Set the label strings according to the keyvalues passed in
	SetTextFromKeyvalues( m_pScenarioInfo->m_pTitle );
	SetTextFromKeyvalues( m_pScenarioInfo->m_pDescOne );
	SetTextFromKeyvalues( m_pScenarioInfo->m_pDescTwo );
	SetTextFromKeyvalues( m_pScenarioInfo->m_pDescThree );
	SetTextFromKeyvalues( m_pScenarioInfo->m_pValueTwo );
	SetTextFromKeyvalues( m_pScenarioInfo->m_pValueThree );

	const char *pDiskName = "unknown";
	KeyValues *pName = m_pDialogKeys->FindKey( "MapDiskNames" );
	if ( pName )
	{
		KeyValues *pScenario = m_pDialogKeys->FindKey( "CONTEXT_SCENARIO" );
		if ( pScenario )
		{
			pDiskName = pName->GetString( pScenario->GetString( "displaystring" ), "unknown" );
		}
	}

	// find the scenario type
	KeyValues *pType = m_pDialogKeys->FindKey( "ScenarioTypes" );
	if ( pType )
	{
		const char *pString = pType->GetString( pDiskName, NULL );
		if ( pString )
		{
			m_pScenarioInfo->m_pSubtitle->SetText( pString );
		}
	}

	// Set the team goals
	KeyValues *pGoals = m_pDialogKeys->FindKey( "TeamGoals" );
	if ( pGoals )
	{
		KeyValues *pTeam = pGoals->FindKey( "Blue" );
		if ( pTeam )
		{
			m_pTeamInfos[BLUE_TEAM_LOBBY]->m_pDescOne->SetText( pTeam->GetString( pDiskName, "" ) );
		}
		pTeam = pGoals->FindKey( "Red" );
		if ( pTeam )
		{
			m_pTeamInfos[RED_TEAM_LOBBY]->m_pDescOne->SetText( pTeam->GetString( pDiskName, "" ) );
		}
	}

	for ( int i = 0; i < TOTAL_LOBBY_TEAMS; ++i )
	{
		UpdatePlayerCountDisplay( i );
	}

	if ( m_bCenterOnScreen )
	{
		MoveToCenterOfScreen();
	}

	// Don't allow player reviews in system link games
	CMatchmakingBasePanel *pBase = dynamic_cast< CMatchmakingBasePanel* >( m_pParent );
	if ( pBase )
	{
		pBase->SetFooterButtonVisible( "#GameUI_PlayerReview", pBase->GetGameType() != GAMETYPE_SYSTEMLINK_MATCH );

		// hide the settings changing if we're in a ranked game
		if ( m_pHostOptionsPanel )
		{
			bool bVisible = pBase->GetGameType() != GAMETYPE_RANKED_MATCH;
			vgui::Label *pSettingsLabel = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("ChangeSettingsButton",true);
			if ( pSettingsLabel )
			{
				pSettingsLabel->SetVisible( bVisible );
			}
			pSettingsLabel = (vgui::Label *)m_pHostOptionsPanel->FindChildByName("ChangeSettingsText",true);
			if ( pSettingsLabel )
			{
				pSettingsLabel->SetVisible( bVisible );
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Loads and initializes all the modules specified in the platform file
//-----------------------------------------------------------------------------
bool CVGuiSystemModuleLoader::LoadPlatformModules(CreateInterfaceFn *factorylist, int factorycount, bool useSteamModules)
{
	if ( IsX360() )
	{
		// not valid for 360
		return false;
	}

	bool bSuccess = true;

	// load platform menu
	KeyValues *kv = new KeyValues("Platform");
	if (!kv->LoadFromFile(g_pFullFileSystem, "steam/games/PlatformMenu.vdf", "PLATFORM"))
	{
		kv->deleteThis();
		return false;
	}

	// walk the platform menu loading all the interfaces
	KeyValues *menuKeys = kv->FindKey("Menu", true);
	for (KeyValues *it = menuKeys->GetFirstSubKey(); it != NULL; it = it->GetNextKey())
	{
		// see if we should skip steam modules
		if (!useSteamModules && it->GetInt("SteamApp"))
			continue;

		const char *pchInterface = it->GetString("interface");

		// don't load friends if we are using Steam Community
		if ( !Q_stricmp( pchInterface, "VGuiModuleTracker001" ) && bSteamCommunityFriendsVersion )
			continue;

		// get copy out of steam cache
		const char *dllPath = it->GetString("dll");

		// load the module (LoadModule calls GetLocalCopy() under steam)
		CSysModule *mod = g_pFullFileSystem->LoadModule(dllPath, "EXECUTABLE_PATH");
		if (!mod)
		{
			Error("Platform Error: bad module '%s', not loading\n", it->GetString("dll"));
			bSuccess = false;
			continue;
		}

		// make sure we get the right version
		IVGuiModule *moduleInterface = (IVGuiModule *)Sys_GetFactory(mod)(pchInterface, NULL);
		if (!moduleInterface)
		{
			Warning("Platform Error: module version ('%s, %s) invalid, not loading\n", it->GetString("dll"), it->GetString("interface"));
			bSuccess = false;
			continue;
		}

		// store off the module
		int newIndex = m_Modules.AddToTail();
		m_Modules[newIndex].module = mod;
		m_Modules[newIndex].moduleInterface = moduleInterface;
		m_Modules[newIndex].data = it;
	}

	m_pPlatformModuleData = kv;
	return InitializeAllModules(factorylist, factorycount) && bSuccess;
}
示例#17
0
	void InitCommentary( void )
	{
		// Install the global cvar callback
		cvar->InstallGlobalChangeCallback( CV_GlobalChange_Commentary );

		// If we find the commentary semaphore, the commentary entities already exist.
		// This occurs when you transition back to a map that has saved commentary nodes in it.
		if ( gEntList.FindEntityByName( NULL, COMMENTARY_SPAWNED_SEMAPHORE ) )
			return;

		// Spawn the commentary semaphore entity
		CBaseEntity *pSemaphore = CreateEntityByName( "info_target" );
		pSemaphore->SetName( MAKE_STRING(COMMENTARY_SPAWNED_SEMAPHORE) );

		bool oldLock = engine->LockNetworkStringTables( false );

		// Find the commentary file
		char szFullName[512];
		Q_snprintf(szFullName,sizeof(szFullName), "maps/%s_commentary.txt", STRING( gpGlobals->mapname ));
		KeyValues *pkvFile = new KeyValues( "Commentary" );
		if ( pkvFile->LoadFromFile( filesystem, szFullName, "MOD" ) )
		{
			Msg( "Commentary: Loading commentary data from %s. \n", szFullName );

			// Load each commentary block, and spawn the entities
			KeyValues *pkvNode = pkvFile->GetFirstSubKey();
			while ( pkvNode )
			{
				// Get node name
				const char *pNodeName = pkvNode->GetName();
				KeyValues *pClassname = pkvNode->FindKey( "classname" );
				if ( pClassname )
				{
					// Use the classname instead
					pNodeName = pClassname->GetString();
				}

				// Spawn the commentary entity
				CBaseEntity *pNode = CreateEntityByName( pNodeName );
				if ( pNode )
				{
					ParseEntKVBlock( pNode, pkvNode );
					DispatchSpawn( pNode );

					EHANDLE hHandle;
					hHandle = pNode;
					m_hSpawnedEntities.AddToTail( hHandle );

					CPointCommentaryNode *pCommNode = dynamic_cast<CPointCommentaryNode*>(pNode);
					if ( pCommNode )
					{
						m_iCommentaryNodeCount++;
						pCommNode->SetNodeNumber( m_iCommentaryNodeCount );
					}
				}
				else
				{
					Warning("Commentary: Failed to spawn commentary entity, type: '%s'\n", pNodeName );
				}

				// Move to next entity
				pkvNode = pkvNode->GetNextKey();
			}

			// Then activate all the entities
			for ( int i = 0; i < m_hSpawnedEntities.Count(); i++ )
			{
				m_hSpawnedEntities[i]->Activate();
			}
		}
		else
		{
			Msg( "Commentary: Could not find commentary data file '%s'. \n", szFullName );
		}

		engine->LockNetworkStringTables( oldLock );
	}
BasicShaderCfg_t *BuildShaderData( const char *dumpFileName )
{
	KeyValues *pKV = new KeyValues( dumpFileName );
	char _path[MAX_PATH];
	Q_snprintf( _path, MAX_PATH, "%s/%s.dump", ::GetDumpDirectory(), dumpFileName );
	Q_FixSlashes( _path );
	pKV->LoadFromFile( g_pFullFileSystem, _path, "MOD" );

	BasicShaderCfg_t *data = new BasicShaderCfg_t();

	const char *szT = pKV->GetString( "vs_name" );
	int len = Q_strlen( szT ) + 1;
	data->ProcVSName = new char[ len ];
	Q_snprintf( data->ProcVSName, len, "%s", szT );

	szT = pKV->GetString( "ps_name" );
	len = Q_strlen( szT ) + 1;
	data->ProcPSName = new char[ len ];
	Q_snprintf( data->ProcPSName, len, "%s", szT );

	szT = pKV->GetString( "shader_filename" );
	len = Q_strlen( szT ) + 1;
	data->Filename = new char[ len ];
	Q_snprintf( data->Filename, len, "%s", szT );
	Q_FixSlashes( data->Filename );

	szT = pKV->GetName();
	len = Q_strlen( szT ) + 1;
	data->CanvasName = new char[ len ];
	Q_snprintf( data->CanvasName, len, "%s", szT );

	Q_snprintf( data->dumpversion, sizeof(data->dumpversion), "%s", pKV->GetString( GetDumpVersion_KeyName() ) );

	data->iShaderModel = pKV->GetInt( "i_sm" );
	data->iCullmode = pKV->GetInt( "i_cull" );
	data->iAlphablendmode = pKV->GetInt( "i_ablend" );
	data->flAlphaTestRef = pKV->GetFloat( "fl_atestref" );
	data->iDepthtestmode = pKV->GetInt( "i_dtest" );
	data->iDepthwritemode = pKV->GetInt( "i_dwrite" );
	data->bsRGBWrite = !!pKV->GetInt( "i_srgbw" );

	data->iVFMT_flags = pKV->GetInt( "i_vfmt_flags" );
	data->iVFMT_numTexcoords = pKV->GetInt( "i_vfmt_texcoords" );
	data->iVFMT_numUserData = pKV->GetInt( "i_vfmt_udata" );
	for ( int i = 0; i < 3; i++ )
	{
		char tmp[48];
		Q_snprintf( tmp, sizeof(tmp), "i_vfmt_texcoordDim_%i", i );
		data->iVFMT_texDim[i] = pKV->GetInt( tmp, GetVarFlagsVarValue( HLSLVAR_FLOAT2 ) + 1 );
	}

	data->bVertexLighting = !!pKV->GetInt( "i_vlit" );
	data->bRefractionSupport = !!pKV->GetInt( "i_vrefract" );

	KeyValues *pSubIdent_VS = pKV->FindKey( "identifiers_VS" );
	if ( pSubIdent_VS )
		ReadIdents( *data->pVS_Identifiers, pSubIdent_VS );

	KeyValues *pSubIdent_PS = pKV->FindKey( "identifiers_PS" );
	if ( pSubIdent_PS )
		ReadIdents( *data->pPS_Identifiers, pSubIdent_PS );

	pKV->deleteThis();
	return data;
}
示例#19
0
void CFolderMenu::Update()
{
	ReloadControlSettings(false, false);

	MoveToCenterOfScreen();

	Button *entry = dynamic_cast<Button *>(FindChildByName("ApproveButton"));
	if (entry)
		entry->SetVisible(true);

	C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();

	if (!pPlayer)
		return;

	if (pPlayer->HasCharacterBeenChosen())
		Q_strcpy(m_szCharacter, pPlayer->GetCharacter());
	else
		m_szCharacter[0] = '\0';

	if (ShouldShowCharacterOnly() && !ShouldShowTeams())
	{
		m_pProfileInfo->SetVisible(true);
		if (m_szPreviewCharacter[0])
			m_pProfileInfo->SetText((std::string("#DA_CharacterInfo_") + m_szPreviewCharacter).c_str());
		else if (m_szCharacter[0])
			m_pProfileInfo->SetText((std::string("#DA_CharacterInfo_") + m_szCharacter).c_str());
		else
			m_pProfileInfo->SetText("#DA_CharacterInfo_None");
	}
	else
		m_pProfileInfo->SetVisible(false);

	CFolderLabel *pCharacterName = dynamic_cast<CFolderLabel *>(FindChildByName("AgentName"));
	if (pCharacterName && !ShouldShowTeams())
	{
		std::string sCharacter;
		if (m_szPreviewCharacter[0])
			sCharacter = std::string("#DA_Character_") + m_szPreviewCharacter;
		else if (m_szCharacter[0])
			sCharacter = std::string("#DA_Character_") + m_szCharacter;

		std::wstring sLocalized;
		wchar_t* pszLocalized = g_pVGuiLocalize->Find( sCharacter.c_str() );

		if (pszLocalized)
			sLocalized += pszLocalized;

		if (pPlayer->m_Shared.m_iStyleSkill)
		{
			std::string sSkill = std::string("#DA_Skill_") + SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get()) + "_Adjective";

			pszLocalized = g_pVGuiLocalize->Find( sSkill.c_str() );

			if (pszLocalized)
				sLocalized += pszLocalized;
		}

		pCharacterName->SetText(sLocalized.c_str());
	}
	else
		pCharacterName->SetText("");

	CFolderLabel* pLabels[2];
	pLabels[0] = dynamic_cast<CFolderLabel *>(FindChildByName("RequestedArmament1"));
	pLabels[1] = dynamic_cast<CFolderLabel *>(FindChildByName("RequestedArmament2"));

	int iArmamentsOn1 = 0;

	std::wostringstream sLabel1;
	std::wostringstream sLabel2;

	SDKWeaponID eFirst = WEAPON_NONE;
	for (int i = 0; i < MAX_LOADOUT; i++)
	{
		if (!pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i))
			continue;

		CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i);
		if (!pWeaponInfo)
			continue;

		if (!eFirst)
		{
			eFirst = (SDKWeaponID)i;

			if (pPlayer->GetLoadoutWeaponCount(eFirst) > 1)
			{
				CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo(eFirst);
				if (pWeaponInfo && pWeaponInfo->m_szAkimbo[0])
				{
					// If we have two of this weapon and this weapon has an akimbo, use the akimbo instead.
					eFirst = AliasToWeaponID(pWeaponInfo->m_szAkimbo);
				}
			}
		}
		else
		{
			if (pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) > 1)
			{
				CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i);
				if (pWeaponInfo && pWeaponInfo->m_szAkimbo[0])
				{
					SDKWeaponID eAkimbo = AliasToWeaponID(pWeaponInfo->m_szAkimbo);
					if (eAkimbo < eFirst)
					{
						// If we have this akimbo and it's preferred to the current weapon, use it instead.
						// (Preferred means lower weapon ID.)
						eFirst = eAkimbo;
					}
				}
			}
		}

		std::wostringstream sLabel;

		const wchar_t *pchFmt = g_pVGuiLocalize->Find( pWeaponInfo->szPrintName );
		if ( pchFmt && pchFmt[0] )
			sLabel << pchFmt;
		else
			sLabel << pWeaponInfo->szPrintName;

		if (pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) > 1)
			sLabel << " x" << pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i) << "\n";
		else
			sLabel << "\n";

		if (iArmamentsOn1 >= 2)
			sLabel2 << sLabel.str();
		else
			sLabel1 << sLabel.str();

		iArmamentsOn1++;
	}

	if (pLabels[0])
		pLabels[0]->SetText(sLabel1.str().c_str());

	if (pLabels[1])
		pLabels[1]->SetText(sLabel2.str().c_str());

	const char szPlayerPreviewTemplate[] =
		"	\"model\"\n"
		"	{\n"
		"		\"spotlight\"	\"1\"\n"
		"		\"modelname\"	\"models/player/frank.mdl\"\n"
		"		\"origin_z\"	\"-57\"\n"
		"		\"origin_y\"	\"10\"\n"
		"		\"origin_x\"	\"110\"\n"
		"		\"angles_y\"	\"180\"\n"

		"		\"animation\"\n"
		"		{\n"
		"			\"sequence\"		\"m1911_idle\"\n"
		"			\"pose_parameters\"\n"
		"			{\n"
		"				\"body_yaw\" \"25.0\"\n"
		"				\"body_pitch\" \"-30.0\"\n"
		"			}\n"
		"		}\n"
			
		"		\"attached_model\"\n"
		"		{\n"
		"			\"modelname\" \"models/weapons/m1911.mdl\"\n"
		"		}\n"
		"	}";

	CModelPanel *pPlayerPreview = dynamic_cast<CModelPanel *>(FindChildByName("player_preview"));
	CSDKWeaponInfo* pWeaponInfo = NULL;
	if (eFirst)
		pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo(eFirst);

	if ((m_szCharacter[0] || m_szPreviewCharacter[0]) && pPlayerPreview && !ShouldShowTeams())
	{
		KeyValues* pValues = new KeyValues("preview");
		pValues->LoadFromBuffer("model", szPlayerPreviewTemplate);

		const char* pCharacter = m_szCharacter;
		if (m_szPreviewCharacter[0])
			pCharacter = m_szPreviewCharacter;

		pValues->SetString("modelname", VarArgs("models/player/%s.mdl", pCharacter));

		if (ShouldShowCharacterOnly() || ShouldShowCharacterAndWeapons())
		{
			pValues->SetFloat("origin_x", hud_characterpreview_x.GetFloat());
			pValues->SetFloat("origin_y", hud_characterpreview_y.GetFloat());
			pValues->SetFloat("origin_z", hud_characterpreview_z.GetFloat());
		}
		else
		{
			pValues->SetFloat("origin_x", hud_playerpreview_x.GetFloat());
			pValues->SetFloat("origin_y", hud_playerpreview_y.GetFloat());
			pValues->SetFloat("origin_z", hud_playerpreview_z.GetFloat());
		}

		if (m_pPage && FStrEq(m_pPage->GetName(), "class") && m_szPreviewSequence[0] && m_szPreviewWeaponModel[0] && !pPlayer->GetLoadoutWeight())
		{
			KeyValues* pAnimation = pValues->FindKey("animation");
			if (pAnimation)
				pAnimation->SetString("sequence", m_szPreviewSequence);

			KeyValues* pWeapon = pValues->FindKey("attached_model");
			if (pWeapon)
				pWeapon->SetString("modelname", m_szPreviewWeaponModel);
		}
		else if (pWeaponInfo)
		{
			KeyValues* pAnimation = pValues->FindKey("animation");
			if (pAnimation)
				pAnimation->SetString("sequence", VarArgs("%s_idle", WeaponIDToAlias(eFirst)));

			KeyValues* pWeapon = pValues->FindKey("attached_model");
			if (pWeapon)
				pWeapon->SetString("modelname", pWeaponInfo->szWorldModel);
		}
		else
		{
			KeyValues* pAnimation = pValues->FindKey("animation");
			if (pAnimation)
				pAnimation->SetString("sequence", "idle");

			KeyValues* pWeapon = pValues->FindKey("attached_model");
			if (pWeapon)
				pWeapon->SetString("modelname", "");
		}

		if (SDKGameRules()->IsTeamplay())
		{
			if (pPlayer->GetTeamNumber() == SDK_TEAM_BLUE)
				pValues->SetInt("skin", 1);
			else if (pPlayer->GetTeamNumber() == SDK_TEAM_RED)
				pValues->SetInt("skin", 2);
			else
				pValues->SetInt("skin", 0);
		}
		else
			pValues->SetInt("skin", 0);

		pPlayerPreview->ParseModelInfo(pValues);

		pValues->deleteThis();
	}
	else if (pPlayerPreview)
		pPlayerPreview->SwapModel("");

	for ( int i = 0; i < m_apWeaponIcons.Count(); i++)
	{
		if (m_apWeaponIcons[i].m_pWeaponName)
			m_apWeaponIcons[i].m_pWeaponName->DeletePanel();
	
		if (m_apWeaponIcons[i].m_pSlots)
			m_apWeaponIcons[i].m_pSlots->DeletePanel();

		if (m_apWeaponIcons[i].m_pImage)
			m_apWeaponIcons[i].m_pImage->DeletePanel();

		if (m_apWeaponIcons[i].m_pDelete)
			m_apWeaponIcons[i].m_pDelete->DeletePanel();
	}

	m_apWeaponIcons.RemoveAll();

	const char szWeaponPreviewTemplate[] =
		"	\"model\"\n"
		"	{\n"
		"		\"spotlight\"	\"1\"\n"
		"		\"modelname\"	\"models/weapons/beretta.mdl\"\n"
		"		\"origin_x\"	\"30\"\n"
		"		\"origin_y\"	\"3\"\n"
		"		\"origin_z\"	\"-3\"\n"
		"		\"angles_y\"	\"200\"\n"
		"	}";

	Panel *pWeaponIconArea = FindChildByName("WeaponIconArea");
	if ((ShouldShowCharacterAndWeapons() || ShouldShowEverything()) && pWeaponIconArea)
	{
		int iWeaponAreaX, iWeaponAreaY, iWeaponAreaW, iWeaponAreaH;
		pWeaponIconArea->GetPos(iWeaponAreaX, iWeaponAreaY);
		pWeaponIconArea->GetSize(iWeaponAreaW, iWeaponAreaH);

		int iMargin = 5;

		int iBoxSize = (iWeaponAreaW-5)/2;

		int iWeapon = 0;

		for (int i = 0; i < MAX_LOADOUT; i++)
		{
			if (!pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i))
				continue;

			CSDKWeaponInfo* pWeaponInfo = CSDKWeaponInfo::GetWeaponInfo((SDKWeaponID)i);
			if (!pWeaponInfo)
				continue;

			for (int j = 0; j < pPlayer->GetLoadoutWeaponCount((SDKWeaponID)i); j++)
			{
				float flMoveRight = 0;
				if (iWeapon%2 == 1)
					flMoveRight = iBoxSize + iMargin;

				CWeaponIcon* pIcon = &m_apWeaponIcons[m_apWeaponIcons.AddToTail()];

				pIcon->m_pWeaponName = new CFolderLabel(this, NULL);
				pIcon->m_pWeaponName->SetText(VarArgs("#DA_Weapon_Obituary_%s", pWeaponInfo->szClassName+7)); // Use the obit version because it's shorter
				pIcon->m_pWeaponName->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + 10 + (iWeapon/2) * (iBoxSize+iMargin));
				pIcon->m_pWeaponName->SetSize(iBoxSize, 15);
				pIcon->m_pWeaponName->SetContentAlignment(Label::a_center);
				pIcon->m_pWeaponName->SetZPos(-5);
				pIcon->m_pWeaponName->SetFont(vgui::scheme()->GetIScheme(GetScheme())->GetFont("FolderLarge"));
				pIcon->m_pWeaponName->SetScheme("FolderScheme");

				std::wostringstream sSlotsLabel;

				if (pWeaponInfo->iWeight)
				{
					const wchar_t *pchFmt = g_pVGuiLocalize->Find( "#DA_BuyMenu_Weapon_Slots" );
					if ( pchFmt && pchFmt[0] )
						sSlotsLabel << pchFmt;
					else
						sSlotsLabel << "Slots: ";

					sSlotsLabel << pWeaponInfo->iWeight;

					pIcon->m_pSlots = new CFolderLabel(this, NULL);
					pIcon->m_pSlots->SetText(sSlotsLabel.str().c_str());
					pIcon->m_pSlots->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + iBoxSize - 10 + (iWeapon/2) * (iBoxSize+iMargin));
					pIcon->m_pSlots->SetSize(iBoxSize, 15);
					pIcon->m_pSlots->SetContentAlignment(Label::a_center);
					pIcon->m_pSlots->SetZPos(-5);
					pIcon->m_pSlots->SetFont(vgui::scheme()->GetIScheme(GetScheme())->GetFont("FolderSmall"));
					pIcon->m_pSlots->SetScheme("FolderScheme");
				}

				KeyValues* pValues = new KeyValues("preview");
				pValues->LoadFromBuffer("model", szWeaponPreviewTemplate);
				pValues->SetString("modelname", pWeaponInfo->szWorldModel);

				if (pWeaponInfo->m_eWeaponType == WT_PISTOL)
				{
					pValues->SetInt("origin_x", 20);
				}
				else if (pWeaponInfo->m_eWeaponType == WT_RIFLE)
				{
					pValues->SetInt("origin_x", 50);
					pValues->SetInt("angles_y", 210);
				}
				else if (pWeaponInfo->m_eWeaponType == WT_SHOTGUN)
				{
					pValues->SetInt("origin_x", 50);
					pValues->SetInt("origin_y", 10);
					pValues->SetInt("angles_y", 150);
				}
				else if (pWeaponInfo->m_eWeaponType == WT_SMG)
				{
				}
				else if (pWeaponInfo->m_eWeaponType == WT_GRENADE)
				{
					pValues->SetInt("origin_x", 20);
				}

				pIcon->m_pImage = new CModelPanel(this, NULL);
				pIcon->m_pImage->SetPos(iWeaponAreaX + flMoveRight, iWeaponAreaY + (iWeapon/2) * (iBoxSize+iMargin));
				pIcon->m_pImage->SetSize(iBoxSize, iBoxSize);
				pIcon->m_pImage->SetZPos(-15);
				pIcon->m_pImage->SetScheme("FolderScheme");
				pIcon->m_pImage->ParseModelInfo(pValues);

				pValues->deleteThis();

				pIcon->m_pDelete = new CImageButton(this, VarArgs("delete_%d", iWeapon));
				pIcon->m_pDelete->SetDimensions(iWeaponAreaX + iBoxSize - 8 + flMoveRight, iWeaponAreaY + 30 + (iWeapon/2) * (iBoxSize+iMargin), 12, 12);
				pIcon->m_pDelete->SetZPos(15);
				pIcon->m_pDelete->SetImage("folder_delete");
				pIcon->m_pDelete->SetPaintBorderEnabled(false);
				pIcon->m_pDelete->SetPaintBackgroundEnabled(true);
				pIcon->m_pDelete->SetCommand(VarArgs("buy remove %d", i));

				iWeapon++;
			}
		}
	}

	CFolderLabel* pWeaponTotalWeightNumber = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponTotalWeightNumber"));
	CFolderLabel* pWeaponTotalWeight = dynamic_cast<CFolderLabel*>(FindChildByName("WeaponTotalWeight"));
	if ((ShouldShowCharacterAndWeapons() || ShouldShowEverything()) && pPlayer->GetLoadoutWeight())
	{
		if (pWeaponTotalWeightNumber)
		{
			wchar_t szText[20];
			_snwprintf( szText, ARRAYSIZE(szText) - 1, L"%d/%d", pPlayer->GetLoadoutWeight(), MAX_LOADOUT_WEIGHT );
			pWeaponTotalWeightNumber->SetText(szText);
			pWeaponTotalWeightNumber->SetVisible(true);
		}

		if (pWeaponTotalWeight)
			pWeaponTotalWeight->SetVisible(true);
	}
	else
	{
		if (pWeaponTotalWeightNumber)
			pWeaponTotalWeightNumber->SetVisible(false);

		if (pWeaponTotalWeight)
			pWeaponTotalWeight->SetVisible(false);
	}

	if (ShouldShowEverything())
	{
		CFolderLabel *pSkillInfo = dynamic_cast<CFolderLabel *>(FindChildByName("SkillInfo"));
		CPanelTexture *pSkillIcon = dynamic_cast<CPanelTexture *>(FindChildByName("SkillIcon"));

		if (pSkillInfo && pSkillIcon)
		{
			if (pPlayer->m_Shared.m_iStyleSkill)
			{
				pSkillInfo->SetText((std::string("#DA_SkillInfo_") + SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get())).c_str());
				pSkillIcon->SetImage(SkillIDToAlias((SkillID)pPlayer->m_Shared.m_iStyleSkill.Get()));
			}
			else
			{
				pSkillInfo->SetText("");
				pSkillIcon->SetImage("");
			}
		}
	}

	m_pSuicideOption->SetVisible(pPlayer->IsAlive() && !ShouldShowTeams());

	Button *pProceedButton = dynamic_cast<Button *>(FindChildByName("ProceedButton"));
	if (pProceedButton)
		pProceedButton->SetVisible(m_pPage && FStrEq(m_pPage->GetName(), PANEL_BUY));

	Button *pApproveButton = dynamic_cast<Button *>(FindChildByName("ApproveButton"));
	if (pApproveButton)
		pApproveButton->SetVisible(IsLoadoutComplete());

	Button *pAgentsTab = dynamic_cast<Button *>(FindChildByName("AgentsTab"));
	if (pAgentsTab)
		pAgentsTab->SetVisible(pPlayer->HasCharacterBeenChosen());

	Button *pWeaponsTab = dynamic_cast<Button *>(FindChildByName("WeaponsTab"));
	if (pWeaponsTab)
		pWeaponsTab->SetVisible(pPlayer->HasCharacterBeenChosen());

	Button *pSkillsTab = dynamic_cast<Button *>(FindChildByName("SkillsTab"));
	if (pSkillsTab)
		pSkillsTab->SetVisible(pPlayer->HasSkillsTabBeenSeen());

	Button *pChangeTeams = dynamic_cast<Button *>(FindChildByName("ChangeTeamsButton"));
	if (pChangeTeams)
		pChangeTeams->SetVisible(SDKGameRules()->IsTeamplay());
}
示例#20
0
文件: hud.cpp 项目: Yosam02/game
//-----------------------------------------------------------------------------
// Purpose: This is called every time the DLL is loaded
//-----------------------------------------------------------------------------
void CHud::Init(void)
{
    HOOK_HUD_MESSAGE(gHUD, ResetHUD);

#ifdef CSTRIKE_DLL
    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);
}
示例#21
0
void LoadObjectInfos( IBaseFileSystem *pFileSystem )
{
	const char *pFilename = "scripts/objects.txt";

	// Make sure this stuff hasn't already been loaded.
	Assert( !AreObjectInfosLoaded() );

	KeyValues *pValues = new KeyValues( "Object descriptions" );
	if ( !pValues->LoadFromFile( pFileSystem, pFilename, "GAME" ) )
	{
		Error( "Can't open %s for object info.", pFilename );
		pValues->deleteThis();
		return;
	}

	// Now read each class's information in.
	for ( int iObj=0; iObj < ARRAYSIZE( g_ObjectInfos ); iObj++ )
	{
		CObjectInfo *pInfo = &g_ObjectInfos[iObj];
		KeyValues *pSub = pValues->FindKey( pInfo->m_pObjectName );
		if ( !pSub )
		{
			Error( "Missing section '%s' from %s.", pInfo->m_pObjectName, pFilename );
			pValues->deleteThis();
			return;
		}

		// Read all the info in.
		if ( (pInfo->m_flBuildTime = pSub->GetFloat( "BuildTime", -999 )) == -999 ||
			(pInfo->m_nMaxObjects = pSub->GetInt( "MaxObjects", -999 )) == -999 ||
			(pInfo->m_Cost = pSub->GetInt( "Cost", -999 )) == -999 ||
			(pInfo->m_CostMultiplierPerInstance = pSub->GetFloat( "CostMultiplier", -999 )) == -999 ||
			(pInfo->m_UpgradeCost = pSub->GetInt( "UpgradeCost", -999 )) == -999 ||
			(pInfo->m_MaxUpgradeLevel = pSub->GetInt( "MaxUpgradeLevel", -999 )) == -999 ||
			(pInfo->m_SelectionSlot = pSub->GetInt( "SelectionSlot", -999 )) == -999 ||
			(pInfo->m_SelectionPosition = pSub->GetInt( "SelectionPosition", -999 )) == -999 )
		{
			Error( "Missing data for object '%s' in %s.", pInfo->m_pObjectName, pFilename );
			pValues->deleteThis();
			return;
		}

		pInfo->m_pClassName = ReadAndAllocStringValue( pSub, "ClassName", pFilename );
		pInfo->m_pStatusName = ReadAndAllocStringValue( pSub, "StatusName", pFilename );
		pInfo->m_pBuilderWeaponName = ReadAndAllocStringValue( pSub, "BuilderWeaponName", pFilename );
		pInfo->m_pBuilderPlacementString = ReadAndAllocStringValue( pSub, "BuilderPlacementString", pFilename );
		pInfo->m_bSolidToPlayerMovement = pSub->GetInt( "SolidToPlayerMovement", 0 ) ? true : false;
		pInfo->m_pIconActive = ReadAndAllocStringValue( pSub, "IconActive", pFilename );
		pInfo->m_pIconInactive = ReadAndAllocStringValue( pSub, "IconInactive", pFilename );
		pInfo->m_pViewModel = ReadAndAllocStringValue( pSub, "Viewmodel", pFilename );
		pInfo->m_pPlayerModel = ReadAndAllocStringValue( pSub, "Playermodel", pFilename );
		pInfo->m_iDisplayPriority = pSub->GetInt( "DisplayPriority", 0 );
		pInfo->m_pHudStatusIcon = ReadAndAllocStringValue( pSub, "HudStatusIcon", pFilename );
		pInfo->m_bVisibleInWeaponSelection = ( pSub->GetInt( "VisibleInWeaponSelection", 1 ) > 0 );
		pInfo->m_pExplodeSound = ReadAndAllocStringValue( pSub, "ExplodeSound", pFilename );
		pInfo->m_pExplosionParticleEffect = ReadAndAllocStringValue( pSub, "ExplodeEffect", pFilename );
		pInfo->m_bAutoSwitchTo = ( pSub->GetInt( "autoswitchto", 0 ) > 0 );

		pInfo->m_iMetalToDropInGibs = pSub->GetInt( "MetalToDropInGibs", 0 );
	}

	pValues->deleteThis();
}
//-----------------------------------------------------------------------------
// 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);
}
示例#23
0
void CWeapons::LoadWeapons(const char *szWeaponListName, WeaponsData_t *pDefault)
{
	if ((szWeaponListName != NULL) && (szWeaponListName[0] != 0))
	{
		KeyValues *kv = new KeyValues("Weapons");
		char szFilename[1024];

		CBotGlobals::BuildFileName(szFilename, "weapons", BOT_CONFIG_FOLDER, "ini", false);

		if (kv)
		{
			if (kv->LoadFromFile(filesystem, szFilename, NULL))
			{
				kv = kv->FindKey(szWeaponListName);

				if (kv)
				{
					kv = kv->GetFirstSubKey();

					if (0)
						kv = kv->GetFirstTrueSubKey();

					while (kv != NULL)
					{
						WeaponsData_t newWeapon;

						memset(&newWeapon, 0, sizeof(WeaponsData_t));

						const char *szKeyName = kv->GetName();

						char lowered[64];

						strncpy(lowered, szKeyName, 63);
						lowered[63] = 0;

						__strlow(lowered);

						newWeapon.szWeaponName = CStrings::GetString(lowered);
						newWeapon.iId = kv->GetInt("id");
						newWeapon.iSlot = kv->GetInt("slot");
						newWeapon.minPrimDist = kv->GetFloat("minPrimDist");
						newWeapon.maxPrimDist = kv->GetFloat("maxPrimDist");
						newWeapon.m_fProjSpeed = kv->GetFloat("m_fProjSpeed");
						newWeapon.m_iAmmoIndex = kv->GetInt("m_iAmmoIndex");
						newWeapon.m_iPreference = kv->GetInt("m_iPreference");

						KeyValues *flags = kv->FindKey("flags");

						if (flags)
						{
							int i = 0;

							while (szWeaponFlags[i][0] != '\0')
							{
								if (flags->FindKey(szWeaponFlags[i]) && (flags->GetInt(szWeaponFlags[i]) == 1))
									newWeapon.m_iFlags |= (1 << i);

								i++;
							}
						}

						AddWeapon(new CWeapon(&newWeapon));

						kv = kv->GetNextTrueSubKey();
					}
				}

			}


			kv->deleteThis();

		}
	}

	if (pDefault != NULL)
	{
		// No weapons from INI file then add default
		if (m_theWeapons.size() == 0)
		{
			while (pDefault->szWeaponName[0] != '\0')
			{
				AddWeapon(new CWeapon(pDefault));
				pDefault++;
			}
		}
	}
}
示例#24
0
bool CMapAdd::RunLabel( const char *mapaddMap, const char *szLabel)
{

	if(AllocPooledString(mapaddMap) == AllocPooledString("") || !mapaddMap || !szLabel || AllocPooledString(szLabel) == AllocPooledString(""))
		return false; //Failed to load!
	//FileHandle_t fh = filesystem->Open(szMapadd,"r","MOD");
	// Open the mapadd data file, and abort if we can't
	KeyValues *pMapAdd = new KeyValues( "MapAdd" );
	if(pMapAdd->LoadFromFile( filesystem, mapaddMap, "MOD" ))
	{
		KeyValues *pMapAdd2 = pMapAdd->FindKey(szLabel);
		if(pMapAdd2)
		{
			KeyValues *pMapAddEnt = pMapAdd2->GetFirstTrueSubKey();
			while (pMapAddEnt)
			{
				if(!HandlePlayerEntity(pMapAddEnt, false) && !HandleRemoveEnitity( pMapAddEnt ) && !HandleSMODEntity(pMapAddEnt) && !HandleSpecialEnitity(pMapAddEnt))
				{
					Vector SpawnVector = Vector(0,0,0);
					QAngle SpawnAngle = QAngle(0,0,0);
			
					SpawnVector.x = pMapAddEnt->GetFloat("x", SpawnVector.x);
					SpawnVector.y = pMapAddEnt->GetFloat("y", SpawnVector.y);
					SpawnVector.z = pMapAddEnt->GetFloat("z", SpawnVector.z);

					SpawnAngle[PITCH] = pMapAddEnt->GetFloat("pitch", SpawnAngle[PITCH]);
					SpawnAngle[YAW] = pMapAddEnt->GetFloat("yaw", SpawnAngle[YAW]);
					SpawnAngle[ROLL] = pMapAddEnt->GetFloat("roll", SpawnAngle[ROLL]);

					CBaseEntity *createEnt = CBaseEntity::CreateNoSpawn(pMapAddEnt->GetName(),SpawnVector,SpawnAngle);
					KeyValues *pEntKeyValues = pMapAddEnt->FindKey("KeyValues");
					if(pEntKeyValues && createEnt)
					{
						Msg("keyvalue for %s Found!\n",pMapAddEnt->GetName());
						KeyValues *pEntKeyValuesAdd = pEntKeyValues->GetFirstValue();
						while(pEntKeyValuesAdd && createEnt)
						{
							if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("model"))
							{
								PrecacheModel(pEntKeyValuesAdd->GetString(""));
								createEnt->SetModel(pEntKeyValuesAdd->GetString(""));
							}
					/*		else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("name"))
							{
								createEnt->SetName(AllocPooledString(pEntKeyValuesAdd->GetString("")));
							}
							else if(AllocPooledString(pEntKeyValuesAdd->GetName()) == AllocPooledString("spawnflags"))
							{
								createEnt->AddSpawnFlags(pEntKeyValuesAdd->GetInt());
							}*/
							else
							{
								createEnt->KeyValue(pEntKeyValuesAdd->GetName(),pEntKeyValuesAdd->GetString(""));
							}
							pEntKeyValuesAdd = pEntKeyValuesAdd->GetNextValue();
						}
					}
					//createEnt->Activate();//Is this a good idea? Not sure!
					//createEnt->Spawn();
					DispatchSpawn( createEnt ); //I derped
				}
				pMapAddEnt = pMapAddEnt->GetNextTrueSubKey(); //Got to keep this!
			}
		}
	}
	
	pMapAdd->deleteThis();
	return true;
}
void CHudAnimationInfo::PaintMappingInfo( int& x, int& y, Panel *element, PanelAnimationMap *map )
{
	if ( !map )
		return;

	// Draw label
	surface()->DrawSetTextFont( m_LabelFont );
	surface()->DrawSetTextColor( m_LabelColor );
	surface()->DrawSetTextPos( x, y );

	const char *className = "";
	if ( map->pfnClassName )
	{
		className = (*map->pfnClassName)();
	}

	const char *p = className;
	while ( *p )
	{
		surface()->DrawUnicodeChar( *p );
		p++;
	}

	y += surface()->GetFontTall( m_LabelFont ) + 1;

	x += 10;


	int c = map->entries.Count();
	for ( int i = 0; i < c; i++ )
	{
		PanelAnimationMapEntry *e = &map->entries[ i ];

		char sz[ 512 ];
		char value[ 256 ];

		Color col( 0, 0, 0, 0 );
		Color  *pColor = NULL;
		KeyValues *kv = new KeyValues( e->name() );
		if ( element->RequestInfo( kv ) )
		{
			KeyValues *dat = kv->FindKey(e->name());
			if ( dat && dat->GetDataType() == KeyValues::TYPE_COLOR )
			{
				col = dat->GetColor();
				Q_snprintf( value, sizeof( value ), "%i, %i, %i, %i",
					col[0], col[1], col[2], col[3] );
				pColor = &col;
			}
			else
			{
				Q_snprintf( value, sizeof( value ), "%s",
					dat->GetString() );
			}
		}
		else
		{
			Q_strncpy( value, "???", sizeof( value ) );
		}

		Q_snprintf( sz, sizeof( sz ), "%-30s %-20s (%s)",
			e->name(), e->type(), value );

		kv->deleteThis();

		PaintString( x, y, sz, pColor );
	}

	x -= 10;

	if ( map->baseMap )
	{
		PaintMappingInfo( x, y, element, map->baseMap );
	}
}
示例#26
0
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 );
			}
		}
	}
}
示例#27
0
文件: hud.cpp 项目: Yosam02/game
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();
}
示例#28
0
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
    }
}
示例#29
0
//---------------------------------------------------------------------------------
// Purpose: called when a client types in a command (only a subset of commands however, not CON_COMMAND's)
//---------------------------------------------------------------------------------
PLUGIN_RESULT CEmptyServerPlugin::ClientCommand( edict_t *pEntity )
{
	const char *pcmd = engine->Cmd_Argv(0);

	if ( !pEntity || pEntity->IsFree() ) 
	{
		return PLUGIN_CONTINUE;
	}

	if ( FStrEq( pcmd, "menu" ) )
	{
		KeyValues *kv = new KeyValues( "menu" );
		kv->SetString( "title", "You've got options, hit ESC" );
		kv->SetInt( "level", 1 );
		kv->SetColor( "color", Color( 255, 0, 0, 255 ));
		kv->SetInt( "time", 20 );
		kv->SetString( "msg", "Pick an option\nOr don't." );
		
		for( int i = 1; i < 9; i++ )
		{
			char num[10], msg[10], cmd[10];
			Q_snprintf( num, sizeof(num), "%i", i );
			Q_snprintf( msg, sizeof(msg), "Option %i", i );
			Q_snprintf( cmd, sizeof(cmd), "option%i", i );

			KeyValues *item1 = kv->FindKey( num, true );
			item1->SetString( "msg", msg );
			item1->SetString( "command", cmd );
		}

		helpers->CreateMessage( pEntity, DIALOG_MENU, kv, this );
		kv->deleteThis();
		return PLUGIN_STOP; // we handled this function
	}
	else if ( FStrEq( pcmd, "rich" ) )
	{
		KeyValues *kv = new KeyValues( "menu" );
		kv->SetString( "title", "A rich message" );
		kv->SetInt( "level", 1 );
		kv->SetInt( "time", 20 );
		kv->SetString( "msg", "This is a long long long text string.\n\nIt also has line breaks." );
		
		helpers->CreateMessage( pEntity, DIALOG_TEXT, kv, this );
		kv->deleteThis();
		return PLUGIN_STOP; // we handled this function
	}
	else if ( FStrEq( pcmd, "msg" ) )
	{
		KeyValues *kv = new KeyValues( "menu" );
		kv->SetString( "title", "Just a simple hello" );
		kv->SetInt( "level", 1 );
		kv->SetInt( "time", 20 );
		
		helpers->CreateMessage( pEntity, DIALOG_MSG, kv, this );
		kv->deleteThis();
		return PLUGIN_STOP; // we handled this function
	}
	else if ( FStrEq( pcmd, "entry" ) )
	{
		KeyValues *kv = new KeyValues( "entry" );
		kv->SetString( "title", "Stuff" );
		kv->SetString( "msg", "Enter something" );
		kv->SetString( "command", "say" ); // anything they enter into the dialog turns into a say command
		kv->SetInt( "level", 1 );
		kv->SetInt( "time", 20 );
		
		helpers->CreateMessage( pEntity, DIALOG_ENTRY, kv, this );
		kv->deleteThis();
		return PLUGIN_STOP; // we handled this function		
	}


	return PLUGIN_CONTINUE;
}
示例#30
0
//=============================================================================
void InGameChapterSelect::ApplySchemeSettings(vgui::IScheme *pScheme)
{
	BaseClass::ApplySchemeSettings(pScheme);

	SetPaintBackgroundEnabled( true );

	// Determine current game settings
	KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL );
	KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings );

	char const *szGameMode = pGameSettings->GetString( "game/mode", "campaign" );

	if ( !GameModeIsSingleChapter( szGameMode ) )
		pGameSettings->SetInt( "game/chapter", 1 );

	// Get mission and campaign info
	KeyValues *pInfoMission = NULL;
	KeyValues *pInfoChapter = g_pMatchExtSwarm->GetMapInfo( pGameSettings, &pInfoMission );

	// Check if this is a custom mission?
	if ( pInfoMission && !pInfoMission->GetBool( "builtin" ) )
		pInfoChapter = pInfoMission = NULL;	// trigger to use another builtin mission

	if ( !pInfoMission || !pInfoChapter )
	{
		KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions();
		for ( pInfoMission = pAllMissions ? pAllMissions->GetFirstTrueSubKey() : NULL;
			  pInfoMission; pInfoMission = pInfoMission->GetNextTrueSubKey() )
		{
			if ( !pInfoMission->GetBool( "builtin" ) )
				continue;

			pInfoChapter = pInfoMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) );
			if ( pInfoChapter )
				break;
		}
	}

	Assert( pInfoMission && pInfoChapter );

	// set the dropdowns
	DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) );
	DropDownMenu *pChapterDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpChapter" ) );
	if( pMissionDropDown && pChapterDropDown ) //missions change what the available campaigns are, we should listen on that flyout as well
	{
		pMissionDropDown->SetFlyout( CFmtStr( "FlmMission%s", szGameMode ) );

		if ( pInfoMission && pInfoChapter )
		{
			pMissionDropDown->SetCurrentSelection( CFmtStr( "cmd_campaign_%s", pInfoMission->GetString( "name" ) ) );
			Q_strncpy( m_chCampaign, pInfoMission->GetString( "name" ), ARRAYSIZE( m_chCampaign ) );

			// Set this after setting the mission dropdown, as that will default the chapter to the first in the campaign
			pChapterDropDown->SetCurrentSelection( CFmtStr( "#L4D360UI_Chapter_%d", pInfoChapter->GetInt( "chapter" ) ) );
			m_nChapter = pInfoChapter->GetInt( "chapter" );
		}

		FlyoutMenu *flyout = pMissionDropDown->GetCurrentFlyout();
		if( flyout )
		{
			flyout->CloseMenu( NULL );
		}

		flyout = pChapterDropDown->GetCurrentFlyout();
		if( flyout )
		{
			flyout->CloseMenu( NULL );
		}

		if ( m_ActiveControl )
		{
			m_ActiveControl->NavigateFrom( );
		}
		pMissionDropDown->NavigateTo();
		m_ActiveControl = pMissionDropDown;

		// Chapters are directly selectable only in some game modes
		pChapterDropDown->SetEnabled( GameModeIsSingleChapter( szGameMode ) );
	}

	SetPaintBackgroundEnabled( true );
	SetupAsDialogStyle();
}