From 023be7f5415e299ae8f77f3af3c385881b36ed3f Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 13 Jul 2020 02:46:54 -0400 Subject: [PATCH] Respect x/y flip and palette for external tileset editor tile selections --- include/ui/tileseteditortileselector.h | 3 +- src/ui/tileseteditortileselector.cpp | 57 +++++++++++++------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/include/ui/tileseteditortileselector.h b/include/ui/tileseteditortileselector.h index 38347b39..3effca8c 100644 --- a/include/ui/tileseteditortileselector.h +++ b/include/ui/tileseteditortileselector.h @@ -39,7 +39,7 @@ private: bool externalSelection; int externalSelectionWidth; int externalSelectionHeight; - QList externalSelectedTiles; + QList externalSelectedTiles; Tileset *primaryTileset; Tileset *secondaryTileset; @@ -52,6 +52,7 @@ private: uint16_t getTileId(int x, int y); QPoint getTileCoords(uint16_t); QList getCurPaletteTable(); + QList buildSelectedTiles(int, int, QList); signals: void hoveredTileChanged(uint16_t); diff --git a/src/ui/tileseteditortileselector.cpp b/src/ui/tileseteditortileselector.cpp index ea736868..4be3ccfa 100644 --- a/src/ui/tileseteditortileselector.cpp +++ b/src/ui/tileseteditortileselector.cpp @@ -95,45 +95,46 @@ void TilesetEditorTileSelector::updateSelectedTiles() { QList TilesetEditorTileSelector::getSelectedTiles() { if (this->externalSelection) { - return this->externalSelectedTiles; + return buildSelectedTiles(this->externalSelectionWidth, this->externalSelectionHeight, this->externalSelectedTiles); } else { - QList tiles; - QList> tileMatrix; - QList selected = this->selectedTiles; QPoint dimensions = this->getSelectionDimensions(); - int width = dimensions.x(); - int height = dimensions.y(); - for (int j = 0; j < height; j++) { - QList row; - for (int i = 0; i < width; i++) { - int index = i + j * width; - uint16_t tile = selected.at(index); - if (this->xFlip) - row.prepend(Tile(tile, this->xFlip, this->yFlip, this->paletteId)); - else - row.append(Tile(tile, this->xFlip, this->yFlip, this->paletteId)); - } - if (this->yFlip) - tileMatrix.prepend(row); - else - tileMatrix.append(row); - } - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - tiles.append(tileMatrix.at(j).at(i)); - } - } - return tiles; + return buildSelectedTiles(dimensions.x(), dimensions.y(), this->selectedTiles); } } +QList TilesetEditorTileSelector::buildSelectedTiles(int width, int height, QList selected) { + QList tiles; + QList> tileMatrix; + for (int j = 0; j < height; j++) { + QList row; + for (int i = 0; i < width; i++) { + int index = i + j * width; + uint16_t tile = selected.at(index); + if (this->xFlip) + row.prepend(Tile(tile, this->xFlip, this->yFlip, this->paletteId)); + else + row.append(Tile(tile, this->xFlip, this->yFlip, this->paletteId)); + } + if (this->yFlip) + tileMatrix.prepend(row); + else + tileMatrix.append(row); + } + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + tiles.append(tileMatrix.at(j).at(i)); + } + } + return tiles; +} + void TilesetEditorTileSelector::setExternalSelection(int width, int height, QList tiles) { this->externalSelection = true; 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.at(i).tile); } this->draw();