Fix layer flip to work on all incomplete metatile selections

This commit is contained in:
GriffinR 2020-07-14 16:27:10 -04:00 committed by huderlem
parent cf9314eaa6
commit 70b8806737
3 changed files with 11 additions and 8 deletions

View file

@ -24,7 +24,7 @@ public:
void setPaletteId(int);
void setTileFlips(bool, bool);
QList<Tile> getSelectedTiles();
void setExternalSelection(int, int, QList<Tile>);
void setExternalSelection(int, int, QList<Tile>, QList<int>);
QPoint getTileCoordsOnWidget(uint16_t);
QImage buildPrimaryTilesIndexedImage();
QImage buildSecondaryTilesIndexedImage();
@ -41,6 +41,7 @@ private:
int externalSelectionWidth;
int externalSelectionHeight;
QList<Tile> externalSelectedTiles;
QList<int> externalSelectedPos;
Tileset *primaryTileset;
Tileset *secondaryTileset;

View file

@ -328,6 +328,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int width, int height) {
QList<Tile> tiles;
QList<int> 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();
}

View file

@ -128,7 +128,8 @@ QList<Tile> 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<Tile> TilesetEditorTileSelector::buildSelectedTiles(int width, int height,
return tiles;
}
void TilesetEditorTileSelector::setExternalSelection(int width, int height, QList<Tile> tiles) {
void TilesetEditorTileSelector::setExternalSelection(int width, int height, QList<Tile> tiles, QList<int> 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();
}