diff --git a/mainwindow.cpp b/mainwindow.cpp index 3e1e48f2..a053ec90 100755 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -284,6 +284,7 @@ void MainWindow::loadDataStructures() { Project *project = editor->project; project->readMapAttributesTable(); project->readAllMapAttributes(); + project->readItemNames(); } void MainWindow::populateMapList() { @@ -644,6 +645,11 @@ void MainWindow::updateSelectedObjects() { combo->addItem(value); } combo->addItems(*editor->project->mapNames); + } else if (key == "item") { + if (!editor->project->itemNames->contains(value)) { + combo->addItem(value); + } + combo->addItems(*editor->project->itemNames); } else { combo->addItem(value); } diff --git a/project.cpp b/project.cpp index 4db155e2..d036795c 100755 --- a/project.cpp +++ b/project.cpp @@ -18,6 +18,7 @@ Project::Project() groupNames = new QStringList; map_groups = new QMap; mapNames = new QStringList; + itemNames = new QStringList; map_cache = new QMap; mapConstantsToMapNames = new QMap; mapNamesToMapConstants = new QMap; @@ -1062,6 +1063,29 @@ QStringList Project::getBattleScenes() { return names; } +void Project::readItemNames() { + QString text = readTextFile(root + "/include/constants/items.h"); + if (!text.isNull()) { + QStringList itemDefinePrefixes; + itemDefinePrefixes << "ITEM_"; + QMap itemDefines = readCDefines(text, itemDefinePrefixes); + + // The item names should to be sorted by their underlying value, not alphabetically. + // Reverse the map and read out the resulting keys in order. + QMultiMap itemDefinesInverse; + for (QString itemName : itemDefines.keys()) { + itemDefinesInverse.insert(itemDefines[itemName], itemName); + } + + for (int itemValue : itemDefinesInverse.keys()) { + QList names = itemDefinesInverse.values(itemValue); + for (QString name : names) { + itemNames->append(name); + } + } + } +} + QStringList Project::getSongNames() { QStringList names; QString text = readTextFile(root + "/include/constants/songs.h"); diff --git a/project.h b/project.h index 37ae487f..2a67f0b6 100755 --- a/project.h +++ b/project.h @@ -23,7 +23,7 @@ public: QMap mapAttributesTableMaster; QMap> mapAttributes; QMap> mapAttributesMaster; - + QStringList *itemNames = NULL; QMap *map_cache; Map* loadMap(QString); @@ -73,6 +73,7 @@ public: QStringList getWeathers(); QStringList getMapTypes(); QStringList getBattleScenes(); + void readItemNames(); void loadObjectPixmaps(QList objects); QMap getMapObjGfxConstants();