From 502ebd449f78dcf67838bfe70f176d2c9a1ef2a9 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Mon, 14 Sep 2020 21:06:04 -0400 Subject: [PATCH 01/25] Use correct function for setting cursorMapTileRect visibility --- src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ee1bd97e..d98ed68a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1377,7 +1377,7 @@ void MainWindow::on_actionCursor_Tile_Outline_triggered() porymapConfig.setShowCursorTile(enabled); this->editor->settings->cursorTileRectEnabled = enabled; if (this->editor->map_item->has_mouse) { - this->editor->cursorMapTileRect->setVisible(enabled); + this->editor->cursorMapTileRect->setVisibility(enabled); } } From 18cb48f8069baeeae019b7573abc6c1d7ab9ec8a Mon Sep 17 00:00:00 2001 From: ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> Date: Sun, 4 Oct 2020 20:47:32 -0500 Subject: [PATCH 02/25] Fix typo editing from github is poggers --- src/ui/tileseteditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 984322f9..75a60b9a 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -526,7 +526,7 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) { if (image.colorCount() == 0) { QMessageBox msgBox(this); msgBox.setText("Select Palette for Tiles"); - msgBox.setInformativeText(QString("The provided image is not indexed. Please select a palette file to for the image. An indexed image will be generated using the provided image and palette.") + msgBox.setInformativeText(QString("The provided image is not indexed. Please select a palette file for the image. An indexed image will be generated using the provided image and palette.") .arg(image.colorCount())); msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Icon::Warning); From db20d01f3c422143dfccb3cf210ea3091674ec69 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Sun, 11 Oct 2020 12:07:11 -0400 Subject: [PATCH 03/25] Focus map zoom on currently hovered metatile --- forms/mainwindow.ui | 46 +++++++++++++++++++------------ src/mainwindow.cpp | 66 +++++++++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 37 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 7fc0974c..3e7535e5 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -236,23 +236,23 @@ - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -357,6 +357,12 @@ 0 + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + true @@ -438,6 +444,12 @@ false + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAsNeeded + QAbstractScrollArea::AdjustIgnored diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d98ed68a..c06db464 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1451,13 +1451,39 @@ void MainWindow::scaleMapView(int s) { double exp = editor->scale_exp; double sfactor = pow(base,s); + ui->graphicsView_Map->setUpdatesEnabled(false); + + const auto mapAnchor = ui->graphicsView_Map->transformationAnchor(); + const auto connectionsAnchor = ui->graphicsView_Connections->transformationAnchor(); + ui->graphicsView_Map->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + ui->graphicsView_Connections->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + ui->graphicsView_Map->scale(sfactor,sfactor); ui->graphicsView_Connections->scale(sfactor,sfactor); int width = static_cast(ceil((editor->scene->width()) * pow(base,exp))) + 2; int height = static_cast(ceil((editor->scene->height()) * pow(base,exp))) + 2; - ui->graphicsView_Map->setFixedSize(width, height); - ui->graphicsView_Connections->setFixedSize(width, height); + QSize viewSize = ui->scrollAreaWidgetContents_5->size(); + + if (width < viewSize.width()) { + ui->graphicsView_Map->setFixedWidth(width); + ui->graphicsView_Connections->setFixedWidth(width); + } else { + ui->graphicsView_Map->setFixedWidth(viewSize.width()); + ui->graphicsView_Connections->setFixedWidth(viewSize.width()); + } + if (height < viewSize.height()) { + ui->graphicsView_Map->setFixedHeight(height); + ui->graphicsView_Connections->setFixedHeight(height); + } else { + ui->graphicsView_Map->setFixedHeight(viewSize.height()); + ui->graphicsView_Connections->setFixedHeight(viewSize.height()); + } + + ui->graphicsView_Map->setTransformationAnchor(mapAnchor); + ui->graphicsView_Connections->setTransformationAnchor(connectionsAnchor); + + ui->graphicsView_Map->setUpdatesEnabled(true); } } @@ -2139,9 +2165,9 @@ void MainWindow::on_toolButton_Paint_clicked() if (ui->tabWidget_2->currentIndex() == 0) editor->cursorMapTileRect->stopSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - QScroller::ungrabGesture(ui->scrollArea); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->graphicsView_Map); checkToolButtons(); } @@ -2156,9 +2182,9 @@ void MainWindow::on_toolButton_Select_clicked() editor->settings->mapCursor = QCursor(); editor->cursorMapTileRect->setSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - QScroller::ungrabGesture(ui->scrollArea); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->graphicsView_Map); checkToolButtons(); } @@ -2173,9 +2199,9 @@ void MainWindow::on_toolButton_Fill_clicked() editor->settings->mapCursor = QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10); editor->cursorMapTileRect->setSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - QScroller::ungrabGesture(ui->scrollArea); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->graphicsView_Map); checkToolButtons(); } @@ -2190,9 +2216,9 @@ void MainWindow::on_toolButton_Dropper_clicked() editor->settings->mapCursor = QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10); editor->cursorMapTileRect->setSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - QScroller::ungrabGesture(ui->scrollArea); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->graphicsView_Map); checkToolButtons(); } @@ -2207,9 +2233,9 @@ void MainWindow::on_toolButton_Move_clicked() editor->settings->mapCursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7); editor->cursorMapTileRect->setSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + QScroller::grabGesture(ui->graphicsView_Map, QScroller::LeftMouseButtonGesture); checkToolButtons(); } @@ -2224,9 +2250,9 @@ void MainWindow::on_toolButton_Shift_clicked() editor->settings->mapCursor = QCursor(QPixmap(":/icons/shift_cursor.ico"), 10, 10); editor->cursorMapTileRect->setSingleTileMode(); - ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - QScroller::ungrabGesture(ui->scrollArea); + ui->graphicsView_Map->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->graphicsView_Map->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QScroller::ungrabGesture(ui->graphicsView_Map); checkToolButtons(); } From 5247dd18c0656cab740e6ed5cb4927b7a6330e72 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 13 Oct 2020 06:07:31 -0400 Subject: [PATCH 04/25] Refactor map zooming into the Editor --- include/editor.h | 3 ++- include/mainwindow.h | 5 ---- src/editor.cpp | 43 ++++++++++++++++++++++++++++- src/mainwindow.cpp | 64 +++----------------------------------------- 4 files changed, 47 insertions(+), 68 deletions(-) diff --git a/include/editor.h b/include/editor.h index c9f7bcea..fd773e68 100644 --- a/include/editor.h +++ b/include/editor.h @@ -148,6 +148,7 @@ public: bool selectingEvent = false; void shouldReselectEvents(); + void scaleMapView(int); private: void setConnectionItemsVisible(bool); @@ -198,6 +199,7 @@ private slots: void onHoveredMapMovementPermissionChanged(int, int); void onHoveredMapMovementPermissionCleared(); void onSelectedMetatilesChanged(); + void onWheelZoom(int); signals: void objectsChanged(); @@ -206,7 +208,6 @@ signals: void wildMonDataChanged(); void warpEventDoubleClicked(QString mapName, QString warpNum); void currentMetatilesSelectionChanged(); - void wheelZoom(int delta); }; #endif // EDITOR_H diff --git a/include/mainwindow.h b/include/mainwindow.h index f6b382c2..a9180402 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -109,11 +109,6 @@ public: Q_INVOKABLE QList getMetatileLayerOpacity(); Q_INVOKABLE void setMetatileLayerOpacity(QList order); - -public slots: - void scaleMapView(int); - void onWheelZoom(int); - private slots: void on_action_Open_Project_triggered(); void on_action_Reload_Project_triggered(); diff --git a/src/editor.cpp b/src/editor.cpp index 1345adb6..9b052982 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -887,6 +887,47 @@ void Editor::onSelectedMetatilesChanged() { this->redrawCurrentMetatilesSelection(); } +void Editor::onWheelZoom(int s) { + // Don't zoom the map when the user accidentally scrolls while performing a magic fill. (ctrl + middle button click) + if (!(QApplication::mouseButtons() & Qt::MiddleButton)) { + scaleMapView(s); + } +} + +void Editor::scaleMapView(int s) { + if ((scale_exp + s) <= 5 && (scale_exp + s) >= -2) // sane limits + { + if (s == 0) + s = -scale_exp; + + scale_exp += s; + + double base = scale_base; + double exp = scale_exp; + double sfactor = pow(base, s); + + const auto mapAnchor = ui->graphicsView_Map->transformationAnchor(); + const auto connectionsAnchor = ui->graphicsView_Connections->transformationAnchor(); + ui->graphicsView_Map->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + ui->graphicsView_Connections->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + + ui->graphicsView_Map->scale(sfactor, sfactor); + ui->graphicsView_Connections->scale(sfactor, sfactor); + + int width = static_cast(ceil((scene->width()) * pow(base, exp))) + 2; + int height = static_cast(ceil((scene->height()) * pow(base, exp))) + 2; + QSize viewSize = ui->scrollAreaWidgetContents_5->size(); + int minWidth = qMin(width, viewSize.width()); + int minHeight = qMin(height, viewSize.height()); + + ui->graphicsView_Map->setFixedSize(minWidth, minHeight); + ui->graphicsView_Connections->setFixedSize(minWidth, minHeight); + + ui->graphicsView_Map->setTransformationAnchor(mapAnchor); + ui->graphicsView_Connections->setTransformationAnchor(connectionsAnchor); + } +} + void Editor::onHoveredMapMetatileChanged(int x, int y) { this->playerViewRect->updateLocation(x, y); this->cursorMapTileRect->updateLocation(x, y); @@ -1209,7 +1250,7 @@ bool Editor::displayMap() { scene = new QGraphicsScene; MapSceneEventFilter *filter = new MapSceneEventFilter(); scene->installEventFilter(filter); - connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::wheelZoom); + connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::onWheelZoom); } if (map_item && scene) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c06db464..394e58d8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -148,7 +148,6 @@ void MainWindow::initEditor() { connect(this->editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString))); connect(this->editor, SIGNAL(currentMetatilesSelectionChanged()), this, SLOT(currentMetatilesSelectionChanged())); connect(this->editor, SIGNAL(wildMonDataChanged()), this, SLOT(onWildMonDataChanged())); - connect(this->editor, &Editor::wheelZoom, this, &MainWindow::onWheelZoom); this->loadUserSettings(); @@ -1349,11 +1348,11 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index) } void MainWindow::on_actionZoom_In_triggered() { - scaleMapView(1); + editor->scaleMapView(1); } void MainWindow::on_actionZoom_Out_triggered() { - scaleMapView(-1); + editor->scaleMapView(-1); } void MainWindow::on_actionBetter_Cursors_triggered() { @@ -1430,65 +1429,8 @@ void MainWindow::on_actionMap_Shift_triggered() on_toolButton_Shift_clicked(); } -void MainWindow::onWheelZoom(int s) { - // Don't zoom the map when the user accidentally scrolls while performing a magic fill. (ctrl + middle button click) - if (!(QApplication::mouseButtons() & Qt::MiddleButton)) { - scaleMapView(s); - } -} - -void MainWindow::scaleMapView(int s) { - if ((editor->scale_exp + s) <= 5 && (editor->scale_exp + s) >= -2) // sane limits - { - if (s == 0) - { - s = -editor->scale_exp; - } - - editor->scale_exp += s; - - double base = editor->scale_base; - double exp = editor->scale_exp; - double sfactor = pow(base,s); - - ui->graphicsView_Map->setUpdatesEnabled(false); - - const auto mapAnchor = ui->graphicsView_Map->transformationAnchor(); - const auto connectionsAnchor = ui->graphicsView_Connections->transformationAnchor(); - ui->graphicsView_Map->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - ui->graphicsView_Connections->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - - ui->graphicsView_Map->scale(sfactor,sfactor); - ui->graphicsView_Connections->scale(sfactor,sfactor); - - int width = static_cast(ceil((editor->scene->width()) * pow(base,exp))) + 2; - int height = static_cast(ceil((editor->scene->height()) * pow(base,exp))) + 2; - QSize viewSize = ui->scrollAreaWidgetContents_5->size(); - - if (width < viewSize.width()) { - ui->graphicsView_Map->setFixedWidth(width); - ui->graphicsView_Connections->setFixedWidth(width); - } else { - ui->graphicsView_Map->setFixedWidth(viewSize.width()); - ui->graphicsView_Connections->setFixedWidth(viewSize.width()); - } - if (height < viewSize.height()) { - ui->graphicsView_Map->setFixedHeight(height); - ui->graphicsView_Connections->setFixedHeight(height); - } else { - ui->graphicsView_Map->setFixedHeight(viewSize.height()); - ui->graphicsView_Connections->setFixedHeight(viewSize.height()); - } - - ui->graphicsView_Map->setTransformationAnchor(mapAnchor); - ui->graphicsView_Connections->setTransformationAnchor(connectionsAnchor); - - ui->graphicsView_Map->setUpdatesEnabled(true); - } -} - void MainWindow::resetMapViewScale() { - scaleMapView(0); + editor->scaleMapView(0); } void MainWindow::addNewEvent(QString event_type) From ef9c4c73c3ced82fc57deee6549995f55889abf3 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 13 Oct 2020 10:14:16 -0400 Subject: [PATCH 05/25] Remove scrollArea surrounding graphicsView_Map --- forms/mainwindow.ui | 134 +++++++------------------------------------- src/editor.cpp | 28 ++------- src/mainwindow.cpp | 1 - 3 files changed, 25 insertions(+), 138 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 3e7535e5..e79eebd8 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -350,129 +350,37 @@ 0 - + - 1 + 0 0 + + false + + + false + - Qt::ScrollBarAlwaysOff + Qt::ScrollBarAsNeeded - Qt::ScrollBarAlwaysOff + Qt::ScrollBarAsNeeded - - true + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + + + QGraphicsView::AnchorUnderMouse + + + QGraphicsView::AnchorUnderMouse - - - - 0 - 0 - 543 - 600 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Horizontal - - - - 166 - 16 - - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - - - - 0 - 0 - - - - false - - - false - - - Qt::ScrollBarAsNeeded - - - Qt::ScrollBarAsNeeded - - - QAbstractScrollArea::AdjustIgnored - - - QGraphicsView::NoDrag - - - - - - - Qt::Vertical - - - - 16 - 166 - - - - - - diff --git a/src/editor.cpp b/src/editor.cpp index 9b052982..2652c4e6 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -898,33 +898,13 @@ void Editor::scaleMapView(int s) { if ((scale_exp + s) <= 5 && (scale_exp + s) >= -2) // sane limits { if (s == 0) - s = -scale_exp; - - scale_exp += s; - - double base = scale_base; - double exp = scale_exp; - double sfactor = pow(base, s); - - const auto mapAnchor = ui->graphicsView_Map->transformationAnchor(); - const auto connectionsAnchor = ui->graphicsView_Connections->transformationAnchor(); - ui->graphicsView_Map->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); - ui->graphicsView_Connections->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + scale_exp = 0; + else + scale_exp += s; + double sfactor = pow(scale_base, s); ui->graphicsView_Map->scale(sfactor, sfactor); ui->graphicsView_Connections->scale(sfactor, sfactor); - - int width = static_cast(ceil((scene->width()) * pow(base, exp))) + 2; - int height = static_cast(ceil((scene->height()) * pow(base, exp))) + 2; - QSize viewSize = ui->scrollAreaWidgetContents_5->size(); - int minWidth = qMin(width, viewSize.width()); - int minHeight = qMin(height, viewSize.height()); - - ui->graphicsView_Map->setFixedSize(minWidth, minHeight); - ui->graphicsView_Connections->setFixedSize(minWidth, minHeight); - - ui->graphicsView_Map->setTransformationAnchor(mapAnchor); - ui->graphicsView_Connections->setTransformationAnchor(connectionsAnchor); } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 394e58d8..38f51b9d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -563,7 +563,6 @@ void MainWindow::refreshMapScene() ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect()); - ui->graphicsView_Map->setFixedSize(width, height); ui->graphicsView_Map->editor = editor; ui->graphicsView_Connections->setScene(editor->scene); From f404f8c11f49dd6c89e8924266f4c112440323a0 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 13 Oct 2020 12:23:13 -0400 Subject: [PATCH 06/25] Remove scrollArea surrounding graphicsView_Connections --- forms/mainwindow.ui | 267 +++++++++++++++----------------------------- src/mainwindow.cpp | 7 -- 2 files changed, 92 insertions(+), 182 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index e79eebd8..d9d28960 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2071,7 +2071,7 @@ 0 - + @@ -2195,7 +2195,41 @@ - + + + + + 0 + 0 + + + + false + + + false + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAsNeeded + + + QAbstractScrollArea::AdjustIgnored + + + QGraphicsView::NoDrag + + + QGraphicsView::AnchorUnderMouse + + + QGraphicsView::AnchorUnderMouse + + + + @@ -2311,200 +2345,83 @@ - - + + + + + 0 + 0 + + QFrame::StyledPanel QFrame::Raised - + + + 4 + - 0 + 4 - 0 + 4 - 0 + 4 - 0 + 4 - - 0 - - - - - - 1 - 0 - + + + + Dive Map - - true - - - - - 0 - 0 - 118 - 118 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - 0 - 0 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - + + + + <html><head/><body><p>Destination map name when using <span style=" font-weight:600;">Dive</span>. If empty, no such connection will exist.</p></body></html> - - QFrame::StyledPanel + + true - - QFrame::Raised - - - - 4 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - Dive Map - - - - - - - <html><head/><body><p>Destination map name when using <span style=" font-weight:600;">Dive</span>. If empty, no such connection will exist.</p></body></html> - - - true - - - - - - - Emerge Map - - - - - - - <html><head/><body><p>Destination map name when emerging using <span style=" font-weight:600;">Dive</span>. If empty, no such connection will exist.</p></body></html> - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + Emerge Map + + + + + + + <html><head/><body><p>Destination map name when emerging using <span style=" font-weight:600;">Dive</span>. If empty, no such connection will exist.</p></body></html> + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 38f51b9d..3d2edab6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -555,19 +555,12 @@ void MainWindow::refreshMapScene() { on_mainTabBar_tabBarClicked(ui->mainTabBar->currentIndex()); - double base = editor->scale_base; - double exp = editor->scale_exp; - - int width = static_cast(ceil((editor->scene->width()) * pow(base,exp))) + 2; - int height = static_cast(ceil((editor->scene->height()) * pow(base,exp))) + 2; - ui->graphicsView_Map->setScene(editor->scene); ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect()); ui->graphicsView_Map->editor = editor; ui->graphicsView_Connections->setScene(editor->scene); ui->graphicsView_Connections->setSceneRect(editor->scene->sceneRect()); - ui->graphicsView_Connections->setFixedSize(width, height); ui->graphicsView_Metatiles->setScene(editor->scene_metatiles); //ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect()); From 2f20a5d0b304b1ca3d6b3097fe624c871d2937da Mon Sep 17 00:00:00 2001 From: BigBahss Date: Wed, 14 Oct 2020 01:57:59 -0400 Subject: [PATCH 07/25] Hide connection tiles that cant be seen from current map --- include/editor.h | 2 ++ src/editor.cpp | 33 +++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 1 + 3 files changed, 36 insertions(+) diff --git a/include/editor.h b/include/editor.h index fd773e68..b887d558 100644 --- a/include/editor.h +++ b/include/editor.h @@ -64,6 +64,7 @@ public: void displayMapBorder(); void displayMapGrid(); void displayWildMonTables(); + void maskNonVisibleConnectionTiles(); void updateMapBorder(); void updateMapConnections(); @@ -109,6 +110,7 @@ public: ConnectionPixmapItem* selected_connection_item = nullptr; QList connection_items; QList connection_edit_items; + QGraphicsPathItem *connection_mask = nullptr; CollisionPixmapItem *collision_item = nullptr; QGraphicsItemGroup *events_group = nullptr; QList borderItems; diff --git a/src/editor.cpp b/src/editor.cpp index 2652c4e6..020e925c 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -759,11 +759,13 @@ void Editor::updateCurrentConnectionDirection(QString curDirection) { QString originalDirection = selected_connection_item->connection->direction; setCurrentConnectionDirection(curDirection); updateMirroredConnectionDirection(selected_connection_item->connection, originalDirection); + maskNonVisibleConnectionTiles(); } void Editor::onConnectionMoved(MapConnection* connection) { updateMirroredConnectionOffset(connection); onConnectionOffsetChanged(connection->offset.toInt()); + maskNonVisibleConnectionTiles(); } void Editor::onConnectionOffsetChanged(int newOffset) { @@ -1458,6 +1460,8 @@ void Editor::displayMapConnections() { if (!connection_edit_items.empty()) { onConnectionItemSelected(connection_edit_items.first()); } + + maskNonVisibleConnectionTiles(); } void Editor::createConnectionItem(MapConnection* connection, bool hide) { @@ -1502,6 +1506,31 @@ void Editor::createConnectionItem(MapConnection* connection, bool hide) { connection_edit_items.append(connection_edit_item); } +// Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE). +void Editor::maskNonVisibleConnectionTiles() { + if (connection_mask) { + if (connection_mask->scene()) { + connection_mask->scene()->removeItem(connection_mask); + } + delete connection_mask; + } + + QPainterPath mask; + mask.addRect(scene->itemsBoundingRect().toRect()); + mask.addRect( + -BORDER_DISTANCE * 16, + -BORDER_DISTANCE * 16, + (map->getWidth() + BORDER_DISTANCE * 2) * 16, + (map->getHeight() + BORDER_DISTANCE * 2) * 16 + ); + + // Mask the tiles with the current theme's background color. + QPen pen(ui->graphicsView_Map->palette().color(QPalette::Base)); + QBrush brush(ui->graphicsView_Map->palette().color(QPalette::Base)); + + connection_mask = scene->addPath(mask, pen, brush); +} + void Editor::displayMapBorder() { for (QGraphicsPixmapItem* item : borderItems) { if (item->scene()) { @@ -1548,6 +1577,8 @@ void Editor::updateMapConnections() { connection_edit_items[i]->basePixmap = pixmap; connection_edit_items[i]->setPixmap(pixmap); } + + maskNonVisibleConnectionTiles(); } int Editor::getBorderDrawDistance(int dimension) { @@ -1604,6 +1635,7 @@ void Editor::updateConnectionOffset(int offset) { } selected_connection_item->blockSignals(false); updateMirroredConnectionOffset(selected_connection_item->connection); + maskNonVisibleConnectionTiles(); } void Editor::setConnectionMap(QString mapName) { @@ -1624,6 +1656,7 @@ void Editor::setConnectionMap(QString mapName) { selected_connection_item->connection->map_name = mapName; setCurrentConnectionDirection(selected_connection_item->connection->direction); updateMirroredConnectionMap(selected_connection_item->connection, originalMapName); + maskNonVisibleConnectionTiles(); } void Editor::addNewConnection() { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3d2edab6..6814c2fc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2536,6 +2536,7 @@ void MainWindow::on_actionThemes_triggered() QString theme = themeSelector->currentText(); porymapConfig.setTheme(theme); this->setTheme(theme); + editor->maskNonVisibleConnectionTiles(); } }); connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject())); From 89e3ef16b4975f920e2fec9229a058e4a93feaef Mon Sep 17 00:00:00 2001 From: BigBahss Date: Wed, 14 Oct 2020 15:28:44 -0400 Subject: [PATCH 08/25] Fix crash when setting map connection to "None" --- src/editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 1345adb6..2c7ad55c 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1593,7 +1593,7 @@ void Editor::setConnectionMap(QString mapName) { if (!selected_connection_item) return; - if (mapName.isEmpty()) { + if (mapName.isEmpty() || mapName == NONE_MAP_NAME) { removeCurrentConnection(); return; } @@ -1744,7 +1744,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) { } } - if (mapName.isEmpty()) { + if (mapName.isEmpty() || mapName == NONE_MAP_NAME) { // Remove dive/emerge connection if (connection) { map->connections.removeOne(connection); From 4f68f85c906127b2cbdfeb9619e4d5d323e8323a Mon Sep 17 00:00:00 2001 From: garak Date: Sat, 10 Oct 2020 18:29:25 -0400 Subject: [PATCH 09/25] docs: increase page width, add favicon --- docsrc/_static/css/custom.css | 9 +++++++++ docsrc/conf.py | 2 ++ 2 files changed, 11 insertions(+) create mode 100644 docsrc/_static/css/custom.css diff --git a/docsrc/_static/css/custom.css b/docsrc/_static/css/custom.css new file mode 100644 index 00000000..11221bf6 --- /dev/null +++ b/docsrc/_static/css/custom.css @@ -0,0 +1,9 @@ +/* do not limit the width of the page */ +.wy-nav-content { + max-width: 75%; +} + +.wy-side-scroll { + width: auto; + overflow-y: auto; +} diff --git a/docsrc/conf.py b/docsrc/conf.py index 61a5c36f..b3b45935 100644 --- a/docsrc/conf.py +++ b/docsrc/conf.py @@ -99,6 +99,8 @@ html_context = { # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] +html_favicon = '../resources/icons/porymap-icon-2.ico' + # Custom sidebar templates, must be a dictionary that maps document names # to template names. # From 1ea50d79552badfd9c891debd7d6ac5910e4c880 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Sat, 10 Oct 2020 14:06:51 -0400 Subject: [PATCH 10/25] Cleanup large log file on startup --- include/log.h | 1 + src/log.cpp | 11 +++++++++++ src/mainwindow.cpp | 2 ++ 3 files changed, 14 insertions(+) diff --git a/include/log.h b/include/log.h index c908eee9..87e0ae01 100644 --- a/include/log.h +++ b/include/log.h @@ -20,5 +20,6 @@ void logError(QString message); void log(QString message, LogType type); QString getLogPath(); QString getMostRecentError(); +bool cleanupLargeLog(); #endif // LOG_H diff --git a/src/log.cpp b/src/log.cpp index 3b5d5eb0..64f6753a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -86,3 +86,14 @@ QString getLogPath() { QString getMostRecentError() { return mostRecentError; } + +bool cleanupLargeLog() { + QFile logFile(getLogPath()); + if (logFile.size() < 20000000) + return false; + + bool removed = logFile.remove(); + if (removed) + logWarn(QString("Previous log file %1 was cleared due to being over 20MB in size.").arg(getLogPath())); + return removed; +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d98ed68a..e2ae8bdb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) : QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico")); ui->setupUi(this); + cleanupLargeLog(); + this->initWindow(); if (!this->openRecentProject()) { // Re-initialize everything to a blank slate if opening the recent project failed. From 68d4f47dbbada3bd36163dceeb6aec805df2500d Mon Sep 17 00:00:00 2001 From: BigBahss Date: Thu, 15 Oct 2020 18:52:29 -0400 Subject: [PATCH 11/25] Add scrolling to collision tab --- forms/mainwindow.ui | 192 ++++++++++++++++++++++++++------------------ 1 file changed, 113 insertions(+), 79 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 7fc0974c..c07bb7bc 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -1213,93 +1213,127 @@ QLayout::SetDefaultConstraint - 0 + 3 - 0 + 3 - 0 + 3 - 0 + 3 - - - - - 0 - 0 - - - - - 64 - 512 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 0 - - - 100 - - - 50 - - - Qt::Horizontal - - - - - - - Opacity + + + + true + + + + 0 + 0 + 434 + 643 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Opacity + + + + + + + 0 + + + 100 + + + 50 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + 86 + 20 + + + + + + + + + 0 + 0 + + + + + 64 + 512 + + + + + + + + Qt::Horizontal + + + + 86 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 94 + + + + + + From bb61dc9b5194b2c5adfeacaa7b82af4370c798f4 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 13:48:45 -0400 Subject: [PATCH 12/25] Add dynamic FlowLayout class --- include/ui/flowlayout.h | 37 +++++++++++ porymap.pro | 2 + src/ui/flowlayout.cpp | 136 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 include/ui/flowlayout.h create mode 100644 src/ui/flowlayout.cpp diff --git a/include/ui/flowlayout.h b/include/ui/flowlayout.h new file mode 100644 index 00000000..6364dfd0 --- /dev/null +++ b/include/ui/flowlayout.h @@ -0,0 +1,37 @@ +#ifndef FLOWLAYOUT_H +#define FLOWLAYOUT_H + +#include +#include + + +class FlowLayout : public QLayout +{ +public: + explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); + explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1); + ~FlowLayout(); + + void addItem(QLayoutItem *item) override; + int horizontalSpacing() const; + int verticalSpacing() const; + Qt::Orientations expandingDirections() const override; + bool hasHeightForWidth() const override; + int heightForWidth(int) const override; + int count() const override; + QLayoutItem *itemAt(int index) const override; + QSize minimumSize() const override; + void setGeometry(const QRect &rect) override; + QSize sizeHint() const override; + QLayoutItem *takeAt(int index) override; + +private: + int doLayout(const QRect &rect, bool testOnly) const; + int smartSpacing(QStyle::PixelMetric pm) const; + + QList itemList; + int horzSpace; + int vertSpace; +}; + +#endif // FLOWLAYOUT_H diff --git a/porymap.pro b/porymap.pro index 04fb94e2..da274dba 100644 --- a/porymap.pro +++ b/porymap.pro @@ -68,6 +68,7 @@ SOURCES += src/core/block.cpp \ src/ui/regionmapeditor.cpp \ src/ui/newmappopup.cpp \ src/ui/mapimageexporter.cpp \ + src/ui/flowlayout.cpp \ src/config.cpp \ src/editor.cpp \ src/main.cpp \ @@ -134,6 +135,7 @@ HEADERS += include/core/block.h \ include/ui/regionmapeditor.h \ include/ui/newmappopup.h \ include/ui/mapimageexporter.h \ + include/ui/flowlayout.h \ include/config.h \ include/editor.h \ include/mainwindow.h \ diff --git a/src/ui/flowlayout.cpp b/src/ui/flowlayout.cpp new file mode 100644 index 00000000..2d5a5faa --- /dev/null +++ b/src/ui/flowlayout.cpp @@ -0,0 +1,136 @@ +#include + +#include + + +FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) : + QLayout(parent), + horzSpace(hSpacing), + vertSpace(vSpacing) +{ + setContentsMargins(margin, margin, margin, margin); +} + +FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) : + horzSpace(hSpacing), + vertSpace(vSpacing) +{ + setContentsMargins(margin, margin, margin, margin); +} + +FlowLayout::~FlowLayout() +{ + QLayoutItem *item; + while ((item = takeAt(0))) + delete item; +} + +void FlowLayout::addItem(QLayoutItem *item) { + itemList.append(item); +} + +int FlowLayout::horizontalSpacing() const { + if (horzSpace >= 0) + return horzSpace; + else + return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); +} + +int FlowLayout::verticalSpacing() const { + if (vertSpace >= 0) + return vertSpace; + else + return smartSpacing(QStyle::PM_LayoutVerticalSpacing); +} + +int FlowLayout::count() const { + return itemList.size(); +} + +QLayoutItem *FlowLayout::itemAt(int index) const { + return itemList.value(index); +} + +QLayoutItem *FlowLayout::takeAt(int index) { + if (index >= 0 && index < itemList.size()) + return itemList.takeAt(index); + return nullptr; +} + +Qt::Orientations FlowLayout::expandingDirections() const { + return { }; +} + +bool FlowLayout::hasHeightForWidth() const { + return true; +} + +int FlowLayout::heightForWidth(int width) const { + int height = doLayout(QRect(0, 0, width, 0), true); + return height; +} + +void FlowLayout::setGeometry(const QRect &rect) { + QLayout::setGeometry(rect); + doLayout(rect, false); +} + +QSize FlowLayout::sizeHint() const { + return minimumSize(); +} + +QSize FlowLayout::minimumSize() const { + QSize size; + for (const QLayoutItem *item : qAsConst(itemList)) + size = size.expandedTo(item->minimumSize()); + + const QMargins margins = contentsMargins(); + size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom()); + return size; +} + +int FlowLayout::doLayout(const QRect &rect, bool testOnly) const { + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); + int x = effectiveRect.x(); + int y = effectiveRect.y(); + int lineHeight = 0; + + for (QLayoutItem *item : qAsConst(itemList)) { + const QWidget *wid = item->widget(); + int spaceX = horizontalSpacing(); + if (spaceX == -1) + spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal); + int spaceY = verticalSpacing(); + if (spaceY == -1) + spaceY = wid->style()->layoutSpacing(QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); + + int nextX = x + item->sizeHint().width() + spaceX; + if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { + x = effectiveRect.x(); + y = y + lineHeight + spaceY; + nextX = x + item->sizeHint().width() + spaceX; + lineHeight = 0; + } + + if (!testOnly) + item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); + + x = nextX; + lineHeight = qMax(lineHeight, item->sizeHint().height()); + } + return y + lineHeight - rect.y() + bottom; +} + +int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const { + QObject *parent = this->parent(); + if (!parent) { + return -1; + } else if (parent->isWidgetType()) { + QWidget *pw = static_cast(parent); + return pw->style()->pixelMetric(pm, nullptr, pw); + } else { + return static_cast(parent)->spacing(); + } +} From f449f370a0c8a179367232ab8f651091e67a9098 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 15:02:06 -0400 Subject: [PATCH 13/25] Implement FlowLayout for frame_mapTools --- forms/mainwindow.ui | 260 ++++++++++++++++++++++++-------------------- src/mainwindow.cpp | 14 +++ 2 files changed, 156 insertions(+), 118 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index c07bb7bc..1ca0f6e0 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -467,7 +467,7 @@ - + 0 @@ -488,132 +488,159 @@ - 4 + 3 - 4 + 3 - 4 + 3 - 4 + 3 - 4 + 3 - - - true + + + QFrame::NoFrame - - <html><head/><body><p>Pencil</p><p><span style=" font-weight:600;">Click</span> and drag to draw on the map.</p><p><span style=" font-weight:600;">Right-click</span> and drag to select tiles.</p></body></html> - - - Paint - - - - :/icons/pencil.ico:/icons/pencil.ico - - - true - - - true - - - false - - - - - - - true - - - <html><head/><body><p>Pointer</p><p>Does nothing</p></body></html> - - - Select - - - - :/icons/cursor.ico:/icons/cursor.ico - - - true - - - - - - - <html><head/><body><p>Bucket Fill</p><p>Fills all similar tiles in a region with the selected metatiles or collision attributes</p></body></html> - - - Fill - - - - :/icons/fill_color.ico:/icons/fill_color.ico - - - true - - - - - - - <html><head/><body><p>Eyedropper</p><p><span style=" font-weight:600;">Click</span> to select a metatile or collision attribute.</p></body></html> - - - Dropper - - - - :/icons/pipette.ico:/icons/pipette.ico - - - true - - - - - - - <html><head/><body><p>Move</p><p>Click to drag map around.</p></body></html> - - - ... - - - - :/icons/move.ico:/icons/move.ico - - - true - - - - - - - <html><head/><body><p>Map Shift</p><p><span style=" font-weight:600;">Click and drag</span> on the map to shift the positions of all metatiles (Map tab) or events (Events tab) at once. This is useful after resizing a map.</p></body></html> - - - Shift - - - - :/icons/shift.ico:/icons/shift.ico - - - true + + QFrame::Raised + + + 3 + + + 0 + + + 0 + + + 9 + + + 0 + + + + + true + + + <html><head/><body><p>Pencil</p><p><span style=" font-weight:600;">Click</span> and drag to draw on the map.</p><p><span style=" font-weight:600;">Right-click</span> and drag to select tiles.</p></body></html> + + + Paint + + + + :/icons/pencil.ico:/icons/pencil.ico + + + true + + + true + + + false + + + + + + + true + + + <html><head/><body><p>Pointer</p><p>Does nothing</p></body></html> + + + Select + + + + :/icons/cursor.ico:/icons/cursor.ico + + + true + + + + + + + <html><head/><body><p>Bucket Fill</p><p>Fills all similar tiles in a region with the selected metatiles or collision attributes</p></body></html> + + + Fill + + + + :/icons/fill_color.ico:/icons/fill_color.ico + + + true + + + + + + + <html><head/><body><p>Eyedropper</p><p><span style=" font-weight:600;">Click</span> to select a metatile or collision attribute.</p></body></html> + + + Dropper + + + + :/icons/pipette.ico:/icons/pipette.ico + + + true + + + + + + + <html><head/><body><p>Move</p><p>Click to drag map around.</p></body></html> + + + ... + + + + :/icons/move.ico:/icons/move.ico + + + true + + + + + + + <html><head/><body><p>Map Shift</p><p><span style=" font-weight:600;">Click and drag</span> on the map to shift the positions of all metatiles (Map tab) or events (Events tab) at once. This is useful after resizing a map.</p></body></html> + + + Shift + + + + :/icons/shift.ico:/icons/shift.ico + + + true + + + + @@ -621,9 +648,6 @@ <html><head/><body><p>Smart-path mode allows easier drawing of paths. If a 3x3 metatile block is selcted in the right panel, then smart path mode will automatically form a pathway using those selected blocks.</p><p>When smart-path mode is <span style=" font-weight:600;">not</span> enabled, clicking and dragging a selection will tile it in a grid.</p><p>Hold down the <span style=" font-weight:600;">shift</span> key while editing to quickly enable smart-path mode.</p></body></html> - - margin-left: 10px - Smart Paths diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e2ae8bdb..7c4436bf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -13,6 +13,7 @@ #include "adjustingstackedwidget.h" #include "draggablepixmapitem.h" #include "editcommands.h" +#include "flowlayout.h" #include #include @@ -135,6 +136,19 @@ void MainWindow::initCustomUI() { connect(labelCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ stack->setCurrentIndex(index); }); + + // Convert the layout of the map tools' frame into an adjustable FlowLayout + FlowLayout *flowLayout = new FlowLayout; + flowLayout->setContentsMargins(ui->frame_mapTools->layout()->contentsMargins()); + flowLayout->setSpacing(ui->frame_mapTools->layout()->spacing()); + for (auto *child : ui->frame_mapTools->findChildren(QString(), Qt::FindDirectChildrenOnly)) { + flowLayout->addWidget(child); + child->setFixedHeight( + ui->frame_mapTools->height() - flowLayout->contentsMargins().top() - flowLayout->contentsMargins().bottom() + ); + } + delete ui->frame_mapTools->layout(); + ui->frame_mapTools->setLayout(flowLayout); } void MainWindow::initExtraSignals() { From 8154b7c6543713b4709c1af905682002336b009c Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 16:23:41 -0400 Subject: [PATCH 14/25] Allow MainWindow height to resize smaller --- forms/mainwindow.ui | 6 ------ 1 file changed, 6 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 1ca0f6e0..cab34787 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -1816,12 +1816,6 @@ - - - 0 - 0 - - 0 From 5b24ac1bbe4b7a58178d109d79cd3e15b5a82d93 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 18:20:53 -0400 Subject: [PATCH 15/25] Allow frame_Objects width to resize smaller, cleanup various ui elements --- forms/eventpropertiesframe.ui | 15 +--- forms/mainwindow.ui | 144 ++++++++++++++++------------------ 2 files changed, 72 insertions(+), 87 deletions(-) diff --git a/forms/eventpropertiesframe.ui b/forms/eventpropertiesframe.ui index bd739561..4629438f 100644 --- a/forms/eventpropertiesframe.ui +++ b/forms/eventpropertiesframe.ui @@ -243,13 +243,10 @@ - - - 0 - 0 - - + + QFormLayout::WrapLongRows + 9 @@ -274,12 +271,6 @@ true - - - 0 - 0 - - Qt::StrongFocus diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index cab34787..08e5a51b 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -15,6 +15,18 @@ + + 9 + + + 6 + + + 9 + + + 0 + @@ -41,7 +53,7 @@ 0 - 0 + 3 0 @@ -94,24 +106,6 @@ - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - <html><head/><body><p>Expand all map folders</p></body></html> @@ -132,24 +126,6 @@ - - - 0 - 0 - - - - - 23 - 22 - - - - - 23 - 22 - - <html><head/><body><p>Collapse all map list folders</p></body></html> @@ -230,29 +206,47 @@ + + + 1 + 0 + + 0 + + 0 + + + 0 + + + 0 + + + 0 + - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -1249,7 +1243,7 @@ 3 - + true @@ -1368,6 +1362,18 @@ + + 1 + + + 1 + + + 1 + + + 1 + @@ -1381,7 +1387,7 @@ - 444 + 330 0 @@ -1437,11 +1443,11 @@ - - - 40 - 32 - + + + 0 + 0 + <html><head/><body><p>Add a new event to the map.</p></body></html> @@ -1461,17 +1467,11 @@ - + 0 0 - - - 40 - 32 - - <html><head/><body><p>Delete the selected event from the map.</p></body></html> @@ -1495,18 +1495,12 @@ Qt::Horizontal - - - 40 - 20 - - - + 0 0 From f08d02a67f4682bb560474d730276547df66b7e6 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 19:07:49 -0400 Subject: [PATCH 16/25] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aaeeef7..245fcc7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Fixed - Fix a bug with the current metatile selection zoom. - Fix bug preventing the status bar from updating the current position while dragging events. -- Fix porymap icon not showing on window or panel on Linux +- Fix porymap icon not showing on window or panel on Linux. +- Zooming the map in/out will now focus on the cursor. ## [4.3.1] - 2020-07-17 ### Added From ebe55c76e03a1c575131888cf36b72d1b110a827 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 20 Oct 2020 19:13:11 -0400 Subject: [PATCH 17/25] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aaeeef7..db5d9e24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Fixed - Fix a bug with the current metatile selection zoom. - Fix bug preventing the status bar from updating the current position while dragging events. -- Fix porymap icon not showing on window or panel on Linux +- Fix porymap icon not showing on window or panel on Linux. +- The main window can now be resized to fit on lower resolution displays. ## [4.3.1] - 2020-07-17 ### Added From 5624de750b3fc0838107972b5b44543c65343b0f Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 15 Sep 2020 14:57:46 -0400 Subject: [PATCH 18/25] Save & restore tileset editor geometry & state from config --- include/config.h | 12 +++++++---- src/config.cpp | 45 +++++++++++++++++++++++++++++----------- src/mainwindow.cpp | 15 ++++++++------ src/ui/tileseteditor.cpp | 5 +++++ 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/include/config.h b/include/config.h index 4bd21cfe..e9aa6943 100644 --- a/include/config.h +++ b/include/config.h @@ -50,7 +50,8 @@ public: void setRecentMap(QString map); void setMapSortOrder(MapSortOrder order); void setPrettyCursors(bool enabled); - void setGeometry(QByteArray, QByteArray, QByteArray, QByteArray); + void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray); + void setTilesetEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); void setMetatilesZoom(int zoom); void setShowPlayerView(bool enabled); @@ -62,7 +63,8 @@ public: QString getRecentMap(); MapSortOrder getMapSortOrder(); bool getPrettyCursors(); - QMap getGeometry(); + QMap getMainGeometry(); + QMap getTilesetEditorGeometry(); int getCollisionOpacity(); int getMetatilesZoom(); bool getShowPlayerView(); @@ -83,11 +85,13 @@ private: QByteArray bytesFromString(QString); MapSortOrder mapSortOrder; bool prettyCursors; - QByteArray windowGeometry; - QByteArray windowState; + QByteArray mainWindowGeometry; + QByteArray mainWindowState; QByteArray mapSplitterState; QByteArray eventsSlpitterState; QByteArray mainSplitterState; + QByteArray tilesetEditorGeometry; + QByteArray tilesetEditorState; int collisionOpacity; int metatilesZoom; bool showPlayerView; diff --git a/src/config.cpp b/src/config.cpp index 8934f707..f12c3789 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -122,10 +122,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->mapSortOrder = MapSortOrder::Group; logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value)); } - } else if (key == "window_geometry") { - this->windowGeometry = bytesFromString(value); - } else if (key == "window_state") { - this->windowState = bytesFromString(value); + } else if (key == "main_window_geometry") { + this->mainWindowGeometry = bytesFromString(value); + } else if (key == "main_window_state") { + this->mainWindowState = bytesFromString(value); } else if (key == "map_splitter_state") { this->mapSplitterState = bytesFromString(value); } else if (key == "main_splitter_state") { @@ -137,6 +137,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { logWarn(QString("Invalid config value for collision_opacity: '%1'. Must be an integer.").arg(value)); this->collisionOpacity = 50; } + } else if (key == "tileset_editor_geometry") { + this->tilesetEditorGeometry = bytesFromString(value); + } else if (key == "tileset_editor_state") { + this->tilesetEditorState = bytesFromString(value); } else if (key == "metatiles_zoom") { bool ok; this->metatilesZoom = qMax(10, qMin(100, value.toInt(&ok))); @@ -186,10 +190,12 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("recent_map", this->recentMap); map.insert("pretty_cursors", this->prettyCursors ? "1" : "0"); map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder)); - map.insert("window_geometry", stringFromByteArray(this->windowGeometry)); - map.insert("window_state", stringFromByteArray(this->windowState)); + map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry)); + map.insert("main_window_state", stringFromByteArray(this->mainWindowState)); map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState)); map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState)); + map.insert("tileset_editor_geometry", stringFromByteArray(this->tilesetEditorGeometry)); + map.insert("tileset_editor_state", stringFromByteArray(this->tilesetEditorState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom)); map.insert("show_player_view", this->showPlayerView ? "1" : "0"); @@ -243,15 +249,21 @@ void PorymapConfig::setMonitorFiles(bool monitor) { this->save(); } -void PorymapConfig::setGeometry(QByteArray windowGeometry_, QByteArray windowState_, +void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { - this->windowGeometry = windowGeometry_; - this->windowState = windowState_; + this->mainWindowGeometry = mainWindowGeometry_; + this->mainWindowState = mainWindowState_; this->mapSplitterState = mapSplitterState_; this->mainSplitterState = mainSplitterState_; this->save(); } +void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_, QByteArray tilesetEditorState_) { + this->tilesetEditorGeometry = tilesetEditorGeometry_; + this->tilesetEditorState = tilesetEditorState_; + this->save(); +} + void PorymapConfig::setCollisionOpacity(int opacity) { this->collisionOpacity = opacity; // don't auto-save here because this can be called very frequently. @@ -296,17 +308,26 @@ bool PorymapConfig::getPrettyCursors() { return this->prettyCursors; } -QMap PorymapConfig::getGeometry() { +QMap PorymapConfig::getMainGeometry() { QMap geometry; - geometry.insert("window_geometry", this->windowGeometry); - geometry.insert("window_state", this->windowState); + geometry.insert("main_window_geometry", this->mainWindowGeometry); + geometry.insert("main_window_state", this->mainWindowState); geometry.insert("map_splitter_state", this->mapSplitterState); geometry.insert("main_splitter_state", this->mainSplitterState); return geometry; } +QMap PorymapConfig::getTilesetEditorGeometry() { + QMap geometry; + + geometry.insert("tileset_editor_geometry", this->tilesetEditorGeometry); + geometry.insert("tileset_editor_state", this->tilesetEditorState); + + return geometry; +} + int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e2ae8bdb..4738d004 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -350,10 +350,10 @@ void MainWindow::loadUserSettings() { } void MainWindow::restoreWindowState() { - logInfo("Restoring window geometry from previous session."); - QMap geometry = porymapConfig.getGeometry(); - this->restoreGeometry(geometry.value("window_geometry")); - this->restoreState(geometry.value("window_state")); + logInfo("Restoring main window geometry from previous session."); + QMap geometry = porymapConfig.getMainGeometry(); + this->restoreGeometry(geometry.value("main_window_geometry")); + this->restoreState(geometry.value("main_window_state")); this->ui->splitter_map->restoreState(geometry.value("map_splitter_state")); this->ui->splitter_main->restoreState(geometry.value("main_splitter_state")); } @@ -2518,7 +2518,10 @@ void MainWindow::on_actionTileset_Editor_triggered() this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this); connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString))); connect(this->tilesetEditor, &QObject::destroyed, [=](QObject *) { this->tilesetEditor = nullptr; }); - this->tilesetEditor->setAttribute(Qt::WA_DeleteOnClose); + logInfo("Restoring tileset editor geometry from previous session."); + QMap geometry = porymapConfig.getTilesetEditorGeometry(); + this->tilesetEditor->restoreGeometry(geometry.value("tileset_editor_geometry")); + this->tilesetEditor->restoreState(geometry.value("tileset_editor_state")); } if (!this->tilesetEditor->isVisible()) { @@ -2697,7 +2700,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { } } - porymapConfig.setGeometry( + porymapConfig.setMainGeometry( this->saveGeometry(), this->saveState(), this->ui->splitter_map->saveState(), diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 75a60b9a..de095a80 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -606,6 +606,11 @@ void TilesetEditor::closeEvent(QCloseEvent *event) } else { event->accept(); } + + porymapConfig.setTilesetEditorGeometry( + this->saveGeometry(), + this->saveState() + ); } void TilesetEditor::on_actionChange_Metatiles_Count_triggered() From daae6fe52bb414a5d91979a782bb8c9525f16d08 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 15 Sep 2020 19:03:15 -0400 Subject: [PATCH 19/25] Save & restore region map editor geometry & state from config --- include/config.h | 4 ++++ src/config.cpp | 21 +++++++++++++++++++++ src/mainwindow.cpp | 5 ++++- src/ui/regionmapeditor.cpp | 5 +++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index e9aa6943..54f592ea 100644 --- a/include/config.h +++ b/include/config.h @@ -52,6 +52,7 @@ public: void setPrettyCursors(bool enabled); void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray); void setTilesetEditorGeometry(QByteArray, QByteArray); + void setRegionMapEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); void setMetatilesZoom(int zoom); void setShowPlayerView(bool enabled); @@ -65,6 +66,7 @@ public: bool getPrettyCursors(); QMap getMainGeometry(); QMap getTilesetEditorGeometry(); + QMap getRegionMapEditorGeometry(); int getCollisionOpacity(); int getMetatilesZoom(); bool getShowPlayerView(); @@ -92,6 +94,8 @@ private: QByteArray mainSplitterState; QByteArray tilesetEditorGeometry; QByteArray tilesetEditorState; + QByteArray regionMapEditorGeometry; + QByteArray regionMapEditorState; int collisionOpacity; int metatilesZoom; bool showPlayerView; diff --git a/src/config.cpp b/src/config.cpp index f12c3789..349cb0e2 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -141,6 +141,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->tilesetEditorGeometry = bytesFromString(value); } else if (key == "tileset_editor_state") { this->tilesetEditorState = bytesFromString(value); + } else if (key == "region_map_editor_geometry") { + this->regionMapEditorGeometry = bytesFromString(value); + } else if (key == "region_map_editor_state") { + this->regionMapEditorState = bytesFromString(value); } else if (key == "metatiles_zoom") { bool ok; this->metatilesZoom = qMax(10, qMin(100, value.toInt(&ok))); @@ -196,6 +200,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState)); map.insert("tileset_editor_geometry", stringFromByteArray(this->tilesetEditorGeometry)); map.insert("tileset_editor_state", stringFromByteArray(this->tilesetEditorState)); + map.insert("region_map_editor_geometry", stringFromByteArray(this->regionMapEditorGeometry)); + map.insert("region_map_editor_state", stringFromByteArray(this->regionMapEditorState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom)); map.insert("show_player_view", this->showPlayerView ? "1" : "0"); @@ -264,6 +270,12 @@ void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_, this->save(); } +void PorymapConfig::setRegionMapEditorGeometry(QByteArray regionMapEditorGeometry_, QByteArray regionMapEditorState_) { + this->regionMapEditorGeometry = regionMapEditorGeometry_; + this->regionMapEditorState = regionMapEditorState_; + this->save(); +} + void PorymapConfig::setCollisionOpacity(int opacity) { this->collisionOpacity = opacity; // don't auto-save here because this can be called very frequently. @@ -328,6 +340,15 @@ QMap PorymapConfig::getTilesetEditorGeometry() { return geometry; } +QMap PorymapConfig::getRegionMapEditorGeometry() { + QMap geometry; + + geometry.insert("region_map_editor_geometry", this->regionMapEditorGeometry); + geometry.insert("region_map_editor_state", this->regionMapEditorState); + + return geometry; +} + int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4738d004..0e77fffc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2661,7 +2661,10 @@ void MainWindow::on_actionRegion_Map_Editor_triggered() { return; } connect(this->regionMapEditor, &QObject::destroyed, [=](QObject *) { this->regionMapEditor = nullptr; }); - this->regionMapEditor->setAttribute(Qt::WA_DeleteOnClose); + logInfo("Restoring region map editor geometry from previous session."); + QMap geometry = porymapConfig.getRegionMapEditorGeometry(); + this->regionMapEditor->restoreGeometry(geometry.value("region_map_editor_geometry")); + this->regionMapEditor->restoreState(geometry.value("region_map_editor_state")); } if (!this->regionMapEditor->isVisible()) { diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 1ced19b6..b6d9030b 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -899,6 +899,11 @@ void RegionMapEditor::closeEvent(QCloseEvent *event) } else { event->accept(); } + + porymapConfig.setRegionMapEditorGeometry( + this->saveGeometry(), + this->saveState() + ); } void RegionMapEditor::on_verticalSlider_Zoom_Map_Image_valueChanged(int val) { From 8b7f4069cdab6c33a97b70a24cb671cdca4c6f37 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 15 Sep 2020 21:43:52 -0400 Subject: [PATCH 20/25] Save & restore palette editor geometry & state from config --- include/config.h | 4 ++++ include/ui/paletteeditor.h | 1 + src/config.cpp | 21 +++++++++++++++++++++ src/ui/paletteeditor.cpp | 10 +++++++++- src/ui/tileseteditor.cpp | 4 ++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 54f592ea..008eeeb7 100644 --- a/include/config.h +++ b/include/config.h @@ -52,6 +52,7 @@ public: void setPrettyCursors(bool enabled); void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray); void setTilesetEditorGeometry(QByteArray, QByteArray); + void setPaletteEditorGeometry(QByteArray, QByteArray); void setRegionMapEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); void setMetatilesZoom(int zoom); @@ -66,6 +67,7 @@ public: bool getPrettyCursors(); QMap getMainGeometry(); QMap getTilesetEditorGeometry(); + QMap getPaletteEditorGeometry(); QMap getRegionMapEditorGeometry(); int getCollisionOpacity(); int getMetatilesZoom(); @@ -94,6 +96,8 @@ private: QByteArray mainSplitterState; QByteArray tilesetEditorGeometry; QByteArray tilesetEditorState; + QByteArray paletteEditorGeometry; + QByteArray paletteEditorState; QByteArray regionMapEditorGeometry; QByteArray regionMapEditorState; int collisionOpacity; diff --git a/include/ui/paletteeditor.h b/include/ui/paletteeditor.h index 9cd4da03..9bf58062 100644 --- a/include/ui/paletteeditor.h +++ b/include/ui/paletteeditor.h @@ -46,6 +46,7 @@ private: void setColor(int); void commitEditHistory(int paletteid); void setColorsFromHistory(PaletteHistoryItem*, int); + void closeEvent(QCloseEvent*); signals: void closed(); diff --git a/src/config.cpp b/src/config.cpp index 349cb0e2..3c9fe33d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -141,6 +141,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->tilesetEditorGeometry = bytesFromString(value); } else if (key == "tileset_editor_state") { this->tilesetEditorState = bytesFromString(value); + } else if (key == "palette_editor_geometry") { + this->paletteEditorGeometry = bytesFromString(value); + } else if (key == "palette_editor_state") { + this->paletteEditorState = bytesFromString(value); } else if (key == "region_map_editor_geometry") { this->regionMapEditorGeometry = bytesFromString(value); } else if (key == "region_map_editor_state") { @@ -200,6 +204,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState)); map.insert("tileset_editor_geometry", stringFromByteArray(this->tilesetEditorGeometry)); map.insert("tileset_editor_state", stringFromByteArray(this->tilesetEditorState)); + map.insert("palette_editor_geometry", stringFromByteArray(this->paletteEditorGeometry)); + map.insert("palette_editor_state", stringFromByteArray(this->paletteEditorState)); map.insert("region_map_editor_geometry", stringFromByteArray(this->regionMapEditorGeometry)); map.insert("region_map_editor_state", stringFromByteArray(this->regionMapEditorState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); @@ -270,6 +276,12 @@ void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_, this->save(); } +void PorymapConfig::setPaletteEditorGeometry(QByteArray paletteEditorGeometry_, QByteArray paletteEditorState_) { + this->paletteEditorGeometry = paletteEditorGeometry_; + this->paletteEditorState = paletteEditorState_; + this->save(); +} + void PorymapConfig::setRegionMapEditorGeometry(QByteArray regionMapEditorGeometry_, QByteArray regionMapEditorState_) { this->regionMapEditorGeometry = regionMapEditorGeometry_; this->regionMapEditorState = regionMapEditorState_; @@ -340,6 +352,15 @@ QMap PorymapConfig::getTilesetEditorGeometry() { return geometry; } +QMap PorymapConfig::getPaletteEditorGeometry() { + QMap geometry; + + geometry.insert("palette_editor_geometry", this->paletteEditorGeometry); + geometry.insert("palette_editor_state", this->paletteEditorState); + + return geometry; +} + QMap PorymapConfig::getRegionMapEditorGeometry() { QMap geometry; diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index fd9eeb9a..c24aad6a 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -1,9 +1,10 @@ #include "paletteeditor.h" #include "ui_paletteeditor.h" #include "paletteutil.h" +#include "config.h" +#include "log.h" #include #include -#include "log.h" PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset *secondaryTileset, int paletteId, QWidget *parent) : QMainWindow(parent), @@ -311,3 +312,10 @@ void PaletteEditor::on_actionImport_Palette_triggered() this->commitEditHistory(paletteId); emit this->changedPaletteColor(); } + +void PaletteEditor::closeEvent(QCloseEvent*) { + porymapConfig.setPaletteEditorGeometry( + this->saveGeometry(), + this->saveState() + ); +} diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index de095a80..580ad4cc 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -694,6 +694,10 @@ void TilesetEditor::on_actionChange_Palettes_triggered() this->paletteEditor = new PaletteEditor(this->project, this->primaryTileset, this->secondaryTileset, this->paletteId, this); connect(this->paletteEditor, SIGNAL(changedPaletteColor()), this, SLOT(onPaletteEditorChangedPaletteColor())); connect(this->paletteEditor, SIGNAL(changedPalette(int)), this, SLOT(onPaletteEditorChangedPalette(int))); + logInfo("Restoring palette editor geometry from previous session."); + QMap geometry = porymapConfig.getPaletteEditorGeometry(); + this->paletteEditor->restoreGeometry(geometry.value("palette_editor_geometry")); + this->paletteEditor->restoreState(geometry.value("palette_editor_state")); } if (!this->paletteEditor->isVisible()) { From 81ad828a532bc46cb8219009c33691afc6012f86 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 15 Sep 2020 22:15:30 -0400 Subject: [PATCH 21/25] Fix palette editor windowTitle --- forms/paletteeditor.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forms/paletteeditor.ui b/forms/paletteeditor.ui index 03650e9f..b87b4398 100644 --- a/forms/paletteeditor.ui +++ b/forms/paletteeditor.ui @@ -14,7 +14,7 @@ Qt::ClickFocus - MainWindow + Palette Editor From 7cbdea4e26e04846f565b09086217bd876eeea0e Mon Sep 17 00:00:00 2001 From: BigBahss Date: Wed, 16 Sep 2020 04:08:17 -0400 Subject: [PATCH 22/25] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aaeeef7..8f0d0d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - The New Map dialog now gives an option to specify the "Show Location Name" field. - Some new shortcuts were added in [porymap/#290](https://github.com/huderlem/porymap/pull/290). - All plain text boxes now have a clear button to delete the text. +- The window sizes and positions of the tileset editor, palette editor, and region map editor are now stored in `porymap.cfg`. ### Changed - Holding `shift` now toggles "Smart Path" drawing; when the "Smart Paths" checkbox is checked, holding `shift` will temporarily disable it. @@ -22,7 +23,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Fixed - Fix a bug with the current metatile selection zoom. - Fix bug preventing the status bar from updating the current position while dragging events. -- Fix porymap icon not showing on window or panel on Linux +- Fix porymap icon not showing on window or panel on Linux. ## [4.3.1] - 2020-07-17 ### Added From e4095130c576acdc48d161875314213998be5af8 Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 25 Sep 2020 08:12:13 -0400 Subject: [PATCH 23/25] Fix closing tileset editor not closing palette editor --- include/ui/paletteeditor.h | 1 + include/ui/regionmapeditor.h | 1 + include/ui/tileseteditor.h | 9 +++++-- src/mainwindow.cpp | 15 ++++------- src/mainwindow_scriptapi.cpp | 2 +- src/ui/paletteeditor.cpp | 8 ++++++ src/ui/regionmapeditor.cpp | 8 ++++++ src/ui/tileseteditor.cpp | 52 +++++++++++++++++++++++++++--------- 8 files changed, 70 insertions(+), 26 deletions(-) diff --git a/include/ui/paletteeditor.h b/include/ui/paletteeditor.h index 9bf58062..2dbd6d29 100644 --- a/include/ui/paletteeditor.h +++ b/include/ui/paletteeditor.h @@ -45,6 +45,7 @@ private: void refreshColor(int); void setColor(int); void commitEditHistory(int paletteid); + void restoreWindowState(); void setColorsFromHistory(PaletteHistoryItem*, int); void closeEvent(QCloseEvent*); diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index a664df77..484103f3 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -97,6 +97,7 @@ private: bool createCityMap(QString name); bool tryInsertNewMapEntry(QString); + void restoreWindowState(); void closeEvent(QCloseEvent* event); private slots: diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index fde5a4be..a3aa4589 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -37,8 +37,9 @@ class TilesetEditor : public QMainWindow public: explicit TilesetEditor(Project*, Map*, QWidget *parent = nullptr); ~TilesetEditor(); - void setMap(Map*); - void setTilesets(QString, QString); + void update(Map *map, QString primaryTilsetLabel, QString secondaryTilesetLabel); + void updateMap(Map *map); + void updateTilesets(QString primaryTilsetLabel, QString secondaryTilesetLabel); bool selectMetatile(uint16_t metatileId); private slots: @@ -98,6 +99,9 @@ private: void initTileSelector(); void initSelectedTileItem(); void initMetatileLayersItem(); + void restoreWindowState(); + void setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel); + void reset(); void drawSelectedTiles(); void importTilesetTiles(Tileset*, bool); void importTilesetMetatiles(Tileset*, bool); @@ -110,6 +114,7 @@ private: MetatileLayersItem *metatileLayersItem = nullptr; PaletteEditor *paletteEditor = nullptr; Project *project = nullptr; + Map *map = nullptr; Metatile *metatile = nullptr; int paletteId; bool tileXFlip; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e77fffc..8ef1e5af 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1206,8 +1206,11 @@ void MainWindow::on_actionNew_Tileset_triggered() { void MainWindow::updateTilesetEditor() { if (this->tilesetEditor) { - this->tilesetEditor->setMap(this->editor->map); - this->tilesetEditor->setTilesets(editor->ui->comboBox_PrimaryTileset->currentText(), editor->ui->comboBox_SecondaryTileset->currentText()); + this->tilesetEditor->update( + this->editor->map, + editor->ui->comboBox_PrimaryTileset->currentText(), + editor->ui->comboBox_SecondaryTileset->currentText() + ); } } @@ -2518,10 +2521,6 @@ void MainWindow::on_actionTileset_Editor_triggered() this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this); connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString))); connect(this->tilesetEditor, &QObject::destroyed, [=](QObject *) { this->tilesetEditor = nullptr; }); - logInfo("Restoring tileset editor geometry from previous session."); - QMap geometry = porymapConfig.getTilesetEditorGeometry(); - this->tilesetEditor->restoreGeometry(geometry.value("tileset_editor_geometry")); - this->tilesetEditor->restoreState(geometry.value("tileset_editor_state")); } if (!this->tilesetEditor->isVisible()) { @@ -2661,10 +2660,6 @@ void MainWindow::on_actionRegion_Map_Editor_triggered() { return; } connect(this->regionMapEditor, &QObject::destroyed, [=](QObject *) { this->regionMapEditor = nullptr; }); - logInfo("Restoring region map editor geometry from previous session."); - QMap geometry = porymapConfig.getRegionMapEditorGeometry(); - this->regionMapEditor->restoreGeometry(geometry.value("region_map_editor_geometry")); - this->regionMapEditor->restoreState(geometry.value("region_map_editor_state")); } if (!this->regionMapEditor->isVisible()) { diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index cc89fc0b..b60ba820 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -247,7 +247,7 @@ void MainWindow::addImage(int x, int y, QString filepath) { void MainWindow::refreshAfterPaletteChange(Tileset *tileset) { if (this->tilesetEditor) { - this->tilesetEditor->setTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); + this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); } this->editor->metatile_selector_item->draw(); this->editor->selected_border_metatiles_item->draw(); diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index c24aad6a..0e1366e6 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -113,6 +113,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset this->initColorSliders(); this->setPaletteId(paletteId); this->commitEditHistory(this->ui->spinBox_PaletteId->value()); + this->restoreWindowState(); } PaletteEditor::~PaletteEditor() @@ -228,6 +229,13 @@ void PaletteEditor::commitEditHistory(int paletteId) { this->palettesHistory[paletteId].push(commit); } +void PaletteEditor::restoreWindowState() { + logInfo("Restoring palette editor geometry from previous session."); + QMap geometry = porymapConfig.getPaletteEditorGeometry(); + this->restoreGeometry(geometry.value("palette_editor_geometry")); + this->restoreState(geometry.value("palette_editor_state")); +} + void PaletteEditor::on_actionUndo_triggered() { int paletteId = this->ui->spinBox_PaletteId->value(); diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index b6d9030b..ce3440dd 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -24,6 +24,7 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) : this->project = project_; this->region_map = new RegionMap; this->ui->action_RegionMap_Resize->setVisible(false); + this->restoreWindowState(); } RegionMapEditor::~RegionMapEditor() @@ -42,6 +43,13 @@ RegionMapEditor::~RegionMapEditor() delete scene_region_map_tiles; } +void RegionMapEditor::restoreWindowState() { + logInfo("Restoring region map editor geometry from previous session."); + QMap geometry = porymapConfig.getRegionMapEditorGeometry(); + this->restoreGeometry(geometry.value("region_map_editor_geometry")); + this->restoreState(geometry.value("region_map_editor_state")); +} + void RegionMapEditor::on_action_RegionMap_Save_triggered() { setCurrentSquareOptions(); if (project && region_map) { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 580ad4cc..af5da658 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -100,6 +100,7 @@ void TilesetEditor::init(Project *project, Map *map) { this->initTileSelector(); this->initSelectedTileItem(); this->metatileSelector->select(0); + this->restoreWindowState(); MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy()); metatileHistory.push(commit); @@ -113,11 +114,17 @@ bool TilesetEditor::selectMetatile(uint16_t metatileId) { return true; } -void TilesetEditor::setMap(Map *map) { +void TilesetEditor::update(Map *map, QString primaryTilesetLabel, QString secondaryTilesetLabel) { + this->updateMap(map); + this->updateTilesets(primaryTilesetLabel, secondaryTilesetLabel); +} + +void TilesetEditor::updateMap(Map *map) { + this->map = map; this->metatileSelector->map = map; } -void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { +void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { if (this->hasUnsavedChanges) { QMessageBox::StandardButton result = QMessageBox::question( this, @@ -129,13 +136,17 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi this->on_actionSave_Tileset_triggered(); } this->hasUnsavedChanges = false; - delete this->primaryTileset; - delete this->secondaryTileset; + this->setTilesets(primaryTilesetLabel, secondaryTilesetLabel); + this->refresh(); +} + +void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { Tileset *primaryTileset = project->getTileset(primaryTilesetLabel); Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel); + if (this->primaryTileset) delete this->primaryTileset; + if (this->secondaryTileset) delete this->secondaryTileset; this->primaryTileset = primaryTileset->copy(); this->secondaryTileset = secondaryTileset->copy(); - this->refresh(); } void TilesetEditor::refresh() { @@ -196,6 +207,21 @@ void TilesetEditor::initSelectedTileItem() { this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); } +void TilesetEditor::restoreWindowState() { + logInfo("Restoring tileset editor geometry from previous session."); + QMap geometry = porymapConfig.getTilesetEditorGeometry(); + this->restoreGeometry(geometry.value("tileset_editor_geometry")); + this->restoreState(geometry.value("tileset_editor_state")); +} + +void TilesetEditor::reset() { + this->hasUnsavedChanges = false; + this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name); + if (this->paletteEditor) + this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); + this->refresh(); +} + void TilesetEditor::drawSelectedTiles() { if (!this->selectedTileScene) { return; @@ -599,6 +625,7 @@ void TilesetEditor::closeEvent(QCloseEvent *event) this->on_actionSave_Tileset_triggered(); event->accept(); } else if (result == QMessageBox::No) { + this->reset(); event->accept(); } else if (result == QMessageBox::Cancel) { event->ignore(); @@ -607,10 +634,13 @@ void TilesetEditor::closeEvent(QCloseEvent *event) event->accept(); } - porymapConfig.setTilesetEditorGeometry( - this->saveGeometry(), - this->saveState() - ); + if (event->isAccepted()) { + if (this->paletteEditor) this->paletteEditor->close(); + porymapConfig.setTilesetEditorGeometry( + this->saveGeometry(), + this->saveState() + ); + } } void TilesetEditor::on_actionChange_Metatiles_Count_triggered() @@ -694,10 +724,6 @@ void TilesetEditor::on_actionChange_Palettes_triggered() this->paletteEditor = new PaletteEditor(this->project, this->primaryTileset, this->secondaryTileset, this->paletteId, this); connect(this->paletteEditor, SIGNAL(changedPaletteColor()), this, SLOT(onPaletteEditorChangedPaletteColor())); connect(this->paletteEditor, SIGNAL(changedPalette(int)), this, SLOT(onPaletteEditorChangedPalette(int))); - logInfo("Restoring palette editor geometry from previous session."); - QMap geometry = porymapConfig.getPaletteEditorGeometry(); - this->paletteEditor->restoreGeometry(geometry.value("palette_editor_geometry")); - this->paletteEditor->restoreState(geometry.value("palette_editor_state")); } if (!this->paletteEditor->isVisible()) { From f47e8b1903b71251083bf62559adfb6048b0546d Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 25 Sep 2020 08:20:51 -0400 Subject: [PATCH 24/25] Refactor TilesetEditor --- include/ui/tileseteditor.h | 11 +- src/ui/tileseteditor.cpp | 220 +++++++++++++++++++------------------ 2 files changed, 122 insertions(+), 109 deletions(-) diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index a3aa4589..283f9cde 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -93,13 +93,17 @@ private slots: void on_actionImport_Secondary_Metatiles_triggered(); private: - void init(Project*, Map*); - void closeEvent(QCloseEvent*); - void initMetatileSelector(Map*); + void initUi(); + void setMetatileBehaviors(); + void setMetatileLayersUi(); + void setVersionSpecificUi(); + void setMetatileLabelValidator(); + void initMetatileSelector(); void initTileSelector(); void initSelectedTileItem(); void initMetatileLayersItem(); void restoreWindowState(); + void initMetatileHistory(); void setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel); void reset(); void drawSelectedTiles(); @@ -107,6 +111,7 @@ private: void importTilesetMetatiles(Tileset*, bool); void refresh(); void saveMetatileLabel(); + void closeEvent(QCloseEvent*); Ui::TilesetEditor *ui; History metatileHistory; TilesetEditorMetatileSelector *metatileSelector = nullptr; diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index af5da658..950b8d46 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -14,10 +14,14 @@ TilesetEditor::TilesetEditor(Project *project, Map *map, QWidget *parent) : QMainWindow(parent), - ui(new Ui::TilesetEditor) + ui(new Ui::TilesetEditor), + project(project), + map(map), + hasUnsavedChanges(false) { - this->init(project, map); - new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(on_actionRedo_triggered())); + this->setTilesets(this->map->layout->tileset_primary_label, this->map->layout->tileset_secondary_label); + this->initUi(); + this->initMetatileHistory(); } TilesetEditor::~TilesetEditor() @@ -37,83 +41,6 @@ TilesetEditor::~TilesetEditor() delete metatileLayersScene; } -void TilesetEditor::init(Project *project, Map *map) { - ui->setupUi(this); - this->project = project; - - this->hasUnsavedChanges = false; - this->tileXFlip = ui->checkBox_xFlip->isChecked(); - this->tileYFlip = ui->checkBox_yFlip->isChecked(); - this->paletteId = ui->spinBox_paletteSelector->value(); - - Tileset *primaryTileset = project->getTileset(map->layout->tileset_primary_label); - Tileset *secondaryTileset = project->getTileset(map->layout->tileset_secondary_label); - if (this->primaryTileset) delete this->primaryTileset; - if (this->secondaryTileset) delete this->secondaryTileset; - this->primaryTileset = primaryTileset->copy(); - this->secondaryTileset = secondaryTileset->copy(); - - QList sortedBehaviors; - for (int num : project->metatileBehaviorMapInverse.keys()) { - this->ui->comboBox_metatileBehaviors->addItem(project->metatileBehaviorMapInverse[num], num); - } - - if (!projectConfig.getTripleLayerMetatilesEnabled()) { - this->ui->comboBox_layerType->addItem("Normal - Middle/Top", 0); - this->ui->comboBox_layerType->addItem("Covered - Bottom/Middle", 1); - this->ui->comboBox_layerType->addItem("Split - Bottom/Top", 2); - } else { - this->ui->comboBox_layerType->setVisible(false); - this->ui->label_layerType->setVisible(false); - this->ui->label_BottomTop->setText("Bottom/Middle/Top"); - } - - this->ui->spinBox_paletteSelector->setMinimum(0); - this->ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1); - - if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { - this->ui->comboBox_encounterType->setVisible(true); - this->ui->label_encounterType->setVisible(true); - this->ui->comboBox_encounterType->addItem("None", 0); - this->ui->comboBox_encounterType->addItem("Land", 1); - this->ui->comboBox_encounterType->addItem("Water", 2); - this->ui->comboBox_terrainType->setVisible(true); - this->ui->label_terrainType->setVisible(true); - this->ui->comboBox_terrainType->addItem("Normal", 0); - this->ui->comboBox_terrainType->addItem("Grass", 1); - this->ui->comboBox_terrainType->addItem("Water", 2); - this->ui->comboBox_terrainType->addItem("Waterfall", 3); - } else { - this->ui->comboBox_encounterType->setVisible(false); - this->ui->label_encounterType->setVisible(false); - this->ui->comboBox_terrainType->setVisible(false); - this->ui->label_terrainType->setVisible(false); - } - - //only allow characters valid for a symbol - QRegExp expression("[_A-Za-z0-9]*$"); - QRegExpValidator *validator = new QRegExpValidator(expression); - this->ui->lineEdit_metatileLabel->setValidator(validator); - - this->initMetatileSelector(map); - this->initMetatileLayersItem(); - this->initTileSelector(); - this->initSelectedTileItem(); - this->metatileSelector->select(0); - this->restoreWindowState(); - - MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy()); - metatileHistory.push(commit); -} - -bool TilesetEditor::selectMetatile(uint16_t metatileId) { - if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false; - this->metatileSelector->select(metatileId); - QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(metatileId); - this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y()); - return true; -} - void TilesetEditor::update(Map *map, QString primaryTilesetLabel, QString secondaryTilesetLabel) { this->updateMap(map); this->updateTilesets(primaryTilesetLabel, secondaryTilesetLabel); @@ -140,6 +67,14 @@ void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondar this->refresh(); } +bool TilesetEditor::selectMetatile(uint16_t metatileId) { + if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false; + this->metatileSelector->select(metatileId); + QPoint pos = this->metatileSelector->getMetatileIdCoordsOnWidget(metatileId); + this->ui->scrollArea_Metatiles->ensureVisible(pos.x(), pos.y()); + return true; +} + void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { Tileset *primaryTileset = project->getTileset(primaryTilesetLabel); Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel); @@ -149,23 +84,77 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi this->secondaryTileset = secondaryTileset->copy(); } -void TilesetEditor::refresh() { - this->metatileLayersItem->setTilesets(this->primaryTileset, this->secondaryTileset); - this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); - this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); - this->metatileSelector->select(this->metatileSelector->getSelectedMetatile()); - this->drawSelectedTiles(); +void TilesetEditor::initUi() { + ui->setupUi(this); + new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(on_actionRedo_triggered())); + this->tileXFlip = ui->checkBox_xFlip->isChecked(); + this->tileYFlip = ui->checkBox_yFlip->isChecked(); + this->paletteId = ui->spinBox_paletteSelector->value(); + this->ui->spinBox_paletteSelector->setMinimum(0); + this->ui->spinBox_paletteSelector->setMaximum(Project::getNumPalettesTotal() - 1); - 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->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); + this->setMetatileBehaviors(); + this->setMetatileLayersUi(); + this->setVersionSpecificUi(); + this->setMetatileLabelValidator(); + + this->initMetatileSelector(); + this->initMetatileLayersItem(); + this->initTileSelector(); + this->initSelectedTileItem(); + this->metatileSelector->select(0); + this->restoreWindowState(); } -void TilesetEditor::initMetatileSelector(Map *map) +void TilesetEditor::setMetatileBehaviors() { + for (int num : project->metatileBehaviorMapInverse.keys()) { + this->ui->comboBox_metatileBehaviors->addItem(project->metatileBehaviorMapInverse[num], num); + } +} + +void TilesetEditor::setMetatileLayersUi() { + if (!projectConfig.getTripleLayerMetatilesEnabled()) { + this->ui->comboBox_layerType->addItem("Normal - Middle/Top", 0); + this->ui->comboBox_layerType->addItem("Covered - Bottom/Middle", 1); + this->ui->comboBox_layerType->addItem("Split - Bottom/Top", 2); + } else { + this->ui->comboBox_layerType->setVisible(false); + this->ui->label_layerType->setVisible(false); + this->ui->label_BottomTop->setText("Bottom/Middle/Top"); + } +} + +void TilesetEditor::setVersionSpecificUi() { + if (projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered) { + this->ui->comboBox_encounterType->setVisible(true); + this->ui->label_encounterType->setVisible(true); + this->ui->comboBox_encounterType->addItem("None", 0); + this->ui->comboBox_encounterType->addItem("Land", 1); + this->ui->comboBox_encounterType->addItem("Water", 2); + this->ui->comboBox_terrainType->setVisible(true); + this->ui->label_terrainType->setVisible(true); + this->ui->comboBox_terrainType->addItem("Normal", 0); + this->ui->comboBox_terrainType->addItem("Grass", 1); + this->ui->comboBox_terrainType->addItem("Water", 2); + this->ui->comboBox_terrainType->addItem("Waterfall", 3); + } else { + this->ui->comboBox_encounterType->setVisible(false); + this->ui->label_encounterType->setVisible(false); + this->ui->comboBox_terrainType->setVisible(false); + this->ui->label_terrainType->setVisible(false); + } +} + +void TilesetEditor::setMetatileLabelValidator() { + //only allow characters valid for a symbol + QRegExp expression("[_A-Za-z0-9]*$"); + QRegExpValidator *validator = new QRegExpValidator(expression); + this->ui->lineEdit_metatileLabel->setValidator(validator); +} + +void TilesetEditor::initMetatileSelector() { - this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset, map); + this->metatileSelector = new TilesetEditorMetatileSelector(this->primaryTileset, this->secondaryTileset, this->map); connect(this->metatileSelector, SIGNAL(hoveredMetatileChanged(uint16_t)), this, SLOT(onHoveredMetatileChanged(uint16_t))); connect(this->metatileSelector, SIGNAL(hoveredMetatileCleared()), @@ -181,6 +170,19 @@ void TilesetEditor::initMetatileSelector(Map *map) this->ui->graphicsView_Metatiles->setFixedSize(this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2); } +void TilesetEditor::initMetatileLayersItem() { + Metatile *metatile = Tileset::getMetatile(this->metatileSelector->getSelectedMetatile(), this->primaryTileset, this->secondaryTileset); + this->metatileLayersItem = new MetatileLayersItem(metatile, this->primaryTileset, this->secondaryTileset); + connect(this->metatileLayersItem, SIGNAL(tileChanged(int, int)), + this, SLOT(onMetatileLayerTileChanged(int, int))); + connect(this->metatileLayersItem, SIGNAL(selectedTilesChanged(QPoint, int, int)), + this, SLOT(onMetatileLayerSelectionChanged(QPoint, int, int))); + + this->metatileLayersScene = new QGraphicsScene; + this->metatileLayersScene->addItem(this->metatileLayersItem); + this->ui->graphicsView_metatileLayers->setScene(this->metatileLayersScene); +} + void TilesetEditor::initTileSelector() { this->tileSelector = new TilesetEditorTileSelector(this->primaryTileset, this->secondaryTileset, projectConfig.getTripleLayerMetatilesEnabled()); @@ -214,6 +216,11 @@ void TilesetEditor::restoreWindowState() { this->restoreState(geometry.value("tileset_editor_state")); } +void TilesetEditor::initMetatileHistory() { + MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy()); + metatileHistory.push(commit); +} + void TilesetEditor::reset() { this->hasUnsavedChanges = false; this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name); @@ -222,6 +229,20 @@ void TilesetEditor::reset() { this->refresh(); } +void TilesetEditor::refresh() { + this->metatileLayersItem->setTilesets(this->primaryTileset, this->secondaryTileset); + this->tileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); + this->metatileSelector->setTilesets(this->primaryTileset, this->secondaryTileset); + this->metatileSelector->select(this->metatileSelector->getSelectedMetatile()); + this->drawSelectedTiles(); + + 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->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); +} + void TilesetEditor::drawSelectedTiles() { if (!this->selectedTileScene) { return; @@ -248,19 +269,6 @@ void TilesetEditor::drawSelectedTiles() { this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); } -void TilesetEditor::initMetatileLayersItem() { - Metatile *metatile = Tileset::getMetatile(this->metatileSelector->getSelectedMetatile(), this->primaryTileset, this->secondaryTileset); - this->metatileLayersItem = new MetatileLayersItem(metatile, this->primaryTileset, this->secondaryTileset); - connect(this->metatileLayersItem, SIGNAL(tileChanged(int, int)), - this, SLOT(onMetatileLayerTileChanged(int, int))); - connect(this->metatileLayersItem, SIGNAL(selectedTilesChanged(QPoint, int, int)), - this, SLOT(onMetatileLayerSelectionChanged(QPoint, int, int))); - - this->metatileLayersScene = new QGraphicsScene; - this->metatileLayersScene->addItem(this->metatileLayersItem); - this->ui->graphicsView_metatileLayers->setScene(this->metatileLayersScene); -} - void TilesetEditor::onHoveredMetatileChanged(uint16_t metatileId) { Metatile *metatile = Tileset::getMetatile(metatileId, this->primaryTileset, this->secondaryTileset); QString message; From 2a37c186127243cc0738a0de444e11427744158f Mon Sep 17 00:00:00 2001 From: BigBahss Date: Fri, 23 Oct 2020 00:43:25 -0400 Subject: [PATCH 25/25] Fix connection mask palette color --- src/editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor.cpp b/src/editor.cpp index 020e925c..97a693e6 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1525,8 +1525,8 @@ void Editor::maskNonVisibleConnectionTiles() { ); // Mask the tiles with the current theme's background color. - QPen pen(ui->graphicsView_Map->palette().color(QPalette::Base)); - QBrush brush(ui->graphicsView_Map->palette().color(QPalette::Base)); + QPen pen(ui->graphicsView_Map->palette().color(QPalette::Active, QPalette::Base)); + QBrush brush(ui->graphicsView_Map->palette().color(QPalette::Active, QPalette::Base)); connection_mask = scene->addPath(mask, pen, brush); }