|
@@ -40,6 +40,7 @@ void Editor::setEditingMap() {
|
40
|
40
|
map_item->draw();
|
41
|
41
|
map_item->setVisible(true);
|
42
|
42
|
map_item->setEnabled(true);
|
|
43
|
+ setConnectionsVisibility(true);
|
43
|
44
|
}
|
44
|
45
|
if (collision_item) {
|
45
|
46
|
collision_item->setVisible(false);
|
|
@@ -52,8 +53,8 @@ void Editor::setEditingMap() {
|
52
|
53
|
void Editor::setEditingCollision() {
|
53
|
54
|
current_view = collision_item;
|
54
|
55
|
if (collision_item) {
|
55
|
|
- collision_item->draw();
|
56
|
56
|
collision_item->setVisible(true);
|
|
57
|
+ setConnectionsVisibility(true);
|
57
|
58
|
}
|
58
|
59
|
if (map_item) {
|
59
|
60
|
map_item->setVisible(false);
|
|
@@ -71,12 +72,88 @@ void Editor::setEditingObjects() {
|
71
|
72
|
if (map_item) {
|
72
|
73
|
map_item->setVisible(true);
|
73
|
74
|
map_item->setEnabled(false);
|
|
75
|
+ setConnectionsVisibility(true);
|
74
|
76
|
}
|
75
|
77
|
if (collision_item) {
|
76
|
78
|
collision_item->setVisible(false);
|
77
|
79
|
}
|
78
|
80
|
}
|
79
|
81
|
|
|
82
|
+void Editor::setEditingConnections(QString direction) {
|
|
83
|
+ current_view = map_item;
|
|
84
|
+ if (map_item) {
|
|
85
|
+ map_item->draw();
|
|
86
|
+ map_item->setVisible(true);
|
|
87
|
+ map_item->setEnabled(true);
|
|
88
|
+ setConnectionsVisibility(false);
|
|
89
|
+ showCurrentConnectionMap(direction);
|
|
90
|
+ }
|
|
91
|
+ if (collision_item) {
|
|
92
|
+ collision_item->setVisible(false);
|
|
93
|
+ }
|
|
94
|
+ if (objects_group) {
|
|
95
|
+ objects_group->setVisible(false);
|
|
96
|
+ }
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+void Editor::showCurrentConnectionMap(QString curDirection) {
|
|
100
|
+ bool connectionExists = false;
|
|
101
|
+ for (Connection* connection : map->connections) {
|
|
102
|
+ if (connection->direction != curDirection) continue;
|
|
103
|
+ if (connection_item) {
|
|
104
|
+ scene->removeItem(connection_item);
|
|
105
|
+ delete connection_item;
|
|
106
|
+ connection_item = NULL;
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ connectionExists = true;
|
|
110
|
+ Map *connected_map = project->getMap(connection->map_name);
|
|
111
|
+ QPixmap pixmap = connected_map->renderConnection(*connection);
|
|
112
|
+ int offset = connection->offset.toInt(nullptr, 0);
|
|
113
|
+ int x = 0, y = 0;
|
|
114
|
+ if (connection->direction == "up") {
|
|
115
|
+ x = offset * 16;
|
|
116
|
+ y = -pixmap.height();
|
|
117
|
+ } else if (connection->direction == "down") {
|
|
118
|
+ x = offset * 16;
|
|
119
|
+ y = map->getHeight() * 16;
|
|
120
|
+ } else if (connection->direction == "left") {
|
|
121
|
+ x = -pixmap.width();
|
|
122
|
+ y = offset * 16;
|
|
123
|
+ } else if (connection->direction == "right") {
|
|
124
|
+ x = map->getWidth() * 16;
|
|
125
|
+ y = offset * 16;
|
|
126
|
+ }
|
|
127
|
+ connection_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
|
128
|
+ connection_item->setX(x);
|
|
129
|
+ connection_item->setY(y);
|
|
130
|
+ connection_item->setZValue(21);
|
|
131
|
+ scene->addItem(connection_item);
|
|
132
|
+ scene->setSceneRect(0, 0, pixmap.width() + map_item->pixmap().width(), pixmap.height() + map_item->pixmap().height());
|
|
133
|
+
|
|
134
|
+ connect(connection_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
|
135
|
+ onConnectionOffsetChanged(connection->offset.toInt());
|
|
136
|
+ break;
|
|
137
|
+ }
|
|
138
|
+
|
|
139
|
+ if (!connectionExists && connection_item) {
|
|
140
|
+ scene->removeItem(connection_item);
|
|
141
|
+ delete connection_item;
|
|
142
|
+ connection_item = NULL;
|
|
143
|
+ }
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+void Editor::onConnectionOffsetChanged(int newOffset) {
|
|
147
|
+ emit connectionOffsetChanged(newOffset);
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+void Editor::setConnectionsVisibility(bool visible) {
|
|
151
|
+ for (QGraphicsPixmapItem* item : map->connection_items) {
|
|
152
|
+ item->setVisible(visible);
|
|
153
|
+ item->setActive(visible);
|
|
154
|
+ }
|
|
155
|
+}
|
|
156
|
+
|
80
|
157
|
void Editor::setMap(QString map_name) {
|
81
|
158
|
if (map_name.isNull()) {
|
82
|
159
|
return;
|
|
@@ -231,6 +308,7 @@ void Editor::displayMapConnections() {
|
231
|
308
|
item->setX(x);
|
232
|
309
|
item->setY(y);
|
233
|
310
|
scene->addItem(item);
|
|
311
|
+ map->connection_items.insert(connection->direction, item);
|
234
|
312
|
}
|
235
|
313
|
}
|
236
|
314
|
|
|
@@ -263,6 +341,17 @@ void Editor::displayMapGrid() {
|
263
|
341
|
}
|
264
|
342
|
}
|
265
|
343
|
|
|
344
|
+void Editor::updateConnectionOffset(int offset) {
|
|
345
|
+ connection_item->blockSignals(true);
|
|
346
|
+ connection_item->connection->offset = QString::number(offset);
|
|
347
|
+ if (connection_item->connection->direction == "up" || connection_item->connection->direction == "down") {
|
|
348
|
+ connection_item->setX(connection_item->initialX + (offset - connection_item->initialOffset) * 16);
|
|
349
|
+ } else {
|
|
350
|
+ connection_item->setY(connection_item->initialY + (offset - connection_item->initialOffset) * 16);
|
|
351
|
+ }
|
|
352
|
+ connection_item->blockSignals(false);
|
|
353
|
+}
|
|
354
|
+
|
266
|
355
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
267
|
356
|
draw();
|
268
|
357
|
}
|
|
@@ -345,6 +434,57 @@ void CollisionMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
345
|
434
|
}
|
346
|
435
|
}
|
347
|
436
|
|
|
437
|
+QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
438
|
+{
|
|
439
|
+ if (change == ItemPositionChange) {
|
|
440
|
+ QPointF newPos = value.toPointF();
|
|
441
|
+
|
|
442
|
+ qreal x, y;
|
|
443
|
+ int newOffset = initialOffset;
|
|
444
|
+ if (connection->direction == "up" || connection->direction == "down") {
|
|
445
|
+ x = round(newPos.x() / 16) * 16;
|
|
446
|
+ newOffset += (x - initialX) / 16;
|
|
447
|
+ }
|
|
448
|
+ else {
|
|
449
|
+ x = initialX;
|
|
450
|
+ }
|
|
451
|
+
|
|
452
|
+ if (connection->direction == "right" || connection->direction == "left") {
|
|
453
|
+ y = round(newPos.y() / 16) * 16;
|
|
454
|
+ newOffset += (y - initialY) / 16;
|
|
455
|
+ }
|
|
456
|
+ else {
|
|
457
|
+ y = initialY;
|
|
458
|
+ }
|
|
459
|
+
|
|
460
|
+ emit connectionMoved(newOffset);
|
|
461
|
+ connection->offset = QString::number(newOffset);
|
|
462
|
+ return QPointF(x, y);
|
|
463
|
+ }
|
|
464
|
+ else {
|
|
465
|
+ return QGraphicsItem::itemChange(change, value);
|
|
466
|
+ }
|
|
467
|
+}
|
|
468
|
+void ConnectionPixmapItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
|
|
469
|
+ QPointF pos = event->pos();
|
|
470
|
+ qDebug() << "enter: " << pos.x() << ", " << pos.y();
|
|
471
|
+}
|
|
472
|
+void ConnectionPixmapItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event) {
|
|
473
|
+ QPointF pos = event->pos();
|
|
474
|
+ qDebug() << "drag: " << pos.x() << ", " << pos.y();
|
|
475
|
+}
|
|
476
|
+void ConnectionPixmapItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
|
|
477
|
+ QPointF pos = event->pos();
|
|
478
|
+ qDebug() << "leave: " << pos.x() << ", " << pos.y();
|
|
479
|
+}
|
|
480
|
+void ConnectionPixmapItem::dropEvent(QGraphicsSceneDragDropEvent *event) {
|
|
481
|
+ QPointF pos = event->pos();
|
|
482
|
+ qDebug() << "drop: " << pos.x() << ", " << pos.y();
|
|
483
|
+}
|
|
484
|
+void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent* event) {
|
|
485
|
+ QPointF pos = event->pos();
|
|
486
|
+}
|
|
487
|
+
|
348
|
488
|
void ElevationMetatilesPixmapItem::updateCurHoveredMetatile(QPointF pos) {
|
349
|
489
|
int x = ((int)pos.x()) / 16;
|
350
|
490
|
int y = ((int)pos.y()) / 16;
|