diff --git a/include/core/maplayout.h b/include/core/maplayout.h index eabe2c8e..1e809c13 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -19,14 +19,12 @@ class Layout : public QObject { public: Layout() {} + void copyAttributesFrom(Layout *other); + static QString layoutConstantFromName(QString mapName); bool loaded = false; - /// !TODO - /* NEW */ - QList maps; - QString id; QString name; @@ -126,6 +124,4 @@ signals: void needsRedrawing(); }; -using MapLayout = Layout; - #endif // MAPLAYOUT_H diff --git a/include/editor.h b/include/editor.h index 29709df8..d6d973b5 100644 --- a/include/editor.h +++ b/include/editor.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "mapconnection.h" #include "metatileselector.h" @@ -45,8 +46,8 @@ public: QObject *parent = nullptr; Project *project = nullptr; - Map *map = nullptr; - Layout *layout = nullptr; /* NEW */ + QPointer map = nullptr; // !TODO: since removed onMapCacheCleared, make sure this works as intended + QPointer layout = nullptr; /* NEW */ QUndoGroup editGroup; // Manages the undo history for each map diff --git a/include/mainwindow.h b/include/mainwindow.h index 52773f5e..522bf0f2 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -187,7 +187,6 @@ private slots: void onWildMonDataChanged(); void openNewMapPopupWindow(); void onNewMapCreated(); - void onMapCacheCleared(); void importMapFromAdvanceMap1_92(); void onMapRulerStatusChanged(const QString &); void applyUserShortcuts(); diff --git a/include/project.h b/include/project.h index ddffe49b..9a58905f 100644 --- a/include/project.h +++ b/include/project.h @@ -58,7 +58,7 @@ public: QString layoutsLabel; QMap layoutIdsToNames; QMap mapLayouts; - QMap mapLayoutsMaster; +// QMap mapLayoutsMaster; QMap mapSecToMapHoverName; QMap mapSectionNameToValue; QMap mapSectionValueToName; @@ -95,6 +95,7 @@ public: void clearMapCache(); void clearTilesetCache(); + void clearLayoutsTable(); struct DataQualifiers { @@ -265,7 +266,6 @@ private: signals: void reloadProject(); void uncheckMonitorFilesAction(); - void mapCacheCleared(); void disableWildEncountersUI(); }; diff --git a/resources/icons/minimap.ico b/resources/icons/minimap.ico index b9315712..548c7c8f 100644 Binary files a/resources/icons/minimap.ico and b/resources/icons/minimap.ico differ diff --git a/src/core/maplayout.cpp b/src/core/maplayout.cpp index 7002f908..1923cf3d 100644 --- a/src/core/maplayout.cpp +++ b/src/core/maplayout.cpp @@ -5,6 +5,55 @@ #include "scripting.h" #include "imageproviders.h" + // QString id; + // QString name; + + // int width; + // int height; + // int border_width; + // int border_height; + + // QString border_path; + // QString blockdata_path; + + // QString tileset_primary_label; + // QString tileset_secondary_label; + + // Tileset *tileset_primary = nullptr; + // Tileset *tileset_secondary = nullptr; + + // Blockdata blockdata; + + // QImage image; + // QPixmap pixmap; + // QImage border_image; + // QPixmap border_pixmap; + // QImage collision_image; + // QPixmap collision_pixmap; + + // Blockdata border; + // Blockdata cached_blockdata; + // Blockdata cached_collision; + // Blockdata cached_border; + // struct { + // Blockdata blocks; + // QSize mapDimensions; + // Blockdata border; + // QSize borderDimensions; + // } lastCommitBlocks; // to track map changes + + // QList metatileLayerOrder; + // QList metatileLayerOpacity; + + // LayoutPixmapItem *layoutItem = nullptr; + // CollisionPixmapItem *collisionItem = nullptr; + // BorderMetatilesPixmapItem *borderItem = nullptr; + + // QUndoStack editHistory; +void Layout::copyAttributesFrom(Layout *other) { + // +} + QString Layout::layoutConstantFromName(QString mapName) { // Transform map names of the form 'GraniteCave_B1F` into layout constants like 'LAYOUT_GRANITE_CAVE_B1F'. static const QRegularExpression caseChange("([a-z])([A-Z])"); diff --git a/src/core/mapparser.cpp b/src/core/mapparser.cpp index 986c2c24..3d4258bd 100644 --- a/src/core/mapparser.cpp +++ b/src/core/mapparser.cpp @@ -7,7 +7,7 @@ MapParser::MapParser() { } -MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) +Layout *MapParser::parse(QString filepath, bool *error, Project *project) { QFile file(filepath); if (!file.open(QIODevice::ReadOnly)) { @@ -69,7 +69,7 @@ MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) } } - MapLayout *mapLayout = new MapLayout(); + Layout *mapLayout = new Layout(); mapLayout->width = mapWidth; mapLayout->height = mapHeight; mapLayout->border_width = (borderWidth == 0) ? DEFAULT_BORDER_WIDTH : borderWidth; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b182782f..25e73e73 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -377,6 +377,15 @@ void MainWindow::showWindowTitle() { .arg(editor->project->getProjectTitle()) ); } + if (editor && editor->layout) { + // // QPixmap pixmap = editor->layout ? editor->layout->render(true) : QPixmap(); + QPixmap pixmap = editor->layout ? editor->layout->render(false) : QPixmap(); + if (!pixmap.isNull()) { + ui->mainTabBar->setTabIcon(0, QIcon(pixmap.scaled(16, 16))); + } else { + ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); + } + } } void MainWindow::markMapEdited() { @@ -449,6 +458,7 @@ void MainWindow::applyMapListFilter(QString filterText) { } /// !TODO + // ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false); // ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true); // ui->mapList->scrollTo(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), QAbstractItemView::PositionAtCenter); } @@ -541,7 +551,6 @@ bool MainWindow::openProject(QString dir) { editor->closeProject(); editor->project = new Project(this); QObject::connect(editor->project, &Project::reloadProject, this, &MainWindow::on_action_Reload_Project_triggered); - QObject::connect(editor->project, &Project::mapCacheCleared, this, &MainWindow::onMapCacheCleared); QObject::connect(editor->project, &Project::disableWildEncountersUI, [this]() { this->setWildEncountersUIEnabled(false); }); QObject::connect(editor->project, &Project::uncheckMonitorFilesAction, [this]() { porymapConfig.setMonitorFiles(false); @@ -555,6 +564,7 @@ bool MainWindow::openProject(QString dir) { } else { QString open_map = editor->map->name; editor->project->fileWatcher.removePaths(editor->project->fileWatcher.files()); + editor->project->clearLayoutsTable(); editor->project->clearMapCache(); editor->project->clearTilesetCache(); success = loadDataStructures() && populateMapList() && setMap(open_map, true); @@ -701,6 +711,8 @@ bool MainWindow::setMap(QString map_name, bool scroll) { this->ui->mainTabBar->setTabEnabled(3, true); this->ui->mainTabBar->setTabEnabled(4, true); + this->ui->comboBox_LayoutSelector->setEnabled(true); + refreshMapScene(); displayMapProperties(); @@ -1129,111 +1141,6 @@ void MainWindow::scrollTreeView(QString itemName) { } void MainWindow::sortMapList() { - // Project *project = editor->project; - - // QIcon mapFolderIcon; - // mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off); - // mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On); - - // 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); - - // ui->mapList->setUpdatesEnabled(false); - // mapListModel->clear(); - // mapGroupItemsList->clear(); - // QStandardItem *root = mapListModel->invisibleRootItem(); - - // switch (mapSortOrder) - // { - // case MapSortOrder::SortByGroup: - // 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::SortByArea: - // { - // QMap mapsecToGroupNum; - // for (int i = 0; i < project->mapSectionNameToValue.size(); i++) { - // QString mapsec_name = project->mapSectionValueToName.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::SortByLayout: - // { - // QMap layoutIndices; - // for (int i = 0; i < project->mapLayoutsTable.length(); i++) { - // QString layoutId = project->mapLayoutsTable.value(i); - // MapLayout *layout = project->mapLayouts.value(layoutId); - // QStandardItem *layoutItem = new QStandardItem; - // layoutItem->setText(layout->name); - // layoutItem->setIcon(folderIcon); - // layoutItem->setEditable(false); - // layoutItem->setData(layout->name, Qt::UserRole); - // layoutItem->setData("map_layout", MapListUserRoles::TypeRole); - // layoutItem->setData(layout->id, MapListUserRoles::TypeRole2); - // layoutItem->setData(i, MapListUserRoles::GroupRole); - // root->appendRow(layoutItem); - // mapGroupItemsList->append(layoutItem); - // layoutIndices[layoutId] = 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 layoutId = project->readMapLayoutId(map_name); - // QStandardItem *layoutItem = mapGroupItemsList->at(layoutIndices.value(layoutId)); - // layoutItem->setIcon(mapFolderIcon); - // layoutItem->appendRow(map); - // mapListIndexes.insert(map_name, map->index()); - // } - // } - // break; - // } - // } - - // ui->mapList->setUpdatesEnabled(true); - // ui->mapList->repaint(); - // updateMapList(); } void MainWindow::onOpenMapListContextMenu(const QPoint &point) { @@ -2533,10 +2440,6 @@ void MainWindow::onLayoutNeedsRedrawing() { redrawLayoutScene(); } -void MainWindow::onMapCacheCleared() { - editor->map = nullptr; -} - void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryTilesetLabel) { // If saved tilesets are currently in-use, update them and redraw // Otherwise overwrite the cache for the saved tileset @@ -2612,7 +2515,7 @@ void MainWindow::importMapFromAdvanceMap1_92() this->editor->project->setImportExportPath(filepath); MapParser parser; bool error = false; - MapLayout *mapLayout = parser.parse(filepath, &error, editor->project); + Layout *mapLayout = parser.parse(filepath, &error, editor->project); if (error) { QMessageBox msgBox(this); msgBox.setText("Failed to import map from Advance Map 1.92 .map file."); diff --git a/src/project.cpp b/src/project.cpp index c203944c..f4672fab 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -45,6 +45,7 @@ Project::Project(QWidget *parent) : Project::~Project() { + clearLayoutsTable(); clearMapCache(); clearTilesetCache(); } @@ -108,7 +109,6 @@ void Project::clearMapCache() { delete map; } mapCache.clear(); - emit mapCacheCleared(); } void Project::clearTilesetCache() { @@ -119,6 +119,17 @@ void Project::clearTilesetCache() { tilesetCache.clear(); } +void Project::clearLayoutsTable() { + // clearMapLayouts + // QMap mapLayouts; + // QMap mapLayoutsMaster; + for (Layout *layout : mapLayouts.values()) { + if (layout) + delete layout; + } + mapLayouts.clear(); +} + Map* Project::loadMap(QString map_name) { Map *map; if (mapCache.contains(map_name)) { @@ -379,7 +390,7 @@ QString Project::readMapLocation(QString map_name) { return ParseUtil::jsonToQString(mapObj["region_map_section"]); } -bool Project::loadLayout(MapLayout *layout) { +bool Project::loadLayout(Layout *layout) { // !TODO: make sure this doesn't break anything, maybe do something better. new layouts work too? if (!layout->loaded) { // Force these to run even if one fails @@ -476,7 +487,7 @@ bool Project::readMapLayouts() { logError(QString("Layout %1 is missing field(s) in %2.").arg(i).arg(layoutsFilepath)); return false; } - MapLayout *layout = new MapLayout(); + Layout *layout = new Layout(); layout->id = ParseUtil::jsonToQString(layoutObj["id"]); if (layout->id.isEmpty()) { logError(QString("Missing 'id' value on layout %1 in %2").arg(i).arg(layoutsFilepath)); @@ -557,8 +568,6 @@ bool Project::readMapLayouts() { } // Deep copy - mapLayoutsMaster = mapLayouts; - mapLayoutsMaster.detach(); mapLayoutsTableMaster = mapLayoutsTable; mapLayoutsTableMaster.detach(); return true; @@ -578,7 +587,7 @@ void Project::saveMapLayouts() { bool useCustomBorderSize = projectConfig.getUseCustomBorderSize(); OrderedJson::array layoutsArr; for (QString layoutId : mapLayoutsTableMaster) { - MapLayout *layout = mapLayouts.value(layoutId); + Layout *layout = mapLayouts.value(layoutId); OrderedJson::object layoutObj; layoutObj["id"] = layout->id; layoutObj["name"] = layout->name; @@ -1046,7 +1055,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) { } } -bool Project::loadLayoutTilesets(MapLayout *layout) { +bool Project::loadLayoutTilesets(Layout *layout) { layout->tileset_primary = getTileset(layout->tileset_primary_label); if (!layout->tileset_primary) { QString defaultTileset = this->getDefaultPrimaryTilesetLabel(); @@ -1114,7 +1123,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) { return tileset; } -bool Project::loadBlockdata(MapLayout *layout) { +bool Project::loadBlockdata(Layout *layout) { QString path = QString("%1/%2").arg(root).arg(layout->blockdata_path); layout->blockdata = readBlockdata(path); layout->lastCommitBlocks.blocks = layout->blockdata; @@ -1143,7 +1152,7 @@ void Project::setNewMapBlockdata(Map *map) { map->layout->lastCommitBlocks.mapDimensions = QSize(width, height); } -bool Project::loadLayoutBorder(MapLayout *layout) { +bool Project::loadLayoutBorder(Layout *layout) { QString path = QString("%1/%2").arg(root).arg(layout->border_path); layout->border = readBlockdata(path); layout->lastCommitBlocks.border = layout->border; @@ -1361,10 +1370,10 @@ void Project::updateMapLayout(Map* map) { mapLayoutsTableMaster.append(map->layoutId); } - // !TODO + // !TODO: why is[was] this a deep copy?? // Deep copy - // MapLayout *layout = mapLayouts.value(map->layoutId); - // MapLayout *newLayout = new MapLayout(); + // Layout *layout = mapLayouts.value(map->layoutId); + // Layout *newLayout = new Layout(); // *newLayout = *layout; // mapLayoutsMaster.insert(map->layoutId, newLayout); } diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index eb3eae45..597d53d1 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -110,12 +110,12 @@ void NewMapPopup::init(MapSortOrder type, QVariant data) { } // Creating new map from AdvanceMap import -void NewMapPopup::init(MapLayout *mapLayout) { +void NewMapPopup::init(Layout *mapLayout) { this->importedMap = true; useLayoutSettings(mapLayout); this->map = new Map(); - this->map->layout = new MapLayout(); + this->map->layout = new Layout(); this->map->layout->blockdata = mapLayout->blockdata; if (!mapLayout->border.isEmpty()) { @@ -203,7 +203,7 @@ void NewMapPopup::saveSettings() { settings.floorNumber = ui->spinBox_NewMap_Floor_Number->value(); } -void NewMapPopup::useLayoutSettings(MapLayout *layout) { +void NewMapPopup::useLayoutSettings(Layout *layout) { if (!layout) return; settings.width = layout->width; settings.height = layout->height; @@ -241,7 +241,7 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() { return; } Map *newMap = new Map; - MapLayout *layout; + Layout *layout; // If map name is not unique, use default value. Also use only valid characters. // After stripping invalid characters, strip any leading digits. @@ -266,8 +266,8 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() { layout = this->project->mapLayouts.value(this->layoutId); newMap->needsLayoutDir = false; } else { - layout = new MapLayout; - layout->id = MapLayout::layoutConstantFromName(newMapName); + layout = new Layout; + layout->id = Layout::layoutConstantFromName(newMapName); layout->name = QString("%1_Layout").arg(newMap->name); layout->width = this->ui->spinBox_NewMap_Width->value(); layout->height = this->ui->spinBox_NewMap_Height->value();