From bcba146be95960ebe25af65381bd22cd6d5120b8 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 7 Jan 2024 16:42:46 -0500 Subject: [PATCH] Add zoom sliders to the Tileset Editor --- forms/tileseteditor.ui | 1085 +++++++++++++++++++----------------- include/config.h | 8 + include/ui/tileseteditor.h | 2 + src/config.cpp | 24 + src/ui/tileseteditor.cpp | 32 +- 5 files changed, 642 insertions(+), 509 deletions(-) diff --git a/forms/tileseteditor.ui b/forms/tileseteditor.ui index c1c929d8..34e13d55 100644 --- a/forms/tileseteditor.ui +++ b/forms/tileseteditor.ui @@ -19,38 +19,27 @@ - - - - 1 - 0 - + + + Qt::Horizontal - - - 274 - 0 - + + false - - - 274 - 16777215 - - - - true - - - - - 0 - 0 - 272 - 625 - + + + + 0 + 0 + - + + QFrame::NoFrame + + + QFrame::Plain + + 0 @@ -63,440 +52,151 @@ 0 - - 6 - - - + + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 223 + 593 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + Qt::Horizontal - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 0 + + + QFrame::NoFrame - - 0 + + QFrame::Raised - - 0 - - - 0 - - - - - - 0 - 166 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - QLayout::SetMinimumSize + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + - - 0 + + + 0 + 166 + - - 0 + + QFrame::NoFrame - - 0 + + QFrame::Raised - - 0 - - - - - - 0 - 0 - - - - Metatile Properties - - - false - - - false - - - - - - - - - - - - true - - - - - - - Metatile Label (Optional) - - - - - - - Metatile Behavior - - - - - - - - 0 - 0 - - - - - 66 - 34 - - - - - 66 - 34 - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - - - - Bottom/Top - - - - - - - Encounter Type - - - - - - - Terrain Type - - - - - - - - - - Layer Type - - - - - - - <html><head/><body><p>Copies the full metatile label to the clipboard.</p></body></html> - - - ... - - - - :/icons/clipboard.ico:/icons/clipboard.ico - - - - - - - - - - - - - - 0 - 0 - - - - Tile Properties - - - false - - - - - - Palette - - - - - - - - 0 - 0 - - - - - - - - X Flip - - - - - - - Qt::LeftToRight - - - - - - - - - - Y Flip - - - - - - - - - - - - - - - 0 - 0 - - - - - 0 - 62 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Selection - - - - - - - - 18 - 18 - - - - - 66 - 34 - - - - QFrame::StyledPanel - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - - - - - - - - Qt::Vertical - - - - 20 - 10 - - - - - - - - Qt::Vertical - - - - 20 - 10 - - - - - - - - - - - - - - - 0 - 0 - - - - true - - - - - 0 - 0 - 411 - 272 - - - + + + QLayout::SetMinimumSize + 0 @@ -509,73 +209,444 @@ 0 - - - - Qt::Vertical + + + + Metatile Properties - - - 20 - 40 - + + false - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff + + false + + + + + + 0 + 0 + + + + + 66 + 34 + + + + + 96 + 34 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + 0 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + + 0 + 0 + + + + + + + + Metatile Label (Optional) + + + + + + + <html><head/><body><p>Copies the full metatile label to the clipboard.</p></body></html> + + + ... + + + + :/icons/clipboard.ico:/icons/clipboard.ico + + + + + + + + 0 + 0 + + + + + 185 + 0 + + + + + + + + + 0 + 0 + + + + + + + + Layer Type + + + + + + + true + + + + + + + Metatile Behavior + + + + + + + Qt::Horizontal + + + QSizePolicy::Maximum + + + + 10 + 20 + + + + + + + + Encounter Type + + + + + + + Terrain Type + + + + + + + Bottom/Top + + + + - - - - Qt::Horizontal + + + + + 0 + 0 + - - - 40 - 20 - + + Tile Properties - + + false + + + + + + Palette + + + + + + + + + + X Flip + + + + + + + Qt::LeftToRight + + + + + + + + + + Y Flip + + + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 5 + + + + + + + + + 0 + 0 + + + + + 98 + 62 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Selection + + + + + + + + 18 + 18 + + + + + 98 + 34 + + + + QFrame::StyledPanel + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + + + + Qt::Vertical + + + + 20 + 10 + + + + + + - - - + + + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 455 + 232 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + + diff --git a/include/config.h b/include/config.h index 7ae31839..8d7c3f45 100644 --- a/include/config.h +++ b/include/config.h @@ -58,6 +58,8 @@ public: this->collisionOpacity = 50; this->collisionZoom = 30; this->metatilesZoom = 30; + this->tilesetEditorMetatilesZoom = 30; + this->tilesetEditorTilesZoom = 30; this->showPlayerView = false; this->showCursorTile = true; this->showBorder = true; @@ -87,6 +89,8 @@ public: void setCollisionOpacity(int opacity); void setCollisionZoom(int zoom); void setMetatilesZoom(int zoom); + void setTilesetEditorMetatilesZoom(int zoom); + void setTilesetEditorTilesZoom(int zoom); void setShowPlayerView(bool enabled); void setShowCursorTile(bool enabled); void setShowBorder(bool enabled); @@ -115,6 +119,8 @@ public: int getCollisionOpacity(); int getCollisionZoom(); int getMetatilesZoom(); + int getTilesetEditorMetatilesZoom(); + int getTilesetEditorTilesZoom(); bool getShowPlayerView(); bool getShowCursorTile(); bool getShowBorder(); @@ -160,6 +166,8 @@ private: int collisionOpacity; int collisionZoom; int metatilesZoom; + int tilesetEditorMetatilesZoom; + int tilesetEditorTilesZoom; bool showPlayerView; bool showCursorTile; bool showBorder; diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index a904a150..043af02e 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -115,6 +115,8 @@ private slots: void on_actionCut_triggered(); void on_actionCopy_triggered(); void on_actionPaste_triggered(); + void on_horizontalSlider_MetatilesZoom_valueChanged(int value); + void on_horizontalSlider_TilesZoom_valueChanged(int value); private: void initUi(); diff --git a/src/config.cpp b/src/config.cpp index 11bd06dc..8e8e922f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -367,6 +367,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->metatilesZoom = getConfigInteger(key, value, 10, 100, 30); } else if (key == "collision_zoom") { this->collisionZoom = getConfigInteger(key, value, 10, 100, 30); + } else if (key == "tileset_editor_metatiles_zoom") { + this->tilesetEditorMetatilesZoom = getConfigInteger(key, value, 10, 100, 30); + } else if (key == "tileset_editor_tiles_zoom") { + this->tilesetEditorTilesZoom = getConfigInteger(key, value, 10, 100, 30); } else if (key == "show_player_view") { this->showPlayerView = getConfigBool(key, value); } else if (key == "show_cursor_tile") { @@ -426,6 +430,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("collision_opacity", QString::number(this->collisionOpacity)); map.insert("collision_zoom", QString::number(this->collisionZoom)); map.insert("metatiles_zoom", QString::number(this->metatilesZoom)); + map.insert("tileset_editor_metatiles_zoom", QString::number(this->tilesetEditorMetatilesZoom)); + map.insert("tileset_editor_tiles_zoom", QString::number(this->tilesetEditorTilesZoom)); map.insert("show_player_view", this->showPlayerView ? "1" : "0"); map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0"); map.insert("show_border", this->showBorder ? "1" : "0"); @@ -551,6 +557,16 @@ void PorymapConfig::setMetatilesZoom(int zoom) { // don't auto-save here because this can be called very frequently. } +void PorymapConfig::setTilesetEditorMetatilesZoom(int zoom) { + this->tilesetEditorMetatilesZoom = zoom; + // don't auto-save here because this can be called very frequently. +} + +void PorymapConfig::setTilesetEditorTilesZoom(int zoom) { + this->tilesetEditorTilesZoom = zoom; + // don't auto-save here because this can be called very frequently. +} + void PorymapConfig::setShowPlayerView(bool enabled) { this->showPlayerView = enabled; this->save(); @@ -693,6 +709,14 @@ int PorymapConfig::getMetatilesZoom() { return this->metatilesZoom; } +int PorymapConfig::getTilesetEditorMetatilesZoom() { + return this->tilesetEditorMetatilesZoom; +} + +int PorymapConfig::getTilesetEditorTilesZoom() { + return this->tilesetEditorTilesZoom; +} + bool PorymapConfig::getShowPlayerView() { return this->showPlayerView; } diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 0032264e..e7178b53 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -196,7 +196,7 @@ void TilesetEditor::initMetatileSelector() this->metatileSelector->draw(); this->ui->graphicsView_Metatiles->setScene(this->metatilesScene); - this->ui->graphicsView_Metatiles->setFixedSize(this->metatileSelector->pixmap().width() + 2, this->metatileSelector->pixmap().height() + 2); + this->ui->horizontalSlider_MetatilesZoom->setValue(porymapConfig.getTilesetEditorMetatilesZoom()); } void TilesetEditor::initMetatileLayersItem() { @@ -232,7 +232,7 @@ void TilesetEditor::initTileSelector() this->tileSelector->draw(); this->ui->graphicsView_Tiles->setScene(this->tilesScene); - this->ui->graphicsView_Tiles->setFixedSize(this->tileSelector->pixmap().width() + 2, this->tileSelector->pixmap().height() + 2); + this->ui->horizontalSlider_TilesZoom->setValue(porymapConfig.getTilesetEditorTilesZoom()); } void TilesetEditor::initSelectedTileItem() { @@ -1177,3 +1177,31 @@ void TilesetEditor::on_copyButton_metatileLabel_clicked() { QGuiApplication::clipboard()->setText(label); QToolTip::showText(this->ui->copyButton_metatileLabel->mapToGlobal(QPoint(0, 0)), "Copied!"); } + +void TilesetEditor::on_horizontalSlider_MetatilesZoom_valueChanged(int value) { + porymapConfig.setTilesetEditorMetatilesZoom(value); + double scale = pow(3.0, static_cast(value - 30) / 30.0); + + QTransform transform; + transform.scale(scale, scale); + QSize size(this->metatileSelector->pixmap().width(), this->metatileSelector->pixmap().height()); + size *= scale; + + this->ui->graphicsView_Metatiles->setResizeAnchor(QGraphicsView::NoAnchor); + this->ui->graphicsView_Metatiles->setTransform(transform); + this->ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2); +} + +void TilesetEditor::on_horizontalSlider_TilesZoom_valueChanged(int value) { + porymapConfig.setTilesetEditorTilesZoom(value); + double scale = pow(3.0, static_cast(value - 30) / 30.0); + + QTransform transform; + transform.scale(scale, scale); + QSize size(this->tileSelector->pixmap().width(), this->tileSelector->pixmap().height()); + size *= scale; + + this->ui->graphicsView_Tiles->setResizeAnchor(QGraphicsView::NoAnchor); + this->ui->graphicsView_Tiles->setTransform(transform); + this->ui->graphicsView_Tiles->setFixedSize(size.width() + 2, size.height() + 2); +}