Respect x/y flip for selections with different flip states

This commit is contained in:
GriffinR 2020-07-13 13:08:57 -04:00 committed by huderlem
parent 023be7f541
commit b5b227a6a0
3 changed files with 18 additions and 19 deletions

View file

@ -39,7 +39,7 @@ private:
bool externalSelection;
int externalSelectionWidth;
int externalSelectionHeight;
QList<uint16_t> externalSelectedTiles;
QList<Tile> externalSelectedTiles;
Tileset *primaryTileset;
Tileset *secondaryTileset;
@ -52,7 +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>);
QList<Tile> buildSelectedTiles(int, int, QList<Tile>);
signals:
void hoveredTileChanged(uint16_t);

View file

@ -341,18 +341,9 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int
}
}
if (width == 1 && height == 1) {
this->tileSelector->select(static_cast<uint16_t>(tiles[0].tile));
if (width == 1 && height == 1)
ui->spinBox_paletteSelector->setValue(tiles[0].palette);
ui->checkBox_xFlip->setChecked(tiles[0].xflip);
ui->checkBox_yFlip->setChecked(tiles[0].yflip);
QPoint pos = tileSelector->getTileCoordsOnWidget(static_cast<uint16_t>(tiles[0].tile));
ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y());
}
else {
this->tileSelector->setExternalSelection(width, height, tiles);
}
this->tileSelector->setExternalSelection(width, height, tiles);
this->metatileLayersItem->clearLastModifiedCoords();
}

View file

@ -98,22 +98,30 @@ QList<Tile> TilesetEditorTileSelector::getSelectedTiles() {
return buildSelectedTiles(this->externalSelectionWidth, this->externalSelectionHeight, this->externalSelectedTiles);
} else {
QPoint dimensions = this->getSelectionDimensions();
return buildSelectedTiles(dimensions.x(), dimensions.y(), this->selectedTiles);
QList<Tile> tiles;
for (int i = 0; i < this->selectedTiles.length(); i++) {
uint16_t tile = this->selectedTiles.at(i);
tiles.append(Tile(tile, false, false, this->paletteId));
}
return buildSelectedTiles(dimensions.x(), dimensions.y(), tiles);
}
}
QList<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height, QList<uint16_t> selected) {
QList<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height, QList<Tile> 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);
Tile tile = selected.at(index);
tile.xflip ^= this->xFlip;
tile.yflip ^= this->yFlip;
tile.palette = this->paletteId;
if (this->xFlip)
row.prepend(Tile(tile, this->xFlip, this->yFlip, this->paletteId));
row.prepend(tile);
else
row.append(Tile(tile, this->xFlip, this->yFlip, this->paletteId));
row.append(tile);
}
if (this->yFlip)
tileMatrix.prepend(row);
@ -134,7 +142,7 @@ void TilesetEditorTileSelector::setExternalSelection(int width, int height, QLis
this->externalSelectionHeight = height;
this->externalSelectedTiles.clear();
for (int i = 0; i < tiles.length(); i++) {
this->externalSelectedTiles.append(tiles.at(i).tile);
this->externalSelectedTiles.append(tiles.at(i));
}
this->draw();