|
@@ -3,8 +3,9 @@
|
3
|
3
|
#include <QPainter>
|
4
|
4
|
#include <QMouseEvent>
|
5
|
5
|
|
6
|
|
-Editor::Editor()
|
|
6
|
+Editor::Editor(Ui::MainWindow* ui)
|
7
|
7
|
{
|
|
8
|
+ this->ui = ui;
|
8
|
9
|
selected_events = new QList<DraggablePixmapItem*>;
|
9
|
10
|
}
|
10
|
11
|
|
|
@@ -37,9 +38,11 @@ void Editor::redo() {
|
37
|
38
|
void Editor::setEditingMap() {
|
38
|
39
|
current_view = map_item;
|
39
|
40
|
if (map_item) {
|
|
41
|
+ displayMapConnections();
|
40
|
42
|
map_item->draw();
|
41
|
43
|
map_item->setVisible(true);
|
42
|
44
|
map_item->setEnabled(true);
|
|
45
|
+ setConnectionsVisibility(true);
|
43
|
46
|
}
|
44
|
47
|
if (collision_item) {
|
45
|
48
|
collision_item->setVisible(false);
|
|
@@ -47,13 +50,15 @@ void Editor::setEditingMap() {
|
47
|
50
|
if (objects_group) {
|
48
|
51
|
objects_group->setVisible(false);
|
49
|
52
|
}
|
|
53
|
+ setBorderItemsVisible(true);
|
|
54
|
+ setConnectionItemsVisible(false);
|
50
|
55
|
}
|
51
|
56
|
|
52
|
57
|
void Editor::setEditingCollision() {
|
53
|
58
|
current_view = collision_item;
|
54
|
59
|
if (collision_item) {
|
55
|
|
- collision_item->draw();
|
56
|
60
|
collision_item->setVisible(true);
|
|
61
|
+ setConnectionsVisibility(true);
|
57
|
62
|
}
|
58
|
63
|
if (map_item) {
|
59
|
64
|
map_item->setVisible(false);
|
|
@@ -61,6 +66,8 @@ void Editor::setEditingCollision() {
|
61
|
66
|
if (objects_group) {
|
62
|
67
|
objects_group->setVisible(false);
|
63
|
68
|
}
|
|
69
|
+ setBorderItemsVisible(true);
|
|
70
|
+ setConnectionItemsVisible(false);
|
64
|
71
|
}
|
65
|
72
|
|
66
|
73
|
void Editor::setEditingObjects() {
|
|
@@ -71,10 +78,232 @@ void Editor::setEditingObjects() {
|
71
|
78
|
if (map_item) {
|
72
|
79
|
map_item->setVisible(true);
|
73
|
80
|
map_item->setEnabled(false);
|
|
81
|
+ setConnectionsVisibility(true);
|
74
|
82
|
}
|
75
|
83
|
if (collision_item) {
|
76
|
84
|
collision_item->setVisible(false);
|
77
|
85
|
}
|
|
86
|
+ setBorderItemsVisible(true);
|
|
87
|
+ setConnectionItemsVisible(false);
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+void Editor::setEditingConnections() {
|
|
91
|
+ current_view = map_item;
|
|
92
|
+ if (map_item) {
|
|
93
|
+ map_item->draw();
|
|
94
|
+ map_item->setVisible(true);
|
|
95
|
+ map_item->setEnabled(false);
|
|
96
|
+ populateConnectionMapPickers();
|
|
97
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
98
|
+ setConnectionsVisibility(false);
|
|
99
|
+ setDiveEmergeControls();
|
|
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);
|
|
105
|
+ }
|
|
106
|
+ }
|
|
107
|
+ if (collision_item) {
|
|
108
|
+ collision_item->setVisible(false);
|
|
109
|
+ }
|
|
110
|
+ if (objects_group) {
|
|
111
|
+ objects_group->setVisible(false);
|
|
112
|
+ }
|
|
113
|
+ setBorderItemsVisible(true, 0.4);
|
|
114
|
+ setConnectionItemsVisible(true);
|
|
115
|
+}
|
|
116
|
+
|
|
117
|
+void Editor::setDiveEmergeControls() {
|
|
118
|
+ ui->comboBox_DiveMap->blockSignals(true);
|
|
119
|
+ ui->comboBox_EmergeMap->blockSignals(true);
|
|
120
|
+ ui->comboBox_DiveMap->setCurrentText("");
|
|
121
|
+ ui->comboBox_EmergeMap->setCurrentText("");
|
|
122
|
+ for (Connection* connection : map->connections) {
|
|
123
|
+ if (connection->direction == "dive") {
|
|
124
|
+ ui->comboBox_DiveMap->setCurrentText(connection->map_name);
|
|
125
|
+ } else if (connection->direction == "emerge") {
|
|
126
|
+ ui->comboBox_EmergeMap->setCurrentText(connection->map_name);
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+ ui->comboBox_DiveMap->blockSignals(false);
|
|
130
|
+ ui->comboBox_EmergeMap->blockSignals(false);
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+void Editor::populateConnectionMapPickers() {
|
|
134
|
+ ui->comboBox_ConnectedMap->blockSignals(true);
|
|
135
|
+ ui->comboBox_DiveMap->blockSignals(true);
|
|
136
|
+ ui->comboBox_EmergeMap->blockSignals(true);
|
|
137
|
+
|
|
138
|
+ ui->comboBox_ConnectedMap->clear();
|
|
139
|
+ ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
|
140
|
+ ui->comboBox_DiveMap->clear();
|
|
141
|
+ ui->comboBox_DiveMap->addItems(*project->mapNames);
|
|
142
|
+ ui->comboBox_EmergeMap->clear();
|
|
143
|
+ ui->comboBox_EmergeMap->addItems(*project->mapNames);
|
|
144
|
+
|
|
145
|
+ ui->comboBox_ConnectedMap->blockSignals(false);
|
|
146
|
+ ui->comboBox_DiveMap->blockSignals(true);
|
|
147
|
+ ui->comboBox_EmergeMap->blockSignals(true);
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+void Editor::setConnectionItemsVisible(bool visible) {
|
|
151
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
152
|
+ item->setVisible(visible);
|
|
153
|
+ item->setEnabled(visible);
|
|
154
|
+ }
|
|
155
|
+}
|
|
156
|
+
|
|
157
|
+void Editor::setBorderItemsVisible(bool visible, qreal opacity) {
|
|
158
|
+ for (QGraphicsPixmapItem* item : borderItems) {
|
|
159
|
+ item->setVisible(visible);
|
|
160
|
+ item->setOpacity(opacity);
|
|
161
|
+ }
|
|
162
|
+}
|
|
163
|
+
|
|
164
|
+void Editor::setCurrentConnectionDirection(QString curDirection) {
|
|
165
|
+ if (!selected_connection_item)
|
|
166
|
+ return;
|
|
167
|
+
|
|
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;
|
|
174
|
+ int x = 0, y = 0;
|
|
175
|
+ if (selected_connection_item->connection->direction == "up") {
|
|
176
|
+ x = offset * 16;
|
|
177
|
+ y = -pixmap.height();
|
|
178
|
+ } else if (selected_connection_item->connection->direction == "down") {
|
|
179
|
+ x = offset * 16;
|
|
180
|
+ y = map->getHeight() * 16;
|
|
181
|
+ } else if (selected_connection_item->connection->direction == "left") {
|
|
182
|
+ x = -pixmap.width();
|
|
183
|
+ y = offset * 16;
|
|
184
|
+ } else if (selected_connection_item->connection->direction == "right") {
|
|
185
|
+ x = map->getWidth() * 16;
|
|
186
|
+ y = offset * 16;
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ selected_connection_item->basePixmap = pixmap;
|
|
190
|
+ QPainter painter(&pixmap);
|
|
191
|
+ painter.setPen(QColor(255, 0, 255));
|
|
192
|
+ painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
193
|
+ painter.end();
|
|
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);
|
|
202
|
+
|
|
203
|
+ setConnectionEditControlValues(selected_connection_item->connection);
|
|
204
|
+}
|
|
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
|
+
|
|
220
|
+void Editor::onConnectionOffsetChanged(int newOffset) {
|
|
221
|
+ ui->spinBox_ConnectionOffset->blockSignals(true);
|
|
222
|
+ ui->spinBox_ConnectionOffset->setValue(newOffset);
|
|
223
|
+ ui->spinBox_ConnectionOffset->blockSignals(false);
|
|
224
|
+
|
|
225
|
+}
|
|
226
|
+
|
|
227
|
+void Editor::setConnectionEditControlValues(Connection* connection) {
|
|
228
|
+ QString mapName = connection ? connection->map_name : "";
|
|
229
|
+ QString direction = connection ? connection->direction : "";
|
|
230
|
+ int offset = connection ? connection->offset.toInt() : 0;
|
|
231
|
+
|
|
232
|
+ ui->comboBox_ConnectedMap->blockSignals(true);
|
|
233
|
+ ui->comboBox_ConnectionDirection->blockSignals(true);
|
|
234
|
+ ui->spinBox_ConnectionOffset->blockSignals(true);
|
|
235
|
+
|
|
236
|
+ ui->comboBox_ConnectedMap->setCurrentText(mapName);
|
|
237
|
+ ui->comboBox_ConnectionDirection->setCurrentText(direction);
|
|
238
|
+ ui->spinBox_ConnectionOffset->setValue(offset);
|
|
239
|
+
|
|
240
|
+ ui->comboBox_ConnectedMap->blockSignals(false);
|
|
241
|
+ ui->comboBox_ConnectionDirection->blockSignals(false);
|
|
242
|
+ ui->spinBox_ConnectionOffset->blockSignals(false);
|
|
243
|
+}
|
|
244
|
+
|
|
245
|
+void Editor::setConnectionEditControlsEnabled(bool enabled) {
|
|
246
|
+ ui->comboBox_ConnectionDirection->setEnabled(enabled);
|
|
247
|
+ ui->comboBox_ConnectedMap->setEnabled(enabled);
|
|
248
|
+ ui->spinBox_ConnectionOffset->setEnabled(enabled);
|
|
249
|
+
|
|
250
|
+ if (!enabled) {
|
|
251
|
+ setConnectionEditControlValues(false);
|
|
252
|
+ }
|
|
253
|
+}
|
|
254
|
+
|
|
255
|
+void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
|
256
|
+ if (!connectionItem)
|
|
257
|
+ return;
|
|
258
|
+
|
|
259
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
260
|
+ bool isSelectedItem = item == connectionItem;
|
|
261
|
+ int zValue = isSelectedItem ? 0 : -1;
|
|
262
|
+ qreal opacity = isSelectedItem ? 1 : 0.75;
|
|
263
|
+ item->setZValue(zValue);
|
|
264
|
+ item->render(opacity);
|
|
265
|
+ if (isSelectedItem) {
|
|
266
|
+ QPixmap pixmap = item->pixmap();
|
|
267
|
+ QPainter painter(&pixmap);
|
|
268
|
+ painter.setPen(QColor(255, 0, 255));
|
|
269
|
+ painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
270
|
+ painter.end();
|
|
271
|
+ item->setPixmap(pixmap);
|
|
272
|
+ }
|
|
273
|
+ }
|
|
274
|
+ selected_connection_item = connectionItem;
|
|
275
|
+ setConnectionEditControlsEnabled(true);
|
|
276
|
+ setConnectionEditControlValues(selected_connection_item->connection);
|
|
277
|
+ ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());
|
|
278
|
+ ui->spinBox_ConnectionOffset->setMinimum(selected_connection_item->getMinOffset());
|
|
279
|
+ onConnectionOffsetChanged(selected_connection_item->connection->offset.toInt());
|
|
280
|
+}
|
|
281
|
+
|
|
282
|
+void Editor::setSelectedConnectionFromMap(QString mapName) {
|
|
283
|
+ // Search for the first connection that connects to the given map map.
|
|
284
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
285
|
+ if (item->connection->map_name == mapName) {
|
|
286
|
+ onConnectionItemSelected(item);
|
|
287
|
+ break;
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+}
|
|
291
|
+
|
|
292
|
+void Editor::onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem) {
|
|
293
|
+ emit loadMapRequested(connectionItem->connection->map_name, map->name);
|
|
294
|
+}
|
|
295
|
+
|
|
296
|
+void Editor::onConnectionDirectionChanged(QString newDirection) {
|
|
297
|
+ ui->comboBox_ConnectionDirection->blockSignals(true);
|
|
298
|
+ ui->comboBox_ConnectionDirection->setCurrentText(newDirection);
|
|
299
|
+ ui->comboBox_ConnectionDirection->blockSignals(false);
|
|
300
|
+}
|
|
301
|
+
|
|
302
|
+void Editor::setConnectionsVisibility(bool visible) {
|
|
303
|
+ for (QGraphicsPixmapItem* item : map->connection_items) {
|
|
304
|
+ item->setVisible(visible);
|
|
305
|
+ item->setActive(visible);
|
|
306
|
+ }
|
78
|
307
|
}
|
79
|
308
|
|
80
|
309
|
void Editor::setMap(QString map_name) {
|
|
@@ -205,33 +434,65 @@ DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
205
|
434
|
}
|
206
|
435
|
|
207
|
436
|
void Editor::displayMapConnections() {
|
|
437
|
+ for (QGraphicsPixmapItem* item : map->connection_items) {
|
|
438
|
+ delete item;
|
|
439
|
+ }
|
|
440
|
+ map->connection_items.clear();
|
|
441
|
+
|
|
442
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
443
|
+ delete item;
|
|
444
|
+ }
|
|
445
|
+ selected_connection_item = NULL;
|
|
446
|
+ connection_edit_items.clear();
|
|
447
|
+
|
208
|
448
|
for (Connection *connection : map->connections) {
|
209
|
449
|
if (connection->direction == "dive" || connection->direction == "emerge") {
|
210
|
450
|
continue;
|
211
|
451
|
}
|
212
|
|
- Map *connected_map = project->getMap(connection->map_name);
|
213
|
|
- QPixmap pixmap = connected_map->renderConnection(*connection);
|
214
|
|
- int offset = connection->offset.toInt(nullptr, 0);
|
215
|
|
- int x = 0, y = 0;
|
216
|
|
- if (connection->direction == "up") {
|
217
|
|
- x = offset * 16;
|
218
|
|
- y = -pixmap.height();
|
219
|
|
- } else if (connection->direction == "down") {
|
220
|
|
- x = offset * 16;
|
221
|
|
- y = map->getHeight() * 16;
|
222
|
|
- } else if (connection->direction == "left") {
|
223
|
|
- x = -pixmap.width();
|
224
|
|
- y = offset * 16;
|
225
|
|
- } else if (connection->direction == "right") {
|
226
|
|
- x = map->getWidth() * 16;
|
227
|
|
- y = offset * 16;
|
228
|
|
- }
|
229
|
|
- QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
230
|
|
- item->setZValue(-1);
|
231
|
|
- item->setX(x);
|
232
|
|
- item->setY(y);
|
233
|
|
- scene->addItem(item);
|
|
452
|
+ createConnectionItem(connection, false);
|
|
453
|
+ }
|
|
454
|
+
|
|
455
|
+ if (!connection_edit_items.empty()) {
|
|
456
|
+ onConnectionItemSelected(connection_edit_items.first());
|
|
457
|
+ }
|
|
458
|
+}
|
|
459
|
+
|
|
460
|
+void Editor::createConnectionItem(Connection* connection, bool hide) {
|
|
461
|
+ Map *connected_map = project->getMap(connection->map_name);
|
|
462
|
+ QPixmap pixmap = connected_map->renderConnection(*connection);
|
|
463
|
+ int offset = connection->offset.toInt(nullptr, 0);
|
|
464
|
+ int x = 0, y = 0;
|
|
465
|
+ if (connection->direction == "up") {
|
|
466
|
+ x = offset * 16;
|
|
467
|
+ y = -pixmap.height();
|
|
468
|
+ } else if (connection->direction == "down") {
|
|
469
|
+ x = offset * 16;
|
|
470
|
+ y = map->getHeight() * 16;
|
|
471
|
+ } else if (connection->direction == "left") {
|
|
472
|
+ x = -pixmap.width();
|
|
473
|
+ y = offset * 16;
|
|
474
|
+ } else if (connection->direction == "right") {
|
|
475
|
+ x = map->getWidth() * 16;
|
|
476
|
+ y = offset * 16;
|
234
|
477
|
}
|
|
478
|
+
|
|
479
|
+ QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
|
480
|
+ item->setZValue(-1);
|
|
481
|
+ item->setX(x);
|
|
482
|
+ item->setY(y);
|
|
483
|
+ scene->addItem(item);
|
|
484
|
+ map->connection_items.append(item);
|
|
485
|
+ item->setVisible(!hide);
|
|
486
|
+
|
|
487
|
+ ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
|
|
488
|
+ connection_edit_item->setX(x);
|
|
489
|
+ connection_edit_item->setY(y);
|
|
490
|
+ connection_edit_item->setZValue(-1);
|
|
491
|
+ scene->addItem(connection_edit_item);
|
|
492
|
+ connect(connection_edit_item, SIGNAL(connectionMoved(Connection*)), this, SLOT(onConnectionMoved(Connection*)));
|
|
493
|
+ connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
|
494
|
+ connect(connection_edit_item, SIGNAL(connectionItemDoubleClicked(ConnectionPixmapItem*)), this, SLOT(onConnectionItemDoubleClicked(ConnectionPixmapItem*)));
|
|
495
|
+ connection_edit_items.append(connection_edit_item);
|
235
|
496
|
}
|
236
|
497
|
|
237
|
498
|
void Editor::displayMapBorder() {
|
|
@@ -243,6 +504,7 @@ void Editor::displayMapBorder() {
|
243
|
504
|
item->setY(y * 16);
|
244
|
505
|
item->setZValue(-2);
|
245
|
506
|
scene->addItem(item);
|
|
507
|
+ borderItems.append(item);
|
246
|
508
|
}
|
247
|
509
|
}
|
248
|
510
|
|
|
@@ -252,17 +514,213 @@ void Editor::displayMapGrid() {
|
252
|
514
|
for (int i = 0; i <= map->getWidth(); i++) {
|
253
|
515
|
int x = i * 16;
|
254
|
516
|
QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
|
255
|
|
- line->setVisible(gridToggleCheckbox->isChecked());
|
256
|
|
- connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
|
517
|
+ line->setVisible(ui->checkBox_ToggleGrid->isChecked());
|
|
518
|
+ connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
257
|
519
|
}
|
258
|
520
|
for (int j = 0; j <= map->getHeight(); j++) {
|
259
|
521
|
int y = j * 16;
|
260
|
522
|
QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
|
261
|
|
- line->setVisible(gridToggleCheckbox->isChecked());
|
262
|
|
- connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
|
523
|
+ line->setVisible(ui->checkBox_ToggleGrid->isChecked());
|
|
524
|
+ connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
263
|
525
|
}
|
264
|
526
|
}
|
265
|
527
|
|
|
528
|
+void Editor::updateConnectionOffset(int offset) {
|
|
529
|
+ if (!selected_connection_item)
|
|
530
|
+ return;
|
|
531
|
+
|
|
532
|
+ selected_connection_item->blockSignals(true);
|
|
533
|
+ offset = qMin(offset, selected_connection_item->getMaxOffset());
|
|
534
|
+ offset = qMax(offset, selected_connection_item->getMinOffset());
|
|
535
|
+ selected_connection_item->connection->offset = QString::number(offset);
|
|
536
|
+ if (selected_connection_item->connection->direction == "up" || selected_connection_item->connection->direction == "down") {
|
|
537
|
+ selected_connection_item->setX(selected_connection_item->initialX + (offset - selected_connection_item->initialOffset) * 16);
|
|
538
|
+ } else if (selected_connection_item->connection->direction == "left" || selected_connection_item->connection->direction == "right") {
|
|
539
|
+ selected_connection_item->setY(selected_connection_item->initialY + (offset - selected_connection_item->initialOffset) * 16);
|
|
540
|
+ }
|
|
541
|
+ selected_connection_item->blockSignals(false);
|
|
542
|
+ updateMirroredConnectionOffset(selected_connection_item->connection);
|
|
543
|
+}
|
|
544
|
+
|
|
545
|
+void Editor::setConnectionMap(QString mapName) {
|
|
546
|
+ if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
|
|
547
|
+ qDebug() << "Invalid map name " << mapName << " specified for connection.";
|
|
548
|
+ return;
|
|
549
|
+ }
|
|
550
|
+ if (!selected_connection_item)
|
|
551
|
+ return;
|
|
552
|
+
|
|
553
|
+ if (mapName.isEmpty()) {
|
|
554
|
+ removeCurrentConnection();
|
|
555
|
+ return;
|
|
556
|
+ }
|
|
557
|
+
|
|
558
|
+ QString originalMapName = selected_connection_item->connection->map_name;
|
|
559
|
+ setConnectionEditControlsEnabled(true);
|
|
560
|
+ selected_connection_item->connection->map_name = mapName;
|
|
561
|
+ setCurrentConnectionDirection(selected_connection_item->connection->direction);
|
|
562
|
+ updateMirroredConnectionMap(selected_connection_item->connection, originalMapName);
|
|
563
|
+}
|
|
564
|
+
|
|
565
|
+void Editor::addNewConnection() {
|
|
566
|
+ // Find direction with least number of connections.
|
|
567
|
+ QMap<QString, int> directionCounts = QMap<QString, int>({{"up", 0}, {"right", 0}, {"down", 0}, {"left", 0}});
|
|
568
|
+ for (Connection* connection : map->connections) {
|
|
569
|
+ directionCounts[connection->direction]++;
|
|
570
|
+ }
|
|
571
|
+ QString minDirection = "up";
|
|
572
|
+ int minCount = INT_MAX;
|
|
573
|
+ for (QString direction : directionCounts.keys()) {
|
|
574
|
+ if (directionCounts[direction] < minCount) {
|
|
575
|
+ minDirection = direction;
|
|
576
|
+ minCount = directionCounts[direction];
|
|
577
|
+ }
|
|
578
|
+ }
|
|
579
|
+
|
|
580
|
+ // Don't connect the map to itself.
|
|
581
|
+ QString defaultMapName = project->mapNames->first();
|
|
582
|
+ if (defaultMapName == map->name) {
|
|
583
|
+ defaultMapName = project->mapNames->value(1);
|
|
584
|
+ }
|
|
585
|
+
|
|
586
|
+ Connection* newConnection = new Connection;
|
|
587
|
+ newConnection->direction = minDirection;
|
|
588
|
+ newConnection->offset = "0";
|
|
589
|
+ newConnection->map_name = defaultMapName;
|
|
590
|
+ map->connections.append(newConnection);
|
|
591
|
+ createConnectionItem(newConnection, true);
|
|
592
|
+ onConnectionItemSelected(connection_edit_items.last());
|
|
593
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
594
|
+
|
|
595
|
+ updateMirroredConnection(newConnection, newConnection->direction, newConnection->map_name);
|
|
596
|
+}
|
|
597
|
+
|
|
598
|
+void Editor::updateMirroredConnectionOffset(Connection* connection) {
|
|
599
|
+ updateMirroredConnection(connection, connection->direction, connection->map_name);
|
|
600
|
+}
|
|
601
|
+void Editor::updateMirroredConnectionDirection(Connection* connection, QString originalDirection) {
|
|
602
|
+ updateMirroredConnection(connection, originalDirection, connection->map_name);
|
|
603
|
+}
|
|
604
|
+void Editor::updateMirroredConnectionMap(Connection* connection, QString originalMapName) {
|
|
605
|
+ updateMirroredConnection(connection, connection->direction, originalMapName);
|
|
606
|
+}
|
|
607
|
+void Editor::removeMirroredConnection(Connection* connection) {
|
|
608
|
+ updateMirroredConnection(connection, connection->direction, connection->map_name, true);
|
|
609
|
+}
|
|
610
|
+void Editor::updateMirroredConnection(Connection* connection, QString originalDirection, QString originalMapName, bool isDelete) {
|
|
611
|
+ if (!ui->checkBox_MirrorConnections->isChecked())
|
|
612
|
+ return;
|
|
613
|
+
|
|
614
|
+ static QMap<QString, QString> oppositeDirections = QMap<QString, QString>({
|
|
615
|
+ {"up", "down"}, {"right", "left"},
|
|
616
|
+ {"down", "up"}, {"left", "right"},
|
|
617
|
+ {"dive", "emerge"},{"emerge", "dive"}});
|
|
618
|
+ QString oppositeDirection = oppositeDirections.value(originalDirection);
|
|
619
|
+
|
|
620
|
+ // Find the matching connection in the connected map.
|
|
621
|
+ QMap<QString, Map*> *mapcache = project->map_cache;
|
|
622
|
+ Connection* mirrorConnection = NULL;
|
|
623
|
+ Map* otherMap = project->getMap(originalMapName);
|
|
624
|
+ for (Connection* conn : otherMap->connections) {
|
|
625
|
+ if (conn->direction == oppositeDirection && conn->map_name == map->name) {
|
|
626
|
+ mirrorConnection = conn;
|
|
627
|
+ }
|
|
628
|
+ }
|
|
629
|
+
|
|
630
|
+ if (isDelete) {
|
|
631
|
+ if (mirrorConnection) {
|
|
632
|
+ otherMap->connections.removeOne(mirrorConnection);
|
|
633
|
+ delete mirrorConnection;
|
|
634
|
+ }
|
|
635
|
+ return;
|
|
636
|
+ }
|
|
637
|
+
|
|
638
|
+ if (connection->direction != originalDirection || connection->map_name != originalMapName) {
|
|
639
|
+ if (mirrorConnection) {
|
|
640
|
+ otherMap->connections.removeOne(mirrorConnection);
|
|
641
|
+ delete mirrorConnection;
|
|
642
|
+ mirrorConnection = NULL;
|
|
643
|
+ otherMap = project->getMap(connection->map_name);
|
|
644
|
+ }
|
|
645
|
+ }
|
|
646
|
+
|
|
647
|
+ // Create a new mirrored connection, if a matching one doesn't already exist.
|
|
648
|
+ if (!mirrorConnection) {
|
|
649
|
+ mirrorConnection = new Connection;
|
|
650
|
+ mirrorConnection->direction = oppositeDirections.value(connection->direction);
|
|
651
|
+ mirrorConnection->map_name = map->name;
|
|
652
|
+ otherMap->connections.append(mirrorConnection);
|
|
653
|
+ }
|
|
654
|
+
|
|
655
|
+ mirrorConnection->offset = QString::number(-connection->offset.toInt());
|
|
656
|
+}
|
|
657
|
+
|
|
658
|
+void Editor::removeCurrentConnection() {
|
|
659
|
+ if (!selected_connection_item)
|
|
660
|
+ return;
|
|
661
|
+
|
|
662
|
+ map->connections.removeOne(selected_connection_item->connection);
|
|
663
|
+ connection_edit_items.removeOne(selected_connection_item);
|
|
664
|
+ removeMirroredConnection(selected_connection_item->connection);
|
|
665
|
+
|
|
666
|
+ scene->removeItem(selected_connection_item);
|
|
667
|
+ delete selected_connection_item;
|
|
668
|
+ selected_connection_item = NULL;
|
|
669
|
+ setConnectionEditControlsEnabled(false);
|
|
670
|
+ ui->spinBox_ConnectionOffset->setValue(0);
|
|
671
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
672
|
+
|
|
673
|
+ if (connection_edit_items.length() > 0) {
|
|
674
|
+ onConnectionItemSelected(connection_edit_items.last());
|
|
675
|
+ }
|
|
676
|
+}
|
|
677
|
+
|
|
678
|
+void Editor::updateDiveMap(QString mapName) {
|
|
679
|
+ updateDiveEmergeMap(mapName, "dive");
|
|
680
|
+}
|
|
681
|
+
|
|
682
|
+void Editor::updateEmergeMap(QString mapName) {
|
|
683
|
+ updateDiveEmergeMap(mapName, "emerge");
|
|
684
|
+}
|
|
685
|
+
|
|
686
|
+void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
|
|
687
|
+ if (!mapName.isEmpty() && !project->mapNamesToMapConstants->contains(mapName)) {
|
|
688
|
+ qDebug() << "Invalid " << direction << " map connection: " << mapName;
|
|
689
|
+ return;
|
|
690
|
+ }
|
|
691
|
+
|
|
692
|
+ Connection* connection = NULL;
|
|
693
|
+ for (Connection* conn : map->connections) {
|
|
694
|
+ if (conn->direction == direction) {
|
|
695
|
+ connection = conn;
|
|
696
|
+ break;
|
|
697
|
+ }
|
|
698
|
+ }
|
|
699
|
+
|
|
700
|
+ if (mapName.isEmpty()) {
|
|
701
|
+ // Remove dive/emerge connection
|
|
702
|
+ if (connection) {
|
|
703
|
+ map->connections.removeOne(connection);
|
|
704
|
+ removeMirroredConnection(connection);
|
|
705
|
+ }
|
|
706
|
+ } else {
|
|
707
|
+ if (!connection) {
|
|
708
|
+ connection = new Connection;
|
|
709
|
+ connection->direction = direction;
|
|
710
|
+ connection->offset = "0";
|
|
711
|
+ connection->map_name = mapName;
|
|
712
|
+ map->connections.append(connection);
|
|
713
|
+ updateMirroredConnection(connection, connection->direction, connection->map_name);
|
|
714
|
+ } else {
|
|
715
|
+ QString originalMapName = connection->map_name;
|
|
716
|
+ connection->map_name = mapName;
|
|
717
|
+ updateMirroredConnectionMap(connection, originalMapName);
|
|
718
|
+ }
|
|
719
|
+ }
|
|
720
|
+
|
|
721
|
+ ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
|
722
|
+}
|
|
723
|
+
|
266
|
724
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
267
|
725
|
draw();
|
268
|
726
|
}
|
|
@@ -363,6 +821,62 @@ void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
363
|
821
|
}
|
364
|
822
|
}
|
365
|
823
|
|
|
824
|
+int ConnectionPixmapItem::getMinOffset() {
|
|
825
|
+ if (connection->direction == "up" || connection->direction == "down")
|
|
826
|
+ return 1 - (this->pixmap().width() / 16);
|
|
827
|
+ else
|
|
828
|
+ return 1 - (this->pixmap().height() / 16);
|
|
829
|
+}
|
|
830
|
+int ConnectionPixmapItem::getMaxOffset() {
|
|
831
|
+ if (connection->direction == "up" || connection->direction == "down")
|
|
832
|
+ return baseMapWidth - 1;
|
|
833
|
+ else
|
|
834
|
+ return baseMapHeight - 1;
|
|
835
|
+}
|
|
836
|
+QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
837
|
+{
|
|
838
|
+ if (change == ItemPositionChange) {
|
|
839
|
+ QPointF newPos = value.toPointF();
|
|
840
|
+
|
|
841
|
+ qreal x, y;
|
|
842
|
+ int newOffset = initialOffset;
|
|
843
|
+ if (connection->direction == "up" || connection->direction == "down") {
|
|
844
|
+ x = round(newPos.x() / 16) * 16;
|
|
845
|
+ newOffset += (x - initialX) / 16;
|
|
846
|
+ newOffset = qMin(newOffset, this->getMaxOffset());
|
|
847
|
+ newOffset = qMax(newOffset, this->getMinOffset());
|
|
848
|
+ x = newOffset * 16;
|
|
849
|
+ }
|
|
850
|
+ else {
|
|
851
|
+ x = initialX;
|
|
852
|
+ }
|
|
853
|
+
|
|
854
|
+ if (connection->direction == "right" || connection->direction == "left") {
|
|
855
|
+ y = round(newPos.y() / 16) * 16;
|
|
856
|
+ newOffset += (y - initialY) / 16;
|
|
857
|
+ newOffset = qMin(newOffset, this->getMaxOffset());
|
|
858
|
+ newOffset = qMax(newOffset, this->getMinOffset());
|
|
859
|
+ y = newOffset * 16;
|
|
860
|
+ }
|
|
861
|
+ else {
|
|
862
|
+ y = initialY;
|
|
863
|
+ }
|
|
864
|
+
|
|
865
|
+ connection->offset = QString::number(newOffset);
|
|
866
|
+ emit connectionMoved(connection);
|
|
867
|
+ return QPointF(x, y);
|
|
868
|
+ }
|
|
869
|
+ else {
|
|
870
|
+ return QGraphicsItem::itemChange(change, value);
|
|
871
|
+ }
|
|
872
|
+}
|
|
873
|
+void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
|
874
|
+ emit connectionItemSelected(this);
|
|
875
|
+}
|
|
876
|
+void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
|
|
877
|
+ emit connectionItemDoubleClicked(this);
|
|
878
|
+}
|
|
879
|
+
|
366
|
880
|
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
367
|
881
|
int x = ((int)pos.x()) / 16;
|
368
|
882
|
int y = ((int)pos.y()) / 16;
|