diff --git a/forms/regionmapeditor.ui b/forms/regionmapeditor.ui index 3eda7dcd..0cba8783 100644 --- a/forms/regionmapeditor.ui +++ b/forms/regionmapeditor.ui @@ -1092,7 +1092,10 @@ + + + @@ -1147,6 +1150,16 @@ Swap... + + + Reset Image + + + + + Reset Layout + + diff --git a/include/core/regionmap.h b/include/core/regionmap.h index e9bf94bc..96838fc7 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -70,6 +70,8 @@ public: void resize(int width, int height); void resetSquare(int index); + void resetLayout(); + void resetImage(); void replaceSectionId(unsigned oldId, unsigned newId); int width(); diff --git a/include/project.h b/include/project.h index b4270bff..c1d55ff0 100644 --- a/include/project.h +++ b/include/project.h @@ -29,7 +29,9 @@ public: QString layoutsLabel; QMap mapLayouts; QMap mapLayoutsMaster; - QStringList *regionMapSections = nullptr; + QMap *mapSecToMapHoverName; + QMap mapSectionNameToValue; + QMap mapSectionValueToName; QStringList *itemNames = nullptr; QStringList *flagNames = nullptr; QStringList *varNames = nullptr; @@ -47,8 +49,6 @@ public: Map* loadMap(QString); Map* getMap(QString); - QMap *mapSecToMapHoverName; - QMap *tileset_cache = nullptr; Tileset* loadTileset(QString, Tileset *tileset = nullptr); Tileset* getTileset(QString, bool forceLoad = false); diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index de2a8cfc..1d8301e1 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -92,6 +92,8 @@ private slots: void on_action_RegionMap_Undo_triggered(); void on_action_RegionMap_Redo_triggered(); void on_action_RegionMap_Resize_triggered(); + void on_action_RegionMap_ResetImage_triggered(); + void on_action_RegionMap_ResetLayout_triggered(); void on_action_Swap_triggered(); void on_action_RegionMap_Generate_triggered(); void on_tabWidget_Region_Map_currentChanged(int); diff --git a/src/config.cpp b/src/config.cpp index 32ad12fe..e689b91e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -260,7 +260,7 @@ void PorymapConfig::setShowCursorTile(bool enabled) { } void PorymapConfig::setRegionMapDimensions(int width, int height) { - this->regionMapDimensions = QSize(width, height);//QString("%1x%2").arg(width).arg(height); + this->regionMapDimensions = QSize(width, height); } QString PorymapConfig::getRecentProject() { diff --git a/src/core/regionmap.cpp b/src/core/regionmap.cpp index ab8609de..41212fa1 100644 --- a/src/core/regionmap.cpp +++ b/src/core/regionmap.cpp @@ -116,8 +116,9 @@ void RegionMap::readLayout() { for (int y = 0; y < layout_height_; y++) { for (int x = 0; x < layout_width_; x++) { int i = img_index_(x,y); - map_squares[i].secid = static_cast(mapBinData.at(layout_index_(x,y))); - QString secname = (*(project->regionMapSections))[static_cast(mapBinData.at(layout_index_(x,y)))]; + uint8_t id = static_cast(mapBinData.at(layout_index_(x,y))); + map_squares[i].secid = id; + QString secname = project->mapSectionValueToName.value(id); if (secname != "MAPSEC_NONE") map_squares[i].has_map = true; map_squares[i].mapsec = secname; map_squares[i].map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name); @@ -140,7 +141,7 @@ void RegionMap::saveLayout() { entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n"; - for (auto sec : *(project->regionMapSections)) { + for (auto sec : project->mapSectionNameToValue.keys()) { if (!mapSecToMapEntry.contains(sec)) continue; struct RegionMapEntry entry = mapSecToMapEntry.value(sec); entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", " @@ -168,7 +169,7 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) { int index = getMapSquareIndex(x + this->padLeft, y + this->padTop); if (!sec.isEmpty()) { this->map_squares[index].has_map = sec == "MAPSEC_NONE" ? false : true; - this->map_squares[index].secid = static_cast(project->regionMapSections->indexOf(sec)); + this->map_squares[index].secid = static_cast(project->mapSectionNameToValue.value(sec)); this->map_squares[index].mapsec = sec; if (!name.isEmpty()) { this->map_squares[index].map_name = name; @@ -191,11 +192,20 @@ void RegionMap::resetSquare(int index) { this->map_squares[index].mapsec = "MAPSEC_NONE"; this->map_squares[index].map_name = QString(); this->map_squares[index].has_map = false; - this->map_squares[index].secid = static_cast(project->regionMapSections->indexOf("MAPSEC_NONE")); + this->map_squares[index].secid = static_cast(project->mapSectionNameToValue.value("MAPSEC_NONE")); this->map_squares[index].has_city_map = false; this->map_squares[index].city_map_name = QString(); this->map_squares[index].duplicated = false; - logInfo(QString("Reset map square at (%1, %2).").arg(this->map_squares[index].x).arg(this->map_squares[index].y)); +} + +void RegionMap::resetLayout() { + for (int i = 0; i < map_squares.size(); i++) + resetSquare(i); +} + +void RegionMap::resetImage() { + for (int i = 0; i < map_squares.size(); i++) + this->map_squares[i].tile_img_id = 0x00; } void RegionMap::replaceSectionId(unsigned oldId, unsigned newId) { @@ -203,7 +213,7 @@ void RegionMap::replaceSectionId(unsigned oldId, unsigned newId) { if (square.secid == oldId) { square.has_map = false; square.secid = newId; - QString secname = (*(project->regionMapSections))[newId]; + QString secname = project->mapSectionValueToName.value(newId); if (secname != "MAPSEC_NONE") square.has_map = true; square.mapsec = secname; square.map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 382e6399..07c62fdc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -469,7 +469,7 @@ void MainWindow::displayMapProperties() { ui->comboBox_Song->addItems(songs); ui->comboBox_Song->setCurrentText(map->song); - ui->comboBox_Location->addItems(*project->regionMapSections); + ui->comboBox_Location->addItems(project->mapSectionValueToName.values()); ui->comboBox_Location->setCurrentText(map->location); QMap tilesets = project->getTilesets(); @@ -661,8 +661,8 @@ void MainWindow::sortMapList() { case MapSortOrder::Area: { QMap mapsecToGroupNum; - for (int i = 0; i < project->regionMapSections->length(); i++) { - QString mapsec_name = project->regionMapSections->value(i); + 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); @@ -1979,21 +1979,6 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); } -void MainWindow::on_pushButton_RM_Options_save_clicked() { - this->editor->region_map->saveOptions( - this->editor->region_map_layout_item->selectedTile, - this->ui->comboBox_RM_ConnectedMap->currentText(), - this->ui->lineEdit_RM_MapName->text(), - this->ui->spinBox_RM_Options_x->value(), - this->ui->spinBox_RM_Options_y->value() - ); - this->editor->region_map_layout_item->draw(); -} - -void MainWindow::on_pushButton_CityMap_save_clicked() { - this->editor->city_map_item->save(); -} - void MainWindow::on_actionRegion_Map_Editor_triggered() { if (!this->regionMapEditor) { this->regionMapEditor = new RegionMapEditor(this, this->editor->project); diff --git a/src/project.cpp b/src/project.cpp index d763efba..79c15d60 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -31,7 +31,6 @@ Project::Project() groupNames = new QStringList; map_groups = new QMap; mapNames = new QStringList; - regionMapSections = new QStringList; itemNames = new QStringList; flagNames = new QStringList; varNames = new QStringList; @@ -1510,8 +1509,18 @@ void Project::readTilesetProperties() { void Project::readRegionMapSections() { QString filepath = root + "/include/constants/region_map_sections.h"; - QStringList prefixes = (QStringList() << "MAPSEC_"); - readCDefinesSorted(filepath, prefixes, regionMapSections); + this->mapSectionNameToValue.clear(); + this->mapSectionValueToName.clear(); + QString text = readTextFile(filepath); + if (!text.isNull()) { + QStringList prefixes = (QStringList() << "MAPSEC_"); + this->mapSectionNameToValue = readCDefines(text, prefixes); + for (QString defineName : this->mapSectionNameToValue.keys()) { + this->mapSectionValueToName.insert(this->mapSectionNameToValue[defineName], defineName); + } + } else { + logError(QString("Failed to read C defines file: '%1'").arg(filepath)); + } } void Project::readItemNames() { diff --git a/src/ui/citymappixmapitem.cpp b/src/ui/citymappixmapitem.cpp index bbe31f65..3d0eb2ca 100644 --- a/src/ui/citymappixmapitem.cpp +++ b/src/ui/citymappixmapitem.cpp @@ -54,9 +54,6 @@ void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) { } void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - QPointF pos = event->pos(); - int x = static_cast(pos.x()) / 8; - int y = static_cast(pos.y()) / 8; emit mouseEvent(event, this); } diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 6978932b..941ddd44 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -70,7 +70,7 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { } ui->comboBox_NewMap_Type->addItems(*project->mapTypes); - ui->comboBox_NewMap_Location->addItems(*project->regionMapSections); + ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec); ui->frame_NewMap_Options->setEnabled(true); diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 793a00bf..fa2ef5c0 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) : @@ -41,8 +40,6 @@ RegionMapEditor::~RegionMapEditor() void RegionMapEditor::on_action_RegionMap_Save_triggered() { if (project && region_map) { - region_map->save(); - this->city_map_item->save(); this->region_map->saveOptions( this->region_map_layout_item->selectedTile, this->ui->comboBox_RM_ConnectedMap->currentText(), @@ -50,6 +47,8 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() { this->ui->spinBox_RM_Options_x->value(), this->ui->spinBox_RM_Options_y->value() ); + this->region_map->save(); + this->city_map_item->save(); this->currIndex = this->region_map_layout_item->highlightedTile; this->region_map_layout_item->highlightedTile = -1; displayRegionMap(); @@ -144,7 +143,7 @@ void RegionMapEditor::displayRegionMapLayout() { void RegionMapEditor::displayRegionMapLayoutOptions() { this->ui->comboBox_RM_ConnectedMap->clear(); - this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections)); + this->ui->comboBox_RM_ConnectedMap->addItems(this->project->mapSectionValueToName.values()); this->ui->frame_RM_Options->setEnabled(true); @@ -567,10 +566,10 @@ void RegionMapEditor::on_action_Swap_triggered() { QFormLayout form(&popup); QComboBox *oldSecBox = new QComboBox(); - oldSecBox->addItems(*(this->project->regionMapSections)); + oldSecBox->addItems(this->project->mapSectionValueToName.values()); form.addRow(new QLabel("Old Map Section:"), oldSecBox); QComboBox *newSecBox = new QComboBox(); - newSecBox->addItems(*(this->project->regionMapSections)); + newSecBox->addItems(this->project->mapSectionValueToName.values()); form.addRow(new QLabel("New Map Section:"), newSecBox); QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup); @@ -584,8 +583,8 @@ void RegionMapEditor::on_action_Swap_triggered() { beforeSection = oldSecBox->currentText(); afterSection = newSecBox->currentText(); if (!beforeSection.isEmpty() && !afterSection.isEmpty()) { - oldId = static_cast(project->regionMapSections->indexOf(beforeSection)); - newId = static_cast(project->regionMapSections->indexOf(afterSection)); + oldId = static_cast(this->project->mapSectionNameToValue.value(beforeSection)); + newId = static_cast(this->project->mapSectionNameToValue.value(afterSection)); popup.accept(); } }); @@ -598,6 +597,41 @@ void RegionMapEditor::on_action_Swap_triggered() { } } +void RegionMapEditor::on_action_RegionMap_ResetImage_triggered() { + QMessageBox::StandardButton result = QMessageBox::question( + this, + "WARNING", + "This action will reset the entire map image to metatile 0x00, continue?", + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Yes + ); + + if (result == QMessageBox::Yes) { + this->region_map->resetImage(); + displayRegionMapImage(); + displayRegionMapLayout(); + } else { + return; + } +} + +void RegionMapEditor::on_action_RegionMap_ResetLayout_triggered() { + QMessageBox::StandardButton result = QMessageBox::question( + this, + "WARNING", + "This action will reset the entire map layout to MAPSEC_NONE, continue?", + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Yes + ); + + if (result == QMessageBox::Yes) { + this->region_map->resetLayout(); + displayRegionMapLayout(); + } else { + return; + } +} + void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) { this->displayCityMap(file); this->cityMapFirstDraw = true; diff --git a/src/ui/regionmappixmapitem.cpp b/src/ui/regionmappixmapitem.cpp index 976d1ae9..5488ca4c 100644 --- a/src/ui/regionmappixmapitem.cpp +++ b/src/ui/regionmappixmapitem.cpp @@ -50,9 +50,6 @@ void RegionMapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { } void RegionMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - QPointF pos = event->pos(); - int x = static_cast(pos.x()) / 8; - int y = static_cast(pos.y()) / 8; emit mouseEvent(event, this); }