当前位置: 首页>>代码示例>>C++>>正文


C++ XMLParser::getXMLAttributeAsColor方法代码示例

本文整理汇总了C++中XMLParser::getXMLAttributeAsColor方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLParser::getXMLAttributeAsColor方法的具体用法?C++ XMLParser::getXMLAttributeAsColor怎么用?C++ XMLParser::getXMLAttributeAsColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLParser的用法示例。


在下文中一共展示了XMLParser::getXMLAttributeAsColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

	BuildingBlueprint::BuildingBlueprint( XMLParser& parser, const XMLNode* buildingBlueprintNode )
		:	m_supplyProvided( 0 )
	{
		parser.validateXMLChildElements( buildingBlueprintNode, "Cost,Health,Vision,UnitsProduced,Visual,Construction", "SupplyProvided" );
		parser.validateXMLAttributes( buildingBlueprintNode, "name", "" );

		m_name = parser.getXMLAttributeAsString( buildingBlueprintNode, "name", "" );

		const XMLNode* visual = buildingBlueprintNode->FirstChildElement( "Visual" );
		parser.validateXMLAttributes( visual, "color,width,height,selectionTexture", "texture" );

		Color4f color = parser.getXMLAttributeAsColor( visual, "color", color::WHITE );
		m_width = parser.getXMLAttributeAsFloat( visual, "width", 0.0f );
		m_height = parser.getXMLAttributeAsFloat( visual, "height", 0.0f );
		std::string textureName = parser.getXMLAttributeAsString( visual, "texture", "" );
		std::string selectionTextureName = parser.getXMLAttributeAsString( visual, "selectionTexture", "" );
		
		Texture* texture = Renderer::getTexture( textureName );
		Texture* selectionTexture = Renderer::getTexture( selectionTextureName );


		Material* mat = Renderer::createMaterial( m_name + "_mat", "RTSEntityShader" );
		mat->addUniform( "uUseDiffuseMap", 0 );
		mat->addUniform( "uColorTint", color::WHITE );
		mat->addUniform( "uTeamColor", color::WHITE );
		if( texture )
		{
			mat->addTexture( "uDiffuseMap", texture );
			mat->updateUniform( "uUseDiffuseMap", 1 );
		}
		m_mesh = MeshFactory::generateAAPlaneXY( m_width, m_height, m_name + "_mat", color ); 

		Material* selectMat = Renderer::createMaterial( m_name + "_selection_mat", "RTSEntityShader" );
		selectMat->addUniform( "uUseDiffuseMap", 0 );
		selectMat->addUniform( "uColorTint", color::WHITE );
		selectMat->addUniform( "uTeamColor", color::WHITE );
		if( texture )
		{
			selectMat->addTexture( "uDiffuseMap", selectionTexture );
			selectMat->updateUniform( "uUseDiffuseMap", 1 );
		}
		m_selectionMesh = MeshFactory::generateAAPlaneXY( m_width, m_height, m_name + "_selection_mat", color );

		Material* healthMat = Renderer::createMaterial( m_name + "_health_mat", "RTSEntityShader" );
		healthMat->addUniform( "uUseDiffuseMap", 0 );
		healthMat->addUniform( "uColorTint", color::WHITE );
		healthMat->addUniform( "uTeamColor", color::WHITE );
		m_healthBar = MeshFactory::generateAAPlaneXY( m_width, 0.1f, m_name + "_health_mat", color::WHITE );

		const XMLNode* cost = buildingBlueprintNode->FirstChildElement( "Cost" );
		parser.validateXMLAttributes( cost, "time,fishFingers", "custard,timeEnergy" );

		m_cost.fishFingers	= parser.getXMLAttributeAsInt( cost, "fishFingers", 0 );
		m_cost.custard		= parser.getXMLAttributeAsInt( cost, "custard", 0 );
		m_cost.timeEnergy	= parser.getXMLAttributeAsInt( cost, "timeEnergy", 0 );
		m_cost.time			= parser.getXMLAttributeAsInt( cost, "time", 0 );

		const XMLNode* construction = buildingBlueprintNode->FirstChildElement( "Construction" );
		parser.validateXMLAttributes( construction, "canBeBuiltOn", "mustBeBuiltAdjTo" );

		m_constructionRules.canBeBuiltOn = parser.getXMLAttributeAsListOfStrings( construction, "canBeBuiltOn" );
		m_constructionRules.mustBeBuiltAdjTo = parser.getXMLAttributeAsListOfStrings( construction, "mustBeBuiltAdjTo" );

		const XMLNode* health = buildingBlueprintNode->FirstChildElement( "Health" );
		parser.validateXMLAttributes( health, "max", "" );

		m_maxHealth		= parser.getXMLAttributeAsFloat( health, "max", 0.0f );

		const XMLNode* visionRange = buildingBlueprintNode->FirstChildElement( "Vision" );
		parser.validateXMLAttributes( visionRange, "range", "" );
		m_visionRange = parser.getXMLAttributeAsFloat( visionRange, "range", 0.0f );

		const XMLNode* unitsProduced = buildingBlueprintNode->FirstChildElement( "UnitsProduced" );
		parser.validateXMLChildElements( unitsProduced, "Unit", "" );

		for( const XMLNode* unit = unitsProduced->FirstChildElement( "Unit" ); unit != nullptr; unit = unit->NextSiblingElement( "Unit" ) )
		{
			parser.validateXMLAttributes( unit, "name,hotkey", "" );
			std::string name = parser.getXMLAttributeAsString( unit, "name", "" );
			std::string hotkey = parser.getXMLAttributeAsString( unit, "hotkey", "" );
			if( hotkey.size() > 0 )
				m_unitsProduced[ hotkey[0] ] = name;			
		}

		const XMLNode* supplyProvided = buildingBlueprintNode->FirstChildElement( "SupplyProvided" );
		if( supplyProvided )
		{
			parser.validateXMLAttributes( supplyProvided, "amount", "" );
			m_supplyProvided = parser.getXMLAttributeAsInt( supplyProvided, "amount", 0 );
		}	

		registerBP( m_name );
	}
开发者ID:hulcyp,项目名称:PortfolioProjects,代码行数:93,代码来源:BuildingBlueprint.cpp


注:本文中的XMLParser::getXMLAttributeAsColor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。