|
@@ -97,6 +97,7 @@ void Editor::setEditingConnections() {
|
97
|
97
|
ui->comboBox_ConnectedMap->clear();
|
98
|
98
|
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
99
|
99
|
ui->comboBox_ConnectedMap->blockSignals(false);
|
|
100
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
100
|
101
|
setConnectionsVisibility(false);
|
101
|
102
|
if (current_connection_edit_item) {
|
102
|
103
|
onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
|
|
@@ -195,6 +196,9 @@ void Editor::setConnectionEditControlsEnabled(bool enabled) {
|
195
|
196
|
}
|
196
|
197
|
|
197
|
198
|
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
|
199
|
+ if (!connectionItem)
|
|
200
|
+ return;
|
|
201
|
+
|
198
|
202
|
for (ConnectionPixmapItem* item : connection_edit_items) {
|
199
|
203
|
bool isSelectedItem = item == connectionItem;
|
200
|
204
|
int zValue = isSelectedItem ? 0 : -1;
|
|
@@ -372,39 +376,7 @@ void Editor::displayMapConnections() {
|
372
|
376
|
if (connection->direction == "dive" || connection->direction == "emerge") {
|
373
|
377
|
continue;
|
374
|
378
|
}
|
375
|
|
- Map *connected_map = project->getMap(connection->map_name);
|
376
|
|
- QPixmap pixmap = connected_map->renderConnection(*connection);
|
377
|
|
- int offset = connection->offset.toInt(nullptr, 0);
|
378
|
|
- int x = 0, y = 0;
|
379
|
|
- if (connection->direction == "up") {
|
380
|
|
- x = offset * 16;
|
381
|
|
- y = -pixmap.height();
|
382
|
|
- } else if (connection->direction == "down") {
|
383
|
|
- x = offset * 16;
|
384
|
|
- y = map->getHeight() * 16;
|
385
|
|
- } else if (connection->direction == "left") {
|
386
|
|
- x = -pixmap.width();
|
387
|
|
- y = offset * 16;
|
388
|
|
- } else if (connection->direction == "right") {
|
389
|
|
- x = map->getWidth() * 16;
|
390
|
|
- y = offset * 16;
|
391
|
|
- }
|
392
|
|
-
|
393
|
|
- QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
394
|
|
- item->setZValue(-1);
|
395
|
|
- item->setX(x);
|
396
|
|
- item->setY(y);
|
397
|
|
- scene->addItem(item);
|
398
|
|
- map->connection_items.append(item);
|
399
|
|
-
|
400
|
|
- ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
401
|
|
- connection_edit_item->setX(x);
|
402
|
|
- connection_edit_item->setY(y);
|
403
|
|
- connection_edit_item->setZValue(-1);
|
404
|
|
- scene->addItem(connection_edit_item);
|
405
|
|
- connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
406
|
|
- connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
407
|
|
- connection_edit_items.append(connection_edit_item);
|
|
379
|
+ createConnectionItem(connection, false);
|
408
|
380
|
}
|
409
|
381
|
|
410
|
382
|
if (!connection_edit_items.empty()) {
|
|
@@ -412,6 +384,43 @@ void Editor::displayMapConnections() {
|
412
|
384
|
}
|
413
|
385
|
}
|
414
|
386
|
|
|
387
|
+void Editor::createConnectionItem(Connection* connection, bool hide) {
|
|
388
|
+ Map *connected_map = project->getMap(connection->map_name);
|
|
389
|
+ QPixmap pixmap = connected_map->renderConnection(*connection);
|
|
390
|
+ int offset = connection->offset.toInt(nullptr, 0);
|
|
391
|
+ int x = 0, y = 0;
|
|
392
|
+ if (connection->direction == "up") {
|
|
393
|
+ x = offset * 16;
|
|
394
|
+ y = -pixmap.height();
|
|
395
|
+ } else if (connection->direction == "down") {
|
|
396
|
+ x = offset * 16;
|
|
397
|
+ y = map->getHeight() * 16;
|
|
398
|
+ } else if (connection->direction == "left") {
|
|
399
|
+ x = -pixmap.width();
|
|
400
|
+ y = offset * 16;
|
|
401
|
+ } else if (connection->direction == "right") {
|
|
402
|
+ x = map->getWidth() * 16;
|
|
403
|
+ y = offset * 16;
|
|
404
|
+ }
|
|
405
|
+
|
|
406
|
+ QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
|
407
|
+ item->setZValue(-1);
|
|
408
|
+ item->setX(x);
|
|
409
|
+ item->setY(y);
|
|
410
|
+ scene->addItem(item);
|
|
411
|
+ map->connection_items.append(item);
|
|
412
|
+ item->setVisible(!hide);
|
|
413
|
+
|
|
414
|
+ ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
|
415
|
+ connection_edit_item->setX(x);
|
|
416
|
+ connection_edit_item->setY(y);
|
|
417
|
+ connection_edit_item->setZValue(-1);
|
|
418
|
+ scene->addItem(connection_edit_item);
|
|
419
|
+ connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
|
420
|
+ connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
|
421
|
+ connection_edit_items.append(connection_edit_item);
|
|
422
|
+}
|
|
423
|
+
|
415
|
424
|
void Editor::displayMapBorder() {
|
416
|
425
|
QPixmap pixmap = map->renderBorder();
|
417
|
426
|
for (int y = -6; y < map->getHeight() + 6; y += 2)
|
|
@@ -465,13 +474,7 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
465
|
474
|
return;
|
466
|
475
|
|
467
|
476
|
if (mapName.isEmpty()) {
|
468
|
|
- map->connections.removeOne(current_connection_edit_item->connection);
|
469
|
|
- connection_edit_items.removeOne(current_connection_edit_item);
|
470
|
|
- scene->removeItem(current_connection_edit_item);
|
471
|
|
- delete current_connection_edit_item;
|
472
|
|
- current_connection_edit_item = NULL;
|
473
|
|
- setConnectionEditControlsEnabled(false);
|
474
|
|
- ui->spinBox_ConnectionOffset->setValue(0);
|
|
477
|
+ removeCurrentConnection();
|
475
|
478
|
return;
|
476
|
479
|
} else {
|
477
|
480
|
setConnectionEditControlsEnabled(true);
|
|
@@ -481,6 +484,49 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
481
|
484
|
setCurrentConnectionDirection(direction);
|
482
|
485
|
}
|
483
|
486
|
|
|
487
|
+void Editor::addNewConnection() {
|
|
488
|
+ // Find direction with least number of connections.
|
|
489
|
+ QMap<QString, int> directionCounts = QMap<QString, int>({{"up", 0}, {"right", 0}, {"down", 0}, {"left", 0}});
|
|
490
|
+ for (Connection* connection : map->connections) {
|
|
491
|
+ directionCounts[connection->direction]++;
|
|
492
|
+ }
|
|
493
|
+ QString minDirection = "up";
|
|
494
|
+ int minCount = INT_MAX;
|
|
495
|
+ for (QString direction : directionCounts.keys()) {
|
|
496
|
+ if (directionCounts[direction] < minCount) {
|
|
497
|
+ minDirection = direction;
|
|
498
|
+ minCount = directionCounts[direction];
|
|
499
|
+ }
|
|
500
|
+ }
|
|
501
|
+
|
|
502
|
+ Connection* newConnection = new Connection;
|
|
503
|
+ newConnection->direction = minDirection;
|
|
504
|
+ newConnection->offset = "0";
|
|
505
|
+ newConnection->map_name = project->mapNames->first();
|
|
506
|
+ map->connections.append(newConnection);
|
|
507
|
+ createConnectionItem(newConnection, true);
|
|
508
|
+ onConnectionItemSelected(connection_edit_items.last());
|
|
509
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
510
|
+}
|
|
511
|
+
|
|
512
|
+void Editor::removeCurrentConnection() {
|
|
513
|
+ if (!current_connection_edit_item)
|
|
514
|
+ return;
|
|
515
|
+
|
|
516
|
+ map->connections.removeOne(current_connection_edit_item->connection);
|
|
517
|
+ connection_edit_items.removeOne(current_connection_edit_item);
|
|
518
|
+ scene->removeItem(current_connection_edit_item);
|
|
519
|
+ delete current_connection_edit_item;
|
|
520
|
+ current_connection_edit_item = NULL;
|
|
521
|
+ setConnectionEditControlsEnabled(false);
|
|
522
|
+ ui->spinBox_ConnectionOffset->setValue(0);
|
|
523
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
524
|
+
|
|
525
|
+ if (connection_edit_items.length() > 0) {
|
|
526
|
+ onConnectionItemSelected(connection_edit_items.last());
|
|
527
|
+ }
|
|
528
|
+}
|
|
529
|
+
|
484
|
530
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
485
|
531
|
draw();
|
486
|
532
|
}
|