Merge pull request #442 from GriffinRichards/event-paste

Minor fixes to pasting events
This commit is contained in:
Marcus Huderle 2022-09-03 11:02:57 -05:00 committed by GitHub
commit ebe94a1793
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

View file

@ -26,6 +26,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Overhauled the region map editor, adding support for tilemaps, and significant customization. Also now supports pokefirered. - Overhauled the region map editor, adding support for tilemaps, and significant customization. Also now supports pokefirered.
- Metatiles are always rendered accurately with 3 layers, and the unused layer is not assumed to be transparent. - Metatiles are always rendered accurately with 3 layers, and the unused layer is not assumed to be transparent.
- `object_event_graphics_info.h` can now be parsed correctly if it uses structs with attributes. - `object_event_graphics_info.h` can now be parsed correctly if it uses structs with attributes.
- The selection is no longer reset when pasting events. The newly pasted events are selected instead.
- Palette editor ui is updated a bit to allow hex and rgb value input. - Palette editor ui is updated a bit to allow hex and rgb value input.
### Fixed ### Fixed
@ -34,6 +35,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Fix cursor tile and player view outlines not updating immediately when toggled in Collision view. - Fix cursor tile and player view outlines not updating immediately when toggled in Collision view.
- Fix selected space not updating while painting in Collision view. - Fix selected space not updating while painting in Collision view.
- Fix the map music dropdown being empty when importing a map from Advance Map. - Fix the map music dropdown being empty when importing a map from Advance Map.
- Fix object events added by pasting ignoring the map event limit.
- Fixed a bug where saving the tileset editor would reselect the main editor's first selected metatile. - Fixed a bug where saving the tileset editor would reselect the main editor's first selected metatile.
## [4.5.0] - 2021-12-26 ## [4.5.0] - 2021-12-26

View file

@ -151,6 +151,7 @@ public:
void shouldReselectEvents(); void shouldReselectEvents();
void scaleMapView(int); void scaleMapView(int);
void openInTextEditor(const QString &path, int lineNum = 0) const; void openInTextEditor(const QString &path, int lineNum = 0) const;
bool eventLimitReached(QString event_type);
public slots: public slots:
void openMapScripts() const; void openMapScripts() const;
@ -176,7 +177,6 @@ private:
void updateEncounterFields(EncounterFields newFields); void updateEncounterFields(EncounterFields newFields);
QString getMovementPermissionText(uint16_t collision, uint16_t elevation); QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
QString getMetatileDisplayMessage(uint16_t metatileId); QString getMetatileDisplayMessage(uint16_t metatileId);
bool eventLimitReached(Map *, QString);
bool startDetachedProcess(const QString &command, bool startDetachedProcess(const QString &command,
const QString &workingDirectory = QString(), const QString &workingDirectory = QString(),
qint64 *pid = nullptr) const; qint64 *pid = nullptr) const;

View file

@ -2031,7 +2031,7 @@ void Editor::duplicateSelectedEvents() {
for (int i = 0; i < selected_events->length(); i++) { for (int i = 0; i < selected_events->length(); i++) {
Event *original = selected_events->at(i)->event; Event *original = selected_events->at(i)->event;
QString eventType = original->get("event_type"); 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)); logWarn(QString("Skipping duplication, the map limit for events of type '%1' has been reached.").arg(eventType));
continue; continue;
} }
@ -2045,7 +2045,7 @@ void Editor::duplicateSelectedEvents() {
} }
DraggablePixmapItem* Editor::addNewEvent(QString event_type) { 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 *event = Event::createNewEvent(event_type, map->name, project);
event->put("map_name", map->name); event->put("map_name", map->name);
if (event_type == EventType::HealLocation) { if (event_type == EventType::HealLocation) {
@ -2061,7 +2061,7 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
} }
// Currently only object events have an explicit limit // 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 (project && map && !event_type.isEmpty()) {
if (Event::typeToGroup(event_type) == EventGroup::Object) if (Event::typeToGroup(event_type) == EventGroup::Object)

View file

@ -1520,6 +1520,7 @@ void MainWindow::copy() {
if (type == EventType::HealLocation) { if (type == EventType::HealLocation) {
// no copy on heal locations // no copy on heal locations
logWarn(QString("Copying events of type '%1' is not allowed.").arg(type));
continue; continue;
} }
@ -1531,11 +1532,11 @@ void MainWindow::copy() {
eventsArray.append(eventJson); eventsArray.append(eventJson);
} }
if (!eventsArray.isEmpty()) {
copyObject["events"] = eventsArray; copyObject["events"] = eventsArray;
setClipboardData(copyObject); setClipboardData(copyObject);
logInfo("Copied currently selected events to clipboard"); logInfo("Copied currently selected events to clipboard");
}
break; break;
} }
} }
@ -1620,6 +1621,11 @@ void MainWindow::paste() {
// paste the event to the map // paste the event to the map
QString type = event["event_type"].toString(); 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); Event *pasteEvent = Event::createNewEvent(type, editor->map->name, editor->project);
for (auto key : event.toObject().keys()) for (auto key : event.toObject().keys())
@ -1651,9 +1657,10 @@ void MainWindow::paste() {
newEvents.append(pasteEvent); newEvents.append(pasteEvent);
} }
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents)); if (!newEvents.isEmpty()) {
updateObjects(); updateObjects();
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
}
break; break;
} }
} }