コード例 #1
0
// addWeaponToInventory
// add to component
void CWeaponComponent::addWeaponToInventory( const char* weaponName )
{
	SWeapon* weapon = getWeapon(weaponName);

	if ( weapon == NULL )
	{
		CGameConfig::SWeaponInfo* wpInfo = CGameConfig::getInstance()->getWeaponByName(weaponName);
		if ( wpInfo )
		{
			CGameObject *wpObj = new CGameObject(NULL);
			
			// load model
			if ( wpInfo->model.empty() == false )
			{
				CColladaMeshComponent *collada = new CColladaMeshComponent(wpObj);
				collada->loadScene(wpInfo->model.c_str());
				wpObj->addComponent(collada);
				wpObj->initComponent();			
			}
			
			wpObj->setVisible(false);
			wpObj->setParent(m_gameObject);

			m_weapons.push_back( SWeapon() );
			SWeapon& w = m_weapons.back();

			w.m_obj = wpObj;
			w.m_num = 1;
			w.m_info = wpInfo;

			// find type of weapon
			for (int i = (int)Unknown; i < (int)NumWPType; i++)
			{
				if ( wpInfo->type == k_weaponTypeString[i] )
				{
					w.m_type = (EWeaponType)i;
					break;
				}
			}

			switch (w.m_type)
			{
			case Gun:
				{
					CGunComponent *gun = new CGunComponent(wpObj, wpInfo);
					wpObj->addComponent(gun);
				}
				break;
			}

			wpObj->initComponent();
		}
	}
	else
	{
		weapon->m_num++;
	}
}
コード例 #2
0
ファイル: editor.cpp プロジェクト: UFNHGGI/CBGE
void Editor::slot_ObjectList_MenuRequest( const QPoint& p )
{
	if(ui.widgetListObj->itemAt(p) == nullptr)
		return;

	static QMenu			mainMenu;
	static bool				firstExex = true;
	static QAction*			actionDelObj = nullptr;

	if(firstExex)
	{
		firstExex = false;
		actionDelObj = mainMenu.addAction("Delete");

		static QMenu*			menuAddComp = mainMenu.addMenu("Add Component");
		static QVector<QMenu*>  listMenuCompPack;
		
		auto ci = CGame::GetComponentClassHead();
		while(ci)
		{
			for(auto iter = listMenuCompPack.begin(); iter != listMenuCompPack.end(); iter++)
			{
				if(ci->packName() == (*iter)->title())
				{
					if(ci->showInEd())
						(*iter)->addAction(ci->className());
					goto SEC1;
				}
			}

			if(ci->showInEd())
			{
				QMenu* newMenu = menuAddComp->addMenu(ci->packName());
				newMenu->addAction(ci->className());
				listMenuCompPack.push_back(newMenu);
			}
SEC1:
			ci = ci->next();
		}
	}


	QAction* actionRet = mainMenu.exec(ui.widgetListObj->mapToGlobal(p));
	if(actionRet)
	{
		if(actionRet == actionDelObj)
		{
			CGameObject* obj = CGame::GetObjByIndex(ui.widgetListObj->currentRow());
			obj->destroy();
			delete ui.widgetListObj->takeItem(ui.widgetListObj->currentRow());
			Editor::SelectObj(nullptr);
		}
		else
		{
			CGameObject* obj = CGame::GetObjByIndex(ui.widgetListObj->currentRow());
			obj->addComponent(actionRet->text().toAscii().data());
			Editor::SelectObj(obj);
		}

		CGame::EDTick();
	}
}