|
@@ -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
|
|
|
@@ -85,6 +86,10 @@ void Editor::setEditingConnections(QString direction) {
|
85
|
86
|
map_item->draw();
|
86
|
87
|
map_item->setVisible(true);
|
87
|
88
|
map_item->setEnabled(true);
|
|
89
|
+ ui->comboBox_ConnectedMap->blockSignals(true);
|
|
90
|
+ ui->comboBox_ConnectedMap->clear();
|
|
91
|
+ ui->comboBox_ConnectedMap->addItems(*project->mapNames);
|
|
92
|
+ ui->comboBox_ConnectedMap->blockSignals(false);
|
88
|
93
|
setConnectionsVisibility(false);
|
89
|
94
|
showCurrentConnectionMap(direction);
|
90
|
95
|
}
|
|
@@ -124,6 +129,11 @@ void Editor::showCurrentConnectionMap(QString curDirection) {
|
124
|
129
|
x = map->getWidth() * 16;
|
125
|
130
|
y = offset * 16;
|
126
|
131
|
}
|
|
132
|
+
|
|
133
|
+ QPainter painter(&pixmap);
|
|
134
|
+ painter.setPen(QColor(255, 0, 255));
|
|
135
|
+ painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
|
|
136
|
+ painter.end();
|
127
|
137
|
connection_item = new ConnectionPixmapItem(pixmap, connection, x, y);
|
128
|
138
|
connection_item->setX(x);
|
129
|
139
|
connection_item->setY(y);
|
|
@@ -133,18 +143,30 @@ void Editor::showCurrentConnectionMap(QString curDirection) {
|
133
|
143
|
|
134
|
144
|
connect(connection_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
135
|
145
|
onConnectionOffsetChanged(connection->offset.toInt());
|
|
146
|
+
|
|
147
|
+ ui->comboBox_ConnectedMap->setCurrentText(connection->map_name);
|
136
|
148
|
break;
|
137
|
149
|
}
|
138
|
150
|
|
139
|
|
- if (!connectionExists && connection_item) {
|
140
|
|
- scene->removeItem(connection_item);
|
141
|
|
- delete connection_item;
|
142
|
|
- connection_item = NULL;
|
|
151
|
+ if (!connectionExists) {
|
|
152
|
+ if (connection_item) {
|
|
153
|
+ scene->removeItem(connection_item);
|
|
154
|
+ delete connection_item;
|
|
155
|
+ connection_item = NULL;
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ ui->comboBox_ConnectedMap->setCurrentText("");
|
|
159
|
+ ui->spinBox_ConnectionOffset->setDisabled(true);
|
|
160
|
+ ui->spinBox_ConnectionOffset->setValue(0);
|
|
161
|
+ } else {
|
|
162
|
+ ui->spinBox_ConnectionOffset->setDisabled(false);
|
143
|
163
|
}
|
144
|
164
|
}
|
145
|
165
|
|
146
|
166
|
void Editor::onConnectionOffsetChanged(int newOffset) {
|
147
|
|
- emit connectionOffsetChanged(newOffset);
|
|
167
|
+ ui->spinBox_ConnectionOffset->blockSignals(true);
|
|
168
|
+ ui->spinBox_ConnectionOffset->setValue(newOffset);
|
|
169
|
+ ui->spinBox_ConnectionOffset->blockSignals(false);
|
148
|
170
|
}
|
149
|
171
|
|
150
|
172
|
void Editor::setConnectionsVisibility(bool visible) {
|
|
@@ -330,18 +352,21 @@ void Editor::displayMapGrid() {
|
330
|
352
|
for (int i = 0; i <= map->getWidth(); i++) {
|
331
|
353
|
int x = i * 16;
|
332
|
354
|
QGraphicsLineItem *line = scene->addLine(x, 0, x, pixelHeight);
|
333
|
|
- line->setVisible(gridToggleCheckbox->isChecked());
|
334
|
|
- connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
|
355
|
+ line->setVisible(ui->checkBox_ToggleGrid->isChecked());
|
|
356
|
+ connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
335
|
357
|
}
|
336
|
358
|
for (int j = 0; j <= map->getHeight(); j++) {
|
337
|
359
|
int y = j * 16;
|
338
|
360
|
QGraphicsLineItem *line = scene->addLine(0, y, pixelWidth, y);
|
339
|
|
- line->setVisible(gridToggleCheckbox->isChecked());
|
340
|
|
- connect(gridToggleCheckbox, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
|
361
|
+ line->setVisible(ui->checkBox_ToggleGrid->isChecked());
|
|
362
|
+ connect(ui->checkBox_ToggleGrid, &QCheckBox::toggled, [=](bool checked){line->setVisible(checked);});
|
341
|
363
|
}
|
342
|
364
|
}
|
343
|
365
|
|
344
|
366
|
void Editor::updateConnectionOffset(int offset) {
|
|
367
|
+ if (!connection_item)
|
|
368
|
+ return;
|
|
369
|
+
|
345
|
370
|
connection_item->blockSignals(true);
|
346
|
371
|
connection_item->connection->offset = QString::number(offset);
|
347
|
372
|
if (connection_item->connection->direction == "up" || connection_item->connection->direction == "down") {
|
|
@@ -352,6 +377,38 @@ void Editor::updateConnectionOffset(int offset) {
|
352
|
377
|
connection_item->blockSignals(false);
|
353
|
378
|
}
|
354
|
379
|
|
|
380
|
+void Editor::updateConnectionMap(QString mapName, QString direction) {
|
|
381
|
+ if (!mapName.isEmpty() && !project->mapNames->contains(mapName)) {
|
|
382
|
+ qDebug() << "Invalid map name " << mapName << " specified for connection.";
|
|
383
|
+ return;
|
|
384
|
+ }
|
|
385
|
+
|
|
386
|
+ if (connection_item) {
|
|
387
|
+ // Find the connection we are updating.
|
|
388
|
+ bool foundConnection = false;
|
|
389
|
+ for (Connection* connection : map->connections) {
|
|
390
|
+ if (connection->direction == direction) {
|
|
391
|
+ foundConnection = true;
|
|
392
|
+ if (mapName.isEmpty()) {
|
|
393
|
+ map->connections.removeOne(connection);
|
|
394
|
+ } else {
|
|
395
|
+ connection->map_name = mapName;
|
|
396
|
+ }
|
|
397
|
+ break;
|
|
398
|
+ }
|
|
399
|
+ }
|
|
400
|
+ } else if (!mapName.isEmpty()) {
|
|
401
|
+ // Create a brand new connection.
|
|
402
|
+ Connection* newConnection = new Connection;
|
|
403
|
+ newConnection->direction = direction;
|
|
404
|
+ newConnection->offset = "0";
|
|
405
|
+ newConnection->map_name = mapName;
|
|
406
|
+ map->connections.append(newConnection);
|
|
407
|
+ }
|
|
408
|
+
|
|
409
|
+ showCurrentConnectionMap(direction);
|
|
410
|
+}
|
|
411
|
+
|
355
|
412
|
void MetatilesPixmapItem::paintTileChanged(Map *map) {
|
356
|
413
|
draw();
|
357
|
414
|
}
|