diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 675eb420..98d03ba3 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2588,8 +2588,9 @@ - + + @@ -2820,6 +2821,17 @@ <html><head/><body><p>Show the player's view rectangle on the map based on the cursor's position.</p></body></html> + + + true + + + true + + + Cursor Tile Outline + + diff --git a/include/config.h b/include/config.h index b7672746..4f9b2dbe 100644 --- a/include/config.h +++ b/include/config.h @@ -33,6 +33,8 @@ public: this->mapSortOrder = MapSortOrder::Group; this->prettyCursors = true; this->collisionOpacity = 50; + this->showPlayerView = false; + this->showCursorTile = true; } void setRecentProject(QString project); void setRecentMap(QString map); @@ -40,12 +42,16 @@ public: void setPrettyCursors(bool enabled); void setGeometry(QByteArray, QByteArray, QByteArray, QByteArray, QByteArray); void setCollisionOpacity(int opacity); + void setShowPlayerView(bool enabled); + void setShowCursorTile(bool enabled); QString getRecentProject(); QString getRecentMap(); MapSortOrder getMapSortOrder(); bool getPrettyCursors(); QMap getGeometry(); int getCollisionOpacity(); + bool getShowPlayerView(); + bool getShowCursorTile(); protected: QString getConfigFilepath(); void parseConfigKeyValue(QString key, QString value); @@ -64,6 +70,8 @@ private: QByteArray eventsSlpitterState; QByteArray mainSplitterState; int collisionOpacity; + bool showPlayerView; + bool showCursorTile; }; extern PorymapConfig porymapConfig; diff --git a/include/editor.h b/include/editor.h index 8b7e15ac..033c267a 100644 --- a/include/editor.h +++ b/include/editor.h @@ -20,7 +20,7 @@ #include "collisionpixmapitem.h" #include "mappixmapitem.h" #include "settings.h" -#include "playerviewrect.h" +#include "movablerect.h" class DraggablePixmapItem; class MetatilesPixmapItem; @@ -95,7 +95,8 @@ public: QGraphicsItemGroup *events_group = nullptr; QList borderItems; QList gridLines; - PlayerViewRect *playerViewRect = nullptr; + MovableRect *playerViewRect = nullptr; + MovableRect *cursorMapTileRect = nullptr; QGraphicsScene *scene_metatiles = nullptr; QGraphicsScene *scene_current_metatile_selection = nullptr; diff --git a/include/mainwindow.h b/include/mainwindow.h index e03b3741..1032943c 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -75,6 +75,7 @@ private slots: void on_actionZoom_Out_triggered(); void on_actionBetter_Cursors_triggered(); void on_actionPlayer_View_Rectangle_triggered(); + void on_actionCursor_Tile_Outline_triggered(); void on_actionPencil_triggered(); void on_actionPointer_triggered(); void on_actionFlood_Fill_triggered(); diff --git a/include/settings.h b/include/settings.h index d9c1c095..5b989ed5 100644 --- a/include/settings.h +++ b/include/settings.h @@ -11,6 +11,7 @@ public: bool betterCursors; QCursor mapCursor; bool playerViewRectEnabled; + bool cursorTileRectEnabled; }; #endif // SETTINGS_H diff --git a/include/ui/playerviewrect.h b/include/ui/movablerect.h similarity index 51% rename from include/ui/playerviewrect.h rename to include/ui/movablerect.h index 955ab692..8668ad50 100644 --- a/include/ui/playerviewrect.h +++ b/include/ui/movablerect.h @@ -1,13 +1,14 @@ -#ifndef PLAYERVIEWRECT_H -#define PLAYERVIEWRECT_H +#ifndef MOVABLERECT_H +#define MOVABLERECT_H #include #include +#include -class PlayerViewRect : public QGraphicsItem +class MovableRect : public QGraphicsItem { public: - PlayerViewRect(bool *enabled); + MovableRect(bool *enabled, int width, int height, QRgb color); QRectF boundingRect() const override { qreal penWidth = 4; @@ -20,16 +21,18 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { - int width = 30 * 8; - int height = 20 * 8; - painter->setPen(QColor(0xff, 0xff, 0xff)); - painter->drawRect(-2, -2, width + 3, height + 3); + painter->setPen(this->color); + painter->drawRect(-2, -2, this->width + 3, this->height + 3); painter->setPen(QColor(0, 0, 0)); - painter->drawRect(-3, -3, width + 5, height + 5); - painter->drawRect(-1, -1, width + 1, height + 1); + painter->drawRect(-3, -3, this->width + 5, this->height + 5); + painter->drawRect(-1, -1, this->width + 1, this->height + 1); } void updateLocation(int x, int y); bool *enabled; +private: + int width; + int height; + QRgb color; }; -#endif // PLAYERVIEWRECT_H +#endif // MOVABLERECT_H diff --git a/porymap.pro b/porymap.pro index e83bde72..1d22850a 100644 --- a/porymap.pro +++ b/porymap.pro @@ -40,12 +40,12 @@ SOURCES += src/core/block.cpp \ src/ui/mapsceneeventfilter.cpp \ src/ui/metatilelayersitem.cpp \ src/ui/metatileselector.cpp \ + src/ui/movablerect.cpp \ src/ui/movementpermissionsselector.cpp \ src/ui/neweventtoolbutton.cpp \ src/ui/noscrollcombobox.cpp \ src/ui/noscrollspinbox.cpp \ src/ui/paletteeditor.cpp \ - src/ui/playerviewrect.cpp \ src/ui/selectablepixmapitem.cpp \ src/ui/tileseteditor.cpp \ src/ui/tileseteditormetatileselector.cpp \ @@ -87,12 +87,12 @@ HEADERS += include/core/block.h \ include/ui/mapsceneeventfilter.h \ include/ui/metatilelayersitem.h \ include/ui/metatileselector.h \ + include/ui/movablerect.h \ include/ui/movementpermissionsselector.h \ include/ui/neweventtoolbutton.h \ include/ui/noscrollcombobox.h \ include/ui/noscrollspinbox.h \ include/ui/paletteeditor.h \ - include/ui/playerviewrect.h \ include/ui/selectablepixmapitem.h \ include/ui/tileseteditor.h \ include/ui/tileseteditormetatileselector.h \ diff --git a/src/config.cpp b/src/config.cpp index 78dfcb48..79f90735 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -136,6 +136,18 @@ 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 == "show_player_view") { + bool ok; + this->showPlayerView = value.toInt(&ok); + if (!ok) { + logWarn(QString("Invalid config value for show_player_view: '%1'. Must be 0 or 1.").arg(value)); + } + } else if (key == "show_cursor_tile") { + bool ok; + this->showCursorTile = value.toInt(&ok); + if (!ok) { + logWarn(QString("Invalid config value for show_cursor_tile: '%1'. Must be 0 or 1.").arg(value)); + } } else { logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); } @@ -153,6 +165,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("events_splitter_state", stringFromByteArray(this->eventsSlpitterState)); map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); + map.insert("show_player_view", this->showPlayerView ? "1" : "0"); + map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0"); return map; } @@ -208,6 +222,16 @@ void PorymapConfig::setCollisionOpacity(int opacity) { // don't auto-save here because this can be called very frequently. } +void PorymapConfig::setShowPlayerView(bool enabled) { + this->showPlayerView = enabled; + this->save(); +} + +void PorymapConfig::setShowCursorTile(bool enabled) { + this->showCursorTile = enabled; + this->save(); +} + QString PorymapConfig::getRecentProject() { return this->recentProject; } @@ -240,6 +264,14 @@ int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } +bool PorymapConfig::getShowPlayerView() { + return this->showPlayerView; +} + +bool PorymapConfig::getShowCursorTile() { + return this->showCursorTile; +} + const QMap baseGameVersionMap = { {BaseGameVersion::pokeruby, "pokeruby"}, {BaseGameVersion::pokeemerald, "pokeemerald"}, diff --git a/src/editor.cpp b/src/editor.cpp index 3c65b558..bde96990 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -17,7 +17,8 @@ Editor::Editor(Ui::MainWindow* ui) this->ui = ui; this->selected_events = new QList; this->settings = new Settings(); - this->playerViewRect = new PlayerViewRect(&this->settings->playerViewRectEnabled); + this->playerViewRect = new MovableRect(&this->settings->playerViewRectEnabled, 30 * 8, 20 * 8, qRgb(255, 255, 255)); + this->cursorMapTileRect = new MovableRect(&this->settings->cursorTileRectEnabled, 16, 16, qRgb(255, 255, 255)); } void Editor::saveProject() { @@ -354,6 +355,7 @@ void Editor::onSelectedMetatilesChanged() { void Editor::onHoveredMapMetatileChanged(int x, int y) { this->playerViewRect->updateLocation(x, y); + this->cursorMapTileRect->updateLocation(x, y); if (map_item->paintingEnabled && x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) { int blockIndex = y * map->getWidth() + x; int tile = map->layout->blockdata->blocks->at(blockIndex).tile; @@ -367,6 +369,7 @@ void Editor::onHoveredMapMetatileChanged(int x, int y) { void Editor::onHoveredMapMetatileCleared() { this->playerViewRect->setVisible(false); + this->cursorMapTileRect->setVisible(false); if (map_item->paintingEnabled) { this->ui->statusBar->clearMessage(); } @@ -374,6 +377,7 @@ void Editor::onHoveredMapMetatileCleared() { void Editor::onHoveredMapMovementPermissionChanged(int x, int y) { this->playerViewRect->updateLocation(x, y); + this->cursorMapTileRect->updateLocation(x, y); if (map_item->paintingEnabled && x >= 0 && x < map->getWidth() && y >= 0 && y < map->getHeight()) { int blockIndex = y * map->getWidth() + x; uint16_t collision = map->layout->blockdata->blocks->at(blockIndex).collision; @@ -388,6 +392,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) { void Editor::onHoveredMapMovementPermissionCleared() { this->playerViewRect->setVisible(false); + this->cursorMapTileRect->setVisible(false); if (map_item->paintingEnabled) { this->ui->statusBar->clearMessage(); } @@ -445,6 +450,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item int x = static_cast(pos.x()) / 16; int y = static_cast(pos.y()) / 16; this->playerViewRect->updateLocation(x, y); + this->cursorMapTileRect->updateLocation(x, y); if (map_edit_mode == "paint") { if (event->buttons() & Qt::RightButton) { item->updateMetatileSelection(event); @@ -487,6 +493,7 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm int x = static_cast(pos.x()) / 16; int y = static_cast(pos.y()) / 16; this->playerViewRect->updateLocation(x, y); + this->cursorMapTileRect->updateLocation(x, y); if (map_edit_mode == "paint") { if (event->buttons() & Qt::RightButton) { item->updateMovementPermissionSelection(event); @@ -527,6 +534,8 @@ void Editor::displayMap() { if (map_item && scene) { scene->removeItem(map_item); delete map_item; + scene->removeItem(this->playerViewRect); + scene->removeItem(this->cursorMapTileRect); } displayMetatileSelector(); @@ -539,8 +548,11 @@ void Editor::displayMap() { displayMapConnections(); displayMapBorder(); displayMapGrid(); + this->playerViewRect->setZValue(1000); + this->cursorMapTileRect->setZValue(1001); scene->addItem(this->playerViewRect); + scene->addItem(this->cursorMapTileRect); if (map_item) { map_item->setVisible(false); @@ -1071,6 +1083,7 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) { int x = static_cast(mouse->pos().x() + this->pos().x()) / 16; int y = static_cast(mouse->pos().y() + this->pos().y()) / 16; this->editor->playerViewRect->updateLocation(x, y); + this->editor->cursorMapTileRect->updateLocation(x, y); if (x != last_x || y != last_y) { if (editor->selected_events->contains(this)) { for (DraggablePixmapItem *item : *editor->selected_events) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4e5fb0ff..054f0e00 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -205,6 +205,10 @@ void MainWindow::on_lineEdit_filterBox_textChanged(const QString &arg1) void MainWindow::loadUserSettings() { ui->actionBetter_Cursors->setChecked(porymapConfig.getPrettyCursors()); this->editor->settings->betterCursors = porymapConfig.getPrettyCursors(); + ui->actionPlayer_View_Rectangle->setChecked(porymapConfig.getShowPlayerView()); + this->editor->settings->playerViewRectEnabled = porymapConfig.getShowPlayerView(); + ui->actionCursor_Tile_Outline->setChecked(porymapConfig.getShowCursorTile()); + this->editor->settings->cursorTileRectEnabled = porymapConfig.getShowCursorTile(); mapSortOrder = porymapConfig.getMapSortOrder(); ui->horizontalSlider_CollisionTransparency->blockSignals(true); this->editor->collisionOpacity = static_cast(porymapConfig.getCollisionOpacity()) / 100; @@ -972,7 +976,16 @@ void MainWindow::on_actionBetter_Cursors_triggered() { void MainWindow::on_actionPlayer_View_Rectangle_triggered() { - this->editor->settings->playerViewRectEnabled = ui->actionPlayer_View_Rectangle->isChecked(); + bool enabled = ui->actionPlayer_View_Rectangle->isChecked(); + porymapConfig.setShowPlayerView(enabled); + this->editor->settings->playerViewRectEnabled = enabled; +} + +void MainWindow::on_actionCursor_Tile_Outline_triggered() +{ + bool enabled = ui->actionCursor_Tile_Outline->isChecked(); + porymapConfig.setShowCursorTile(enabled); + this->editor->settings->cursorTileRectEnabled = enabled; } void MainWindow::on_actionPencil_triggered() diff --git a/src/settings.cpp b/src/settings.cpp index 235d1371..7da1fcbc 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -5,4 +5,5 @@ Settings::Settings() this->smartPathsEnabled = false; this->betterCursors = true; this->playerViewRectEnabled = false; + this->cursorTileRectEnabled = true; } diff --git a/src/ui/movablerect.cpp b/src/ui/movablerect.cpp new file mode 100644 index 00000000..55327dba --- /dev/null +++ b/src/ui/movablerect.cpp @@ -0,0 +1,17 @@ +#include "movablerect.h" + +MovableRect::MovableRect(bool *enabled, int width, int height, QRgb color) +{ + this->enabled = enabled; + this->width = width; + this->height = height; + this->color = color; + this->setVisible(*enabled); +} + +void MovableRect::updateLocation(int x, int y) +{ + this->setX((x * 16) - this->width / 2 + 8); + this->setY((y * 16) - this->height / 2 + 8); + this->setVisible(*this->enabled); +} diff --git a/src/ui/playerviewrect.cpp b/src/ui/playerviewrect.cpp deleted file mode 100644 index 9757517c..00000000 --- a/src/ui/playerviewrect.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "playerviewrect.h" - -PlayerViewRect::PlayerViewRect(bool *enabled) -{ - this->enabled = enabled; - this->setVisible(*enabled); -} - -void PlayerViewRect::updateLocation(int x, int y) -{ - this->setX((x * 16) - (14 * 8)); - this->setY((y * 16) - (9 * 8)); - this->setVisible(*this->enabled); -}