Exemplo n.º 1
0
Atlas::Objects::Root RuleTreeAdapter::getSelectedRule()
{
	CEGUI::TreeItem* item = mTreeWidget.getFirstSelectedItem();
	if (item) {
		auto itemData = getRule(item->getText().c_str());
		if (itemData.isValid()) {
			return itemData;
		}
	}
	return Atlas::Objects::Root();
}
Exemplo n.º 2
0
void RuleTreeAdapter::addToTree(const Root& rule, CEGUI::TreeItem* parent, bool addRecursive)
{

	CEGUI::TreeItem* item = ColouredTreeItem::create(rule->getId());
	item->toggleIsOpen();
	if (!parent) {
		mTreeWidget.addItem(item);
	} else {
		parent->addItem(item);
	}

	if (addRecursive) {
		std::list<std::string> children;
		extractChildren(rule, children);

		for (auto& child : children) {
			const auto& childData = getRule(child);
			if (childData.isValid()) {
				addToTree(childData, item, addRecursive);
			}
		}
	}

}
void luaPopulateEntityList(CEGUI::Window* entityListWindow)
{
    CEGUI::Tree* theTree = (CEGUI::Tree*)entityListWindow->getChildRecursive("Editing/EntityList/Tree");
//    theTree->initialise();
    theTree->resetList();

    // Create classes, top-level
    readClasses();

    stringTreeItemMap classTreeItems;

    for (unsigned int i = 0; i < classes.size(); i++)
    {
        std::string name = classes[i];

        CEGUI::TreeItem* item = new CEGUI::TreeItem( name );
        item->setAutoDeleted(true);
        item->setTextColours(CEGUI::colour(0.0, 0.0, 0.0));
        theTree->addItem(item);

        classTreeItems.insert( stringTreeItemMap::value_type(name, item) );
    }

    // Insert entities at second level
    for(LogicSystem::LogicEntityMap::iterator iter = LogicSystem::logicEntities.begin();
        iter != LogicSystem::logicEntities.end();
        iter++)
    {
        int uniqueId = iter->first;
        ScriptValuePtr scriptEntity = iter->second.get()->scriptEntity;
        std::string className = scriptEntity->getPropertyString("_class");

        CEGUI::TreeItem* item = new CEGUI::TreeItem( Utility::toString(uniqueId) );
        item->setAutoDeleted(true);
        item->setTextColours(CEGUI::colour(0.0, 0.0, 0.0));
        classTreeItems[className]->addItem(item);
    }

    // Prune classes with 0 entities
    for (unsigned int i = 0; i < classes.size(); i++)
    {
        CEGUI::TreeItem *item = classTreeItems[classes[i]];
        if (item->getItemCount() == 0)
        {
            theTree->removeItem(item);
            // Note: No need to remove from classTreeItems
        }
    }

    // Create tags

    CEGUI::TreeItem* tagsItem = new CEGUI::TreeItem( "__tags__" );
    tagsItem->setAutoDeleted(true);
    tagsItem->setTextColours(CEGUI::colour(0.0, 0.333, 0.0));
    theTree->addItem(tagsItem);

    stringTreeItemMap tagTreeItems;

    for(LogicSystem::LogicEntityMap::iterator iter = LogicSystem::logicEntities.begin();
        iter != LogicSystem::logicEntities.end();
        iter++)
    {
        int uniqueId = iter->first;
        ScriptValuePtr scriptEntity = iter->second.get()->scriptEntity;
        ScriptValuePtr tags = scriptEntity->getProperty("tags");
        int numTags = tags->getPropertyInt("length");

        // Add item under each of its tags, creating the tag category if necessary
        for (int i = 0; i < numTags; i++)
        {
            std::string currTag = tags->getPropertyString( Utility::toString(i) );

            // Add the tag category if needed
            if (tagTreeItems.find(currTag) == tagTreeItems.end())
            {
                CEGUI::TreeItem* item = new CEGUI::TreeItem( currTag );
                item->setAutoDeleted(true);
                item->setTextColours(CEGUI::colour(0.0, 0.0, 0.0));
                tagsItem->addItem(item);

                tagTreeItems.insert( stringTreeItemMap::value_type(currTag, item) );
            }

            // Add the entity to the tag
            CEGUI::TreeItem* item = new CEGUI::TreeItem( Utility::toString(uniqueId) );
            item->setAutoDeleted(true);
            item->setTextColours(CEGUI::colour(0.0, 0.0, 0.0));
            tagTreeItems[currTag]->addItem(item);
        }
    }
}
Exemplo n.º 4
0
/***********************************************************
call to regenerate the quest book display
***********************************************************/
void JournalBox::RebuildBook(bool reset)
{
	CEGUI::Tree * tree = static_cast<CEGUI::Tree *> (
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Tree"));

	CEGUI::Tree * tree2 = static_cast<CEGUI::Tree *> (
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Tree"));

	if(reset)
	{
		tree->resetList();
		tree2->resetList();
		_mapquestarea.clear();
		_mapquestdonearea.clear();
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Description")->setText("");
		CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Description")->setText("");
		_first_book_init = true;
	}


	// rebuild quests
	{
		// remove extra quests
		std::map<std::string, CEGUI::TreeItem *>::iterator itmap = _mapquestarea.begin();
		while(itmap != _mapquestarea.end())
		{
			bool remove = false;
			std::vector<CEGUI::TreeItem*> items = itmap->second->getItemList();
			for(size_t i=0; i<items.size(); ++i)
			{
				if(_QuestsStarted.find(static_cast<MyTreeItem *> (items[i])->QuestId) == _QuestsStarted.end())
				{	
					itmap->second->removeItem(items[i]);
					if(itmap->second->getItemCount() == 0)
						remove = true;
				}
			}

			if(remove)
			{
				tree->removeItem(itmap->second);
				_mapquestarea.erase(itmap++);
			}
			else
				++itmap;
		}

		// add missing quests
		LbaNet::QuestsMap::const_iterator itstarted = _QuestsStarted.begin();
		LbaNet::QuestsMap::const_iterator endstarted = _QuestsStarted.end();
		for(; itstarted != endstarted; ++itstarted)
		{
			const LbaNet::QuestInfo &qi = itstarted->second;
			if(qi.Visible)
			{
				std::string Tittle = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.TittleTextId);
				std::string Description = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.DescriptionTextId);
				std::string QuestArea = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.QuestAreaTextId);

				if(QuestArea == "")
					QuestArea = "General";

				std::vector<CEGUI::String> listt;
				CreateTextList(Description, listt);



				std::map<std::string, CEGUI::TreeItem *>::iterator itm = _mapquestarea.find(QuestArea);
				if(itm != _mapquestarea.end())
				{
					bool found = false;
					std::vector<CEGUI::TreeItem*> items = itm->second->getItemList();
					for(size_t i=0; i<items.size(); ++i)
					{
						if(static_cast<MyTreeItem *> (items[i])->QuestId == qi.Id)
						{	
							found = true;
							break;
						}
					}

					if(!found)
					{
						MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
						itm->second->addItem(titm);

						if(_first_book_init)
						{
							if(_selected_tree_quests == Tittle)
							{
								titm->setSelected(true);
								DisplayDescription (titm->Description, false);
							}
						}
					}
				}
				else
				{
					MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
					std::vector<CEGUI::String> empty;
					CEGUI::TreeItem * root = new MyTreeItem((const unsigned char *)QuestArea.c_str(), empty);
					tree->addItem(root);
					root->addItem(titm);
					_mapquestarea[QuestArea] = root;

					if(_first_book_init)
					{
						if(_selected_tree_quests == Tittle)
						{
							titm->setSelected(true);
							DisplayDescription (titm->Description, false);
						}
					}
				}
			}
		}
	}


	// rebuild quests done
	{
		// remove extra quests
		std::map<std::string, CEGUI::TreeItem *>::iterator itmap = _mapquestdonearea.begin();
		while(itmap != _mapquestdonearea.end())
		{
			bool remove = false;
			std::vector<CEGUI::TreeItem*> items = itmap->second->getItemList();
			for(size_t i=0; i<items.size(); ++i)
			{
				if(_QuestsFinished.find(static_cast<MyTreeItem *> (items[i])->QuestId) == _QuestsFinished.end())
				{	
					itmap->second->removeItem(items[i]);
					if(itmap->second->getItemCount() == 0)
						remove = true;
				}
			}

			if(remove)
			{
				tree->removeItem(itmap->second);
				_mapquestdonearea.erase(itmap++);
			}
			else
				++itmap;
		}

		// add missing quests
		LbaNet::QuestsMap::const_iterator itfinished = _QuestsFinished.begin();
		LbaNet::QuestsMap::const_iterator endfinished = _QuestsFinished.end();
		for(; itfinished != endfinished; ++itfinished)
		{
			const LbaNet::QuestInfo &qi = itfinished->second;
			if(qi.Visible)
			{
				std::string Tittle = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.TittleTextId);
				std::string Description = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.DescriptionTextId);
				std::string QuestArea = Localizer::getInstance()->GetText(Localizer::Quest, (long)qi.QuestAreaTextId);

				if(QuestArea == "")
					QuestArea = Localizer::getInstance()->GetText(Localizer::GUI, 84);

				std::vector<CEGUI::String> listt;
				CreateTextList(Description, listt);



				std::map<std::string, CEGUI::TreeItem *>::iterator itm = _mapquestdonearea.find(QuestArea);
				if(itm != _mapquestdonearea.end())
				{
					bool found = false;
					std::vector<CEGUI::TreeItem*> items = itm->second->getItemList();
					for(size_t i=0; i<items.size(); ++i)
					{
						if(static_cast<MyTreeItem *> (items[i])->QuestId == qi.Id)
						{	
							found = true;
							break;
						}
					}

					if(!found)
					{
						MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
						itm->second->addItem(titm);

						if(_first_book_init)
						{
							if(_selected_tree_done_quests == Tittle)
							{
								titm->setSelected(true);
								DisplayDescription (titm->Description, true);
							}
						}
					}
				}
				else
				{
					MyTreeItem * titm = new MyTreeItem((const unsigned char *)Tittle.c_str(), listt, (long)qi.Id);
					std::vector<CEGUI::String> empty;
					CEGUI::TreeItem * root = new MyTreeItem((const unsigned char *)QuestArea.c_str(), empty);
					tree2->addItem(root);
					root->addItem(titm);
					_mapquestdonearea[QuestArea] = root;

					if(_first_book_init)
					{
						if(_selected_tree_done_quests == Tittle)
						{
							titm->setSelected(true);
							DisplayDescription (titm->Description, true);
						}
					}
				}
			}
		}
	}


	if(!_first_book_init)
	{
		if(tree->getFirstSelectedItem() == NULL)
			CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Description")->setText("");
		
		if(tree2->getFirstSelectedItem() == NULL)
			CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questdonetab/Description")->setText("");
	}

	if(_first_book_init)
	{
		_first_book_init = false;

		{
			std::map<std::string, CEGUI::TreeItem *>::iterator itm =	_mapquestarea.begin();
			std::map<std::string, CEGUI::TreeItem *>::iterator endm =	_mapquestarea.end();
			for(; itm != endm; ++itm)
			{
				if(std::find(_open_tree_quests.begin(), _open_tree_quests.end(), itm->first) != _open_tree_quests.end())
					itm->second->toggleIsOpen();
			}

		}

		{
			std::map<std::string, CEGUI::TreeItem *>::iterator itm =	_mapquestdonearea.begin();
			std::map<std::string, CEGUI::TreeItem *>::iterator endm =	_mapquestdonearea.end();
			for(; itm != endm; ++itm)
			{
				if(std::find(_open_tree_done_quests.begin(), _open_tree_done_quests.end(), itm->first) != _open_tree_done_quests.end())
					itm->second->toggleIsOpen();
			}
		}
	}

}