Kaynağa Gözat

Populate hidden item dropdown menu with item constants

Marcus Huderle 6 yıl önce
ebeveyn
işleme
2bc949612d
3 değiştirilmiş dosya ile 32 ekleme ve 1 silme
  1. 6
    0
      mainwindow.cpp
  2. 24
    0
      project.cpp
  3. 2
    1
      project.h

+ 6
- 0
mainwindow.cpp Dosyayı Görüntüle

@@ -284,6 +284,7 @@ void MainWindow::loadDataStructures() {
284 284
     Project *project = editor->project;
285 285
     project->readMapAttributesTable();
286 286
     project->readAllMapAttributes();
287
+    project->readItemNames();
287 288
 }
288 289
 
289 290
 void MainWindow::populateMapList() {
@@ -644,6 +645,11 @@ void MainWindow::updateSelectedObjects() {
644 645
                     combo->addItem(value);
645 646
                 }
646 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 653
             } else {
648 654
                 combo->addItem(value);
649 655
             }

+ 24
- 0
project.cpp Dosyayı Görüntüle

@@ -18,6 +18,7 @@ Project::Project()
18 18
     groupNames = new QStringList;
19 19
     map_groups = new QMap<QString, int>;
20 20
     mapNames = new QStringList;
21
+    itemNames = new QStringList;
21 22
     map_cache = new QMap<QString, Map*>;
22 23
     mapConstantsToMapNames = new QMap<QString, QString>;
23 24
     mapNamesToMapConstants = new QMap<QString, QString>;
@@ -1062,6 +1063,29 @@ QStringList Project::getBattleScenes() {
1062 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 1089
 QStringList Project::getSongNames() {
1066 1090
     QStringList names;
1067 1091
     QString text = readTextFile(root + "/include/constants/songs.h");

+ 2
- 1
project.h Dosyayı Görüntüle

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