|
@@ -50,10 +50,8 @@ void Editor::setEditingMap() {
|
50
|
50
|
if (objects_group) {
|
51
|
51
|
objects_group->setVisible(false);
|
52
|
52
|
}
|
53
|
|
- if (connection_item) {
|
54
|
|
- connection_item->setVisible(false);
|
55
|
|
- connection_item->setEnabled(false);
|
56
|
|
- }
|
|
53
|
+ setBorderItemsVisible(true);
|
|
54
|
+ setConnectionItemsVisible(false);
|
57
|
55
|
}
|
58
|
56
|
|
59
|
57
|
void Editor::setEditingCollision() {
|
|
@@ -68,10 +66,8 @@ void Editor::setEditingCollision() {
|
68
|
66
|
if (objects_group) {
|
69
|
67
|
objects_group->setVisible(false);
|
70
|
68
|
}
|
71
|
|
- if (connection_item) {
|
72
|
|
- connection_item->setVisible(false);
|
73
|
|
- connection_item->setEnabled(false);
|
74
|
|
- }
|
|
69
|
+ setBorderItemsVisible(true);
|
|
70
|
+ setConnectionItemsVisible(false);
|
75
|
71
|
}
|
76
|
72
|
|
77
|
73
|
void Editor::setEditingObjects() {
|
|
@@ -87,13 +83,11 @@ void Editor::setEditingObjects() {
|
87
|
83
|
if (collision_item) {
|
88
|
84
|
collision_item->setVisible(false);
|
89
|
85
|
}
|
90
|
|
- if (connection_item) {
|
91
|
|
- connection_item->setVisible(false);
|
92
|
|
- connection_item->setEnabled(false);
|
93
|
|
- }
|
|
86
|
+ setBorderItemsVisible(true);
|
|
87
|
+ setConnectionItemsVisible(false);
|
94
|
88
|
}
|
95
|
89
|
|
96
|
|
-void Editor::setEditingConnections(QString direction) {
|
|
90
|
+void Editor::setEditingConnections() {
|
97
|
91
|
current_view = map_item;
|
98
|
92
|
if (map_item) {
|
99
|
93
|
map_item->draw();
|
|
@@ -104,7 +98,10 @@ void Editor::setEditingConnections(QString direction) {
|
104
|
98
|
ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
105
|
99
|
ui->comboBox_ConnectedMap->blockSignals(false);
|
106
|
100
|
setConnectionsVisibility(false);
|
107
|
|
- showCurrentConnectionMap(direction);
|
|
101
|
+ if (current_connection_edit_item) {
|
|
102
|
+ onConnectionOffsetChanged(current_connection_edit_item->connection->offset.toInt());
|
|
103
|
+ updateConnectionMap(current_connection_edit_item->connection->map_name, current_connection_edit_item->connection->direction);
|
|
104
|
+ }
|
108
|
105
|
}
|
109
|
106
|
if (collision_item) {
|
110
|
107
|
collision_item->setVisible(false);
|
|
@@ -112,71 +109,63 @@ void Editor::setEditingConnections(QString direction) {
|
112
|
109
|
if (objects_group) {
|
113
|
110
|
objects_group->setVisible(false);
|
114
|
111
|
}
|
|
112
|
+ setBorderItemsVisible(true, 0.4);
|
|
113
|
+ setConnectionItemsVisible(true);
|
115
|
114
|
}
|
116
|
115
|
|
117
|
|
-void Editor::showCurrentConnectionMap(QString curDirection) {
|
118
|
|
- bool connectionExists = false;
|
119
|
|
- for (Connection* connection : map->connections) {
|
120
|
|
- if (connection->direction != curDirection) continue;
|
121
|
|
- if (connection_item) {
|
122
|
|
- scene->removeItem(connection_item);
|
123
|
|
- delete connection_item;
|
124
|
|
- connection_item = NULL;
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- connectionExists = true;
|
128
|
|
- Map *connected_map = project->getMap(connection->map_name);
|
129
|
|
- QPixmap pixmap = connected_map->renderConnection(*connection);
|
130
|
|
- int offset = connection->offset.toInt(nullptr, 0);
|
131
|
|
- int x = 0, y = 0;
|
132
|
|
- if (connection->direction == "up") {
|
133
|
|
- x = offset * 16;
|
134
|
|
- y = -pixmap.height();
|
135
|
|
- } else if (connection->direction == "down") {
|
136
|
|
- x = offset * 16;
|
137
|
|
- y = map->getHeight() * 16;
|
138
|
|
- } else if (connection->direction == "left") {
|
139
|
|
- x = -pixmap.width();
|
140
|
|
- y = offset * 16;
|
141
|
|
- } else if (connection->direction == "right") {
|
142
|
|
- x = map->getWidth() * 16;
|
143
|
|
- y = offset * 16;
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- QPainter painter(&pixmap);
|
147
|
|
- painter.setPen(QColor(255, 0, 255));
|
148
|
|
- painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
149
|
|
- painter.end();
|
150
|
|
- connection_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
151
|
|
- connection_item->setX(x);
|
152
|
|
- connection_item->setY(y);
|
153
|
|
- connection_item->setZValue(21);
|
154
|
|
- scene->addItem(connection_item);
|
155
|
|
-
|
156
|
|
- connect(connection_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
157
|
|
- onConnectionOffsetChanged(connection->offset.toInt());
|
158
|
|
-
|
159
|
|
- ui->comboBox_ConnectedMap->setCurrentText(connection->map_name);
|
160
|
|
- break;
|
|
116
|
+void Editor::setConnectionItemsVisible(bool visible) {
|
|
117
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
118
|
+ item->setVisible(visible);
|
|
119
|
+ item->setEnabled(visible);
|
161
|
120
|
}
|
|
121
|
+}
|
162
|
122
|
|
163
|
|
- if (!connectionExists) {
|
164
|
|
- if (connection_item) {
|
165
|
|
- delete connection_item;
|
166
|
|
- connection_item = NULL;
|
|
123
|
+void Editor::setBorderItemsVisible(bool visible, qreal opacity) {
|
|
124
|
+ for (QGraphicsPixmapItem* item : borderItems) {
|
|
125
|
+ item->setVisible(visible);
|
|
126
|
+ item->setOpacity(opacity);
|
|
127
|
+ }
|
|
128
|
+}
|
167
|
129
|
|
168
|
|
- if (map->connection_items.contains(curDirection)) {
|
169
|
|
- delete map->connection_items.value(curDirection);
|
170
|
|
- map->connection_items.remove(curDirection);
|
171
|
|
- }
|
172
|
|
- }
|
|
130
|
+void Editor::setCurrentConnectionDirection(QString curDirection) {
|
|
131
|
+ if (!current_connection_edit_item)
|
|
132
|
+ return;
|
173
|
133
|
|
174
|
|
- ui->comboBox_ConnectedMap->setCurrentText("");
|
175
|
|
- ui->spinBox_ConnectionOffset->setDisabled(true);
|
176
|
|
- ui->spinBox_ConnectionOffset->setValue(0);
|
177
|
|
- } else {
|
178
|
|
- ui->spinBox_ConnectionOffset->setDisabled(false);
|
179
|
|
- }
|
|
134
|
+ current_connection_edit_item->connection->direction = curDirection;
|
|
135
|
+ Map *connected_map = project->getMap(current_connection_edit_item->connection->map_name);
|
|
136
|
+ QPixmap pixmap = connected_map->renderConnection(*current_connection_edit_item->connection);
|
|
137
|
+ int offset = current_connection_edit_item->connection->offset.toInt(nullptr, 0);
|
|
138
|
+ current_connection_edit_item->initialOffset = offset;
|
|
139
|
+ int x = 0, y = 0;
|
|
140
|
+ if (current_connection_edit_item->connection->direction == "up") {
|
|
141
|
+ x = offset * 16;
|
|
142
|
+ y = -pixmap.height();
|
|
143
|
+ } else if (current_connection_edit_item->connection->direction == "down") {
|
|
144
|
+ x = offset * 16;
|
|
145
|
+ y = map->getHeight() * 16;
|
|
146
|
+ } else if (current_connection_edit_item->connection->direction == "left") {
|
|
147
|
+ x = -pixmap.width();
|
|
148
|
+ y = offset * 16;
|
|
149
|
+ } else if (current_connection_edit_item->connection->direction == "right") {
|
|
150
|
+ x = map->getWidth() * 16;
|
|
151
|
+ y = offset * 16;
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ current_connection_edit_item->basePixmap = pixmap;
|
|
155
|
+ QPainter painter(&pixmap);
|
|
156
|
+ painter.setPen(QColor(255, 0, 255));
|
|
157
|
+ painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
158
|
+ painter.end();
|
|
159
|
+ current_connection_edit_item->setPixmap(pixmap);
|
|
160
|
+ current_connection_edit_item->initialX = x;
|
|
161
|
+ current_connection_edit_item->initialY = y;
|
|
162
|
+ current_connection_edit_item->blockSignals(true);
|
|
163
|
+ current_connection_edit_item->setX(x);
|
|
164
|
+ current_connection_edit_item->setY(y);
|
|
165
|
+ current_connection_edit_item->setZValue(-1);
|
|
166
|
+ current_connection_edit_item->blockSignals(false);
|
|
167
|
+
|
|
168
|
+ setConnectionEditControlValues(current_connection_edit_item->connection);
|
180
|
169
|
}
|
181
|
170
|
|
182
|
171
|
void Editor::onConnectionOffsetChanged(int newOffset) {
|
|
@@ -185,6 +174,54 @@ void Editor::onConnectionOffsetChanged(int newOffset) {
|
185
|
174
|
ui->spinBox_ConnectionOffset->blockSignals(false);
|
186
|
175
|
}
|
187
|
176
|
|
|
177
|
+void Editor::setConnectionEditControlValues(Connection* connection) {
|
|
178
|
+ ui->comboBox_ConnectedMap->blockSignals(true);
|
|
179
|
+ ui->comboBox_ConnectionDirection->blockSignals(true);
|
|
180
|
+ ui->spinBox_ConnectionOffset->blockSignals(true);
|
|
181
|
+
|
|
182
|
+ ui->comboBox_ConnectedMap->setCurrentText(connection->map_name);
|
|
183
|
+ ui->comboBox_ConnectionDirection->setCurrentText(connection->direction);
|
|
184
|
+ ui->spinBox_ConnectionOffset->setValue(connection->offset.toInt());
|
|
185
|
+
|
|
186
|
+ ui->comboBox_ConnectedMap->blockSignals(false);
|
|
187
|
+ ui->comboBox_ConnectionDirection->blockSignals(false);
|
|
188
|
+ ui->spinBox_ConnectionOffset->blockSignals(false);
|
|
189
|
+}
|
|
190
|
+
|
|
191
|
+void Editor::setConnectionEditControlsEnabled(bool enabled) {
|
|
192
|
+ ui->comboBox_ConnectionDirection->setEnabled(enabled);
|
|
193
|
+ ui->comboBox_ConnectedMap->setEnabled(enabled);
|
|
194
|
+ ui->spinBox_ConnectionOffset->setEnabled(enabled);
|
|
195
|
+}
|
|
196
|
+
|
|
197
|
+void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
|
198
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
199
|
+ bool isSelectedItem = item == connectionItem;
|
|
200
|
+ int zValue = isSelectedItem ? 0 : -1;
|
|
201
|
+ qreal opacity = isSelectedItem ? 1 : 0.75;
|
|
202
|
+ item->setZValue(zValue);
|
|
203
|
+ item->render(opacity);
|
|
204
|
+ if (isSelectedItem) {
|
|
205
|
+ QPixmap pixmap = item->pixmap();
|
|
206
|
+ QPainter painter(&pixmap);
|
|
207
|
+ painter.setPen(QColor(255, 0, 255));
|
|
208
|
+ painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
209
|
+ painter.end();
|
|
210
|
+ item->setPixmap(pixmap);
|
|
211
|
+ }
|
|
212
|
+ }
|
|
213
|
+ current_connection_edit_item = connectionItem;
|
|
214
|
+ current_connection_edit_item->setZValue(0);
|
|
215
|
+ setConnectionEditControlsEnabled(true);
|
|
216
|
+ setConnectionEditControlValues(current_connection_edit_item->connection);
|
|
217
|
+}
|
|
218
|
+
|
|
219
|
+void Editor::onConnectionDirectionChanged(QString newDirection) {
|
|
220
|
+ ui->comboBox_ConnectionDirection->blockSignals(true);
|
|
221
|
+ ui->comboBox_ConnectionDirection->setCurrentText(newDirection);
|
|
222
|
+ ui->comboBox_ConnectionDirection->blockSignals(false);
|
|
223
|
+}
|
|
224
|
+
|
188
|
225
|
void Editor::setConnectionsVisibility(bool visible) {
|
189
|
226
|
for (QGraphicsPixmapItem* item : map->connection_items) {
|
190
|
227
|
item->setVisible(visible);
|
|
@@ -320,10 +357,16 @@ DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
320
|
357
|
}
|
321
|
358
|
|
322
|
359
|
void Editor::displayMapConnections() {
|
323
|
|
- for (QString key : map->connection_items.keys()) {
|
324
|
|
- scene->removeItem(map->connection_items.value(key));
|
325
|
|
- delete map->connection_items.value(key);
|
|
360
|
+ for (QGraphicsPixmapItem* item : map->connection_items) {
|
|
361
|
+ scene->removeItem(item);
|
|
362
|
+ delete item;
|
326
|
363
|
}
|
|
364
|
+ map->connection_items.clear();
|
|
365
|
+
|
|
366
|
+ for (ConnectionPixmapItem* item : connection_edit_items) {
|
|
367
|
+ delete item;
|
|
368
|
+ }
|
|
369
|
+ connection_edit_items.clear();
|
327
|
370
|
|
328
|
371
|
for (Connection *connection : map->connections) {
|
329
|
372
|
if (connection->direction == "dive" || connection->direction == "emerge") {
|
|
@@ -346,12 +389,26 @@ void Editor::displayMapConnections() {
|
346
|
389
|
x = map->getWidth() * 16;
|
347
|
390
|
y = offset * 16;
|
348
|
391
|
}
|
|
392
|
+
|
349
|
393
|
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
|
350
|
394
|
item->setZValue(-1);
|
351
|
395
|
item->setX(x);
|
352
|
396
|
item->setY(y);
|
353
|
397
|
scene->addItem(item);
|
354
|
|
- map->connection_items.insert(connection->direction, 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);
|
|
408
|
+ }
|
|
409
|
+
|
|
410
|
+ if (!connection_edit_items.empty()) {
|
|
411
|
+ onConnectionItemSelected(connection_edit_items.first());
|
355
|
412
|
}
|
356
|
413
|
}
|
357
|
414
|
|
|
@@ -364,6 +421,7 @@ void Editor::displayMapBorder() {
|
364
|
421
|
item->setY(y * 16);
|
365
|
422
|
item->setZValue(-2);
|
366
|
423
|
scene->addItem(item);
|
|
424
|
+ borderItems.append(item);
|
367
|
425
|
}
|
368
|
426
|
}
|
369
|
427
|
|
|
@@ -385,17 +443,17 @@ void Editor::displayMapGrid() {
|
385
|
443
|
}
|
386
|
444
|
|
387
|
445
|
void Editor::updateConnectionOffset(int offset) {
|
388
|
|
- if (!connection_item)
|
|
446
|
+ if (!current_connection_edit_item)
|
389
|
447
|
return;
|
390
|
448
|
|
391
|
|
- connection_item->blockSignals(true);
|
392
|
|
- connection_item->connection->offset = QString::number(offset);
|
393
|
|
- if (connection_item->connection->direction == "up" || connection_item->connection->direction == "down") {
|
394
|
|
- connection_item->setX(connection_item->initialX + (offset - connection_item->initialOffset) * 16);
|
|
449
|
+ current_connection_edit_item->blockSignals(true);
|
|
450
|
+ current_connection_edit_item->connection->offset = QString::number(offset);
|
|
451
|
+ if (current_connection_edit_item->connection->direction == "up" || current_connection_edit_item->connection->direction == "down") {
|
|
452
|
+ current_connection_edit_item->setX(current_connection_edit_item->initialX + (offset - current_connection_edit_item->initialOffset) * 16);
|
395
|
453
|
} else {
|
396
|
|
- connection_item->setY(connection_item->initialY + (offset - connection_item->initialOffset) * 16);
|
|
454
|
+ current_connection_edit_item->setY(current_connection_edit_item->initialY + (offset - current_connection_edit_item->initialOffset) * 16);
|
397
|
455
|
}
|
398
|
|
- connection_item->blockSignals(false);
|
|
456
|
+ current_connection_edit_item->blockSignals(false);
|
399
|
457
|
}
|
400
|
458
|
|
401
|
459
|
void Editor::updateConnectionMap(QString mapName, QString direction) {
|
|
@@ -403,31 +461,24 @@ void Editor::updateConnectionMap(QString mapName, QString direction) {
|
403
|
461
|
qDebug() << "Invalid map name " << mapName << " specified for connection.";
|
404
|
462
|
return;
|
405
|
463
|
}
|
|
464
|
+ if (!current_connection_edit_item)
|
|
465
|
+ return;
|
406
|
466
|
|
407
|
|
- if (connection_item) {
|
408
|
|
- // Find the connection we are updating.
|
409
|
|
- bool foundConnection = false;
|
410
|
|
- for (Connection* connection : map->connections) {
|
411
|
|
- if (connection->direction == direction) {
|
412
|
|
- foundConnection = true;
|
413
|
|
- if (mapName.isEmpty()) {
|
414
|
|
- map->connections.removeOne(connection);
|
415
|
|
- } else {
|
416
|
|
- connection->map_name = mapName;
|
417
|
|
- }
|
418
|
|
- break;
|
419
|
|
- }
|
420
|
|
- }
|
421
|
|
- } else if (!mapName.isEmpty()) {
|
422
|
|
- // Create a brand new connection.
|
423
|
|
- Connection* newConnection = new Connection;
|
424
|
|
- newConnection->direction = direction;
|
425
|
|
- newConnection->offset = "0";
|
426
|
|
- newConnection->map_name = mapName;
|
427
|
|
- map->connections.append(newConnection);
|
|
467
|
+ 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);
|
|
475
|
+ return;
|
|
476
|
+ } else {
|
|
477
|
+ setConnectionEditControlsEnabled(true);
|
428
|
478
|
}
|
429
|
479
|
|
430
|
|
- showCurrentConnectionMap(direction);
|
|
480
|
+ current_connection_edit_item->connection->map_name = mapName;
|
|
481
|
+ setCurrentConnectionDirection(direction);
|
431
|
482
|
}
|
432
|
483
|
|
433
|
484
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
|
@@ -543,24 +594,8 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
|
543
|
594
|
return QGraphicsItem::itemChange(change, value);
|
544
|
595
|
}
|
545
|
596
|
}
|
546
|
|
-void ConnectionPixmapItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
|
547
|
|
- QPointF pos = event->pos();
|
548
|
|
- qDebug() << "enter: " << pos.x() << ", " << pos.y();
|
549
|
|
-}
|
550
|
|
-void ConnectionPixmapItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) {
|
551
|
|
- QPointF pos = event->pos();
|
552
|
|
- qDebug() << "drag: " << pos.x() << ", " << pos.y();
|
553
|
|
-}
|
554
|
|
-void ConnectionPixmapItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
|
555
|
|
- QPointF pos = event->pos();
|
556
|
|
- qDebug() << "leave: " << pos.x() << ", " << pos.y();
|
557
|
|
-}
|
558
|
|
-void ConnectionPixmapItem::dropEvent(QGraphicsSceneDragDropEvent *event) {
|
559
|
|
- QPointF pos = event->pos();
|
560
|
|
- qDebug() << "drop: " << pos.x() << ", " << pos.y();
|
561
|
|
-}
|
562
|
597
|
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
563
|
|
- QPointF pos = event->pos();
|
|
598
|
+ emit connectionItemSelected(this);
|
564
|
599
|
}
|
565
|
600
|
|
566
|
601
|
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
|
@@ -694,10 +729,6 @@ void MapPixmapItem::paintSmartPath(int x, int y) {
|
694
|
729
|
if (left && IS_SMART_PATH_TILE(left))
|
695
|
730
|
id += 8;
|
696
|
731
|
|
697
|
|
- if (block) {
|
698
|
|
- qDebug() << "tile: " << block->tile << "base: " << map->paint_tile << "id: " << id;
|
699
|
|
- }
|
700
|
|
-
|
701
|
732
|
block->tile = map->paint_tile + smartPathTable[id];;
|
702
|
733
|
map->_setBlock(actualX, actualY, *block);
|
703
|
734
|
}
|