Fix metatile behavior value displays

This commit is contained in:
GriffinR 2023-12-19 13:42:07 -05:00
parent 2cdbd029b6
commit ee6d6c7bcc
6 changed files with 29 additions and 19 deletions

View file

@ -75,10 +75,10 @@ public:
QStringList bgEventFacingDirections; QStringList bgEventFacingDirections;
QStringList trainerTypes; QStringList trainerTypes;
QStringList globalScriptLabels; QStringList globalScriptLabels;
QMap<QString, QMap<QString, int>> metatileLabelsMap; QMap<QString, QMap<QString, uint16_t>> metatileLabelsMap;
QMap<QString, int> unusedMetatileLabels; QMap<QString, uint16_t> unusedMetatileLabels;
QMap<QString, int> metatileBehaviorMap; QMap<QString, uint32_t> metatileBehaviorMap;
QMap<int, QString> metatileBehaviorMapInverse; QMap<uint32_t, QString> metatileBehaviorMapInverse;
QSet<uint32_t> warpBehaviorValues; QSet<uint32_t> warpBehaviorValues;
QMap<QString, QString> facingDirections; QMap<QString, QString> facingDirections;
ParseUtil parser; ParseUtil parser;
@ -216,7 +216,7 @@ public:
QString getDefaultSecondaryTilesetLabel(); QString getDefaultSecondaryTilesetLabel();
QString getDynamicMapDefineName(); QString getDynamicMapDefineName();
void updateTilesetMetatileLabels(Tileset *tileset); void updateTilesetMetatileLabels(Tileset *tileset);
QString buildMetatileLabelsText(const QMap<QString, int> defines); QString buildMetatileLabelsText(const QMap<QString, uint16_t> defines);
QString findMetatileLabelsTileset(QString label); QString findMetatileLabelsTileset(QString label);
void setImportExportPath(QString filename); void setImportExportPath(QString filename);

View file

@ -12,6 +12,7 @@ public:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void setTextItem(const QString &text); void setTextItem(const QString &text);
void setNumberItem(int value); void setNumberItem(int value);
void setHexItem(uint32_t value);
private: private:
void setItem(int index, const QString &text); void setItem(int index, const QString &text);

View file

@ -942,8 +942,10 @@ QString Editor::getMetatileDisplayMessage(uint16_t metatileId) {
QString message = QString("Metatile: %1").arg(Metatile::getMetatileIdString(metatileId)); QString message = QString("Metatile: %1").arg(Metatile::getMetatileIdString(metatileId));
if (label.size()) if (label.size())
message += QString(" \"%1\"").arg(label); message += QString(" \"%1\"").arg(label);
if (metatile && metatile->behavior()) // Skip MB_NORMAL if (metatile && metatile->behavior() != 0) { // Skip MB_NORMAL
message += QString(", Behavior: %1").arg(this->project->metatileBehaviorMapInverse.value(metatile->behavior(), QString::number(metatile->behavior()))); const QString behaviorStr = this->project->metatileBehaviorMapInverse.value(metatile->behavior(), "0x" + QString::number(metatile->behavior(), 16));
message += QString(", Behavior: %1").arg(behaviorStr);
}
return message; return message;
} }

View file

@ -899,7 +899,7 @@ void Project::updateTilesetMetatileLabels(Tileset *tileset) {
} }
// Given a map of define names to define values, returns a formatted list of #defines // Given a map of define names to define values, returns a formatted list of #defines
QString Project::buildMetatileLabelsText(const QMap<QString, int> defines) { QString Project::buildMetatileLabelsText(const QMap<QString, uint16_t> defines) {
QStringList labels = defines.keys(); QStringList labels = defines.keys();
// Setup for pretty formatting. // Setup for pretty formatting.
@ -2323,14 +2323,16 @@ bool Project::readMetatileBehaviors() {
const QStringList prefixes = {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)}; const QStringList prefixes = {projectConfig.getIdentifier(ProjectIdentifier::regex_behaviors)};
QString filename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_behaviors); QString filename = projectConfig.getFilePath(ProjectFilePath::constants_metatile_behaviors);
fileWatcher.addPath(root + "/" + filename); fileWatcher.addPath(root + "/" + filename);
this->metatileBehaviorMap = parser.readCDefinesByPrefix(filename, prefixes); QMap<QString, int> defines = parser.readCDefinesByPrefix(filename, prefixes);
if (this->metatileBehaviorMap.isEmpty()) { if (defines.isEmpty()) {
logError(QString("Failed to read metatile behaviors from %1.").arg(filename)); logError(QString("Failed to read metatile behaviors from %1.").arg(filename));
return false; return false;
} }
for (QString defineName : this->metatileBehaviorMap.keys()) { for (auto i = defines.cbegin(), end = defines.cend(); i != end; i++) {
this->metatileBehaviorMapInverse.insert(this->metatileBehaviorMap[defineName], defineName); uint32_t value = static_cast<uint32_t>(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 // Construct warp behavior value list for the warp metatile behavior warning

View file

@ -56,3 +56,8 @@ void NoScrollComboBox::setNumberItem(int value)
{ {
this->setItem(this->findData(value), QString::number(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());
}

View file

@ -373,10 +373,10 @@ void TilesetEditor::onSelectedMetatileChanged(uint16_t metatileId) {
this->ui->lineEdit_metatileLabel->setText(labels.owned); this->ui->lineEdit_metatileLabel->setText(labels.owned);
this->ui->lineEdit_metatileLabel->setPlaceholderText(labels.shared); this->ui->lineEdit_metatileLabel->setPlaceholderText(labels.shared);
this->ui->comboBox_metatileBehaviors->setNumberItem(this->metatile->behavior()); this->ui->comboBox_metatileBehaviors->setHexItem(this->metatile->behavior());
this->ui->comboBox_layerType->setNumberItem(this->metatile->layerType()); this->ui->comboBox_layerType->setHexItem(this->metatile->layerType());
this->ui->comboBox_encounterType->setNumberItem(this->metatile->encounterType()); this->ui->comboBox_encounterType->setHexItem(this->metatile->encounterType());
this->ui->comboBox_terrainType->setNumberItem(this->metatile->terrainType()); this->ui->comboBox_terrainType->setHexItem(this->metatile->terrainType());
} }
void TilesetEditor::onHoveredTileChanged(uint16_t tile) { 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) void TilesetEditor::on_comboBox_metatileBehaviors_currentTextChanged(const QString &metatileBehavior)
{ {
if (this->metatile) { if (this->metatile) {
int behavior; uint32_t behavior;
if (project->metatileBehaviorMap.contains(metatileBehavior)) { if (project->metatileBehaviorMap.contains(metatileBehavior)) {
behavior = project->metatileBehaviorMap[metatileBehavior]; behavior = project->metatileBehaviorMap[metatileBehavior];
} else { } else {
// Check if user has entered a number value instead // Check if user has entered a number value instead
bool ok; bool ok;
behavior = metatileBehavior.toInt(&ok, 0); behavior = metatileBehavior.toUInt(&ok, 0);
if (!ok) return; if (!ok) return;
} }
// This function can also be called when the user selects // This function can also be called when the user selects
// a different metatile. Stop this from being considered a change. // a different metatile. Stop this from being considered a change.
if (this->metatile->behavior() == static_cast<uint32_t>(behavior)) if (this->metatile->behavior() == behavior)
return; return;
Metatile *prevMetatile = new Metatile(*this->metatile); Metatile *prevMetatile = new Metatile(*this->metatile);