void prepareentityclasses() { entityClasses.clear(); ScriptValuePtr classes = ScriptEngineManager::runScript("listEntityClasses()"); for (int i = 0; i < classes->getProperty("length")->getInt(); i++) { entityClasses.push_back(classes->getProperty( Utility::toString(i) )->getString()); } }
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); } } }