diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 7d89a35a..691746c0 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -22,9 +22,9 @@ enum CommandId { ID_PaintCollision, ID_BucketFillCollision, ID_MagicFillCollision, - ID_ResizeMap, + ID_ResizeLayout, ID_PaintBorder, - ID_ScriptEditMap, + ID_ScriptEditLayout, ID_EventMove, ID_EventShift, ID_EventCreate, @@ -194,9 +194,9 @@ private: /// Implements a command to commit a map or border resize action. -class ResizeMap : public QUndoCommand { +class ResizeLayout : public QUndoCommand { public: - ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions, + ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, const Blockdata &oldBorder, const Blockdata &newBorder, @@ -206,15 +206,15 @@ public: void redo() override; bool mergeWith(const QUndoCommand *) override { return false; } - int id() const override { return CommandId::ID_ResizeMap; } + int id() const override { return CommandId::ID_ResizeLayout; } private: Layout *layout = nullptr; - int oldMapWidth; - int oldMapHeight; - int newMapWidth; - int newMapHeight; + int oldLayoutWidth; + int oldLayoutHeight; + int newLayoutWidth; + int newLayoutHeight; int oldBorderWidth; int oldBorderHeight; @@ -342,13 +342,12 @@ public: -// !TODO: rename map vars to layout /// Implements a command to commit map edits from the scripting API. /// The scripting api can edit map/border blocks and dimensions. -class ScriptEditMap : public QUndoCommand { +class ScriptEditLayout : public QUndoCommand { public: - ScriptEditMap(Layout *layout, - QSize oldMapDimensions, QSize newMapDimensions, + ScriptEditLayout(Layout *layout, + QSize oldLayoutDimensions, QSize newLayoutDimensions, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, const Blockdata &oldBorder, const Blockdata &newBorder, @@ -358,7 +357,7 @@ public: void redo() override; bool mergeWith(const QUndoCommand *) override { return false; } - int id() const override { return CommandId::ID_ScriptEditMap; } + int id() const override { return CommandId::ID_ScriptEditLayout; } private: Layout *layout = nullptr; @@ -369,10 +368,10 @@ private: Blockdata newBorder; Blockdata oldBorder; - int oldMapWidth; - int oldMapHeight; - int newMapWidth; - int newMapHeight; + int oldLayoutWidth; + int oldLayoutHeight; + int newLayoutWidth; + int newLayoutHeight; int oldBorderWidth; int oldBorderHeight; diff --git a/include/core/maplayout.h b/include/core/maplayout.h index c17248ce..7ec240b6 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -55,7 +55,7 @@ public: Blockdata cached_border; struct { Blockdata blocks; - QSize mapDimensions; + QSize layoutDimensions; Blockdata border; QSize borderDimensions; } lastCommitBlocks; // to track map changes diff --git a/include/core/regionmapeditcommands.h b/include/core/regionmapeditcommands.h index 69bea251..e142c5cc 100644 --- a/include/core/regionmapeditcommands.h +++ b/include/core/regionmapeditcommands.h @@ -64,9 +64,9 @@ private: /// Edit Layout Dimensions -class ResizeLayout : public QUndoCommand { +class ResizeRMLayout : public QUndoCommand { public: - ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight, + ResizeRMLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight, QMap> oldLayouts, QMap> newLayouts, QUndoCommand *parent = nullptr); void undo() override; diff --git a/include/editor.h b/include/editor.h index d6d973b5..c3e0c5ff 100644 --- a/include/editor.h +++ b/include/editor.h @@ -46,8 +46,8 @@ public: QObject *parent = nullptr; Project *project = nullptr; - QPointer map = nullptr; // !TODO: since removed onMapCacheCleared, make sure this works as intended - QPointer layout = nullptr; /* NEW */ + QPointer map = nullptr; + QPointer layout = nullptr; QUndoGroup editGroup; // Manages the undo history for each map @@ -118,8 +118,6 @@ public: void updateCursorRectPos(int x, int y); void setCursorRectVisible(bool visible); - - QGraphicsScene *scene = nullptr; QGraphicsPixmapItem *current_view = nullptr; LayoutPixmapItem *map_item = nullptr; @@ -154,15 +152,18 @@ public: EditAction mapEditAction = EditAction::Paint; EditAction objectEditAction = EditAction::Select; - /// !TODO this - enum class EditMode { None, Disabled, Map, Layout, Objects, Connections, Encounters }; - EditMode editMode = EditMode::Map; + enum class EditMode { None, Disabled, Metatiles, Collision, Header, Events, Connections, Encounters }; + EditMode editMode = EditMode::None; void setEditMode(EditMode mode) { this->editMode = mode; } EditMode getEditMode() { return this->editMode; } - void setEditingMap(); + bool getEditingLayout(); + + void setEditorView(); + + void setEditingMetatiles(); void setEditingCollision(); - void setEditingLayout(); + void setEditingHeader(); void setEditingObjects(); void setEditingConnections(); void setEditingEncounters(); diff --git a/include/ui/layoutpixmapitem.h b/include/ui/layoutpixmapitem.h index ab4d94a5..08496c54 100644 --- a/include/ui/layoutpixmapitem.h +++ b/include/ui/layoutpixmapitem.h @@ -14,25 +14,16 @@ private: using QGraphicsPixmapItem::paint; public: - enum class PaintMode { - Disabled, - Metatiles, - EventObjects - }; - LayoutPixmapItem(Layout *layout, MetatileSelector *metatileSelector, Settings *settings) { this->layout = layout; // this->map->setMapItem(this); this->metatileSelector = metatileSelector; this->settings = settings; - this->paintingMode = PaintMode::Metatiles; this->lockedAxis = LayoutPixmapItem::Axis::None; this->prevStraightPathState = false; setAcceptHoverEvents(true); } - LayoutPixmapItem::PaintMode paintingMode; - Layout *layout; MetatileSelector *metatileSelector; @@ -95,12 +86,17 @@ public: void lockNondominantAxis(QGraphicsSceneMouseEvent *event); QPoint adjustCoords(QPoint pos); + void setEditsEnabled(bool enabled) { this->editsEnabled = enabled; } + bool getEditsEnabled() { return this->editsEnabled; } + private: void paintSmartPath(int x, int y, bool fromScriptCall = false); static QList smartPathTable; unsigned actionId_ = 0; + bool editsEnabled = true; + signals: void startPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *); void endPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *); diff --git a/src/core/editcommands.cpp b/src/core/editcommands.cpp index a2096905..22227b42 100644 --- a/src/core/editcommands.cpp +++ b/src/core/editcommands.cpp @@ -24,7 +24,6 @@ int getEventTypeMask(QList events) { return eventTypeMask; } -/// !TODO: void renderBlocks(Layout *layout, bool ignoreCache = false) { layout->layoutItem->draw(ignoreCache); layout->collisionItem->draw(ignoreCache); @@ -178,7 +177,7 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) { ************************************************************************ ******************************************************************************/ -ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensions, +ResizeLayout::ResizeLayout(Layout *layout, QSize oldLayoutDimensions, QSize newLayoutDimensions, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, const Blockdata &oldBorder, const Blockdata &newBorder, @@ -187,11 +186,11 @@ ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensi this->layout = layout; - this->oldMapWidth = oldMapDimensions.width(); - this->oldMapHeight = oldMapDimensions.height(); + this->oldLayoutWidth = oldLayoutDimensions.width(); + this->oldLayoutHeight = oldLayoutDimensions.height(); - this->newMapWidth = newMapDimensions.width(); - this->newMapHeight = newMapDimensions.height(); + this->newLayoutWidth = newLayoutDimensions.width(); + this->newLayoutHeight = newLayoutDimensions.height(); this->oldMetatiles = oldMetatiles; this->newMetatiles = newMetatiles; @@ -206,33 +205,33 @@ ResizeMap::ResizeMap(Layout *layout, QSize oldMapDimensions, QSize newMapDimensi this->newBorder = newBorder; } -void ResizeMap::redo() { +void ResizeLayout::redo() { QUndoCommand::redo(); if (!layout) return; layout->blockdata = newMetatiles; - layout->setDimensions(newMapWidth, newMapHeight, false, true); + layout->setDimensions(newLayoutWidth, newLayoutHeight, false, true); layout->border = newBorder; layout->setBorderDimensions(newBorderWidth, newBorderHeight, false, true); - layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight()); + layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight()); layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight()); layout->needsRedrawing(); } -void ResizeMap::undo() { +void ResizeLayout::undo() { if (!layout) return; layout->blockdata = oldMetatiles; - layout->setDimensions(oldMapWidth, oldMapHeight, false, true); + layout->setDimensions(oldLayoutWidth, oldLayoutHeight, false, true); layout->border = oldBorder; layout->setBorderDimensions(oldBorderWidth, oldBorderHeight, false, true); - layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight()); + layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight()); layout->lastCommitBlocks.borderDimensions = QSize(layout->getBorderWidth(), layout->getBorderHeight()); layout->needsRedrawing(); @@ -487,23 +486,23 @@ int EventPaste::id() const { ************************************************************************ ******************************************************************************/ -ScriptEditMap::ScriptEditMap(Layout *layout, - QSize oldMapDimensions, QSize newMapDimensions, +ScriptEditLayout::ScriptEditLayout(Layout *layout, + QSize oldLayoutDimensions, QSize newLayoutDimensions, const Blockdata &oldMetatiles, const Blockdata &newMetatiles, QSize oldBorderDimensions, QSize newBorderDimensions, const Blockdata &oldBorder, const Blockdata &newBorder, QUndoCommand *parent) : QUndoCommand(parent) { - setText("Script Edit Map"); + setText("Script Edit Layout"); this->layout = layout; this->newMetatiles = newMetatiles; this->oldMetatiles = oldMetatiles; - this->oldMapWidth = oldMapDimensions.width(); - this->oldMapHeight = oldMapDimensions.height(); - this->newMapWidth = newMapDimensions.width(); - this->newMapHeight = newMapDimensions.height(); + this->oldLayoutWidth = oldLayoutDimensions.width(); + this->oldLayoutHeight = oldLayoutDimensions.height(); + this->newLayoutWidth = newLayoutDimensions.width(); + this->newLayoutHeight = newLayoutDimensions.height(); this->oldBorder = oldBorder; this->newBorder = newBorder; @@ -514,14 +513,14 @@ ScriptEditMap::ScriptEditMap(Layout *layout, this->newBorderHeight = newBorderDimensions.height(); } -void ScriptEditMap::redo() { +void ScriptEditLayout::redo() { QUndoCommand::redo(); if (!layout) return; - if (newMapWidth != layout->getWidth() || newMapHeight != layout->getHeight()) { + if (newLayoutWidth != layout->getWidth() || newLayoutHeight != layout->getHeight()) { layout->blockdata = newMetatiles; - layout->setDimensions(newMapWidth, newMapHeight, false); + layout->setDimensions(newLayoutWidth, newLayoutHeight, false); } else { layout->setBlockdata(newMetatiles); } @@ -534,21 +533,20 @@ void ScriptEditMap::redo() { } layout->lastCommitBlocks.blocks = newMetatiles; - layout->lastCommitBlocks.mapDimensions = QSize(newMapWidth, newMapHeight); + layout->lastCommitBlocks.layoutDimensions = QSize(newLayoutWidth, newLayoutHeight); layout->lastCommitBlocks.border = newBorder; layout->lastCommitBlocks.borderDimensions = QSize(newBorderWidth, newBorderHeight); - // !TODO renderBlocks(layout); layout->borderItem->draw(); } -void ScriptEditMap::undo() { +void ScriptEditLayout::undo() { if (!layout) return; - if (oldMapWidth != layout->getWidth() || oldMapHeight != layout->getHeight()) { + if (oldLayoutWidth != layout->getWidth() || oldLayoutHeight != layout->getHeight()) { layout->blockdata = oldMetatiles; - layout->setDimensions(oldMapWidth, oldMapHeight, false); + layout->setDimensions(oldLayoutWidth, oldLayoutHeight, false); } else { layout->setBlockdata(oldMetatiles); } @@ -561,11 +559,10 @@ void ScriptEditMap::undo() { } layout->lastCommitBlocks.blocks = oldMetatiles; - layout->lastCommitBlocks.mapDimensions = QSize(oldMapWidth, oldMapHeight); + layout->lastCommitBlocks.layoutDimensions = QSize(oldLayoutWidth, oldLayoutHeight); layout->lastCommitBlocks.border = oldBorder; layout->lastCommitBlocks.borderDimensions = QSize(oldBorderWidth, oldBorderHeight); - // !TODO renderBlocks(layout); layout->borderItem->draw(); diff --git a/src/core/regionmapeditcommands.cpp b/src/core/regionmapeditcommands.cpp index e718d596..1be247b0 100644 --- a/src/core/regionmapeditcommands.cpp +++ b/src/core/regionmapeditcommands.cpp @@ -90,7 +90,7 @@ bool EditLayout::mergeWith(const QUndoCommand *command) { /// -ResizeLayout::ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight, +ResizeRMLayout::ResizeRMLayout(RegionMap *map, int oldWidth, int oldHeight, int newWidth, int newHeight, QMap> oldLayouts, QMap> newLayouts, QUndoCommand *parent) : QUndoCommand(parent) { setText("Change Layout Dimensions"); @@ -104,7 +104,7 @@ ResizeLayout::ResizeLayout(RegionMap *map, int oldWidth, int oldHeight, int newW this->newLayouts = newLayouts; } -void ResizeLayout::redo() { +void ResizeRMLayout::redo() { QUndoCommand::redo(); if (!map) return; @@ -113,7 +113,7 @@ void ResizeLayout::redo() { map->setAllLayouts(this->newLayouts); } -void ResizeLayout::undo() { +void ResizeRMLayout::undo() { if (!map) return; map->setLayoutDimensions(oldWidth, oldHeight, false); @@ -122,8 +122,8 @@ void ResizeLayout::undo() { QUndoCommand::undo(); } -bool ResizeLayout::mergeWith(const QUndoCommand *command) { - const ResizeLayout *other = static_cast(command); +bool ResizeRMLayout::mergeWith(const QUndoCommand *command) { + const ResizeRMLayout *other = static_cast(command); if (this->map != other->map) return false; diff --git a/src/editor.cpp b/src/editor.cpp index d5d48e6a..06cc771f 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -83,130 +83,119 @@ void Editor::closeProject() { } } -void Editor::setEditingMap() { - current_view = map_item; - if (map_item) { - map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles; - displayMapConnections(); - map_item->draw(); - map_item->setVisible(true); - } - if (collision_item) { - collision_item->setVisible(false); - } - if (events_group) { - events_group->setVisible(false); - } - setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); - setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); - setConnectionsEditable(false); - this->cursorMapTileRect->stopSingleTileMode(); - this->cursorMapTileRect->setActive(true); - - if (this->layout) { - this->editGroup.setActiveStack(&this->layout->editHistory); - } - - setMapEditingButtonsEnabled(true); +bool Editor::getEditingLayout() { + return this->editMode == EditMode::Metatiles || this->editMode == EditMode::Collision; } -void Editor::setEditingLayout() { - // -} +void Editor::setEditorView() { + // based on editMode + if (!map_item || !collision_item) return; + if (!this->layout) return; -void Editor::setEditingCollision() { - current_view = collision_item; - if (collision_item) { - displayMapConnections(); - collision_item->draw(); - collision_item->setVisible(true); - } - if (map_item) { - map_item->paintingMode = LayoutPixmapItem::PaintMode::Metatiles; - map_item->draw(); - map_item->setVisible(true); - } - if (events_group) { - events_group->setVisible(false); + map_item->setVisible(true); // is map item ever not visible + collision_item->setVisible(false); + + switch (this->editMode) { + case EditMode::Metatiles: + case EditMode::Connections: + case EditMode::Events: + current_view = map_item; + break; + case EditMode::Collision: + current_view = collision_item; + break; + default: + current_view = nullptr; + return; } + + map_item->draw(); + collision_item->draw(); + displayMapConnections(); + + current_view->setVisible(true); + setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setConnectionsEditable(false); this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setActive(true); - if (this->layout) { + switch (this->editMode) { + case EditMode::Metatiles: + case EditMode::Collision: this->editGroup.setActiveStack(&this->layout->editHistory); - } - - setMapEditingButtonsEnabled(true); -} - -void Editor::setEditingObjects() { - current_view = map_item; - if (events_group) { - events_group->setVisible(true); - } - if (map_item) { - // !TODO: change this pixmapitem paintmode - map_item->paintingMode = LayoutPixmapItem::PaintMode::EventObjects; - displayMapConnections(); - map_item->draw(); - map_item->setVisible(true); - } - if (collision_item) { - collision_item->setVisible(false); - } - setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); - setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); - setConnectionsEditable(false); - this->cursorMapTileRect->setSingleTileMode(); - this->cursorMapTileRect->setActive(false); - - if (this->map) { - this->editGroup.setActiveStack(&this->map->editHistory); - } - - setMapEditingButtonsEnabled(false); -} - -void Editor::setEditingConnections() { - current_view = map_item; - if (map_item) { - map_item->paintingMode = LayoutPixmapItem::PaintMode::Disabled; - map_item->draw(); - map_item->setVisible(true); - populateConnectionMapPickers(); + break; + case EditMode::Events: + if (this->map) { + this->editGroup.setActiveStack(&this->map->editHistory); + } + break; + case EditMode::Connections: + populateConnectionMapPickers(); // !TODO: move to setmap or sumn/ displaymapconnections type ish ui->label_NumConnections->setText(QString::number(map->connections.length())); setDiveEmergeControls(); - bool controlsEnabled = selected_connection_item != nullptr; - setConnectionEditControlsEnabled(controlsEnabled); + + setConnectionEditControlsEnabled(selected_connection_item != nullptr); if (selected_connection_item) { onConnectionOffsetChanged(selected_connection_item->connection->offset); setConnectionMap(selected_connection_item->connection->map_name); setCurrentConnectionDirection(selected_connection_item->connection->direction); } maskNonVisibleConnectionTiles(); - } - if (collision_item) { - collision_item->setVisible(false); - } - if (events_group) { - events_group->setVisible(false); - } - setBorderItemsVisible(true, 0.4); - setConnectionItemsVisible(true); - setConnectionsEditable(true); - this->cursorMapTileRect->setSingleTileMode(); - this->cursorMapTileRect->setActive(false); - if (this->map) { - this->editGroup.setActiveStack(&this->map->editHistory); + setBorderItemsVisible(true, 0.4); + setConnectionItemsVisible(true); + setConnectionsEditable(true); + this->cursorMapTileRect->setActive(false); + map_item->setEditsEnabled(false); // !TODO + case EditMode::Header: + case EditMode::Encounters: + default: + this->editGroup.setActiveStack(nullptr); + break; } + + if (this->events_group) { + this->events_group->setVisible(this->editMode == EditMode::Events); + } + setMapEditingButtonsEnabled(this->editMode != EditMode::Events); +} + +void Editor::setEditingMetatiles() { + this->editMode = EditMode::Metatiles; + + setEditorView(); +} + +void Editor::setEditingCollision() { + this->editMode = EditMode::Collision; + + setEditorView(); +} + +void Editor::setEditingHeader() { + this->editMode = EditMode::Header; + + setEditorView(); +} + +void Editor::setEditingObjects() { + this->editMode = EditMode::Events; + + setEditorView(); +} + +void Editor::setEditingConnections() { + this->editMode = EditMode::Connections; + + setEditorView(); } void Editor::setEditingEncounters() { - // + this->editMode = EditMode::Encounters; + + setEditorView(); } void Editor::setMapEditingButtonsEnabled(bool enabled) { @@ -1048,7 +1037,7 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) { return; this->updateCursorRectPos(x, y); - if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { + if (this->getEditingLayout()) { int blockIndex = y * layout->getWidth() + x; int metatileId = layout->blockdata.at(blockIndex).metatileId; this->ui->statusBar->showMessage(QString("X: %1, Y: %2, %3, Scale = %4x") @@ -1057,19 +1046,19 @@ void Editor::onHoveredMapMetatileChanged(const QPoint &pos) { .arg(getMetatileDisplayMessage(metatileId)) .arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2))); } - else if (map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) { + else if (this->editMode == EditMode::Events) { this->ui->statusBar->showMessage(QString("X: %1, Y: %2, Scale = %3x") .arg(x) .arg(y) .arg(QString::number(zoomLevels[this->scaleIndex], 'g', 2))); } + Scripting::cb_BlockHoverChanged(x, y); } void Editor::onHoveredMapMetatileCleared() { this->setCursorRectVisible(false); - if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles - || map_item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) { + if (!map_item->getEditsEnabled()) { this->ui->statusBar->clearMessage(); } Scripting::cb_BlockHoverCleared(); @@ -1080,7 +1069,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) { return; this->updateCursorRectPos(x, y); - if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { + if (this->getEditingLayout()) { int blockIndex = y * layout->getWidth() + x; uint16_t collision = layout->blockdata.at(blockIndex).collision; uint16_t elevation = layout->blockdata.at(blockIndex).elevation; @@ -1095,7 +1084,7 @@ void Editor::onHoveredMapMovementPermissionChanged(int x, int y) { void Editor::onHoveredMapMovementPermissionCleared() { this->setCursorRectVisible(false); - if (map_item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { + if (this->getEditingLayout()) { this->ui->statusBar->clearMessage(); } Scripting::cb_BlockHoverCleared(); @@ -1142,14 +1131,11 @@ bool Editor::setMap(QString map_name) { this->map = loadedMap; - // remove this - //this->layout = this->map->layout; setLayout(map->layout->id); editGroup.addStack(&map->editHistory); - - // !TODO: determine which stack is active based on edit mode too since layout will have something different editGroup.setActiveStack(&map->editHistory); + selected_events->clear(); if (!displayMap()) { return false; @@ -1163,7 +1149,6 @@ bool Editor::setMap(QString map_name) { } bool Editor::setLayout(QString layoutId) { - // if (layoutId.isEmpty()) return false; this->layout = this->project->loadLayout(layoutId); @@ -1172,8 +1157,6 @@ bool Editor::setLayout(QString layoutId) { return false; } - // !TODO: editGroup addStack - editGroup.addStack(&layout->editHistory); map_ruler->setMapDimensions(QSize(this->layout->getWidth(), this->layout->getHeight())); @@ -1195,7 +1178,7 @@ bool Editor::setLayout(QString layoutId) { } void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) { - if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) { + if (!this->getEditingLayout()) { return; } @@ -1208,7 +1191,7 @@ void Editor::onMapStartPaint(QGraphicsSceneMouseEvent *event, LayoutPixmapItem * } void Editor::onMapEndPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *item) { - if (!(item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles)) { + if (!this->getEditingLayout()) { return; } this->cursorMapTileRect->stopRightClickSelectionAnchor(); @@ -1243,13 +1226,13 @@ void Editor::setStraightPathCursorMode(QGraphicsSceneMouseEvent *event) { void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *item) { // TODO: add event tab object painting tool buttons stuff here - if (item->paintingMode == LayoutPixmapItem::PaintMode::Disabled) { + if (!item->getEditsEnabled()) { return; } QPoint pos = Metatile::coordFromPixmapCoord(event->pos()); - if (item->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { + if (this->getEditingLayout()) { if (mapEditAction == EditAction::Paint) { if (event->buttons() & Qt::RightButton) { item->updateMetatileSelection(event); @@ -1296,7 +1279,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i } item->shift(event); } - } else if (item->paintingMode == LayoutPixmapItem::PaintMode::EventObjects) { + } else if (this->editMode == EditMode::Events) { if (objectEditAction == EditAction::Paint && event->type() == QEvent::GraphicsSceneMousePress) { // Right-clicking while in paint mode will change mode to select. if (event->buttons() & Qt::RightButton) { @@ -1354,7 +1337,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i } void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item) { - if (item->paintingMode != LayoutPixmapItem::PaintMode::Metatiles) { + if (!item->getEditsEnabled()) { return; } @@ -1426,7 +1409,6 @@ bool Editor::displayLayout() { scene->removeItem(this->map_ruler); } - // !TODO: disassociate these functions from Map displayMetatileSelector(); displayMapMetatiles(); displayMovementPermissionSelector(); @@ -2116,7 +2098,7 @@ void Editor::selectedEventIndexChanged(int index, Event::Group eventGroup) { } void Editor::duplicateSelectedEvents() { - if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) + if (!selected_events || !selected_events->length() || !map || !current_view || this->getEditingLayout()) return; QList selectedEvents; @@ -2288,7 +2270,7 @@ bool Editor::startDetachedProcess(const QString &command, const QString &working // is clicking on the background instead of an event. void Editor::objectsView_onMousePress(QMouseEvent *event) { // make sure we are in object editing mode - if (map_item && map_item->paintingMode != LayoutPixmapItem::PaintMode::EventObjects) { + if (map_item && this->editMode != EditMode::Events) { return; } if (this->objectEditAction == EditAction::Paint && event->buttons() & Qt::RightButton) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 02ae9ace..5844afaa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1780,11 +1780,11 @@ void MainWindow::on_mapViewTab_tabBarClicked(int index) Scripting::cb_MapViewTabChanged(oldIndex, index); if (index == 0) { - editor->setEditingMap(); + editor->setEditingMetatiles(); } else if (index == 1) { editor->setEditingCollision(); } else if (index == 2) { - editor->setEditingMap(); + editor->setEditingMetatiles(); if (projectConfig.getPrefabFilepath().isEmpty() && !projectConfig.getPrefabImportPrompted()) { // User hasn't set up prefabs and hasn't been prompted before. // Ask if they'd like to import the default prefabs file. @@ -1802,8 +1802,6 @@ void MainWindow::on_action_Exit_triggered() void MainWindow::on_mainTabBar_tabBarClicked(int index) { - //if (!editor->map) return; - int oldIndex = ui->mainTabBar->currentIndex(); ui->mainTabBar->setCurrentIndex(index); if (index != oldIndex) @@ -1822,6 +1820,8 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index) clickToolButtonFromEditAction(editor->objectEditAction); } else if (index == 3) { editor->setEditingConnections(); + } else if (index == 4) { + editor->setEditingEncounters(); } if (!editor->map) return; @@ -2727,7 +2727,7 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() { if (oldMapDimensions != newMapDimensions || oldBorderDimensions != newBorderDimensions) { layout->setDimensions(newMapDimensions.width(), newMapDimensions.height(), true, true); layout->setBorderDimensions(newBorderDimensions.width(), newBorderDimensions.height(), true, true); - editor->layout->editHistory.push(new ResizeMap(layout, + editor->layout->editHistory.push(new ResizeLayout(layout, oldMapDimensions, newMapDimensions, oldMetatiles, layout->blockdata, oldBorderDimensions, newBorderDimensions, diff --git a/src/project.cpp b/src/project.cpp index 0dfb7763..09657955 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1126,7 +1126,7 @@ bool Project::loadBlockdata(Layout *layout) { QString path = QString("%1/%2").arg(root).arg(layout->blockdata_path); layout->blockdata = readBlockdata(path); layout->lastCommitBlocks.blocks = layout->blockdata; - layout->lastCommitBlocks.mapDimensions = QSize(layout->getWidth(), layout->getHeight()); + layout->lastCommitBlocks.layoutDimensions = QSize(layout->getWidth(), layout->getHeight()); if (layout->blockdata.count() != layout->getWidth() * layout->getHeight()) { logWarn(QString("Layout blockdata length %1 does not match dimensions %2x%3 (should be %4). Resizing blockdata.") @@ -1148,7 +1148,7 @@ void Project::setNewMapBlockdata(Map *map) { map->layout->blockdata.append(block); } map->layout->lastCommitBlocks.blocks = map->layout->blockdata; - map->layout->lastCommitBlocks.mapDimensions = QSize(width, height); + map->layout->lastCommitBlocks.layoutDimensions = QSize(width, height); } bool Project::loadLayoutBorder(Layout *layout) { diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp index 155d3492..ea18e0cc 100644 --- a/src/scriptapi/apimap.cpp +++ b/src/scriptapi/apimap.cpp @@ -44,8 +44,8 @@ void MainWindow::tryCommitMapChanges(bool commitChanges) { if (commitChanges) { Layout *layout = this->editor->layout; if (layout) { - layout->editHistory.push(new ScriptEditMap(layout, - layout->lastCommitBlocks.mapDimensions, QSize(layout->getWidth(), layout->getHeight()), + layout->editHistory.push(new ScriptEditLayout(layout, + layout->lastCommitBlocks.layoutDimensions, QSize(layout->getWidth(), layout->getHeight()), layout->lastCommitBlocks.blocks, layout->blockdata, layout->lastCommitBlocks.borderDimensions, QSize(layout->getBorderWidth(), layout->getBorderHeight()), layout->lastCommitBlocks.border, layout->border diff --git a/src/ui/collisionpixmapitem.cpp b/src/ui/collisionpixmapitem.cpp index 0c809c3f..3a3c62a0 100644 --- a/src/ui/collisionpixmapitem.cpp +++ b/src/ui/collisionpixmapitem.cpp @@ -8,7 +8,7 @@ void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { this->previousPos = pos; emit this->hoveredMapMovementPermissionChanged(pos.x(), pos.y()); } - if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles) { + if (this->settings->betterCursors && this->getEditsEnabled()) { setCursor(this->settings->mapCursor); } } @@ -21,7 +21,7 @@ void CollisionPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { emit this->hoveredMapMovementPermissionCleared(); - if (this->settings->betterCursors && this->paintingMode == LayoutPixmapItem::PaintMode::Metatiles){ + if (this->settings->betterCursors && this->getEditsEnabled()){ unsetCursor(); } this->has_mouse = false; diff --git a/src/ui/layoutpixmapitem.cpp b/src/ui/layoutpixmapitem.cpp index a595695a..93489c7e 100644 --- a/src/ui/layoutpixmapitem.cpp +++ b/src/ui/layoutpixmapitem.cpp @@ -694,7 +694,7 @@ void LayoutPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) { this->metatilePos = pos; emit this->hoveredMapMetatileChanged(pos); } - if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) { + if (this->settings->betterCursors && this->editsEnabled) { setCursor(this->settings->mapCursor); } } @@ -707,7 +707,7 @@ void LayoutPixmapItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event) { void LayoutPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { emit this->hoveredMapMetatileCleared(); - if (this->settings->betterCursors && this->paintingMode != LayoutPixmapItem::PaintMode::Disabled) { + if (this->settings->betterCursors && this->editsEnabled) { unsetCursor(); } this->has_mouse = false; diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index e81208b8..66c0dd0b 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -183,8 +183,8 @@ bool MapImageExporter::historyItemAppliesToFrame(const QUndoCommand *command) { case CommandId::ID_BucketFillMetatile: case CommandId::ID_MagicFillMetatile: case CommandId::ID_ShiftMetatiles: - case CommandId::ID_ResizeMap: - case CommandId::ID_ScriptEditMap: + case CommandId::ID_ResizeLayout: + case CommandId::ID_ScriptEditLayout: return true; case CommandId::ID_PaintCollision: case CommandId::ID_BucketFillCollision: diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 0b13c474..3da703a7 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -94,7 +94,6 @@ void NewMapPopup::init() { ui->spinBox_NewMap_Floor_Number->setValue(settings.floorNumber); // Connect signals - // !TODO: make sure this doesnt reconnect a million times connect(ui->spinBox_NewMap_Width, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); connect(ui->spinBox_NewMap_Height, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 39d79ca7..74cbac4a 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -1101,7 +1101,7 @@ void RegionMapEditor::on_spinBox_RM_LayoutWidth_valueChanged(int value) { int newHeight = this->region_map->layoutHeight(); QMap> newLayouts = this->region_map->getAllLayouts(); - ResizeLayout *commit = new ResizeLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts); + ResizeRMLayout *commit = new ResizeRMLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts); this->region_map->editHistory.push(commit); } } @@ -1118,7 +1118,7 @@ void RegionMapEditor::on_spinBox_RM_LayoutHeight_valueChanged(int value) { int newHeight = this->region_map->layoutHeight(); QMap> newLayouts = this->region_map->getAllLayouts(); - ResizeLayout *commit = new ResizeLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts); + ResizeRMLayout *commit = new ResizeRMLayout(this->region_map, oldWidth, oldHeight, newWidth, newHeight, oldLayouts, newLayouts); this->region_map->editHistory.push(commit); } }