diff --git a/include/project.h b/include/project.h index faa8186c..cf16066f 100644 --- a/include/project.h +++ b/include/project.h @@ -75,10 +75,10 @@ public: QStringList bgEventFacingDirections; QStringList trainerTypes; QStringList globalScriptLabels; - QMap> metatileLabelsMap; - QMap unusedMetatileLabels; - QMap metatileBehaviorMap; - QMap metatileBehaviorMapInverse; + QMap> metatileLabelsMap; + QMap unusedMetatileLabels; + QMap metatileBehaviorMap; + QMap metatileBehaviorMapInverse; QSet warpBehaviorValues; QMap facingDirections; ParseUtil parser; @@ -216,7 +216,7 @@ public: QString getDefaultSecondaryTilesetLabel(); QString getDynamicMapDefineName(); void updateTilesetMetatileLabels(Tileset *tileset); - QString buildMetatileLabelsText(const QMap defines); + QString buildMetatileLabelsText(const QMap defines); QString findMetatileLabelsTileset(QString label); void setImportExportPath(QString filename); diff --git a/include/ui/noscrollcombobox.h b/include/ui/noscrollcombobox.h index 98cacf70..59c680a3 100644 --- a/include/ui/noscrollcombobox.h +++ b/include/ui/noscrollcombobox.h @@ -12,6 +12,7 @@ public: void wheelEvent(QWheelEvent *event); void setTextItem(const QString &text); void setNumberItem(int value); + void setHexItem(uint32_t value); private: void setItem(int index, const QString &text); diff --git a/src/editor.cpp b/src/editor.cpp index 3193df96..d136da51 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -942,8 +942,10 @@ QString Editor::getMetatileDisplayMessage(uint16_t metatileId) { QString message = QString("Metatile: %1").arg(Metatile::getMetatileIdString(metatileId)); if (label.size()) message += QString(" \"%1\"").arg(label); - if (metatile && metatile->behavior()) // Skip MB_NORMAL - message += QString(", Behavior: %1").arg(this->project->metatileBehaviorMapInverse.value(metatile->behavior(), QString::number(metatile->behavior()))); + if (metatile && metatile->behavior() != 0) { // Skip MB_NORMAL + const QString behaviorStr = this->project->metatileBehaviorMapInverse.value(metatile->behavior(), "0x" + QString::number(metatile->behavior(), 16)); + message += QString(", Behavior: %1").arg(behaviorStr); + } return message; } diff --git a/src/project.cpp b/src/project.cpp index cfd76902..d3e14b1a 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -899,7 +899,7 @@ void Project::updateTilesetMetatileLabels(Tileset *tileset) { } // Given a map of define names to define values, returns a formatted list of #defines -QString Project::buildMetatileLabelsText(const QMap defines) { +QString Project::buildMetatileLabelsText(const QMap defines) { QStringList labels = defines.keys(); // Setup for pretty formatting. @@ -2323,14 +2323,16 @@ bool Project::readMetatileBehaviors() { const QStringList prefixes = {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)}; QString filename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_behaviors); fileWatcher.addPath(root + "/" + filename); - this->metatileBehaviorMap = parser.readCDefinesByPrefix(filename, prefixes); - if (this->metatileBehaviorMap.isEmpty()) { + QMap defines = parser.readCDefinesByPrefix(filename, prefixes); + if (defines.isEmpty()) { logError(QString("Failed to read metatile behaviors from %1.").arg(filename)); return false; } - for (QString defineName : this->metatileBehaviorMap.keys()) { - this->metatileBehaviorMapInverse.insert(this->metatileBehaviorMap[defineName], defineName); + for (auto i = defines.cbegin(), end = defines.cend(); i != end; i++) { + uint32_t value = static_cast(i.value()); + this->metatileBehaviorMap.insert(i.key(), value); + this->metatileBehaviorMapInverse.insert(value, i.key()); } // Construct warp behavior value list for the warp metatile behavior warning diff --git a/src/ui/noscrollcombobox.cpp b/src/ui/noscrollcombobox.cpp index ecf2ba3a..ee778df5 100644 --- a/src/ui/noscrollcombobox.cpp +++ b/src/ui/noscrollcombobox.cpp @@ -56,3 +56,8 @@ void NoScrollComboBox::setNumberItem(int value) { this->setItem(this->findData(value), QString::number(value)); } + +void NoScrollComboBox::setHexItem(uint32_t value) +{ + this->setItem(this->findData(value), "0x" + QString::number(value, 16).toUpper()); +} diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 7d680b54..77844ffa 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -373,10 +373,10 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) { this->ui->lineEdit_metatileLabel->setText(labels.owned); this->ui->lineEdit_metatileLabel->setPlaceholderText(labels.shared); - this->ui->comboBox_metatileBehaviors->setNumberItem(this->metatile->behavior()); - this->ui->comboBox_layerType->setNumberItem(this->metatile->layerType()); - this->ui->comboBox_encounterType->setNumberItem(this->metatile->encounterType()); - this->ui->comboBox_terrainType->setNumberItem(this->metatile->terrainType()); + this->ui->comboBox_metatileBehaviors->setHexItem(this->metatile->behavior()); + this->ui->comboBox_layerType->setHexItem(this->metatile->layerType()); + this->ui->comboBox_encounterType->setHexItem(this->metatile->encounterType()); + this->ui->comboBox_terrainType->setHexItem(this->metatile->terrainType()); } void TilesetEditor::onHoveredTileChanged(uint16_t tile) { @@ -493,19 +493,19 @@ void TilesetEditor::on_checkBox_yFlip_stateChanged(int checked) void TilesetEditor::on_comboBox_metatileBehaviors_currentTextChanged(const QString &metatileBehavior) { if (this->metatile) { - int behavior; + uint32_t behavior; if (project->metatileBehaviorMap.contains(metatileBehavior)) { behavior = project->metatileBehaviorMap[metatileBehavior]; } else { // Check if user has entered a number value instead bool ok; - behavior = metatileBehavior.toInt(&ok, 0); + behavior = metatileBehavior.toUInt(&ok, 0); if (!ok) return; } // This function can also be called when the user selects // a different metatile. Stop this from being considered a change. - if (this->metatile->behavior() == static_cast(behavior)) + if (this->metatile->behavior() == behavior) return; Metatile *prevMetatile = new Metatile(*this->metatile);