Browse Source

Double clicking on warp events takes you to the destination map and warp

Marcus Huderle 6 years ago
parent
commit
74c2766c01
4 changed files with 43 additions and 4 deletions
  1. 6
    4
      editor.cpp
  2. 2
    0
      editor.h
  3. 34
    0
      mainwindow.cpp
  4. 1
    0
      mainwindow.h

+ 6
- 4
editor.cpp View File

1515
 }
1515
 }
1516
 
1516
 
1517
 void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
1517
 void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
1518
-    if (clicking) {
1519
-        this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
1520
-        this->editor->updateSelectedEvents();
1521
-    }
1522
     active = false;
1518
     active = false;
1523
 }
1519
 }
1524
 
1520
 
1521
+void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouse) {
1522
+    if (this->event->get("event_type") == EventType::Warp) {
1523
+        emit editor->warpEventDoubleClicked(this->event->get("destination_map_name"), this->event->get("destination_warp"));
1524
+    }
1525
+}
1526
+
1525
 QList<DraggablePixmapItem *> *Editor::getObjects() {
1527
 QList<DraggablePixmapItem *> *Editor::getObjects() {
1526
     QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
1528
     QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
1527
     for (Event *event : map->getAllEvents()) {
1529
     for (Event *event : map->getAllEvents()) {

+ 2
- 0
editor.h View File

138
     void selectedObjectsChanged();
138
     void selectedObjectsChanged();
139
     void loadMapRequested(QString, QString);
139
     void loadMapRequested(QString, QString);
140
     void tilesetChanged(QString);
140
     void tilesetChanged(QString);
141
+    void warpEventDoubleClicked(QString mapName, QString warpNum);
141
 };
142
 };
142
 
143
 
143
 
144
 
228
     void mousePressEvent(QGraphicsSceneMouseEvent*);
229
     void mousePressEvent(QGraphicsSceneMouseEvent*);
229
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
230
     void mouseMoveEvent(QGraphicsSceneMouseEvent*);
230
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
231
     void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
232
+    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
231
 };
233
 };
232
 
234
 
233
 class EventGroup : public QGraphicsItemGroup {
235
 class EventGroup : public QGraphicsItemGroup {

+ 34
- 0
mainwindow.cpp View File

37
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
37
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
38
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
38
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
39
     connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
39
     connect(editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
40
+    connect(editor, SIGNAL(warpEventDoubleClicked(QString,QString)), this, SLOT(openWarpMap(QString,QString)));
40
 
41
 
41
     on_toolButton_Paint_clicked();
42
     on_toolButton_Paint_clicked();
42
 
43
 
196
     ui->graphicsView_Elevation->setFixedSize(editor->elevation_metatiles_item->pixmap().width() + 2, editor->elevation_metatiles_item->pixmap().height() + 2);
197
     ui->graphicsView_Elevation->setFixedSize(editor->elevation_metatiles_item->pixmap().width() + 2, editor->elevation_metatiles_item->pixmap().height() + 2);
197
 }
198
 }
198
 
199
 
200
+void MainWindow::openWarpMap(QString map_name, QString warp_num) {
201
+    // Ensure valid destination map name.
202
+    if (!editor->project->mapNames->contains(map_name)) {
203
+        qDebug() << QString("Invalid warp destination map name '%1'").arg(map_name);
204
+        return;
205
+    }
206
+
207
+    // Ensure valid destination warp number.
208
+    bool ok;
209
+    int warpNum = warp_num.toInt(&ok, 0);
210
+    if (!ok) {
211
+        qDebug() << QString("Invalid warp number '%1' for destination map '%2'").arg(warp_num).arg(map_name);
212
+        return;
213
+    }
214
+
215
+    // Open the destination map, and select the target warp event.
216
+    setMap(map_name);
217
+    QList<Event*> warp_events = editor->map->events["warp_event_group"];
218
+    if (warp_events.length() > warpNum) {
219
+        Event *warp_event = warp_events.at(warpNum);
220
+        QList<DraggablePixmapItem *> *all_events = editor->getObjects();
221
+        for (DraggablePixmapItem *item : *all_events) {
222
+            if (item->event == warp_event) {
223
+                editor->selected_events->clear();
224
+                editor->selected_events->append(item);
225
+                editor->updateSelectedEvents();
226
+            }
227
+        }
228
+
229
+        delete all_events;
230
+    }
231
+}
232
+
199
 void MainWindow::setRecentMap(QString map_name) {
233
 void MainWindow::setRecentMap(QString map_name) {
200
     QSettings settings;
234
     QSettings settings;
201
     QString key = "project:" + editor->project->root;
235
     QString key = "project:" + editor->project->root;

+ 1
- 0
mainwindow.h View File

32
     void on_action_Open_Project_triggered();
32
     void on_action_Open_Project_triggered();
33
     void on_mapList_activated(const QModelIndex &index);
33
     void on_mapList_activated(const QModelIndex &index);
34
     void on_action_Save_Project_triggered();
34
     void on_action_Save_Project_triggered();
35
+    void openWarpMap(QString map_name, QString warp_num);
35
 
36
 
36
     void undo();
37
     void undo();
37
     void redo();
38
     void redo();