|
@@ -203,10 +203,25 @@ void Editor::setCurrentConnectionDirection(QString curDirection) {
|
203
|
203
|
setConnectionEditControlValues(selected_connection_item->connection);
|
204
|
204
|
}
|
205
|
205
|
|
|
206
|
+void Editor::updateCurrentConnectionDirection(QString curDirection) {
|
|
207
|
+ if (!selected_connection_item)
|
|
208
|
+ return;
|
|
209
|
+
|
|
210
|
+ QString originalDirection = selected_connection_item->connection->direction;
|
|
211
|
+ setCurrentConnectionDirection(curDirection);
|
|
212
|
+ updateMirroredConnectionDirection(selected_connection_item->connection, originalDirection);
|
|
213
|
+}
|
|
214
|
+
|
|
215
|
+void Editor::onConnectionMoved(Connection* connection) {
|
|
216
|
+ updateMirroredConnectionOffset(connection);
|
|
217
|
+ onConnectionOffsetChanged(connection->offset.toInt());
|
|
218
|
+}
|
|
219
|
+
|
206
|
220
|
void Editor::onConnectionOffsetChanged(int newOffset) {
|
207
|
221
|
ui->spinBox_ConnectionOffset->blockSignals(true);
|
208
|
222
|
ui->spinBox_ConnectionOffset->setValue(newOffset);
|
209
|
223
|
ui->spinBox_ConnectionOffset->blockSignals(false);
|
|
224
|
+
|
210
|
225
|
}
|
211
|
226
|
|
212
|
227
|
void Editor::setConnectionEditControlValues(Connection* connection) {
|
|
@@ -419,7 +434,6 @@ DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
419
|
434
|
|
420
|
435
|
void Editor::displayMapConnections() {
|
421
|
436
|
for (QGraphicsPixmapItem* item : map->connection_items) {
|
422
|
|
- scene->removeItem(item);
|
423
|
437
|
delete item;
|
424
|
438
|
}
|
425
|
439
|
map->connection_items.clear();
|
|
@@ -474,7 +488,7 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
|
474
|
488
|
connection_edit_item->setY(y);
|
475
|
489
|
connection_edit_item->setZValue(-1);
|
476
|
490
|
scene->addItem(connection_edit_item);
|
477
|
|
- connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
|
491
|
+ connect(connection_edit_item, SIGNAL(connectionMoved(Connection*)), this, SLOT(onConnectionMoved(Connection*)));
|
478
|
492
|
connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
479
|
493
|
connect(connection_edit_item, SIGNAL(connectionItemDoubleClicked(ConnectionPixmapItem*)), this, SLOT(onConnectionItemDoubleClicked(ConnectionPixmapItem*)));
|
480
|
494
|
connection_edit_items.append(connection_edit_item);
|
|
@@ -524,6 +538,7 @@ void Editor::updateConnectionOffset(int offset) {
|
524
|
538
|
selected_connection_item->setY(selected_connection_item->initialY + (offset - selected_connection_item->initialOffset) * 16);
|
525
|
539
|
}
|
526
|
540
|
selected_connection_item->blockSignals(false);
|
|
541
|
+ updateMirroredConnectionOffset(selected_connection_item->connection);
|
527
|
542
|
}
|
528
|
543
|
|
529
|
544
|
void Editor::setConnectionMap(QString mapName) {
|
|
@@ -539,9 +554,11 @@ void Editor::setConnectionMap(QString mapName) {
|
539
|
554
|
return;
|
540
|
555
|
}
|
541
|
556
|
|
|
557
|
+ QString originalMapName = selected_connection_item->connection->map_name;
|
542
|
558
|
setConnectionEditControlsEnabled(true);
|
543
|
559
|
selected_connection_item->connection->map_name = mapName;
|
544
|
560
|
setCurrentConnectionDirection(selected_connection_item->connection->direction);
|
|
561
|
+ updateMirroredConnectionMap(selected_connection_item->connection, originalMapName);
|
545
|
562
|
}
|
546
|
563
|
|
547
|
564
|
void Editor::addNewConnection() {
|
|
@@ -559,14 +576,80 @@ void Editor::addNewConnection() {
|
559
|
576
|
}
|
560
|
577
|
}
|
561
|
578
|
|
|
579
|
+ // Don't connect the map to itself.
|
|
580
|
+ QString defaultMapName = project->mapNames->first();
|
|
581
|
+ if (defaultMapName == map->name) {
|
|
582
|
+ defaultMapName = project->mapNames->value(1);
|
|
583
|
+ }
|
|
584
|
+
|
562
|
585
|
Connection* newConnection = new Connection;
|
563
|
586
|
newConnection->direction = minDirection;
|
564
|
587
|
newConnection->offset = "0";
|
565
|
|
- newConnection->map_name = project->mapNames->first();
|
|
588
|
+ newConnection->map_name = defaultMapName;
|
566
|
589
|
map->connections.append(newConnection);
|
567
|
590
|
createConnectionItem(newConnection, true);
|
568
|
591
|
onConnectionItemSelected(connection_edit_items.last());
|
569
|
592
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
593
|
+
|
|
594
|
+ updateMirroredConnection(newConnection, newConnection->direction, newConnection->map_name);
|
|
595
|
+}
|
|
596
|
+
|
|
597
|
+void Editor::updateMirroredConnectionOffset(Connection* connection) {
|
|
598
|
+ updateMirroredConnection(connection, connection->direction, connection->map_name);
|
|
599
|
+}
|
|
600
|
+void Editor::updateMirroredConnectionDirection(Connection* connection, QString originalDirection) {
|
|
601
|
+ updateMirroredConnection(connection, originalDirection, connection->map_name);
|
|
602
|
+}
|
|
603
|
+void Editor::updateMirroredConnectionMap(Connection* connection, QString originalMapName) {
|
|
604
|
+ updateMirroredConnection(connection, connection->direction, originalMapName);
|
|
605
|
+}
|
|
606
|
+void Editor::removeMirroredConnection(Connection* connection) {
|
|
607
|
+ updateMirroredConnection(connection, connection->direction, connection->map_name, true);
|
|
608
|
+}
|
|
609
|
+void Editor::updateMirroredConnection(Connection* connection, QString originalDirection, QString originalMapName, bool isDelete) {
|
|
610
|
+ if (!ui->checkBox_MirrorConnections->isChecked())
|
|
611
|
+ return;
|
|
612
|
+
|
|
613
|
+ static QMap<QString, QString> oppositeDirections = QMap<QString, QString>({
|
|
614
|
+ {"up", "down"}, {"right", "left"}, {"down", "up"}, {"left", "right"}});
|
|
615
|
+ QString oppositeDirection = oppositeDirections.value(originalDirection);
|
|
616
|
+
|
|
617
|
+ // Find the matching connection in the connected map.
|
|
618
|
+ QMap<QString, Map*> *mapcache = project->map_cache;
|
|
619
|
+ Connection* mirrorConnection = NULL;
|
|
620
|
+ Map* otherMap = project->getMap(originalMapName);
|
|
621
|
+ for (Connection* conn : otherMap->connections) {
|
|
622
|
+ if (conn->direction == oppositeDirection && conn->map_name == map->name) {
|
|
623
|
+ mirrorConnection = conn;
|
|
624
|
+ }
|
|
625
|
+ }
|
|
626
|
+
|
|
627
|
+ if (isDelete) {
|
|
628
|
+ if (mirrorConnection) {
|
|
629
|
+ otherMap->connections.removeOne(mirrorConnection);
|
|
630
|
+ delete mirrorConnection;
|
|
631
|
+ }
|
|
632
|
+ return;
|
|
633
|
+ }
|
|
634
|
+
|
|
635
|
+ if (connection->direction != originalDirection || connection->map_name != originalMapName) {
|
|
636
|
+ if (mirrorConnection) {
|
|
637
|
+ otherMap->connections.removeOne(mirrorConnection);
|
|
638
|
+ delete mirrorConnection;
|
|
639
|
+ mirrorConnection = NULL;
|
|
640
|
+ otherMap = project->getMap(connection->map_name);
|
|
641
|
+ }
|
|
642
|
+ }
|
|
643
|
+
|
|
644
|
+ // Create a new mirrored connection, if a matching one doesn't already exist.
|
|
645
|
+ if (!mirrorConnection) {
|
|
646
|
+ mirrorConnection = new Connection;
|
|
647
|
+ mirrorConnection->direction = oppositeDirections.value(connection->direction);
|
|
648
|
+ mirrorConnection->map_name = map->name;
|
|
649
|
+ otherMap->connections.append(mirrorConnection);
|
|
650
|
+ }
|
|
651
|
+
|
|
652
|
+ mirrorConnection->offset = QString::number(-connection->offset.toInt());
|
570
|
653
|
}
|
571
|
654
|
|
572
|
655
|
void Editor::removeCurrentConnection() {
|
|
@@ -575,6 +658,8 @@ void Editor::removeCurrentConnection() {
|
575
|
658
|
|
576
|
659
|
map->connections.removeOne(selected_connection_item->connection);
|
577
|
660
|
connection_edit_items.removeOne(selected_connection_item);
|
|
661
|
+ removeMirroredConnection(selected_connection_item->connection);
|
|
662
|
+
|
578
|
663
|
scene->removeItem(selected_connection_item);
|
579
|
664
|
delete selected_connection_item;
|
580
|
665
|
selected_connection_item = NULL;
|
|
@@ -751,8 +836,8 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
|
751
|
836
|
y = initialY;
|
752
|
837
|
}
|
753
|
838
|
|
754
|
|
- emit connectionMoved(newOffset);
|
755
|
839
|
connection->offset = QString::number(newOffset);
|
|
840
|
+ emit connectionMoved(connection);
|
756
|
841
|
return QPointF(x, y);
|
757
|
842
|
}
|
758
|
843
|
else {
|