Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes for selection images #592

Merged
merged 7 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
23 changes: 14 additions & 9 deletions forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down
87 changes: 20 additions & 67 deletions forms/tileseteditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -108,28 +95,15 @@
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<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="2">
<spacer name="horizontalSpacer">
<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>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down
2 changes: 2 additions & 0 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 14 additions & 3 deletions include/ui/graphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion include/ui/metatileselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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:
Expand Down
50 changes: 38 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading
Loading