Merge pull request #592 from GriffinRichards/fix-zoom

Misc fixes for selection images
This commit is contained in:
GriffinR 2024-02-07 16:30:40 -05:00 committed by GitHub
commit 142b5de5af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 121 additions and 112 deletions

View file

@ -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.

View file

@ -764,7 +764,7 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<widget class="QWidget" name="scrollAreaWidgetContents_BorderMetatiles">
<property name="geometry">
<rect>
<x>0</x>
@ -803,7 +803,7 @@
</spacer>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView_BorderMetatile">
<widget class="NoScrollGraphicsView" name="graphicsView_BorderMetatile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -883,7 +883,7 @@
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_6">
<widget class="QWidget" name="scrollAreaWidgetContents_SelectedMetatiles">
<property name="geometry">
<rect>
<x>0</x>
@ -922,7 +922,7 @@
</spacer>
</item>
<item>
<widget class="QGraphicsView" name="graphicsView_currentMetatileSelection">
<widget class="NoScrollGraphicsView" name="graphicsView_currentMetatileSelection">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -984,7 +984,7 @@
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<widget class="QWidget" name="scrollAreaWidgetContents_MetatileSelector">
<property name="enabled">
<bool>true</bool>
</property>
@ -1032,7 +1032,7 @@
</spacer>
</item>
<item row="0" column="1">
<widget class="QGraphicsView" name="graphicsView_Metatiles">
<widget class="NoScrollGraphicsView" name="graphicsView_Metatiles">
<property name="enabled">
<bool>true</bool>
</property>
@ -1184,11 +1184,11 @@
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QScrollArea" name="scrollArea_1">
<widget class="QScrollArea" name="scrollArea_Collision">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Collision">
<property name="geometry">
<rect>
<x>0</x>
@ -1227,7 +1227,7 @@
</spacer>
</item>
<item row="2" column="1">
<widget class="QGraphicsView" name="graphicsView_Collision">
<widget class="NoScrollGraphicsView" name="graphicsView_Collision">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -3435,6 +3435,11 @@
<extends>QWidget</extends>
<header>mapview.h</header>
</customwidget>
<customwidget>
<class>NoScrollGraphicsView</class>
<extends>QGraphicsView</extends>
<header>mapview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/images.qrc"/>

View file

@ -58,9 +58,9 @@
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<widget class="QWidget" name="scrollAreaWidgetContents_Metatiles">
<property name="geometry">
<rect>
<x>0</x>
@ -85,21 +85,8 @@
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="1" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QGraphicsView" name="graphicsView_Metatiles">
<item row="0" column="0">
<widget class="NoScrollGraphicsView" name="graphicsView_Metatiles">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
@ -108,28 +95,15 @@
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
@ -561,9 +535,9 @@
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Tiles">
<property name="geometry">
<rect>
<x>0</x>
@ -585,21 +559,8 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QGraphicsView" name="graphicsView_Tiles">
<item row="0" column="0">
<widget class="NoScrollGraphicsView" name="graphicsView_Tiles">
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
@ -608,8 +569,8 @@
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_4">
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -621,19 +582,6 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
@ -858,6 +806,11 @@
<extends>QComboBox</extends>
<header>noscrollcombobox.h</header>
</customwidget>
<customwidget>
<class>NoScrollGraphicsView</class>
<extends>QGraphicsView</extends>
<header>mapview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/images.qrc"/>

View file

@ -390,7 +390,9 @@ private:
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);

View file

@ -4,12 +4,23 @@
#include <QGraphicsView>
#include <QMouseEvent>
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 {

View file

@ -45,13 +45,14 @@ public:
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<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
QPoint getMetatileIdCoordsOnWidget(uint16_t);
void setMap(Map*);
bool isInternalSelection() const { return (!this->externalSelection && !this->prefabSelection); }
Tileset *primaryTileset;
Tileset *secondaryTileset;
protected:

View file

@ -1366,31 +1366,52 @@ void MainWindow::updateTilesetEditor() {
}
}
void MainWindow::redrawMetatileSelection()
{
double scale = pow(3.0, static_cast<double>(porymapConfig.getMetatilesZoom() - 30) / 30.0);
double MainWindow::getMetatilesZoomScale() {
return pow(3.0, static_cast<double>(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;
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
if (size.x() == 1 && size.y() == 1) {
MetatileSelection selection = editor->metatile_selector_item->getMetatileSelection();
if (selection.metatileItems.isEmpty())
return;
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);
}
QPoint size = editor->metatile_selector_item->getSelectionDimensions();
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<double>(editor->selected_border_metatiles_item->pixmap().width()) * scale) + 2,
ceil(static_cast<double>(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) {

View file

@ -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<uint16_t, uint16_t> 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, QList<uint16_
metatileId = 0;
this->selection.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();

View file

@ -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<double>(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<double>(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);
}
}