diff --git a/include/ui/tileseteditortileselector.h b/include/ui/tileseteditortileselector.h index 8109cd88..eb4fc7d6 100644 --- a/include/ui/tileseteditortileselector.h +++ b/include/ui/tileseteditortileselector.h @@ -24,7 +24,7 @@ public: void setPaletteId(int); void setTileFlips(bool, bool); QList getSelectedTiles(); - void setExternalSelection(int, int, QList); + void setExternalSelection(int, int, QList, QList); QPoint getTileCoordsOnWidget(uint16_t); QImage buildPrimaryTilesIndexedImage(); QImage buildSecondaryTilesIndexedImage(); @@ -41,6 +41,7 @@ private: int externalSelectionWidth; int externalSelectionHeight; QList externalSelectedTiles; + QList externalSelectedPos; Tileset *primaryTileset; Tileset *secondaryTileset; diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index d61415c5..b11cfa9e 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -328,6 +328,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) { void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int width, int height) { QList tiles; + QList tileIdxs; int x = selectionOrigin.x(); int y = selectionOrigin.y(); bool isTripleLayerMetatile = projectConfig.getTripleLayerMetatilesEnabled(); @@ -337,13 +338,14 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int int tileIndex = ((x + i) / 2 * 4) + ((y + j) * 2) + ((x + i) % 2); if (tileIndex < maxTileIndex) { tiles.append(this->metatile->tiles->at(tileIndex)); + tileIdxs.append(tileIndex); } } } if (width == 1 && height == 1) ui->spinBox_paletteSelector->setValue(tiles[0].palette); - this->tileSelector->setExternalSelection(width, height, tiles); + this->tileSelector->setExternalSelection(width, height, tiles, tileIdxs); this->metatileLayersItem->clearLastModifiedCoords(); } diff --git a/src/ui/tileseteditortileselector.cpp b/src/ui/tileseteditortileselector.cpp index 8bd6dcfa..78349c63 100644 --- a/src/ui/tileseteditortileselector.cpp +++ b/src/ui/tileseteditortileselector.cpp @@ -128,7 +128,8 @@ QList TilesetEditorTileSelector::buildSelectedTiles(int width, int height, // If we've completed a layer row, or its the last tile of an incompletely // selected layer, then append the layer row to the full row - if (layerRow.length() == 2 || (width % 2 && i == width - 1)) { + // If not an external selection, treat the whole row as 1 "layer" + if (i == width - 1 || (this->externalSelection && (this->externalSelectedPos.at(index) % 4) & 1)) { row.append(layerRow); layerRow.clear(); } @@ -146,16 +147,15 @@ QList TilesetEditorTileSelector::buildSelectedTiles(int width, int height, return tiles; } -void TilesetEditorTileSelector::setExternalSelection(int width, int height, QList tiles) { +void TilesetEditorTileSelector::setExternalSelection(int width, int height, QList tiles, QList tileIdxs) { this->externalSelection = true; this->paletteChanged = false; this->externalSelectionWidth = width; this->externalSelectionHeight = height; this->externalSelectedTiles.clear(); - for (int i = 0; i < tiles.length(); i++) { - this->externalSelectedTiles.append(tiles.at(i)); - } - + this->externalSelectedTiles.append(tiles); + this->externalSelectedPos.clear(); + this->externalSelectedPos.append(tileIdxs); this->draw(); emit selectedTilesChanged(); }