Browse Source

Double-clicking on a connection will load the destination map

Marcus Huderle 6 years ago
parent
commit
bd2c782021
4 changed files with 30 additions and 1 deletions
  1. 18
    1
      editor.cpp
  2. 5
    0
      editor.h
  3. 6
    0
      mainwindow.cpp
  4. 1
    0
      mainwindow.h

+ 18
- 1
editor.cpp View File

@@ -254,13 +254,26 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
254 254
         }
255 255
     }
256 256
     current_connection_edit_item = connectionItem;
257
-    current_connection_edit_item->setZValue(0);
258 257
     setConnectionEditControlsEnabled(true);
259 258
     setConnectionEditControlValues(current_connection_edit_item->connection);
260 259
     ui->spinBox_ConnectionOffset->setMaximum(current_connection_edit_item->getMaxOffset());
261 260
     ui->spinBox_ConnectionOffset->setMinimum(current_connection_edit_item->getMinOffset());
262 261
 }
263 262
 
263
+void Editor::setSelectedConnectionFromMap(QString mapName) {
264
+    // Search for the first connection that connects to the given map map.
265
+    for (ConnectionPixmapItem* item : connection_edit_items) {
266
+        if (item->connection->map_name == mapName) {
267
+            onConnectionItemSelected(item);
268
+            break;
269
+        }
270
+    }
271
+}
272
+
273
+void Editor::onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem) {
274
+    emit loadMapRequested(connectionItem->connection->map_name, map->name);
275
+}
276
+
264 277
 void Editor::onConnectionDirectionChanged(QString newDirection) {
265 278
     ui->comboBox_ConnectionDirection->blockSignals(true);
266 279
     ui->comboBox_ConnectionDirection->setCurrentText(newDirection);
@@ -460,6 +473,7 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
460 473
     scene->addItem(connection_edit_item);
461 474
     connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
462 475
     connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
476
+    connect(connection_edit_item, SIGNAL(connectionItemDoubleClicked(ConnectionPixmapItem*)), this, SLOT(onConnectionItemDoubleClicked(ConnectionPixmapItem*)));
463 477
     connection_edit_items.append(connection_edit_item);
464 478
 }
465 479
 
@@ -746,6 +760,9 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
746 760
 void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
747 761
     emit connectionItemSelected(this);
748 762
 }
763
+void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
764
+    emit connectionItemDoubleClicked(this);
765
+}
749 766
 
750 767
 void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
751 768
     int x = ((int)pos.x()) / 16;

+ 5
- 0
editor.h View File

@@ -55,6 +55,7 @@ public:
55 55
     void removeCurrentConnection();
56 56
     void updateDiveMap(QString mapName);
57 57
     void updateEmergeMap(QString mapName);
58
+    void setSelectedConnectionFromMap(QString mapName);
58 59
 
59 60
     DraggablePixmapItem *addMapObject(Event *event);
60 61
     void selectMapObject(DraggablePixmapItem *object);
@@ -106,11 +107,13 @@ private slots:
106 107
     void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
107 108
     void onConnectionOffsetChanged(int newOffset);
108 109
     void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
110
+    void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
109 111
     void onConnectionDirectionChanged(QString newDirection);
110 112
 
111 113
 signals:
112 114
     void objectsChanged();
113 115
     void selectedObjectsChanged();
116
+    void loadMapRequested(QString, QString);
114 117
 };
115 118
 
116 119
 
@@ -303,8 +306,10 @@ public:
303 306
 protected:
304 307
     QVariant itemChange(GraphicsItemChange change, const QVariant &value);
305 308
     void mousePressEvent(QGraphicsSceneMouseEvent*);
309
+    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
306 310
 signals:
307 311
     void connectionItemSelected(ConnectionPixmapItem* connectionItem);
312
+    void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
308 313
     void connectionMoved(int offset);
309 314
 };
310 315
 

+ 6
- 0
mainwindow.cpp View File

@@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent) :
29 29
     editor = new Editor(ui);
30 30
     connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
31 31
     connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
32
+    connect(editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
32 33
 
33 34
     on_toolButton_Paint_clicked();
34 35
 
@@ -754,6 +755,11 @@ void MainWindow::checkToolButtons() {
754 755
     ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
755 756
 }
756 757
 
758
+void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {
759
+    setMap(mapName);
760
+    editor->setSelectedConnectionFromMap(fromMapName);
761
+}
762
+
757 763
 void MainWindow::onMapChanged(Map *map) {
758 764
     updateMapList();
759 765
 }

+ 1
- 0
mainwindow.h View File

@@ -36,6 +36,7 @@ private slots:
36 36
     void undo();
37 37
     void redo();
38 38
 
39
+    void onLoadMapRequested(QString, QString);
39 40
     void onMapChanged(Map *map);
40 41
 
41 42
     void on_action_Save_triggered();