diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 6f9e1f9c..0f42fff3 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2742,6 +2742,7 @@ + diff --git a/include/ui/newmappopup.h b/include/ui/newmappopup.h index 13c4dfe5..f92c0903 100644 --- a/include/ui/newmappopup.h +++ b/include/ui/newmappopup.h @@ -35,6 +35,7 @@ private: Project *project; void setDefaultValues(int, QString); void setDefaultValuesImportMap(MapLayout *); + void setDefaultValuesProjectConfig(bool, MapLayout*); bool checkNewMapDimensions(); private slots: diff --git a/src/core/mapparser.cpp b/src/core/mapparser.cpp index b9f9fab4..5f9b05d4 100644 --- a/src/core/mapparser.cpp +++ b/src/core/mapparser.cpp @@ -5,7 +5,6 @@ MapParser::MapParser() { - } MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) @@ -48,23 +47,6 @@ MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) (static_cast(in.at(14)) << 16) | (static_cast(in.at(15)) << 24); - /*int maxMetatiles = primaryTileset ? Project::getNumMetatilesPrimary() : Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary(); - int numMetatiles = static_cast(in.at(0)) | - (static_cast(in.at(1)) << 8) | - (static_cast(in.at(2)) << 16) | - (static_cast(in.at(3)) << 24); - if (numMetatiles > maxMetatiles) { - *error = true; - logError(QString(".bvd file contains data for %1 metatiles, but the maximum number of metatiles is %2.").arg(numMetatiles).arg(maxMetatiles)); - return nullptr; - } - - if (numMetatiles < 1) { - *error = true; - logError(QString(".bvd file contains no data for metatiles.")); - return nullptr; - }*/ - int numMetatiles = mapWidth * mapHeight; int expectedFileSize = 20 + (numBorderTiles * 2) + (numMetatiles * 2); if (in.length() != expectedFileSize) { @@ -82,7 +64,7 @@ MapLayout *MapParser::parse(QString filepath, bool *error, Project *project) Blockdata *border = nullptr; if (numBorderTiles != 0) { border = new Blockdata(); - for (int i = 20; (i + 1) < 20 + (numBorderTiles * 2); i += 2) { + for (int i = 20; (i + 1) < mapDataOffset; i += 2) { uint16_t word = static_cast((in[i] & 0xff) + ((in[i + 1] & 0xff) << 8)); border->addBlock(word); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f4465c6a..059c3f68 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2368,22 +2368,6 @@ void MainWindow::importMapFromAdvanceMap1_92() return; } - // TODO: This is crude because it makes a history entry for every newly-imported metatile. - // Revisit this when tiles and num metatiles are added to tileset editory history. - /* int metatileIdBase = primary ? 0 : Project::getNumMetatilesPrimary(); - for (int i = 0; i < metatiles->length(); i++) { - if (i >= tileset->metatiles->length()) { - break; - } - - Metatile *prevMetatile = tileset->metatiles->at(i)->copy(); - MetatileHistoryItem *commit = new MetatileHistoryItem(static_cast(metatileIdBase + i), prevMetatile, metatiles->at(i)->copy()); - metatileHistory.push(commit); - }*/ - - //tileset->metatiles = metatiles; - //this->refresh(); - //this->hasUnsavedChanges = true; openNewMapPopupWindowImportMap(mapLayout); } diff --git a/src/project.cpp b/src/project.cpp index 0997977c..70629725 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1912,8 +1912,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool mapGroups->insert(mapName, groupNum); groupedMapNames[groupNum].append(mapName); - Map *map = new Map; - map = newMap; + Map *map = newMap; map->isPersistedToFile = false; map->setName(mapName); @@ -1923,11 +1922,7 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool if (!existingLayout) { mapLayouts.insert(map->layoutId, map->layout); mapLayoutsTable.append(map->layoutId); - if (importedMap) { - map->layout->lastCommitMapBlocks.blocks = new Blockdata; - map->layout->lastCommitMapBlocks.blocks->copyFrom(map->layout->blockdata); - map->layout->lastCommitMapBlocks.dimensions = QSize(map->getWidth(), map->getHeight()); - } else { + if (!importedMap) { setNewMapBlockdata(map); } if (map->layout->border == nullptr) { diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 04d82410..dcf667cd 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -124,51 +124,7 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->frame_NewMap_Options->setEnabled(true); - switch (projectConfig.getBaseGameVersion()) - { - case BaseGameVersion::pokeruby: - ui->checkBox_NewMap_Allow_Running->setVisible(false); - ui->checkBox_NewMap_Allow_Biking->setVisible(false); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(false); - ui->label_NewMap_Allow_Running->setVisible(false); - ui->label_NewMap_Allow_Biking->setVisible(false); - ui->label_NewMap_Allow_Escape_Rope->setVisible(false); - break; - case BaseGameVersion::pokeemerald: - ui->checkBox_NewMap_Allow_Running->setVisible(true); - ui->checkBox_NewMap_Allow_Biking->setVisible(true); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(true); - ui->label_NewMap_Allow_Running->setVisible(true); - ui->label_NewMap_Allow_Biking->setVisible(true); - ui->label_NewMap_Allow_Escape_Rope->setVisible(true); - break; - case BaseGameVersion::pokefirered: - ui->checkBox_NewMap_Allow_Running->setVisible(true); - ui->checkBox_NewMap_Allow_Biking->setVisible(true); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(true); - ui->label_NewMap_Allow_Running->setVisible(true); - ui->label_NewMap_Allow_Biking->setVisible(true); - ui->label_NewMap_Allow_Escape_Rope->setVisible(true); - break; - } - if (projectConfig.getUseCustomBorderSize()) { - ui->spinBox_NewMap_BorderWidth->setVisible(true); - ui->spinBox_NewMap_BorderHeight->setVisible(true); - ui->label_NewMap_BorderWidth->setVisible(true); - ui->label_NewMap_BorderHeight->setVisible(true); - } else { - ui->spinBox_NewMap_BorderWidth->setVisible(false); - ui->spinBox_NewMap_BorderHeight->setVisible(false); - ui->label_NewMap_BorderWidth->setVisible(false); - ui->label_NewMap_BorderHeight->setVisible(false); - } - if (projectConfig.getFloorNumberEnabled()) { - ui->spinBox_NewMap_Floor_Number->setVisible(true); - ui->label_NewMap_Floor_Number->setVisible(true); - } else { - ui->spinBox_NewMap_Floor_Number->setVisible(false); - ui->label_NewMap_Floor_Number->setVisible(false); - } + setDefaultValuesProjectConfig(false, NULL); } void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { @@ -192,6 +148,18 @@ void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { ui->frame_NewMap_Options->setEnabled(true); + setDefaultValuesProjectConfig(true, mapLayout); + + map = new Map(); + map->layout = new MapLayout(); + map->layout->blockdata = mapLayout->blockdata->copy(); + + if (mapLayout->border != nullptr) { + map->layout->border = mapLayout->border->copy(); + } +} + +void NewMapPopup::setDefaultValuesProjectConfig(bool importedMap, MapLayout *mapLayout) { switch (projectConfig.getBaseGameVersion()) { case BaseGameVersion::pokeruby: @@ -220,15 +188,19 @@ void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { break; } if (projectConfig.getUseCustomBorderSize()) { - ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width.toInt(nullptr, 0)); - ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height.toInt(nullptr, 0)); + if (importedMap) { + ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width.toInt(nullptr, 0)); + ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height.toInt(nullptr, 0)); + } ui->spinBox_NewMap_BorderWidth->setVisible(true); ui->spinBox_NewMap_BorderHeight->setVisible(true); ui->label_NewMap_BorderWidth->setVisible(true); ui->label_NewMap_BorderHeight->setVisible(true); } else { - ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); - ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); + if (importedMap) { + ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); + ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); + } ui->spinBox_NewMap_BorderWidth->setVisible(false); ui->spinBox_NewMap_BorderHeight->setVisible(false); ui->label_NewMap_BorderWidth->setVisible(false); @@ -241,14 +213,6 @@ void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { ui->spinBox_NewMap_Floor_Number->setVisible(false); ui->label_NewMap_Floor_Number->setVisible(false); } - - map = new Map(); - map->layout = new MapLayout(); - map->layout->blockdata = mapLayout->blockdata->copy(); - - if (mapLayout->border != nullptr) { - map->layout->border = mapLayout->border->copy(); - } } void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) { @@ -288,7 +252,7 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() { if (this->existingLayout) { layout = this->project->mapLayouts.value(this->layoutId); - newMap->needsLayoutDir = false; + newMap->needsLayoutDir = false; } else { layout = new MapLayout; layout->id = MapLayout::layoutConstantFromName(newMapName);