Respect x/y flip and palette for external tileset editor tile selections

This commit is contained in:
GriffinR 2020-07-13 02:46:54 -04:00 committed by huderlem
parent c68e352bb1
commit 023be7f541
2 changed files with 31 additions and 29 deletions

View file

@ -39,7 +39,7 @@ private:
bool externalSelection;
int externalSelectionWidth;
int externalSelectionHeight;
QList<Tile> externalSelectedTiles;
QList<uint16_t> externalSelectedTiles;
Tileset *primaryTileset;
Tileset *secondaryTileset;
@ -52,6 +52,7 @@ private:
uint16_t getTileId(int x, int y);
QPoint getTileCoords(uint16_t);
QList<QRgb> getCurPaletteTable();
QList<Tile> buildSelectedTiles(int, int, QList<uint16_t>);
signals:
void hoveredTileChanged(uint16_t);

View file

@ -95,45 +95,46 @@ void TilesetEditorTileSelector::updateSelectedTiles() {
QList<Tile> TilesetEditorTileSelector::getSelectedTiles() {
if (this->externalSelection) {
return this->externalSelectedTiles;
return buildSelectedTiles(this->externalSelectionWidth, this->externalSelectionHeight, this->externalSelectedTiles);
} else {
QList<Tile> tiles;
QList<QList<Tile>> tileMatrix;
QList<uint16_t> selected = this->selectedTiles;
QPoint dimensions = this->getSelectionDimensions();
int width = dimensions.x();
int height = dimensions.y();
for (int j = 0; j < height; j++) {
QList<Tile> 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<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height, QList<uint16_t> selected) {
QList<Tile> tiles;
QList<QList<Tile>> tileMatrix;
for (int j = 0; j < height; j++) {
QList<Tile> 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<Tile> 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();