diff --git a/include/editor.h b/include/editor.h index 11efabda..c44fd960 100644 --- a/include/editor.h +++ b/include/editor.h @@ -151,6 +151,7 @@ public: void shouldReselectEvents(); void scaleMapView(int); void openInTextEditor(const QString &path, int lineNum = 0) const; + bool eventLimitReached(QString event_type); public slots: void openMapScripts() const; @@ -176,7 +177,6 @@ private: void updateEncounterFields(EncounterFields newFields); QString getMovementPermissionText(uint16_t collision, uint16_t elevation); QString getMetatileDisplayMessage(uint16_t metatileId); - bool eventLimitReached(Map *, QString); bool startDetachedProcess(const QString &command, const QString &workingDirectory = QString(), qint64 *pid = nullptr) const; diff --git a/src/editor.cpp b/src/editor.cpp index d15b3bbc..f4890106 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -2031,7 +2031,7 @@ void Editor::duplicateSelectedEvents() { for (int i = 0; i < selected_events->length(); i++) { Event *original = selected_events->at(i)->event; QString eventType = original->get("event_type"); - if (eventLimitReached(map, eventType)) { + if (eventLimitReached(eventType)) { logWarn(QString("Skipping duplication, the map limit for events of type '%1' has been reached.").arg(eventType)); continue; } @@ -2045,7 +2045,7 @@ void Editor::duplicateSelectedEvents() { } DraggablePixmapItem* Editor::addNewEvent(QString event_type) { - if (project && map && !event_type.isEmpty() && !eventLimitReached(map, event_type)) { + if (project && map && !event_type.isEmpty() && !eventLimitReached(event_type)) { Event *event = Event::createNewEvent(event_type, map->name, project); event->put("map_name", map->name); if (event_type == EventType::HealLocation) { @@ -2061,7 +2061,7 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) { } // Currently only object events have an explicit limit -bool Editor::eventLimitReached(Map *map, QString event_type) +bool Editor::eventLimitReached(QString event_type) { if (project && map && !event_type.isEmpty()) { if (Event::typeToGroup(event_type) == EventGroup::Object) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 73ef97c4..91bd32bc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1516,6 +1516,7 @@ void MainWindow::copy() { if (type == EventType::HealLocation) { // no copy on heal locations + logWarn(QString("Copying events of type '%1' is not allowed.").arg(type)); continue; } @@ -1527,11 +1528,11 @@ void MainWindow::copy() { eventsArray.append(eventJson); } - - copyObject["events"] = eventsArray; - setClipboardData(copyObject); - logInfo("Copied currently selected events to clipboard"); - + if (!eventsArray.isEmpty()) { + copyObject["events"] = eventsArray; + setClipboardData(copyObject); + logInfo("Copied currently selected events to clipboard"); + } break; } } @@ -1616,6 +1617,11 @@ void MainWindow::paste() { // paste the event to the map QString type = event["event_type"].toString(); + if (editor->eventLimitReached(type)) { + logWarn(QString("Skipping paste, the map limit for events of type '%1' has been reached.").arg(type)); + continue; + } + Event *pasteEvent = Event::createNewEvent(type, editor->map->name, editor->project); for (auto key : event.toObject().keys()) @@ -1647,9 +1653,10 @@ void MainWindow::paste() { newEvents.append(pasteEvent); } - editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents)); - updateObjects(); - + if (!newEvents.isEmpty()) { + editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents)); + updateObjects(); + } break; } }