Browse Source

Populate hidden item dropdown menu with item constants

Marcus Huderle 6 years ago
parent
commit
2bc949612d
3 changed files with 32 additions and 1 deletions
  1. 6
    0
      mainwindow.cpp
  2. 24
    0
      project.cpp
  3. 2
    1
      project.h

+ 6
- 0
mainwindow.cpp View File

284
     Project *project = editor->project;
284
     Project *project = editor->project;
285
     project->readMapAttributesTable();
285
     project->readMapAttributesTable();
286
     project->readAllMapAttributes();
286
     project->readAllMapAttributes();
287
+    project->readItemNames();
287
 }
288
 }
288
 
289
 
289
 void MainWindow::populateMapList() {
290
 void MainWindow::populateMapList() {
644
                     combo->addItem(value);
645
                     combo->addItem(value);
645
                 }
646
                 }
646
                 combo->addItems(*editor->project->mapNames);
647
                 combo->addItems(*editor->project->mapNames);
648
+            } else if (key == "item") {
649
+                if (!editor->project->itemNames->contains(value)) {
650
+                    combo->addItem(value);
651
+                }
652
+                combo->addItems(*editor->project->itemNames);
647
             } else {
653
             } else {
648
                 combo->addItem(value);
654
                 combo->addItem(value);
649
             }
655
             }

+ 24
- 0
project.cpp View File

18
     groupNames = new QStringList;
18
     groupNames = new QStringList;
19
     map_groups = new QMap<QString, int>;
19
     map_groups = new QMap<QString, int>;
20
     mapNames = new QStringList;
20
     mapNames = new QStringList;
21
+    itemNames = new QStringList;
21
     map_cache = new QMap<QString, Map*>;
22
     map_cache = new QMap<QString, Map*>;
22
     mapConstantsToMapNames = new QMap<QString, QString>;
23
     mapConstantsToMapNames = new QMap<QString, QString>;
23
     mapNamesToMapConstants = new QMap<QString, QString>;
24
     mapNamesToMapConstants = new QMap<QString, QString>;
1062
     return names;
1063
     return names;
1063
 }
1064
 }
1064
 
1065
 
1066
+void Project::readItemNames() {
1067
+    QString text = readTextFile(root + "/include/constants/items.h");
1068
+    if (!text.isNull()) {
1069
+        QStringList itemDefinePrefixes;
1070
+        itemDefinePrefixes << "ITEM_";
1071
+        QMap<QString, int> itemDefines = readCDefines(text, itemDefinePrefixes);
1072
+
1073
+        // The item names should to be sorted by their underlying value, not alphabetically.
1074
+        // Reverse the map and read out the resulting keys in order.
1075
+        QMultiMap<int, QString> itemDefinesInverse;
1076
+        for (QString itemName : itemDefines.keys()) {
1077
+            itemDefinesInverse.insert(itemDefines[itemName], itemName);
1078
+        }
1079
+
1080
+        for (int itemValue : itemDefinesInverse.keys()) {
1081
+            QList<QString> names = itemDefinesInverse.values(itemValue);
1082
+            for (QString name : names) {
1083
+                itemNames->append(name);
1084
+            }
1085
+        }
1086
+    }
1087
+}
1088
+
1065
 QStringList Project::getSongNames() {
1089
 QStringList Project::getSongNames() {
1066
     QStringList names;
1090
     QStringList names;
1067
     QString text = readTextFile(root + "/include/constants/songs.h");
1091
     QString text = readTextFile(root + "/include/constants/songs.h");

+ 2
- 1
project.h View File

23
     QMap<int, QString> mapAttributesTableMaster;
23
     QMap<int, QString> mapAttributesTableMaster;
24
     QMap<QString, QMap<QString, QString>> mapAttributes;
24
     QMap<QString, QMap<QString, QString>> mapAttributes;
25
     QMap<QString, QMap<QString, QString>> mapAttributesMaster;
25
     QMap<QString, QMap<QString, QString>> mapAttributesMaster;
26
-
26
+    QStringList *itemNames = NULL;
27
 
27
 
28
     QMap<QString, Map*> *map_cache;
28
     QMap<QString, Map*> *map_cache;
29
     Map* loadMap(QString);
29
     Map* loadMap(QString);
73
     QStringList getWeathers();
73
     QStringList getWeathers();
74
     QStringList getMapTypes();
74
     QStringList getMapTypes();
75
     QStringList getBattleScenes();
75
     QStringList getBattleScenes();
76
+    void readItemNames();
76
 
77
 
77
     void loadObjectPixmaps(QList<Event*> objects);
78
     void loadObjectPixmaps(QList<Event*> objects);
78
     QMap<QString, int> getMapObjGfxConstants();
79
     QMap<QString, int> getMapObjGfxConstants();