Address review comments.

This commit is contained in:
ultima-soul 2021-07-23 16:20:41 -07:00
parent 8575b83212
commit cdcf535894
6 changed files with 27 additions and 100 deletions

View file

@ -2742,6 +2742,7 @@
<addaction name="actionNew_Tileset"/>
<addaction name="actionTileset_Editor"/>
<addaction name="actionRegion_Map_Editor"/>
<addaction name="separator"/>
<addaction name="actionImport_Map_from_Advance_Map_1_92"/>
</widget>
<widget class="QMenu" name="menuHelp">

View file

@ -35,6 +35,7 @@ private:
Project *project;
void setDefaultValues(int, QString);
void setDefaultValuesImportMap(MapLayout *);
void setDefaultValuesProjectConfig(bool, MapLayout*);
bool checkNewMapDimensions();
private slots:

View file

@ -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<unsigned char>(in.at(14)) << 16) |
(static_cast<unsigned char>(in.at(15)) << 24);
/*int maxMetatiles = primaryTileset ? Project::getNumMetatilesPrimary() : Project::getNumMetatilesTotal() - Project::getNumMetatilesPrimary();
int numMetatiles = static_cast<unsigned char>(in.at(0)) |
(static_cast<unsigned char>(in.at(1)) << 8) |
(static_cast<unsigned char>(in.at(2)) << 16) |
(static_cast<unsigned char>(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<uint16_t>((in[i] & 0xff) + ((in[i + 1] & 0xff) << 8));
border->addBlock(word);
}

View file

@ -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<uint16_t>(metatileIdBase + i), prevMetatile, metatiles->at(i)->copy());
metatileHistory.push(commit);
}*/
//tileset->metatiles = metatiles;
//this->refresh();
//this->hasUnsavedChanges = true;
openNewMapPopupWindowImportMap(mapLayout);
}

View file

@ -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) {

View file

@ -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) {