/*********************************************************** handle event when list is selected ***********************************************************/ bool JournalBox::HandleQuestTreeSelected (const CEGUI::EventArgs& e) { CEGUI::Tree * tree = static_cast<CEGUI::Tree *> ( CEGUI::WindowManager::getSingleton().getWindow("Root/JournalWin/tab/questtab/Tree")); const MyTreeItem * it = static_cast<const MyTreeItem *>(tree->getFirstSelectedItem()); if(it) DisplayDescription (it->Description, false); return true; }
/*********************************************************** 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(); } } } }