diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 4c4a0277..7f85664d 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -10,12 +10,6 @@ 747 - - - 0 - 0 - - porymap @@ -26,28 +20,132 @@ Qt::Horizontal - + + + true + 0 0 - - - 100 - 0 - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectItems - - - false - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 3 + + + 3 + + + 3 + + + + + true + + + + :/icons/sort_alphabet.ico:/icons/sort_alphabet.ico + + + + 16 + 16 + + + + QToolButton::InstantPopup + + + Qt::ToolButtonIconOnly + + + true + + + Qt::NoArrow + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 12 + 20 + + + + + + + + true + + + + + + Filter maps... + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectItems + + + false + + + + @@ -378,8 +476,8 @@ 0 0 - 469 - 608 + 481 + 606 @@ -687,8 +785,8 @@ 0 0 - 324 - 77 + 300 + 70 @@ -799,8 +897,8 @@ 0 0 - 307 - 387 + 304 + 372 @@ -1116,8 +1214,8 @@ 0 0 - 381 - 657 + 385 + 655 @@ -1294,8 +1392,8 @@ 0 0 - 432 - 596 + 428 + 586 @@ -1914,8 +2012,8 @@ 0 0 - 826 - 557 + 829 + 552 @@ -2087,7 +2185,7 @@ 0 0 1117 - 21 + 20 @@ -2275,6 +2373,45 @@ Tileset Editor + + + true + + + + :/icons/sort_alphabet.ico:/icons/sort_alphabet.ico + + + Sort by &Name + + + + + true + + + + :/icons/sort_number.ico:/icons/sort_number.ico + + + Sort by &Group + + + Sort by Group + + + + + true + + + + :/icons/sort_map.ico:/icons/sort_map.ico + + + Sort by &Layout + + diff --git a/include/core/filterchildrenproxymodel.h b/include/core/filterchildrenproxymodel.h new file mode 100644 index 00000000..b73cbd62 --- /dev/null +++ b/include/core/filterchildrenproxymodel.h @@ -0,0 +1,17 @@ +#ifndef FILTERCHILDRENPROXYMODEL_H +#define FILTERCHILDRENPROXYMODEL_H + +#include + +class FilterChildrenProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit FilterChildrenProxyModel(QObject *parent = nullptr); +protected: + bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const; + +}; + +#endif // FILTERCHILDRENPROXYMODEL_H diff --git a/include/mainwindow.h b/include/mainwindow.h index 3ddc3c39..7e295e19 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -13,6 +13,7 @@ #include "map.h" #include "editor.h" #include "tileseteditor.h" +#include "filterchildrenproxymodel.h" namespace Ui { class MainWindow; @@ -128,18 +129,32 @@ private slots: void on_actionTileset_Editor_triggered(); + void mapSortOrder_changed(QAction *action); + + void on_lineEdit_filterBox_textChanged(const QString &arg1); + private: Ui::MainWindow *ui; TilesetEditor *tilesetEditor = nullptr; + FilterChildrenProxyModel *mapListProxyModel; QStandardItemModel *mapListModel; - QList *mapGroupsModel; + QList *mapGroupItemsList; QMap mapListIndexes; Editor *editor = nullptr; QIcon* mapIcon; + QIcon* mapEditedIcon; + + enum MapSortOrder { + Group = 0, + Name = 1, + Layout = 2, + } mapSortOrder; + void setMap(QString, bool scrollTreeView = false); void redrawMapScene(); void loadDataStructures(); void populateMapList(); + void sortMapList(); QString getExistingDirectory(QString); void openProject(QString dir); QString getDefaultMap(); @@ -156,14 +171,18 @@ private: void initExtraShortcuts(); void initExtraSignals(); void initEditor(); + void initMiscHeapObjects(); + void initMapSortOrder(); void loadUserSettings(); void openRecentProject(); void updateTilesetEditor(); + + bool isProjectOpen(); }; enum MapListUserRoles { GroupRole = Qt::UserRole + 1, // Used to hold the map group number. - TypeRole = Qt::UserRole + 2, // Used to differentiate between the different layers of the map list tree view. + TypeRole, // Used to differentiate between the different layers of the map list tree view. }; #endif // MAINWINDOW_H diff --git a/include/project.h b/include/project.h index fa4ee2ed..c3d1bc66 100644 --- a/include/project.h +++ b/include/project.h @@ -64,6 +64,9 @@ public: QString getNewMapName(); QString getProjectTitle(); + QString readMapLayoutId(QString map_name); + QString readMapLocation(QString map_name); + QList* getLabelMacros(QList*, QString); QStringList* getLabelValues(QList*, QString); void readMapHeader(Map*); diff --git a/porymap.pro b/porymap.pro index 70767deb..e96e2f40 100644 --- a/porymap.pro +++ b/porymap.pro @@ -17,6 +17,7 @@ ICON = resources/icons/porymap-icon-1.ico SOURCES += src/core/block.cpp \ src/core/blockdata.cpp \ src/core/event.cpp \ + src/core/filterchildrenproxymodel.cpp \ src/core/heallocation.cpp \ src/core/historyitem.cpp \ src/core/map.cpp \ @@ -54,6 +55,7 @@ SOURCES += src/core/block.cpp \ HEADERS += include/core/block.h \ include/core/blockdata.h \ include/core/event.h \ + include/core/filterchildrenproxymodel.h \ include/core/heallocation.h \ include/core/history.h \ include/core/historyitem.h \ diff --git a/resources/icons/folder_image.ico b/resources/icons/folder_map_edited.ico similarity index 100% rename from resources/icons/folder_image.ico rename to resources/icons/folder_map_edited.ico diff --git a/resources/icons/folder_map_opened.ico b/resources/icons/folder_map_opened.ico new file mode 100644 index 00000000..2b23226a Binary files /dev/null and b/resources/icons/folder_map_opened.ico differ diff --git a/resources/icons/image.ico b/resources/icons/map_edited.ico similarity index 100% rename from resources/icons/image.ico rename to resources/icons/map_edited.ico diff --git a/resources/icons/map_opened.ico b/resources/icons/map_opened.ico new file mode 100644 index 00000000..b0d52dae Binary files /dev/null and b/resources/icons/map_opened.ico differ diff --git a/resources/icons/sort_alphabet.ico b/resources/icons/sort_alphabet.ico new file mode 100644 index 00000000..27744f83 Binary files /dev/null and b/resources/icons/sort_alphabet.ico differ diff --git a/resources/icons/sort_map.ico b/resources/icons/sort_map.ico new file mode 100644 index 00000000..5c64e855 Binary files /dev/null and b/resources/icons/sort_map.ico differ diff --git a/resources/icons/sort_number.ico b/resources/icons/sort_number.ico new file mode 100644 index 00000000..1fa55858 Binary files /dev/null and b/resources/icons/sort_number.ico differ diff --git a/resources/images.qrc b/resources/images.qrc index ac1ff8cb..8f1a09aa 100644 --- a/resources/images.qrc +++ b/resources/images.qrc @@ -3,9 +3,7 @@ icons/folder.ico icons/folder_closed.ico icons/folder_closed_map.ico - icons/folder_image.ico icons/folder_map.ico - icons/image.ico icons/map.ico icons/cursor.ico icons/fill_color.ico @@ -23,5 +21,12 @@ icons/shift.ico icons/shift_cursor.ico icons/porymap-icon-1.ico + icons/folder_map_edited.ico + icons/folder_map_opened.ico + icons/map_edited.ico + icons/map_opened.ico + icons/sort_alphabet.ico + icons/sort_map.ico + icons/sort_number.ico diff --git a/src/core/filterchildrenproxymodel.cpp b/src/core/filterchildrenproxymodel.cpp new file mode 100644 index 00000000..faff6a23 --- /dev/null +++ b/src/core/filterchildrenproxymodel.cpp @@ -0,0 +1,35 @@ +#include "filterchildrenproxymodel.h" + +FilterChildrenProxyModel::FilterChildrenProxyModel(QObject *parent) : + QSortFilterProxyModel(parent) +{ + +} + +bool FilterChildrenProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + // custom behaviour : + if(filterRegExp().isEmpty() == false) + { + // get source-model index for current row + QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ; + if(source_index.isValid()) + { + // if any of children matches the filter, then current index matches the filter as well + int i, nb = sourceModel()->rowCount(source_index); + for (i = 0; i < nb; ++i) + { + if (filterAcceptsRow(i, source_index)) + { + return true; + } + } + // check current index itself + QString key = sourceModel()->data(source_index, filterRole()).toString(); + QString parentKey = sourceModel()->data(source_parent, filterRole()).toString(); + return key.contains(filterRegExp()) || parentKey.contains(filterRegExp()); + } + } + // parent call for initial behaviour + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4adf9562..8ffbeb48 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -39,6 +39,8 @@ MainWindow::MainWindow(QWidget *parent) : this->initExtraSignals(); this->initExtraShortcuts(); this->initEditor(); + this->initMiscHeapObjects(); + this->initMapSortOrder(); this->openRecentProject(); on_toolButton_Paint_clicked(); @@ -50,7 +52,7 @@ MainWindow::~MainWindow() } void MainWindow::initExtraShortcuts() { - new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo())); + new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(redo())); new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale())); ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")}); } @@ -72,12 +74,89 @@ void MainWindow::initEditor() { this->loadUserSettings(); } +void MainWindow::initMiscHeapObjects() { + mapIcon = new QIcon; + mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off); + mapIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal, QIcon::On); + + mapEditedIcon = new QIcon; + mapEditedIcon->addFile(QStringLiteral(":/icons/map_edited.ico"), QSize(), QIcon::Normal, QIcon::Off); + mapEditedIcon->addFile(QStringLiteral(":/icons/map_opened.ico"), QSize(), QIcon::Normal , QIcon::On); + + mapListModel = new QStandardItemModel; + mapGroupItemsList = new QList; + mapListProxyModel = new FilterChildrenProxyModel; + + mapListProxyModel->setSourceModel(mapListModel); + ui->mapList->setModel(mapListProxyModel); +} + +void MainWindow::initMapSortOrder() { + QMenu *mapSortOrderMenu = new QMenu(); + QActionGroup *mapSortOrderActionGroup = new QActionGroup(ui->toolButton_MapSortOrder); + + mapSortOrderMenu->addAction(ui->actionSort_by_Group); + mapSortOrderMenu->addAction(ui->actionSort_by_Name); + mapSortOrderMenu->addAction(ui->actionSort_by_Layout); + ui->toolButton_MapSortOrder->setMenu(mapSortOrderMenu); + + mapSortOrderActionGroup->addAction(ui->actionSort_by_Group); + mapSortOrderActionGroup->addAction(ui->actionSort_by_Name); + mapSortOrderActionGroup->addAction(ui->actionSort_by_Layout); + + connect(ui->toolButton_MapSortOrder, &QToolButton::triggered, this, &MainWindow::mapSortOrder_changed); + + QAction* sortOrder = ui->toolButton_MapSortOrder->menu()->actions()[mapSortOrder]; + ui->toolButton_MapSortOrder->setIcon(sortOrder->icon()); + sortOrder->setChecked(true); +} + +void MainWindow::mapSortOrder_changed(QAction *action) +{ + QSettings settings; + + QList items = ui->toolButton_MapSortOrder->menu()->actions(); + int i = 0; + for (; i < items.count(); i++) + { + if(items[i] == action) + { + break; + } + } + + if (i != mapSortOrder) + { + ui->toolButton_MapSortOrder->setIcon(action->icon()); + mapSortOrder = static_cast(i); + settings.setValue("map_sort_order", i); + + if (isProjectOpen()) + { + sortMapList(); + } + } +} + +void MainWindow::on_lineEdit_filterBox_textChanged(const QString &arg1) +{ + mapListProxyModel->setFilterRegExp(QRegExp(arg1, Qt::CaseInsensitive, QRegExp::FixedString)); + ui->mapList->expandToDepth(0); + ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true); +} + void MainWindow::loadUserSettings() { QSettings settings; bool betterCursors = settings.contains("cursor_mode") && settings.value("cursor_mode") != "0"; ui->actionBetter_Cursors->setChecked(betterCursors); this->editor->settings->betterCursors = betterCursors; + + if (!settings.contains("map_sort_order")) + { + settings.setValue("map_sort_order", 0); + } + mapSortOrder = static_cast(settings.value("map_sort_order").toInt()); } void MainWindow::openRecentProject() { @@ -99,11 +178,7 @@ void MainWindow::openProject(QString dir) { this->statusBar()->showMessage(QString("Opening project %1").arg(dir)); - bool already_open = ( - (editor && editor != nullptr) - && (editor->project && editor->project != nullptr) - && (editor->project->root == dir) - ); + bool already_open = isProjectOpen() && (editor->project->root == dir); if (!already_open) { editor->project = new Project; editor->project->root = dir; @@ -120,6 +195,11 @@ void MainWindow::openProject(QString dir) { this->statusBar()->showMessage(QString("Opened project %1").arg(dir)); } +bool MainWindow::isProjectOpen() { + return (editor && editor != nullptr) + && (editor->project && editor->project != nullptr); +} + QString MainWindow::getDefaultMap() { if (editor && editor->project) { QList names = editor->project->groupedMapNames; @@ -180,15 +260,22 @@ void MainWindow::setMap(QString map_name, bool scrollTreeView) { if (map_name.isNull()) { return; } + if (editor->map != nullptr && !editor->map->name.isNull()) { + ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), false); + } editor->setMap(map_name); redrawMapScene(); displayMapProperties(); if (scrollTreeView) { - ui->mapList->setCurrentIndex(mapListIndexes.value(map_name)); + // Make sure we clear the filter first so we actually have a scroll target + mapListProxyModel->setFilterRegExp(QString::null); + ui->mapList->setCurrentIndex(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name))); ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter); } + ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name)), true); + setWindowTitle(map_name + " - " + editor->project->getProjectTitle()); connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *))); @@ -412,6 +499,11 @@ void MainWindow::loadDataStructures() { } void MainWindow::populateMapList() { + editor->project->readMapGroups(); + sortMapList(); +} + +void MainWindow::sortMapList() { Project *project = editor->project; QIcon mapFolderIcon; @@ -420,44 +512,93 @@ void MainWindow::populateMapList() { QIcon folderIcon; folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off); + //folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On); - mapIcon = new QIcon; - mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off); - mapIcon->addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On); + ui->mapList->setUpdatesEnabled(false); + mapListModel->clear(); + mapGroupItemsList->clear(); + QStandardItem *root = mapListModel->invisibleRootItem(); - mapListModel = new QStandardItemModel; - mapGroupsModel = new QList; - - QStandardItem *entry = new QStandardItem; - entry->setText(project->getProjectTitle()); - entry->setIcon(folderIcon); - entry->setEditable(false); - mapListModel->appendRow(entry); - - QStandardItem *maps = new QStandardItem; - maps->setText("maps"); - maps->setIcon(folderIcon); - maps->setEditable(false); - entry->appendRow(maps); - - project->readMapGroups(); - for (int i = 0; i < project->groupNames->length(); i++) { - QString group_name = project->groupNames->value(i); - QStandardItem *group = new QStandardItem; - group->setText(group_name); - group->setIcon(mapFolderIcon); - group->setEditable(false); - group->setData(group_name, Qt::UserRole); - group->setData("map_group", MapListUserRoles::TypeRole); - group->setData(i, MapListUserRoles::GroupRole); - maps->appendRow(group); - mapGroupsModel->append(group); - QStringList names = project->groupedMapNames.value(i); - for (int j = 0; j < names.length(); j++) { - QString map_name = names.value(j); - QStandardItem *map = createMapItem(map_name, i, j); - group->appendRow(map); - mapListIndexes.insert(map_name, map->index()); + switch (mapSortOrder) + { + case MapSortOrder::Group: + for (int i = 0; i < project->groupNames->length(); i++) { + QString group_name = project->groupNames->value(i); + QStandardItem *group = new QStandardItem; + group->setText(group_name); + group->setIcon(mapFolderIcon); + group->setEditable(false); + group->setData(group_name, Qt::UserRole); + group->setData("map_group", MapListUserRoles::TypeRole); + group->setData(i, MapListUserRoles::GroupRole); + root->appendRow(group); + mapGroupItemsList->append(group); + QStringList names = project->groupedMapNames.value(i); + for (int j = 0; j < names.length(); j++) { + QString map_name = names.value(j); + QStandardItem *map = createMapItem(map_name, i, j); + group->appendRow(map); + mapListIndexes.insert(map_name, map->index()); + } + } + break; + case MapSortOrder::Name: + { + QMap mapsecToGroupNum; + for (int i = 0; i < project->regionMapSections->length(); i++) { + QString mapsec_name = project->regionMapSections->value(i); + QStandardItem *mapsec = new QStandardItem; + mapsec->setText(mapsec_name); + mapsec->setIcon(folderIcon); + mapsec->setEditable(false); + mapsec->setData(mapsec_name, Qt::UserRole); + mapsec->setData("map_sec", MapListUserRoles::TypeRole); + mapsec->setData(i, MapListUserRoles::GroupRole); + root->appendRow(mapsec); + mapGroupItemsList->append(mapsec); + mapsecToGroupNum.insert(mapsec_name, i); + } + for (int i = 0; i < project->groupNames->length(); i++) { + QStringList names = project->groupedMapNames.value(i); + for (int j = 0; j < names.length(); j++) { + QString map_name = names.value(j); + QStandardItem *map = createMapItem(map_name, i, j); + QString location = project->readMapLocation(map_name); + QStandardItem *mapsecItem = mapGroupItemsList->at(mapsecToGroupNum[location]); + mapsecItem->setIcon(mapFolderIcon); + mapsecItem->appendRow(map); + mapListIndexes.insert(map_name, map->index()); + } + } + break; + } + case MapSortOrder::Layout: + { + for (int i = 0; i < project->mapLayoutsTable.length(); i++) { + QString layoutName = project->mapLayoutsTable.value(i); + QStandardItem *layout = new QStandardItem; + layout->setText(layoutName); + layout->setIcon(folderIcon); + layout->setEditable(false); + layout->setData(layoutName, Qt::UserRole); + layout->setData("map_layout", MapListUserRoles::TypeRole); + layout->setData(i, MapListUserRoles::GroupRole); + root->appendRow(layout); + mapGroupItemsList->append(layout); + } + for (int i = 0; i < project->groupNames->length(); i++) { + QStringList names = project->groupedMapNames.value(i); + for (int j = 0; j < names.length(); j++) { + QString map_name = names.value(j); + QStandardItem *map = createMapItem(map_name, i, j); + QString layoutId = project->readMapLayoutId(map_name); + QStandardItem *layoutItem = mapGroupItemsList->at(layoutId.toInt() - 1); + layoutItem->setIcon(mapFolderIcon); + layoutItem->appendRow(map); + mapListIndexes.insert(map_name, map->index()); + } + } + break; } } @@ -466,9 +607,8 @@ void MainWindow::populateMapList() { connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onOpenMapListContextMenu(const QPoint &))); - ui->mapList->setModel(mapListModel); ui->mapList->setUpdatesEnabled(true); - ui->mapList->expandToDepth(2); + ui->mapList->expandToDepth(0); ui->mapList->repaint(); } @@ -484,7 +624,7 @@ QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGr void MainWindow::onOpenMapListContextMenu(const QPoint &point) { - QModelIndex index = ui->mapList->indexAt(point); + QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point)); if (!index.isValid()) { return; } @@ -510,7 +650,7 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) { int groupNum = triggeredAction->data().toInt(); - QStandardItem* groupItem = mapGroupsModel->at(groupNum); + QStandardItem* groupItem = mapGroupItemsList->at(groupNum); QString newMapName = editor->project->getNewMapName(); Map* newMap = editor->project->addNewMapToGroup(newMapName, groupNum); @@ -571,10 +711,9 @@ void MainWindow::markEdited(QModelIndex index) { QString map_name = data.toString(); if (editor->project) { if (editor->project->map_cache->contains(map_name)) { - // Just mark anything that's been opened for now. - // TODO if (project->getMap()->saved) - //ui->mapList->setExpanded(index, true); - ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges()); + if (editor->project->map_cache->value(map_name)->hasUnsavedChanges()) { + mapListModel->itemFromIndex(mapListIndexes.value(map_name))->setIcon(*mapEditedIcon); + } } } } diff --git a/src/project.cpp b/src/project.cpp index f1168123..9ee2acab 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -189,6 +189,36 @@ void Project::readMapHeader(Map* map) { map->battle_scene = header->value(12); } +QString Project::readMapLayoutId(QString map_name) { + if (map_cache->contains(map_name)) { + return map_cache->value(map_name)->layout_id; + } + + ParseUtil *parser = new ParseUtil; + + QString header_text = readTextFile(root + "/data/maps/" + map_name + "/header.inc"); + if (header_text.isNull()) { + return QString::null; + } + QStringList *header = getLabelValues(parser->parseAsm(header_text), map_name); + return header->value(5); +} + +QString Project::readMapLocation(QString map_name) { + if (map_cache->contains(map_name)) { + return map_cache->value(map_name)->location; + } + + ParseUtil *parser = new ParseUtil; + + QString header_text = readTextFile(root + "/data/maps/" + map_name + "/header.inc"); + if (header_text.isNull()) { + return QString::null; + } + QStringList *header = getLabelValues(parser->parseAsm(header_text), map_name); + return header->value(6); +} + void Project::setNewMapHeader(Map* map, int mapIndex) { map->layout_label = QString("%1_Layout").arg(map->name); map->events_label = QString("%1_MapEvents").arg(map->name);; @@ -961,9 +991,9 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { int num_metatiles = tileset->metatiles->count(); int num_metatileAttrs = data.length() / 2; if (num_metatiles != num_metatileAttrs) { - qDebug() << QString("Metatile count %1 does not match metatile attribute count %2").arg(num_metatiles).arg(num_metatileAttrs); - if (num_metatiles > num_metatileAttrs) - num_metatiles = num_metatileAttrs; + qDebug() << QString("Metatile count %1 does not match metatile attribute count %2 in %3").arg(num_metatiles).arg(num_metatileAttrs).arg(tileset->name); + if (num_metatileAttrs > num_metatiles) + num_metatileAttrs = num_metatiles; } for (int i = 0; i < num_metatileAttrs; i++) { int value = (static_cast(data.at(i * 2 + 1)) << 8) | static_cast(data.at(i * 2));