From 76a8c0dc441e4024bb2861a28f091503cd9058a7 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 27 Mar 2020 10:51:57 -0400 Subject: [PATCH] Read trainer type constants --- include/project.h | 2 ++ src/mainwindow.cpp | 29 ++++++----------------------- src/project.cpp | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/project.h b/include/project.h index 1c01b07a..7cd77693 100644 --- a/include/project.h +++ b/include/project.h @@ -49,6 +49,7 @@ public: QStringList *coordEventWeatherNames = nullptr; QStringList *secretBaseIds = nullptr; QStringList *bgEventFacingDirections = nullptr; + QStringList *trainerTypes = nullptr; QMap metatileBehaviorMap; QMap metatileBehaviorMapInverse; QMap facingDirections; @@ -143,6 +144,7 @@ public: bool readCoordEventWeatherNames(); bool readSecretBaseIds(); bool readBgEventFacingDirections(); + bool readTrainerTypes(); bool readMetatileBehaviors(); bool readHealLocations(); bool readMiscellaneousConstants(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f0ff4b9e..595f4606 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -646,6 +646,7 @@ bool MainWindow::loadDataStructures() { && project->readMapBattleScenes() && project->readWeatherNames() && project->readBgEventFacingDirections() + && project->readTrainerTypes() && project->readMetatileBehaviors() && project->readTilesetProperties() && project->readHealLocations() @@ -1522,29 +1523,6 @@ void MainWindow::updateSelectedObjects() { combo = new NoScrollComboBox(widget); combo->setEditable(true); } - // trainer_type has custom values, so it has special signal logic. - if (key == "trainer_type") { - combo->addItem("NONE", "0"); - combo->addItem("NORMAL", "1"); - combo->addItem("SEE ALL DIRECTIONS", "3"); - combo->setToolTip("The trainer type of this object event.\n" - "If it is not a trainer, use NONE. SEE ALL DIRECTIONS\n" - "should only be used with a sight radius of 1."); - combo->setMinimumContentsLength(10); - - int index = combo->findData(value); - if (index != -1) { - combo->setCurrentIndex(index); - } else { - combo->setCurrentText(value); - } - - fl->addRow(new QLabel(field_labels[key], widget), combo); - widget->setLayout(fl); - frame->layout()->addWidget(widget); - item->bindToUserData(combo, key); - continue; - } if (key == "destination_map_name") { if (!editor->project->mapNames->contains(value)) { @@ -1628,6 +1606,11 @@ void MainWindow::updateSelectedObjects() { combo->setMinimumContentsLength(4); } else if (key == "script_label") { combo->setToolTip("The script which is executed with this event."); + } else if (key == "trainer_type") { + combo->addItems(*editor->project->trainerTypes); + combo->setToolTip("The trainer type of this object event.\n" + "If it is not a trainer, use NONE. SEE ALL DIRECTIONS\n" + "should only be used with a sight radius of 1."); } else if (key == "sight_radius_tree_id") { combo->setToolTip("The maximum sight range of a trainer,\n" "OR the unique id of the berry tree."); diff --git a/src/project.cpp b/src/project.cpp index 5b79b29f..f0862c5a 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -44,6 +44,7 @@ Project::Project() coordEventWeatherNames = new QStringList; secretBaseIds = new QStringList; bgEventFacingDirections = new QStringList; + trainerTypes = new QStringList; map_cache = new QMap; mapConstantsToMapNames = new QMap; mapNamesToMapConstants = new QMap; @@ -2142,6 +2143,18 @@ bool Project::readBgEventFacingDirections() { return true; } +bool Project::readTrainerTypes() { + trainerTypes->clear(); + QStringList prefixes = (QStringList() << "TRAINER_TYPE_"); + QString filename = "include/constants/trainer_types.h"; + parser.readCDefinesSorted(filename, prefixes, trainerTypes); + if (trainerTypes->isEmpty()) { + logError(QString("Failed to read trainer type constants from %1").arg(filename)); + return false; + } + return true; +} + bool Project::readMetatileBehaviors() { this->metatileBehaviorMap.clear(); this->metatileBehaviorMapInverse.clear(); @@ -2150,7 +2163,7 @@ bool Project::readMetatileBehaviors() { QString filename = "include/constants/metatile_behaviors.h"; this->metatileBehaviorMap = parser.readCDefines(filename, prefixes); if (this->metatileBehaviorMap.isEmpty()) { - logError(QString("Failed to metatile behaviors from %1.").arg(filename)); + logError(QString("Failed to read metatile behaviors from %1.").arg(filename)); return false; }