瀏覽代碼

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

Marcus Huderle 6 年之前
父節點
當前提交
74c2766c01
共有 4 個文件被更改,包括 43 次插入4 次删除
  1. 6
    4
      editor.cpp
  2. 2
    0
      editor.h
  3. 34
    0
      mainwindow.cpp
  4. 1
    0
      mainwindow.h

+ 6
- 4
editor.cpp 查看文件

@@ -1515,13 +1515,15 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
1515 1515
 }
1516 1516
 
1517 1517
 void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
1518
-    if (clicking) {
1519
-        this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
1520
-        this->editor->updateSelectedEvents();
1521
-    }
1522 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 1527
 QList<DraggablePixmapItem *> *Editor::getObjects() {
1526 1528
     QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
1527 1529
     for (Event *event : map->getAllEvents()) {

+ 2
- 0
editor.h 查看文件

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

+ 34
- 0
mainwindow.cpp 查看文件

@@ -37,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
37 37
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
38 38
     connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
39 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 42
     on_toolButton_Paint_clicked();
42 43
 
@@ -196,6 +197,39 @@ void MainWindow::redrawMapScene()
196 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 233
 void MainWindow::setRecentMap(QString map_name) {
200 234
     QSettings settings;
201 235
     QString key = "project:" + editor->project->root;

+ 1
- 0
mainwindow.h 查看文件

@@ -32,6 +32,7 @@ private slots:
32 32
     void on_action_Open_Project_triggered();
33 33
     void on_mapList_activated(const QModelIndex &index);
34 34
     void on_action_Save_Project_triggered();
35
+    void openWarpMap(QString map_name, QString warp_num);
35 36
 
36 37
     void undo();
37 38
     void redo();