diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb4a29c..9b3b30bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Changed - If Wild Encounters fail to load they are now only disabled for that session, and the settings remain unchanged. - Defaults are used if project constants are missing, rather than failing to open the project or changing settings. +- Selector images now center on the selection when eyedropping or zooming. ### Fixed -- Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed. +- Fix some minor visual issues with the various zoom sliders. +- Smooth out scrolling when mouse is over tile/metatile images. - Fix the Tileset Editor selectors getting extra white space when changing tilesets. - Fix a crash when adding disabled events with the Pencil tool. - Fix error log about failing to find the scripts file when a new map is created. diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index d70180d4..d1ef7767 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -764,7 +764,7 @@ true - + 0 @@ -803,7 +803,7 @@ - + 0 @@ -883,7 +883,7 @@ true - + 0 @@ -922,7 +922,7 @@ - + 0 @@ -984,7 +984,7 @@ Qt::AlignHCenter|Qt::AlignTop - + true @@ -1032,7 +1032,7 @@ - + true @@ -1184,11 +1184,11 @@ - + true - + 0 @@ -1227,7 +1227,7 @@ - + 0 @@ -3435,6 +3435,11 @@ QWidget
mapview.h
+ + NoScrollGraphicsView + QGraphicsView +
mapview.h
+
diff --git a/forms/tileseteditor.ui b/forms/tileseteditor.ui index 34e13d55..c144e5f2 100644 --- a/forms/tileseteditor.ui +++ b/forms/tileseteditor.ui @@ -58,9 +58,9 @@ true
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignHCenter|Qt::AlignTop - + 0 @@ -85,21 +85,8 @@ 6 - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + Qt::ScrollBarAlwaysOff @@ -108,28 +95,15 @@
- - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + - Qt::Horizontal + Qt::Vertical - 40 - 20 + 20 + 40 @@ -561,9 +535,9 @@ true
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignHCenter|Qt::AlignTop - + 0 @@ -585,21 +559,8 @@ 0 - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + Qt::ScrollBarAlwaysOff @@ -608,8 +569,8 @@ - - + + Qt::Vertical @@ -621,19 +582,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - -
@@ -858,6 +806,11 @@ QComboBox
noscrollcombobox.h
+ + NoScrollGraphicsView + QGraphicsView +
mapview.h
+
diff --git a/include/mainwindow.h b/include/mainwindow.h index 7d939595..6f969eba 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -390,7 +390,9 @@ private slots: void openProjectSettingsEditor(int tab); bool isProjectOpen(); void showExportMapImageWindow(ImageExporterMode mode); + double getMetatilesZoomScale(); void redrawMetatileSelection(); + void scrollMetatileSelectorToSelection(); QObjectList shortcutableObjects() const; void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false); diff --git a/include/ui/graphicsview.h b/include/ui/graphicsview.h index cee19293..c0d1592c 100644 --- a/include/ui/graphicsview.h +++ b/include/ui/graphicsview.h @@ -4,12 +4,23 @@ #include #include -class ClickableGraphicsView : public QGraphicsView +class NoScrollGraphicsView : public QGraphicsView { Q_OBJECT public: - ClickableGraphicsView() : QGraphicsView() {} - ClickableGraphicsView(QWidget *parent) : QGraphicsView(parent) {} + NoScrollGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {} + +protected: + void wheelEvent(QWheelEvent *event) { + event->ignore(); + } +}; + +class ClickableGraphicsView : public NoScrollGraphicsView +{ + Q_OBJECT +public: + ClickableGraphicsView(QWidget *parent = nullptr) : NoScrollGraphicsView(parent) {} public: void mouseReleaseEvent(QMouseEvent *event) override { diff --git a/include/ui/metatileselector.h b/include/ui/metatileselector.h index eaf357ca..ec2c49f4 100644 --- a/include/ui/metatileselector.h +++ b/include/ui/metatileselector.h @@ -45,13 +45,14 @@ class MetatileSelector: public SelectablePixmapItem { QPoint getSelectionDimensions(); void draw(); bool select(uint16_t metatile); - bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation); + void selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation); void setTilesets(Tileset*, Tileset*); MetatileSelection getMetatileSelection(); void setPrefabSelection(MetatileSelection selection); void setExternalSelection(int, int, QList, QList>); QPoint getMetatileIdCoordsOnWidget(uint16_t); void setMap(Map*); + bool isInternalSelection() const { return (!this->externalSelection && !this->prefabSelection); } Tileset *primaryTileset; Tileset *secondaryTileset; protected: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 58ba3f13..f7e0dee1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1366,31 +1366,52 @@ void MainWindow::updateTilesetEditor() { } } -void MainWindow::redrawMetatileSelection() -{ - double scale = pow(3.0, static_cast(porymapConfig.getMetatilesZoom() - 30) / 30.0); +double MainWindow::getMetatilesZoomScale() { + return pow(3.0, static_cast(porymapConfig.getMetatilesZoom() - 30) / 30.0); +} + +void MainWindow::redrawMetatileSelection() { + QSize size(editor->current_metatile_selection_item->pixmap().width(), editor->current_metatile_selection_item->pixmap().height()); + ui->graphicsView_currentMetatileSelection->setSceneRect(0, 0, size.width(), size.height()); + + auto scale = getMetatilesZoomScale(); QTransform transform; transform.scale(scale, scale); + size *= scale; ui->graphicsView_currentMetatileSelection->setTransform(transform); - ui->graphicsView_currentMetatileSelection->setFixedSize(editor->current_metatile_selection_item->pixmap().width() * scale + 2, editor->current_metatile_selection_item->pixmap().height() * scale + 2); + ui->graphicsView_currentMetatileSelection->setFixedSize(size.width() + 2, size.height() + 2); + ui->scrollAreaWidgetContents_SelectedMetatiles->adjustSize(); +} + +void MainWindow::scrollMetatileSelectorToSelection() { + // Internal selections or 1x1 external selections can be scrolled to + if (!editor->metatile_selector_item->isInternalSelection() && editor->metatile_selector_item->getSelectionDimensions() != QPoint(1, 1)) + return; + MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); + if (selection.metatileItems.isEmpty()) + return; + + QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId); QPoint size = editor->metatile_selector_item->getSelectionDimensions(); - if (size.x() == 1 && size.y() == 1) { - MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); - QPoint pos = editor->metatile_selector_item->getMetatileIdCoordsOnWidget(selection.metatileItems.first().metatileId); - pos *= scale; - ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); - } + pos += QPoint(size.x() - 1, size.y() - 1) * 16 / 2; // We want to focus on the center of the whole selection + pos *= getMetatilesZoomScale(); + + auto viewport = ui->scrollArea_MetatileSelector->viewport(); + ui->scrollArea_MetatileSelector->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } -void MainWindow::currentMetatilesSelectionChanged() -{ +void MainWindow::currentMetatilesSelectionChanged() { redrawMetatileSelection(); if (this->tilesetEditor) { MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection(); this->tilesetEditor->selectMetatile(selection.metatileItems.first().metatileId); } + + // Don't scroll to internal selections here, it will disrupt the user while they make their selection. + if (!editor->metatile_selector_item->isInternalSelection()) + scrollMetatileSelectorToSelection(); } void MainWindow::on_mapList_activated(const QModelIndex &index) @@ -2831,7 +2852,11 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { ui->graphicsView_BorderMetatile->setFixedSize(ceil(static_cast(editor->selected_border_metatiles_item->pixmap().width()) * scale) + 2, ceil(static_cast(editor->selected_border_metatiles_item->pixmap().height()) * scale) + 2); + ui->scrollAreaWidgetContents_MetatileSelector->adjustSize(); + ui->scrollAreaWidgetContents_BorderMetatiles->adjustSize(); + redrawMetatileSelection(); + scrollMetatileSelectorToSelection(); } void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { @@ -2847,6 +2872,7 @@ void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { ui->graphicsView_Collision->setResizeAnchor(QGraphicsView::NoAnchor); ui->graphicsView_Collision->setTransform(transform); ui->graphicsView_Collision->setFixedSize(size.width() + 2, size.height() + 2); + ui->scrollAreaWidgetContents_Collision->adjustSize(); } void MainWindow::on_spinBox_SelectedCollision_valueChanged(int collision) { diff --git a/src/ui/metatileselector.cpp b/src/ui/metatileselector.cpp index 2c4a5fb3..074b7758 100644 --- a/src/ui/metatileselector.cpp +++ b/src/ui/metatileselector.cpp @@ -59,12 +59,9 @@ bool MetatileSelector::select(uint16_t metatileId) { return true; } -bool MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) { - if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false; - this->select(metatileId); - this->selection.collisionItems.append(CollisionSelectionItem{true, collision, elevation}); - this->selection.hasCollision = true; - return true; +void MetatileSelector::selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation) { + QPair movePermissions(collision, elevation); + this->setExternalSelection(1, 1, {metatileId}, {movePermissions}); } void MetatileSelector::setTilesets(Tileset *primaryTileset, Tileset *secondaryTileset) { @@ -100,6 +97,10 @@ void MetatileSelector::setExternalSelection(int width, int height, QListselection.metatileItems.append(MetatileSelectionItem{true, metatileId}); } + if (this->selection.metatileItems.length() == 1) { + QPoint coords = this->getMetatileIdCoords(this->selection.metatileItems.first().metatileId); + SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0); + } this->draw(); emit selectedMetatilesChanged(); diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 2b097083..4813790a 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -317,7 +317,6 @@ void TilesetEditor::refresh() { this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); this->metatileSelector->select(this->getSelectedMetatileId()); - this->drawSelectedTiles(); if (metatileSelector) { if (metatileSelector->selectorShowUnused || metatileSelector->selectorShowCounts) { @@ -335,7 +334,7 @@ void TilesetEditor::refresh() { this->redrawTileSelector(); this->redrawMetatileSelector(); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); + this->drawSelectedTiles(); } void TilesetEditor::drawSelectedTiles() { @@ -361,7 +360,10 @@ void TilesetEditor::drawSelectedTiles() { this->selectedTilePixmapItem = new QGraphicsPixmapItem(QPixmap::fromImage(selectionImage)); this->selectedTileScene->addItem(this->selectedTilePixmapItem); - this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); + + QSize size(this->selectedTilePixmapItem->pixmap().width(), this->selectedTilePixmapItem->pixmap().height()); + this->ui->graphicsView_selectedTile->setSceneRect(0, 0, size.width(), size.height()); + this->ui->graphicsView_selectedTile->setFixedSize(size.width() + 2, size.height() + 2); } void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) { @@ -1191,7 +1193,7 @@ void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { 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); + this->ui->graphicsView_Metatiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorMetatilesZoom() - 30) / 30.0); QTransform transform; @@ -1203,7 +1205,10 @@ void TilesetEditor::redrawMetatileSelector() { QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(this->getSelectedMetatileId()); pos *= scale; - this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), 8 * scale, 8 * scale); + + this->ui->scrollAreaWidgetContents_Metatiles->adjustSize(); + auto viewport = this->ui->scrollArea_Metatiles->viewport(); + this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { @@ -1213,7 +1218,7 @@ void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { 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); + this->ui->graphicsView_Tiles->setSceneRect(0, 0, size.width(), size.height()); double scale = pow(3.0, static_cast(porymapConfig.getTilesetEditorTilesZoom() - 30) / 30.0); QTransform transform; @@ -1223,10 +1228,13 @@ void TilesetEditor::redrawTileSelector() { this->ui->graphicsView_Tiles->setTransform(transform); this->ui->graphicsView_Tiles->setFixedSize(size.width() + 2, size.height() + 2); + this->ui->scrollAreaWidgetContents_Tiles->adjustSize(); + auto tiles = this->tileSelector->getSelectedTiles(); 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); + auto viewport = this->ui->scrollArea_Tiles->viewport(); + this->ui->scrollArea_Tiles->ensureVisible(pos.x(), pos.y(), viewport->width() / 2, viewport->height() / 2); } }