From 4f0e8716f2811434e681aad574bee78f50ffd268 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 7 Dec 2023 13:45:08 -0500 Subject: [PATCH] Update Collision tab UI --- forms/mainwindow.ui | 149 ++++++++++++++++------- include/config.h | 4 + include/editor.h | 7 +- include/mainwindow.h | 6 +- include/project.h | 4 + include/ui/collisionpixmapitem.h | 12 +- include/ui/movementpermissionsselector.h | 12 +- include/ui/selectablepixmapitem.h | 3 + src/config.cpp | 14 ++- src/editor.cpp | 61 +++++----- src/mainwindow.cpp | 40 +++++- src/project.cpp | 14 +++ src/ui/collisionpixmapitem.cpp | 24 ++-- src/ui/movementpermissionsselector.cpp | 10 +- src/ui/selectablepixmapitem.cpp | 2 + 15 files changed, 263 insertions(+), 99 deletions(-) diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 7b8aa8b4..d61ce9d8 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -1144,7 +1144,14 @@ 3 - + + + + Opacity + + + + true @@ -1154,8 +1161,8 @@ 0 0 - 428 - 696 + 427 + 512 @@ -1174,29 +1181,6 @@ 0 - - - - Opacity - - - - - - - 0 - - - 100 - - - 50 - - - Qt::Horizontal - - - @@ -1224,6 +1208,12 @@ 512 + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + @@ -1256,6 +1246,83 @@ + + + + 10 + + + 90 + + + 30 + + + Qt::Horizontal + + + + + + + 0 + + + 100 + + + 50 + + + Qt::Horizontal + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + Collision + + + + + + + + + + Elevation + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -1314,8 +1381,8 @@ 0 0 - 398 - 631 + 382 + 611 @@ -1615,8 +1682,8 @@ 0 0 - 434 - 581 + 100 + 16 @@ -1709,8 +1776,8 @@ 0 0 - 434 - 581 + 100 + 16 @@ -1803,8 +1870,8 @@ 0 0 - 434 - 581 + 100 + 16 @@ -1903,8 +1970,8 @@ 0 0 - 434 - 581 + 100 + 16 @@ -1997,8 +2064,8 @@ 0 0 - 434 - 581 + 100 + 16 @@ -2051,8 +2118,8 @@ 0 0 - 434 - 625 + 100 + 30 @@ -2388,7 +2455,7 @@ Custom fields will be added to the map.json file for the current map. - true + false false diff --git a/include/config.h b/include/config.h index c7671991..55efd5a0 100644 --- a/include/config.h +++ b/include/config.h @@ -56,6 +56,7 @@ public: this->mapSortOrder = MapSortOrder::Group; this->prettyCursors = true; this->collisionOpacity = 50; + this->collisionZoom = 30; this->metatilesZoom = 30; this->showPlayerView = false; this->showCursorTile = true; @@ -78,6 +79,7 @@ public: void setProjectSettingsEditorGeometry(QByteArray, QByteArray); void setCustomScriptsEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); + void setCollisionZoom(int zoom); void setMetatilesZoom(int zoom); void setShowPlayerView(bool enabled); void setShowCursorTile(bool enabled); @@ -100,6 +102,7 @@ public: QMap getProjectSettingsEditorGeometry(); QMap getCustomScriptsEditorGeometry(); int getCollisionOpacity(); + int getCollisionZoom(); int getMetatilesZoom(); bool getShowPlayerView(); bool getShowCursorTile(); @@ -140,6 +143,7 @@ private: QByteArray customScriptsEditorGeometry; QByteArray customScriptsEditorState; int collisionOpacity; + int collisionZoom; int metatilesZoom; bool showPlayerView; bool showCursorTile; diff --git a/include/editor.h b/include/editor.h index 39272d7c..8f7cd54d 100644 --- a/include/editor.h +++ b/include/editor.h @@ -152,7 +152,7 @@ public: void scaleMapView(int); static void openInTextEditor(const QString &path, int lineNum = 0); bool eventLimitReached(Event::Type type); - static void setCollisionGraphics(); + void setCollisionGraphics(); public slots: void openMapScripts() const; @@ -163,6 +163,10 @@ public slots: void selectedEventIndexChanged(int index, Event::Group eventGroup); private: + const QImage defaultCollisionImgSheet = QImage(":/images/collisions.png"); + const QImage collisionPlaceholder = QImage(":/images/collisions_unknown.png"); + QPixmap collisionSheetPixmap; + void setConnectionItemsVisible(bool); void setBorderItemsVisible(bool, qreal = 1); void setConnectionEditControlValues(MapConnection*); @@ -181,6 +185,7 @@ private: void updateEncounterFields(EncounterFields newFields); QString getMovementPermissionText(uint16_t collision, uint16_t elevation); QString getMetatileDisplayMessage(uint16_t metatileId); + void setCollisionTabSpinBoxes(uint16_t collision, uint16_t elevation); static bool startDetachedProcess(const QString &command, const QString &workingDirectory = QString(), qint64 *pid = nullptr); diff --git a/include/mainwindow.h b/include/mainwindow.h index 0f1eeac7..7bbe5475 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -276,11 +276,13 @@ private slots: void on_pushButton_DeleteCustomHeaderField_clicked(); void on_tableWidget_CustomHeaderFields_cellChanged(int row, int column); void on_horizontalSlider_MetatileZoom_valueChanged(int value); + void on_horizontalSlider_CollisionZoom_valueChanged(int value); void on_pushButton_NewWildMonGroup_clicked(); void on_pushButton_DeleteWildMonGroup_clicked(); void on_pushButton_ConfigureEncountersJSON_clicked(); void on_pushButton_CreatePrefab_clicked(); - + void on_spinBox_SelectedElevation_valueChanged(int elevation); + void on_spinBox_SelectedCollision_valueChanged(int collision); void on_actionRegion_Map_Editor_triggered(); void on_actionPreferences_triggered(); void togglePreferenceSpecificUi(); @@ -370,7 +372,7 @@ private: void initMapSortOrder(); void initShortcuts(); void initExtraShortcuts(); - void setProjectSpecificUIVisibility(); + void setProjectSpecificUI(); void setWildEncountersUIEnabled(bool enabled); void loadUserSettings(); void applyMapListFilter(QString filterText); diff --git a/include/project.h b/include/project.h index 34a8c918..d9365f23 100644 --- a/include/project.h +++ b/include/project.h @@ -230,6 +230,8 @@ public: static bool mapDimensionsValid(int width, int height); bool calculateDefaultMapSize(); static int getMaxObjectEvents(); + static int getMaxCollision(); + static int getMaxElevation(); private: void updateMapLayout(Map*); @@ -253,6 +255,8 @@ private: static int max_map_data_size; static int default_map_size; static int max_object_events; + static int max_collision; + static int max_elevation; QStringListModel eventScriptLabelModel; QCompleter eventScriptLabelCompleter; diff --git a/include/ui/collisionpixmapitem.h b/include/ui/collisionpixmapitem.h index 2e3e74e3..c489ddd7 100644 --- a/include/ui/collisionpixmapitem.h +++ b/include/ui/collisionpixmapitem.h @@ -1,8 +1,9 @@ #ifndef COLLISIONPIXMAPITEM_H #define COLLISIONPIXMAPITEM_H +#include + #include "metatileselector.h" -#include "movementpermissionsselector.h" #include "mappixmapitem.h" #include "map.h" #include "settings.h" @@ -10,13 +11,15 @@ class CollisionPixmapItem : public MapPixmapItem { Q_OBJECT public: - CollisionPixmapItem(Map *map, MovementPermissionsSelector *movementPermissionsSelector, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity) + CollisionPixmapItem(Map *map, QSpinBox * selectedCollision, QSpinBox * selectedElevation, MetatileSelector *metatileSelector, Settings *settings, qreal *opacity) : MapPixmapItem(map, metatileSelector, settings){ - this->movementPermissionsSelector = movementPermissionsSelector; + this->selectedCollision = selectedCollision; + this->selectedElevation = selectedElevation; this->opacity = opacity; map->setCollisionItem(this); } - MovementPermissionsSelector *movementPermissionsSelector; + QSpinBox * selectedCollision; + QSpinBox * selectedElevation; qreal *opacity; void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event); virtual void paint(QGraphicsSceneMouseEvent*); @@ -28,6 +31,7 @@ public: private: unsigned actionId_ = 0; QPoint previousPos; + void updateSelection(QPoint pos); signals: void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *); diff --git a/include/ui/movementpermissionsselector.h b/include/ui/movementpermissionsselector.h index f9a02529..10840d36 100644 --- a/include/ui/movementpermissionsselector.h +++ b/include/ui/movementpermissionsselector.h @@ -6,15 +6,19 @@ class MovementPermissionsSelector: public SelectablePixmapItem { Q_OBJECT public: - MovementPermissionsSelector(int cellWidth, int cellHeight, QPixmap basePixmap) : - SelectablePixmapItem(cellWidth, cellHeight, 1, 1), - basePixmap(basePixmap) { + MovementPermissionsSelector(QPixmap basePixmap) + : SelectablePixmapItem(MovementPermissionsSelector::CellWidth, MovementPermissionsSelector::CellHeight, 1, 1) { + this->basePixmap = basePixmap; setAcceptHoverEvents(true); } void draw(); uint16_t getSelectedCollision(); uint16_t getSelectedElevation(); void select(uint16_t collision, uint16_t elevation); + void setBasePixmap(QPixmap pixmap); + + static const int CellWidth; + static const int CellHeight; protected: void hoverMoveEvent(QGraphicsSceneHoverEvent*); @@ -22,7 +26,7 @@ protected: private: void setSelectedMovementPermissions(QPointF); - const QPixmap basePixmap; + QPixmap basePixmap; signals: void hoveredMovementPermissionChanged(uint16_t, uint16_t); diff --git a/include/ui/selectablepixmapitem.h b/include/ui/selectablepixmapitem.h index cdab4a6a..97a47c43 100644 --- a/include/ui/selectablepixmapitem.h +++ b/include/ui/selectablepixmapitem.h @@ -35,6 +35,9 @@ protected: void mouseMoveEvent(QGraphicsSceneMouseEvent*); void mouseReleaseEvent(QGraphicsSceneMouseEvent*); virtual void drawSelection(); + +signals: + void selectionChanged(int, int, int, int); }; #endif // SELECTABLEPIXMAPITEM_H diff --git a/src/config.cpp b/src/config.cpp index 0fe3f6e9..67dcdf9c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -244,6 +244,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->customScriptsEditorState = bytesFromString(value); } else if (key == "metatiles_zoom") { this->metatilesZoom = getConfigInteger(key, value, 10, 100, 30); + } else if (key == "collision_zoom") { + this->collisionZoom = getConfigInteger(key, value, 10, 100, 30); } else if (key == "show_player_view") { this->showPlayerView = getConfigBool(key, value); } else if (key == "show_cursor_tile") { @@ -293,7 +295,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("custom_scripts_editor_geometry", stringFromByteArray(this->customScriptsEditorGeometry)); map.insert("custom_scripts_editor_state", stringFromByteArray(this->customScriptsEditorState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); - map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom)); + map.insert("collision_zoom", QString::number(this->collisionZoom)); + map.insert("metatiles_zoom", QString::number(this->metatilesZoom)); 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"); @@ -399,6 +402,11 @@ void PorymapConfig::setCollisionOpacity(int opacity) { // don't auto-save here because this can be called very frequently. } +void PorymapConfig::setCollisionZoom(int zoom) { + this->collisionZoom = zoom; + // don't auto-save here because this can be called very frequently. +} + void PorymapConfig::setMetatilesZoom(int zoom) { this->metatilesZoom = zoom; // don't auto-save here because this can be called very frequently. @@ -519,6 +527,10 @@ int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } +int PorymapConfig::getCollisionZoom() { + return this->collisionZoom; +} + int PorymapConfig::getMetatilesZoom() { return this->metatilesZoom; } diff --git a/src/editor.cpp b/src/editor.cpp index 286ae545..5bf12862 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -20,8 +20,6 @@ #include static bool selectNewEvents = false; -static const QPixmap *collisionSheetPixmap = nullptr; -static const int movementPermissionsSelectorCellSize = 32; // 2D array mapping collision+elevation combos to an icon. QList> Editor::collisionIcons; @@ -54,6 +52,8 @@ Editor::~Editor() delete this->playerViewRect; delete this->cursorMapTileRect; delete this->map_ruler; + for (auto sublist : collisionIcons) + qDeleteAll(sublist); closeProject(); } @@ -1430,7 +1430,7 @@ void Editor::displayMapMovementPermissions() { scene->removeItem(collision_item); delete collision_item; } - collision_item = new CollisionPixmapItem(map, this->movement_permissions_selector_item, + collision_item = new CollisionPixmapItem(map, ui->spinBox_SelectedCollision, ui->spinBox_SelectedElevation, this->metatile_selector_item, this->settings, &this->collisionOpacity); connect(collision_item, &CollisionPixmapItem::mouseEvent, this, &Editor::mouseEvent_collision); connect(collision_item, &CollisionPixmapItem::hoveredMapMovementPermissionChanged, @@ -1489,13 +1489,14 @@ void Editor::displayMovementPermissionSelector() { scene_collision_metatiles = new QGraphicsScene; if (!movement_permissions_selector_item) { - movement_permissions_selector_item = new MovementPermissionsSelector(movementPermissionsSelectorCellSize, - movementPermissionsSelectorCellSize, - collisionSheetPixmap ? *collisionSheetPixmap : QPixmap()); + movement_permissions_selector_item = new MovementPermissionsSelector(this->collisionSheetPixmap); connect(movement_permissions_selector_item, &MovementPermissionsSelector::hoveredMovementPermissionChanged, this, &Editor::onHoveredMovementPermissionChanged); connect(movement_permissions_selector_item, &MovementPermissionsSelector::hoveredMovementPermissionCleared, this, &Editor::onHoveredMovementPermissionCleared); + connect(movement_permissions_selector_item, &SelectablePixmapItem::selectionChanged, [this](int x, int y, int, int) { + this->setCollisionTabSpinBoxes(x, y); + }); movement_permissions_selector_item->select(0, projectConfig.getNewMapElevation()); // TODO: New map collision config? } @@ -2235,13 +2236,16 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) { selectingEvent = false; } -// TODO: Show elevation & collision spinners on collision tab -// TODO: Hide selection rect for elevation/collision combos not shown on the image -// TODO: Zoom slider +void Editor::setCollisionTabSpinBoxes(uint16_t collision, uint16_t elevation) { + const QSignalBlocker blocker1(ui->spinBox_SelectedCollision); + const QSignalBlocker blocker2(ui->spinBox_SelectedElevation); + ui->spinBox_SelectedCollision->setValue(collision); + ui->spinBox_SelectedElevation->setValue(elevation); +} + // TODO: Bug--Images with transparency allow users to paint metatiles on the Collision tab // Custom collision graphics may be provided by the user. void Editor::setCollisionGraphics() { - static const QImage defaultCollisionImgSheet = QImage(":/images/collisions.png"); QString customPath = projectConfig.getCollisionSheetPath(); QImage imgSheet; @@ -2255,11 +2259,11 @@ void Editor::setCollisionGraphics() { if (imgSheet.isNull()) { // Custom collision image failed to load, use default logWarn(QString("Failed to load custom collision image '%1', using default.").arg(customPath)); - imgSheet = defaultCollisionImgSheet; + imgSheet = this->defaultCollisionImgSheet; } } else { // No custom collision image specified, use the default. - imgSheet = defaultCollisionImgSheet; + imgSheet = this->defaultCollisionImgSheet; } // Like the vanilla collision image, users are not required to provide an image that gives an icon for every elevation/collision combination. @@ -2267,42 +2271,37 @@ void Editor::setCollisionGraphics() { const int imgColumns = projectConfig.getCollisionSheetWidth(); const int imgRows = projectConfig.getCollisionSheetHeight(); - // Create a pixmap for the selector on the Collision tab - delete collisionSheetPixmap; - collisionSheetPixmap = new QPixmap(QPixmap::fromImage(imgSheet) - .scaled(movementPermissionsSelectorCellSize * imgColumns, - movementPermissionsSelectorCellSize * imgRows)); + // Create a pixmap for the selector on the Collision tab. If a project was previously opened we'll also need to refresh the selector. + this->collisionSheetPixmap = QPixmap::fromImage(imgSheet).scaled(MovementPermissionsSelector::CellWidth * imgColumns, + MovementPermissionsSelector::CellHeight * imgRows); + if (this->movement_permissions_selector_item) + this->movement_permissions_selector_item->setBasePixmap(this->collisionSheetPixmap); for (auto sublist : collisionIcons) qDeleteAll(sublist); collisionIcons.clear(); - // Chop up the collision image sheet into separate icon images to be displayed on the map. - // Any icons for elevation/collision combinations that aren't provided by the image sheet are also created now. - const int w = 16; - const int h = 16; - const int numCollisions = 4; // TODO: Read value from elsewhere - const int numElevations = 16; // TODO: Read value from elsewhere + // Use the image sheet to create an icon for each collision/elevation combination. + // Any icons for combinations that aren't provided by the image sheet are also created now using default graphics. + const int w = 16, h = 16; imgSheet = imgSheet.scaled(w * imgColumns, h * imgRows); - for (int collision = 0; collision < numCollisions; collision++) { + for (int collision = 0; collision <= Project::getMaxCollision(); collision++) { + // If (collision >= imgColumns) here, it's a valid collision value, but it is not represented with an icon on the image sheet. // In this case we just use the rightmost collision icon. This is mostly to support the vanilla case, where technically 0-3 // are valid collision values, but 1-3 have the same meaning, so the vanilla collision selector image only has 2 columns. - int x = ((collision < imgColumns) ? collision : imgColumns) * w; + int x = ((collision < imgColumns) ? collision : (imgColumns - 1)) * w; QList sublist; - for (int elevation = 0; elevation < numElevations; elevation++) { + for (int elevation = 0; elevation <= Project::getMaxElevation(); elevation++) { if (elevation < imgRows) { // This elevation has an icon on the image sheet, add it to the list int y = elevation * h; sublist.append(new QImage(imgSheet.copy(x, y, w, h))); } else { // This is a valid elevation value, but it has no icon on the image sheet. - // Give it a placeholder "?" icon (white if passable, red otherwise) - static const QImage placeholder = QImage(":/images/collisions_unknown.png"); - static const QImage * placeholder_White = new QImage(placeholder.copy(0, 0, w, h)); - static const QImage * placeholder_Red = new QImage(placeholder.copy(w, 0, w, h)); - sublist.append(x == 0 ? placeholder_White : placeholder_Red); + // Give it a placeholder "?" icon (red if impassable, white otherwise) + sublist.append(new QImage(this->collisionPlaceholder.copy(x != 0 ? w : 0, 0, w, h))); } } collisionIcons.append(sublist); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 648950be..87e385b3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -372,7 +372,8 @@ void MainWindow::setWildEncountersUIEnabled(bool enabled) { ui->mainTabBar->setTabEnabled(4, enabled); } -void MainWindow::setProjectSpecificUIVisibility() +// Update the UI using information we've read from the user's project config file. +void MainWindow::setProjectSpecificUI() { this->setWildEncountersUIEnabled(userConfig.getEncounterJsonActive()); @@ -393,7 +394,9 @@ void MainWindow::setProjectSpecificUIVisibility() ui->label_FloorNumber->setVisible(floorNumEnabled); Event::setIcons(); - Editor::setCollisionGraphics(); + editor->setCollisionGraphics(); + ui->spinBox_SelectedElevation->setMaximum(Project::getMaxElevation()); + ui->spinBox_SelectedCollision->setMaximum(Project::getMaxCollision()); } void MainWindow::mapSortOrder_changed(QAction *action) @@ -455,6 +458,9 @@ void MainWindow::loadUserSettings() { ui->horizontalSlider_MetatileZoom->blockSignals(true); ui->horizontalSlider_MetatileZoom->setValue(porymapConfig.getMetatilesZoom()); ui->horizontalSlider_MetatileZoom->blockSignals(false); + ui->horizontalSlider_CollisionZoom->blockSignals(true); + ui->horizontalSlider_CollisionZoom->setValue(porymapConfig.getCollisionZoom()); + ui->horizontalSlider_CollisionZoom->blockSignals(false); setTheme(porymapConfig.getTheme()); } @@ -514,7 +520,7 @@ bool MainWindow::openProject(QString dir) { projectConfig.load(); this->closeSupplementaryWindows(); - this->setProjectSpecificUIVisibility(); + this->setProjectSpecificUI(); this->newMapDefaultsSet = false; Scripting::init(this); @@ -718,6 +724,7 @@ void MainWindow::refreshMapScene() ui->graphicsView_Collision->setFixedSize(editor->movement_permissions_selector_item->pixmap().width() + 2, editor->movement_permissions_selector_item->pixmap().height() + 2); on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value()); + on_horizontalSlider_CollisionZoom_valueChanged(ui->horizontalSlider_CollisionZoom->value()); } void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_group) { @@ -2797,6 +2804,33 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) { redrawMetatileSelection(); } +void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { + porymapConfig.setCollisionZoom(value); + double scale = pow(3.0, static_cast(value - 30) / 30.0); + + QTransform transform; + transform.scale(scale, scale); + QSize size(editor->movement_permissions_selector_item->pixmap().width(), + editor->movement_permissions_selector_item->pixmap().height()); + size *= scale; + + ui->graphicsView_Collision->setResizeAnchor(QGraphicsView::NoAnchor); + ui->graphicsView_Collision->setTransform(transform); + ui->graphicsView_Collision->setFixedSize(size.width() + 2, size.height() + 2); +} + +void MainWindow::on_spinBox_SelectedCollision_valueChanged(int collision) { + if (!this->editor || !this->editor->movement_permissions_selector_item) + return; + this->editor->movement_permissions_selector_item->select(collision, ui->spinBox_SelectedElevation->value()); +} + +void MainWindow::on_spinBox_SelectedElevation_valueChanged(int elevation) { + if (!this->editor || !this->editor->movement_permissions_selector_item) + return; + this->editor->movement_permissions_selector_item->select(ui->spinBox_SelectedCollision->value(), elevation); +} + void MainWindow::on_actionRegion_Map_Editor_triggered() { if (!this->regionMapEditor) { if (!initRegionMapEditor()) { diff --git a/src/project.cpp b/src/project.cpp index fd7d7dcc..9b801e2d 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -35,6 +35,10 @@ int Project::max_map_data_size = 10240; // 0x2800 int Project::default_map_size = 20; int Project::max_object_events = 64; +// TODO: Replace once Block layout can be edited +int Project::max_collision = 3; +int Project::max_elevation = 15; + Project::Project(QWidget *parent) : QObject(parent), eventScriptLabelModel(this), @@ -2579,6 +2583,16 @@ int Project::getMaxObjectEvents() return Project::max_object_events; } +int Project::getMaxCollision() +{ + return Project::max_collision; +} + +int Project::getMaxElevation() +{ + return Project::max_elevation; +} + void Project::setImportExportPath(QString filename) { this->importExportPath = QFileInfo(filename).absolutePath(); diff --git a/src/ui/collisionpixmapitem.cpp b/src/ui/collisionpixmapitem.cpp index eaa4bca1..936d0ac3 100644 --- a/src/ui/collisionpixmapitem.cpp +++ b/src/ui/collisionpixmapitem.cpp @@ -75,8 +75,8 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) { Block block; if (map->getBlock(pos.x(), pos.y(), &block)) { - block.collision = this->movementPermissionsSelector->getSelectedCollision(); - block.elevation = this->movementPermissionsSelector->getSelectedElevation(); + block.collision = this->selectedCollision->value(); + block.elevation = this->selectedElevation->value(); map->setBlock(pos.x(), pos.y(), block, true); } @@ -93,8 +93,8 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { Blockdata oldCollision = map->layout->blockdata; QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); - uint16_t collision = this->movementPermissionsSelector->getSelectedCollision(); - uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation(); + uint16_t collision = this->selectedCollision->value(); + uint16_t elevation = this->selectedElevation->value(); map->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation); if (map->layout->blockdata != oldCollision) { @@ -109,8 +109,8 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { } else if (map) { Blockdata oldCollision = map->layout->blockdata; QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); - uint16_t collision = this->movementPermissionsSelector->getSelectedCollision(); - uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation(); + uint16_t collision = this->selectedCollision->value(); + uint16_t elevation = this->selectedElevation->value(); map->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation); if (map->layout->blockdata != oldCollision) { @@ -121,10 +121,7 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) { QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); - Block block; - if (map->getBlock(pos.x(), pos.y(), &block)) { - this->movementPermissionsSelector->select(block.collision, block.elevation); - } + this->updateSelection(pos); } void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) { @@ -135,9 +132,14 @@ void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseE if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1); if (pos.y() < 0) pos.setY(0); if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1); + this->updateSelection(pos); +} +void CollisionPixmapItem::updateSelection(QPoint pos) { Block block; if (map->getBlock(pos.x(), pos.y(), &block)) { - this->movementPermissionsSelector->select(block.collision, block.elevation); + const QSignalBlocker blocker(this->selectedCollision); // We only need a signal for changing one of them, not both + this->selectedCollision->setValue(block.collision); + this->selectedElevation->setValue(block.elevation); } } diff --git a/src/ui/movementpermissionsselector.cpp b/src/ui/movementpermissionsselector.cpp index 30dfde10..dd611560 100644 --- a/src/ui/movementpermissionsselector.cpp +++ b/src/ui/movementpermissionsselector.cpp @@ -1,11 +1,19 @@ #include "movementpermissionsselector.h" #include +const int MovementPermissionsSelector::CellWidth = 32; +const int MovementPermissionsSelector::CellHeight = 32; + void MovementPermissionsSelector::draw() { this->setPixmap(this->basePixmap); this->drawSelection(); } +void MovementPermissionsSelector::setBasePixmap(QPixmap pixmap) { + this->basePixmap = pixmap; + this->draw(); +} + uint16_t MovementPermissionsSelector::getSelectedCollision() { return static_cast(this->selectionInitialX); } @@ -15,7 +23,7 @@ uint16_t MovementPermissionsSelector::getSelectedElevation() { } void MovementPermissionsSelector::select(uint16_t collision, uint16_t elevation) { - SelectablePixmapItem::select(collision != 0, elevation, 0, 0); + SelectablePixmapItem::select(collision, elevation, 0, 0); } void MovementPermissionsSelector::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { diff --git a/src/ui/selectablepixmapitem.cpp b/src/ui/selectablepixmapitem.cpp index dbfbaa34..7cf17ec1 100644 --- a/src/ui/selectablepixmapitem.cpp +++ b/src/ui/selectablepixmapitem.cpp @@ -22,6 +22,7 @@ void SelectablePixmapItem::select(int x, int y, int width, int height) this->selectionOffsetX = qMax(0, qMin(width, this->maxSelectionWidth)); this->selectionOffsetY = qMax(0, qMin(height, this->maxSelectionHeight)); this->draw(); + emit this->selectionChanged(x, y, width, height); } void SelectablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -76,6 +77,7 @@ void SelectablePixmapItem::updateSelection(int x, int y) } this->draw(); + emit this->selectionChanged(x, y, width, height); } QPoint SelectablePixmapItem::getCellPos(QPointF pos)