ソースを参照

Some cleanup, and disable connection controls when loading map with no connections

Marcus Huderle 6 年 前
コミット
ad7b9ca7b3
共有3 個のファイルを変更した54 個の追加52 個の削除を含む
  1. 51
    49
      editor.cpp
  2. 2
    2
      editor.h
  3. 1
    1
      mainwindow.cpp

+ 51
- 49
editor.cpp ファイルの表示

@@ -97,9 +97,11 @@ void Editor::setEditingConnections() {
97 97
         ui->label_NumConnections->setText(QString::number(map->connections.length()));
98 98
         setConnectionsVisibility(false);
99 99
         setDiveEmergeControls();
100
-        if (current_connection_edit_item) {
101
-            onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
102
-            updateConnectionMap(current_connection_edit_item->connection->map_name, current_connection_edit_item->connection->direction);
100
+        setConnectionEditControlsEnabled(selected_connection_item != NULL);
101
+        if (selected_connection_item) {
102
+            onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt());
103
+            setConnectionMap(selected_connection_item->connection->map_name);
104
+            setCurrentConnectionDirection(selected_connection_item->connection->direction);
103 105
         }
104 106
     }
105 107
     if (collision_item) {
@@ -160,44 +162,45 @@ void Editor::setBorderItemsVisible(bool visible, qreal opacity) {
160 162
 }
161 163
 
162 164
 void Editor::setCurrentConnectionDirection(QString curDirection) {
163
-    if (!current_connection_edit_item)
165
+    if (!selected_connection_item)
164 166
         return;
165 167
 
166
-    current_connection_edit_item->connection->direction = curDirection;
167
-    Map *connected_map = project->getMap(current_connection_edit_item->connection->map_name);
168
-    QPixmap pixmap = connected_map->renderConnection(*current_connection_edit_item->connection);
169
-    int offset = current_connection_edit_item->connection->offset.toInt(nullptr, 0);
170
-    current_connection_edit_item->initialOffset = offset;
168
+    selected_connection_item->connection->direction = curDirection;
169
+
170
+    Map *connected_map = project->getMap(selected_connection_item->connection->map_name);
171
+    QPixmap pixmap = connected_map->renderConnection(*selected_connection_item->connection);
172
+    int offset = selected_connection_item->connection->offset.toInt(nullptr, 0);
173
+    selected_connection_item->initialOffset = offset;
171 174
     int x = 0, y = 0;
172
-    if (current_connection_edit_item->connection->direction == "up") {
175
+    if (selected_connection_item->connection->direction == "up") {
173 176
         x = offset * 16;
174 177
         y = -pixmap.height();
175
-    } else if (current_connection_edit_item->connection->direction == "down") {
178
+    } else if (selected_connection_item->connection->direction == "down") {
176 179
         x = offset * 16;
177 180
         y = map->getHeight() * 16;
178
-    } else if (current_connection_edit_item->connection->direction == "left") {
181
+    } else if (selected_connection_item->connection->direction == "left") {
179 182
         x = -pixmap.width();
180 183
         y = offset * 16;
181
-    } else if (current_connection_edit_item->connection->direction == "right") {
184
+    } else if (selected_connection_item->connection->direction == "right") {
182 185
         x = map->getWidth() * 16;
183 186
         y = offset * 16;
184 187
     }
185 188
 
186
-    current_connection_edit_item->basePixmap = pixmap;
189
+    selected_connection_item->basePixmap = pixmap;
187 190
     QPainter painter(&pixmap);
188 191
     painter.setPen(QColor(255, 0, 255));
189 192
     painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
190 193
     painter.end();
191
-    current_connection_edit_item->setPixmap(pixmap);
192
-    current_connection_edit_item->initialX = x;
193
-    current_connection_edit_item->initialY = y;
194
-    current_connection_edit_item->blockSignals(true);
195
-    current_connection_edit_item->setX(x);
196
-    current_connection_edit_item->setY(y);
197
-    current_connection_edit_item->setZValue(-1);
198
-    current_connection_edit_item->blockSignals(false);
194
+    selected_connection_item->setPixmap(pixmap);
195
+    selected_connection_item->initialX = x;
196
+    selected_connection_item->initialY = y;
197
+    selected_connection_item->blockSignals(true);
198
+    selected_connection_item->setX(x);
199
+    selected_connection_item->setY(y);
200
+    selected_connection_item->setZValue(-1);
201
+    selected_connection_item->blockSignals(false);
199 202
 
200
-    setConnectionEditControlValues(current_connection_edit_item->connection);
203
+    setConnectionEditControlValues(selected_connection_item->connection);
201 204
 }
202 205
 
203 206
 void Editor::onConnectionOffsetChanged(int newOffset) {
@@ -253,11 +256,11 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
253 256
             item->setPixmap(pixmap);
254 257
         }
255 258
     }
256
-    current_connection_edit_item = connectionItem;
259
+    selected_connection_item = connectionItem;
257 260
     setConnectionEditControlsEnabled(true);
258
-    setConnectionEditControlValues(current_connection_edit_item->connection);
259
-    ui->spinBox_ConnectionOffset->setMaximum(current_connection_edit_item->getMaxOffset());
260
-    ui->spinBox_ConnectionOffset->setMinimum(current_connection_edit_item->getMinOffset());
261
+    setConnectionEditControlValues(selected_connection_item->connection);
262
+    ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());
263
+    ui->spinBox_ConnectionOffset->setMinimum(selected_connection_item->getMinOffset());
261 264
 }
262 265
 
263 266
 void Editor::setSelectedConnectionFromMap(QString mapName) {
@@ -424,7 +427,7 @@ void Editor::displayMapConnections() {
424 427
     for (ConnectionPixmapItem* item : connection_edit_items) {
425 428
         delete item;
426 429
     }
427
-    current_connection_edit_item = NULL;
430
+    selected_connection_item = NULL;
428 431
     connection_edit_items.clear();
429 432
 
430 433
     for (Connection *connection : map->connections) {
@@ -508,38 +511,37 @@ void Editor::displayMapGrid() {
508 511
 }
509 512
 
510 513
 void Editor::updateConnectionOffset(int offset) {
511
-    if (!current_connection_edit_item)
514
+    if (!selected_connection_item)
512 515
         return;
513 516
 
514
-    current_connection_edit_item->blockSignals(true);
515
-    offset = qMin(offset, current_connection_edit_item->getMaxOffset());
516
-    offset = qMax(offset, current_connection_edit_item->getMinOffset());
517
-    current_connection_edit_item->connection->offset = QString::number(offset);
518
-    if (current_connection_edit_item->connection->direction == "up" || current_connection_edit_item->connection->direction == "down") {
519
-        current_connection_edit_item->setX(current_connection_edit_item->initialX + (offset - current_connection_edit_item->initialOffset) * 16);
517
+    selected_connection_item->blockSignals(true);
518
+    offset = qMin(offset, selected_connection_item->getMaxOffset());
519
+    offset = qMax(offset, selected_connection_item->getMinOffset());
520
+    selected_connection_item->connection->offset = QString::number(offset);
521
+    if (selected_connection_item->connection->direction == "up" || selected_connection_item->connection->direction == "down") {
522
+        selected_connection_item->setX(selected_connection_item->initialX + (offset - selected_connection_item->initialOffset) * 16);
520 523
     } else {
521
-        current_connection_edit_item->setY(current_connection_edit_item->initialY + (offset - current_connection_edit_item->initialOffset) * 16);
524
+        selected_connection_item->setY(selected_connection_item->initialY + (offset - selected_connection_item->initialOffset) * 16);
522 525
     }
523
-    current_connection_edit_item->blockSignals(false);
526
+    selected_connection_item->blockSignals(false);
524 527
 }
525 528
 
526
-void Editor::updateConnectionMap(QString mapName, QString direction) {
529
+void Editor::setConnectionMap(QString mapName) {
527 530
     if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
528 531
         qDebug() << "Invalid map name " << mapName << " specified for connection.";
529 532
         return;
530 533
     }
531
-    if (!current_connection_edit_item)
534
+    if (!selected_connection_item)
532 535
         return;
533 536
 
534 537
     if (mapName.isEmpty()) {
535 538
         removeCurrentConnection();
536 539
         return;
537
-    } else {
538
-        setConnectionEditControlsEnabled(true);
539 540
     }
540 541
 
541
-    current_connection_edit_item->connection->map_name = mapName;
542
-    setCurrentConnectionDirection(direction);
542
+    setConnectionEditControlsEnabled(true);
543
+    selected_connection_item->connection->map_name = mapName;
544
+    setCurrentConnectionDirection(selected_connection_item->connection->direction);
543 545
 }
544 546
 
545 547
 void Editor::addNewConnection() {
@@ -568,14 +570,14 @@ void Editor::addNewConnection() {
568 570
 }
569 571
 
570 572
 void Editor::removeCurrentConnection() {
571
-    if (!current_connection_edit_item)
573
+    if (!selected_connection_item)
572 574
         return;
573 575
 
574
-    map->connections.removeOne(current_connection_edit_item->connection);
575
-    connection_edit_items.removeOne(current_connection_edit_item);
576
-    scene->removeItem(current_connection_edit_item);
577
-    delete current_connection_edit_item;
578
-    current_connection_edit_item = NULL;
576
+    map->connections.removeOne(selected_connection_item->connection);
577
+    connection_edit_items.removeOne(selected_connection_item);
578
+    scene->removeItem(selected_connection_item);
579
+    delete selected_connection_item;
580
+    selected_connection_item = NULL;
579 581
     setConnectionEditControlsEnabled(false);
580 582
     ui->spinBox_ConnectionOffset->setValue(0);
581 583
     ui->label_NumConnections->setText(QString::number(map->connections.length()));

+ 2
- 2
editor.h ファイルの表示

@@ -50,7 +50,7 @@ public:
50 50
     void setCurrentConnectionDirection(QString curDirection);
51 51
     void setConnectionsVisibility(bool visible);
52 52
     void updateConnectionOffset(int offset);
53
-    void updateConnectionMap(QString mapName, QString direction);
53
+    void setConnectionMap(QString mapName);
54 54
     void addNewConnection();
55 55
     void removeCurrentConnection();
56 56
     void updateDiveMap(QString mapName);
@@ -70,7 +70,7 @@ public:
70 70
     QGraphicsScene *scene = NULL;
71 71
     QGraphicsPixmapItem *current_view = NULL;
72 72
     MapPixmapItem *map_item = NULL;
73
-    ConnectionPixmapItem* current_connection_edit_item = NULL;
73
+    ConnectionPixmapItem* selected_connection_item = NULL;
74 74
     QList<ConnectionPixmapItem*> connection_edit_items;
75 75
     CollisionPixmapItem *collision_item = NULL;
76 76
     QGraphicsItemGroup *objects_group = NULL;

+ 1
- 1
mainwindow.cpp ファイルの表示

@@ -785,7 +785,7 @@ void MainWindow::on_spinBox_ConnectionOffset_valueChanged(int offset)
785 785
 
786 786
 void MainWindow::on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName)
787 787
 {
788
-    editor->updateConnectionMap(mapName, ui->comboBox_ConnectionDirection->currentText().toLower());
788
+    editor->setConnectionMap(mapName);
789 789
 }
790 790
 
791 791
 void MainWindow::on_pushButton_AddConnection_clicked()