diff --git a/CHANGELOG.md b/CHANGELOG.md index c254bfe2..60dcf572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp The **"Breaking Changes"** listed below are changes that have been made in the decompilation projects (e.g. pokeemerald), which porymap requires in order to work properly. It also includes changes to the scripting API that may change the behavior of existing porymap scripts. If porymap is used with a project or API script that is not up-to-date with the breaking changes, then porymap will likely break or behave improperly. ## [Unreleased] -Nothing, yet. +### Fixed +- Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed +- Fix the Tileset Editor selectors getting extra white space when changing tilesets ## [5.3.0] - 2024-01-15 ### Added diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index 043af02e..9ce9777d 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -133,6 +133,8 @@ private: void setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel); void reset(); void drawSelectedTiles(); + void redrawTileSelector(); + void redrawMetatileSelector(); void importTilesetTiles(Tileset*, bool); void importTilesetMetatiles(Tileset*, bool); void refresh(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index e69a8326..3b9c43f9 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -71,8 +71,7 @@ bool TilesetEditor::selectMetatile(uint16_t metatileId) { if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset) || this->lockSelection) return false; this->metatileSelector->select(metatileId); - QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(metatileId); - this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y()); + this->redrawMetatileSelector(); return true; } @@ -197,6 +196,7 @@ void TilesetEditor::initMetatileSelector() this->metatileSelector->draw(); this->ui->graphicsView_Metatiles->setScene(this->metatilesScene); + this->ui->graphicsView_Metatiles->setResizeAnchor(QGraphicsView::AnchorViewCenter); this->ui->horizontalSlider_MetatilesZoom->setValue(porymapConfig.getTilesetEditorMetatilesZoom()); } @@ -237,6 +237,7 @@ void TilesetEditor::initTileSelector() this->tileSelector->draw(); this->ui->graphicsView_Tiles->setScene(this->tilesScene); + this->ui->graphicsView_Tiles->setResizeAnchor(QGraphicsView::AnchorViewCenter); this->ui->horizontalSlider_TilesZoom->setValue(porymapConfig.getTilesetEditorTilesZoom()); } @@ -332,10 +333,8 @@ void TilesetEditor::refresh() { } } - this->ui->graphicsView_Tiles->setSceneRect(0, 0, this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2); - this->ui->graphicsView_Tiles->setFixedSize(this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2); - this->ui->graphicsView_Metatiles->setSceneRect(0, 0, this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2); - this->ui->graphicsView_Metatiles->setFixedSize(this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2); + this->redrawTileSelector(); + this->redrawMetatileSelector(); this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); } @@ -478,13 +477,12 @@ void TilesetEditor::onMetatileLayerSelectionChanged(QPoint selectionOrigin, int } } - if (width == 1 && height == 1) { - this->tileSelector->highlight(static_cast(tiles[0].tileId)); - ui->spinBox_paletteSelector->setValue(tiles[0].palette); - QPoint pos = tileSelector->getTileCoordsOnWidget(static_cast(tiles[0].tileId)); - ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y()); - } this->tileSelector->setExternalSelection(width, height, tiles, tileIdxs); + if (width == 1 && height == 1) { + ui->spinBox_paletteSelector->setValue(tiles[0].palette); + this->tileSelector->highlight(static_cast(tiles[0].tileId)); + this->redrawTileSelector(); + } this->metatileLayersItem->clearLastModifiedCoords(); } @@ -1188,28 +1186,47 @@ void TilesetEditor::on_copyButton_metatileLabel_clicked() { void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { porymapConfig.setTilesetEditorMetatilesZoom(value); - double scale = pow(3.0, static_cast(value - 30) / 30.0); + this->redrawMetatileSelector(); +} +void TilesetEditor::redrawMetatileSelector() { + QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); + this->ui->graphicsView_Metatiles->setSceneRect(0, 0, size.width() + 2, size.height() + 2); + + double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorMetatilesZoom() - 30) / 30.0); QTransform transform; transform.scale(scale, scale); - QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); size *= scale; - this->ui->graphicsView_Metatiles->setResizeAnchor(QGraphicsView::NoAnchor); this->ui->graphicsView_Metatiles->setTransform(transform); this->ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); + + QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(this->getSelectedMetatileId()); + pos *= scale; + this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); } void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { porymapConfig.setTilesetEditorTilesZoom(value); - double scale = pow(3.0, static_cast(value - 30) / 30.0); + this->redrawTileSelector(); +} +void TilesetEditor::redrawTileSelector() { + QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); + this->ui->graphicsView_Tiles->setSceneRect(0, 0, size.width() + 2, size.height() + 2); + + double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorTilesZoom() - 30) / 30.0); QTransform transform; transform.scale(scale, scale); - QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); size *= scale; - this->ui->graphicsView_Tiles->setResizeAnchor(QGraphicsView::NoAnchor); this->ui->graphicsView_Tiles->setTransform(transform); this->ui->graphicsView_Tiles->setFixedSize(size.width() + 2, size.height() + 2); + + auto tiles = this->tileSelector->getSelectedTiles(); // TODO: On non-external selections only + if (!tiles.isEmpty()) { + QPoint pos = this->tileSelector->getTileCoordsOnWidget(tiles[0].tileId); + pos *= scale; + this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); + } }