Add duplicate shortcut for events

This commit is contained in:
GriffinR 2020-07-09 18:31:35 -04:00 committed by huderlem
parent a5bd797914
commit ea2bfa7274
6 changed files with 37 additions and 0 deletions

View file

@ -27,6 +27,7 @@ class Event
{ {
public: public:
Event(); Event();
Event(const Event&);
Event(QJsonObject, QString); Event(QJsonObject, QString);
public: public:
int x() { int x() {

View file

@ -100,6 +100,7 @@ public:
Event* createNewEvent(QString event_type); Event* createNewEvent(QString event_type);
void deleteEvent(Event *); void deleteEvent(Event *);
void updateSelectedEvents(); void updateSelectedEvents();
void duplicateSelectedEvents();
void redrawObject(DraggablePixmapItem *item); void redrawObject(DraggablePixmapItem *item);
QList<DraggablePixmapItem *> *getObjects(); QList<DraggablePixmapItem *> *getObjects();

View file

@ -123,6 +123,7 @@ private slots:
void undo(); void undo();
void redo(); void redo();
void duplicate();
void openInTextEditor(); void openInTextEditor();

View file

@ -19,6 +19,19 @@ Event::Event()
this->usingSprite = false; this->usingSprite = false;
} }
Event::Event(const Event& toCopy)
{
Event();
this->values = toCopy.values;
this->customValues = toCopy.customValues;
this->pixmap = toCopy.pixmap;
this->spriteWidth = toCopy.spriteWidth;
this->spriteHeight = toCopy.spriteHeight;
this->frame = toCopy.frame;
this->hFlip = toCopy.hFlip;
this->usingSprite = toCopy.usingSprite;
}
Event::Event(QJsonObject obj, QString type) Event::Event(QJsonObject obj, QString type)
{ {
Event(); Event();

View file

@ -1881,6 +1881,22 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
} }
} }
void Editor::duplicateSelectedEvents() {
if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != MapPixmapItem::PaintMode::EventObjects)
return;
QList<DraggablePixmapItem*> *duplicates = new QList<DraggablePixmapItem*>;
for (int i = 0; i < selected_events->length(); i++) {
Event *duplicate = new Event(*selected_events->at(i)->event);
map->addEvent(duplicate);
DraggablePixmapItem *object = addMapEvent(duplicate);
duplicates->append(object);
}
selected_events->clear();
selected_events = duplicates;
updateSelectedEvents();
}
DraggablePixmapItem* Editor::addNewEvent(QString event_type) { DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
if (project && map && !event_type.isEmpty()) { if (project && map && !event_type.isEmpty()) {
Event *event = Event::createNewEvent(event_type, map->name, project); Event *event = Event::createNewEvent(event_type, map->name, project);

View file

@ -77,6 +77,7 @@ void MainWindow::initExtraShortcuts() {
new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(redo())); new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(redo()));
new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale())); new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale()));
new QShortcut(QKeySequence("Ctrl+G"), ui->checkBox_ToggleGrid, SLOT(toggle())); new QShortcut(QKeySequence("Ctrl+G"), ui->checkBox_ToggleGrid, SLOT(toggle()));
new QShortcut(QKeySequence("Ctrl+D"), this, SLOT(duplicate()));
ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")}); ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")});
} }
@ -1230,6 +1231,10 @@ void MainWindow::redo() {
editor->redo(); editor->redo();
} }
void MainWindow::duplicate() {
editor->duplicateSelectedEvents();
}
// Open current map scripts in system default editor for .inc files // Open current map scripts in system default editor for .inc files
void MainWindow::openInTextEditor() { void MainWindow::openInTextEditor() {
bool usePoryscript = projectConfig.getUsePoryScript(); bool usePoryscript = projectConfig.getUsePoryScript();