Browse Source

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

Marcus Huderle 6 years ago
parent
commit
ad7b9ca7b3
3 changed files with 54 additions and 52 deletions
  1. 51
    49
      editor.cpp
  2. 2
    2
      editor.h
  3. 1
    1
      mainwindow.cpp

+ 51
- 49
editor.cpp View File

97
         ui->label_NumConnections->setText(QString::number(map->connections.length()));
97
         ui->label_NumConnections->setText(QString::number(map->connections.length()));
98
         setConnectionsVisibility(false);
98
         setConnectionsVisibility(false);
99
         setDiveEmergeControls();
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
     if (collision_item) {
107
     if (collision_item) {
160
 }
162
 }
161
 
163
 
162
 void Editor::setCurrentConnectionDirection(QString curDirection) {
164
 void Editor::setCurrentConnectionDirection(QString curDirection) {
163
-    if (!current_connection_edit_item)
165
+    if (!selected_connection_item)
164
         return;
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
     int x = 0, y = 0;
174
     int x = 0, y = 0;
172
-    if (current_connection_edit_item->connection->direction == "up") {
175
+    if (selected_connection_item->connection->direction == "up") {
173
         x = offset * 16;
176
         x = offset * 16;
174
         y = -pixmap.height();
177
         y = -pixmap.height();
175
-    } else if (current_connection_edit_item->connection->direction == "down") {
178
+    } else if (selected_connection_item->connection->direction == "down") {
176
         x = offset * 16;
179
         x = offset * 16;
177
         y = map->getHeight() * 16;
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
         x = -pixmap.width();
182
         x = -pixmap.width();
180
         y = offset * 16;
183
         y = offset * 16;
181
-    } else if (current_connection_edit_item->connection->direction == "right") {
184
+    } else if (selected_connection_item->connection->direction == "right") {
182
         x = map->getWidth() * 16;
185
         x = map->getWidth() * 16;
183
         y = offset * 16;
186
         y = offset * 16;
184
     }
187
     }
185
 
188
 
186
-    current_connection_edit_item->basePixmap = pixmap;
189
+    selected_connection_item->basePixmap = pixmap;
187
     QPainter painter(&pixmap);
190
     QPainter painter(&pixmap);
188
     painter.setPen(QColor(255, 0, 255));
191
     painter.setPen(QColor(255, 0, 255));
189
     painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
192
     painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
190
     painter.end();
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
 void Editor::onConnectionOffsetChanged(int newOffset) {
206
 void Editor::onConnectionOffsetChanged(int newOffset) {
253
             item->setPixmap(pixmap);
256
             item->setPixmap(pixmap);
254
         }
257
         }
255
     }
258
     }
256
-    current_connection_edit_item = connectionItem;
259
+    selected_connection_item = connectionItem;
257
     setConnectionEditControlsEnabled(true);
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
 void Editor::setSelectedConnectionFromMap(QString mapName) {
266
 void Editor::setSelectedConnectionFromMap(QString mapName) {
424
     for (ConnectionPixmapItem* item : connection_edit_items) {
427
     for (ConnectionPixmapItem* item : connection_edit_items) {
425
         delete item;
428
         delete item;
426
     }
429
     }
427
-    current_connection_edit_item = NULL;
430
+    selected_connection_item = NULL;
428
     connection_edit_items.clear();
431
     connection_edit_items.clear();
429
 
432
 
430
     for (Connection *connection : map->connections) {
433
     for (Connection *connection : map->connections) {
508
 }
511
 }
509
 
512
 
510
 void Editor::updateConnectionOffset(int offset) {
513
 void Editor::updateConnectionOffset(int offset) {
511
-    if (!current_connection_edit_item)
514
+    if (!selected_connection_item)
512
         return;
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
     } else {
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
     if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
530
     if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
528
         qDebug() << "Invalid map name " << mapName << " specified for connection.";
531
         qDebug() << "Invalid map name " << mapName << " specified for connection.";
529
         return;
532
         return;
530
     }
533
     }
531
-    if (!current_connection_edit_item)
534
+    if (!selected_connection_item)
532
         return;
535
         return;
533
 
536
 
534
     if (mapName.isEmpty()) {
537
     if (mapName.isEmpty()) {
535
         removeCurrentConnection();
538
         removeCurrentConnection();
536
         return;
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
 void Editor::addNewConnection() {
547
 void Editor::addNewConnection() {
568
 }
570
 }
569
 
571
 
570
 void Editor::removeCurrentConnection() {
572
 void Editor::removeCurrentConnection() {
571
-    if (!current_connection_edit_item)
573
+    if (!selected_connection_item)
572
         return;
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
     setConnectionEditControlsEnabled(false);
581
     setConnectionEditControlsEnabled(false);
580
     ui->spinBox_ConnectionOffset->setValue(0);
582
     ui->spinBox_ConnectionOffset->setValue(0);
581
     ui->label_NumConnections->setText(QString::number(map->connections.length()));
583
     ui->label_NumConnections->setText(QString::number(map->connections.length()));

+ 2
- 2
editor.h View File

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

+ 1
- 1
mainwindow.cpp View File

785
 
785
 
786
 void MainWindow::on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName)
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
 void MainWindow::on_pushButton_AddConnection_clicked()
791
 void MainWindow::on_pushButton_AddConnection_clicked()