Support 'mirror' connection editing. Can be toggled off via checkbox
This commit is contained in:
parent
ad7b9ca7b3
commit
1a10eac29f
5 changed files with 133 additions and 9 deletions
93
editor.cpp
93
editor.cpp
|
@ -203,10 +203,25 @@ void Editor::setCurrentConnectionDirection(QString curDirection) {
|
||||||
setConnectionEditControlValues(selected_connection_item->connection);
|
setConnectionEditControlValues(selected_connection_item->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::updateCurrentConnectionDirection(QString curDirection) {
|
||||||
|
if (!selected_connection_item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString originalDirection = selected_connection_item->connection->direction;
|
||||||
|
setCurrentConnectionDirection(curDirection);
|
||||||
|
updateMirroredConnectionDirection(selected_connection_item->connection, originalDirection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::onConnectionMoved(Connection* connection) {
|
||||||
|
updateMirroredConnectionOffset(connection);
|
||||||
|
onConnectionOffsetChanged(connection->offset.toInt());
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::onConnectionOffsetChanged(int newOffset) {
|
void Editor::onConnectionOffsetChanged(int newOffset) {
|
||||||
ui->spinBox_ConnectionOffset->blockSignals(true);
|
ui->spinBox_ConnectionOffset->blockSignals(true);
|
||||||
ui->spinBox_ConnectionOffset->setValue(newOffset);
|
ui->spinBox_ConnectionOffset->setValue(newOffset);
|
||||||
ui->spinBox_ConnectionOffset->blockSignals(false);
|
ui->spinBox_ConnectionOffset->blockSignals(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setConnectionEditControlValues(Connection* connection) {
|
void Editor::setConnectionEditControlValues(Connection* connection) {
|
||||||
|
@ -419,7 +434,6 @@ DraggablePixmapItem *Editor::addMapObject(Event *event) {
|
||||||
|
|
||||||
void Editor::displayMapConnections() {
|
void Editor::displayMapConnections() {
|
||||||
for (QGraphicsPixmapItem* item : map->connection_items) {
|
for (QGraphicsPixmapItem* item : map->connection_items) {
|
||||||
scene->removeItem(item);
|
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
map->connection_items.clear();
|
map->connection_items.clear();
|
||||||
|
@ -474,7 +488,7 @@ void Editor::createConnectionItem(Connection* connection, bool hide) {
|
||||||
connection_edit_item->setY(y);
|
connection_edit_item->setY(y);
|
||||||
connection_edit_item->setZValue(-1);
|
connection_edit_item->setZValue(-1);
|
||||||
scene->addItem(connection_edit_item);
|
scene->addItem(connection_edit_item);
|
||||||
connect(connection_edit_item, SIGNAL(connectionMoved(int)), this, SLOT(onConnectionOffsetChanged(int)));
|
connect(connection_edit_item, SIGNAL(connectionMoved(Connection*)), this, SLOT(onConnectionMoved(Connection*)));
|
||||||
connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
connect(connection_edit_item, SIGNAL(connectionItemSelected(ConnectionPixmapItem*)), this, SLOT(onConnectionItemSelected(ConnectionPixmapItem*)));
|
||||||
connect(connection_edit_item, SIGNAL(connectionItemDoubleClicked(ConnectionPixmapItem*)), this, SLOT(onConnectionItemDoubleClicked(ConnectionPixmapItem*)));
|
connect(connection_edit_item, SIGNAL(connectionItemDoubleClicked(ConnectionPixmapItem*)), this, SLOT(onConnectionItemDoubleClicked(ConnectionPixmapItem*)));
|
||||||
connection_edit_items.append(connection_edit_item);
|
connection_edit_items.append(connection_edit_item);
|
||||||
|
@ -524,6 +538,7 @@ void Editor::updateConnectionOffset(int offset) {
|
||||||
selected_connection_item->setY(selected_connection_item->initialY + (offset - selected_connection_item->initialOffset) * 16);
|
selected_connection_item->setY(selected_connection_item->initialY + (offset - selected_connection_item->initialOffset) * 16);
|
||||||
}
|
}
|
||||||
selected_connection_item->blockSignals(false);
|
selected_connection_item->blockSignals(false);
|
||||||
|
updateMirroredConnectionOffset(selected_connection_item->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setConnectionMap(QString mapName) {
|
void Editor::setConnectionMap(QString mapName) {
|
||||||
|
@ -539,9 +554,11 @@ void Editor::setConnectionMap(QString mapName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString originalMapName = selected_connection_item->connection->map_name;
|
||||||
setConnectionEditControlsEnabled(true);
|
setConnectionEditControlsEnabled(true);
|
||||||
selected_connection_item->connection->map_name = mapName;
|
selected_connection_item->connection->map_name = mapName;
|
||||||
setCurrentConnectionDirection(selected_connection_item->connection->direction);
|
setCurrentConnectionDirection(selected_connection_item->connection->direction);
|
||||||
|
updateMirroredConnectionMap(selected_connection_item->connection, originalMapName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::addNewConnection() {
|
void Editor::addNewConnection() {
|
||||||
|
@ -559,14 +576,80 @@ void Editor::addNewConnection() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't connect the map to itself.
|
||||||
|
QString defaultMapName = project->mapNames->first();
|
||||||
|
if (defaultMapName == map->name) {
|
||||||
|
defaultMapName = project->mapNames->value(1);
|
||||||
|
}
|
||||||
|
|
||||||
Connection* newConnection = new Connection;
|
Connection* newConnection = new Connection;
|
||||||
newConnection->direction = minDirection;
|
newConnection->direction = minDirection;
|
||||||
newConnection->offset = "0";
|
newConnection->offset = "0";
|
||||||
newConnection->map_name = project->mapNames->first();
|
newConnection->map_name = defaultMapName;
|
||||||
map->connections.append(newConnection);
|
map->connections.append(newConnection);
|
||||||
createConnectionItem(newConnection, true);
|
createConnectionItem(newConnection, true);
|
||||||
onConnectionItemSelected(connection_edit_items.last());
|
onConnectionItemSelected(connection_edit_items.last());
|
||||||
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
ui->label_NumConnections->setText(QString::number(map->connections.length()));
|
||||||
|
|
||||||
|
updateMirroredConnection(newConnection, newConnection->direction, newConnection->map_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::updateMirroredConnectionOffset(Connection* connection) {
|
||||||
|
updateMirroredConnection(connection, connection->direction, connection->map_name);
|
||||||
|
}
|
||||||
|
void Editor::updateMirroredConnectionDirection(Connection* connection, QString originalDirection) {
|
||||||
|
updateMirroredConnection(connection, originalDirection, connection->map_name);
|
||||||
|
}
|
||||||
|
void Editor::updateMirroredConnectionMap(Connection* connection, QString originalMapName) {
|
||||||
|
updateMirroredConnection(connection, connection->direction, originalMapName);
|
||||||
|
}
|
||||||
|
void Editor::removeMirroredConnection(Connection* connection) {
|
||||||
|
updateMirroredConnection(connection, connection->direction, connection->map_name, true);
|
||||||
|
}
|
||||||
|
void Editor::updateMirroredConnection(Connection* connection, QString originalDirection, QString originalMapName, bool isDelete) {
|
||||||
|
if (!ui->checkBox_MirrorConnections->isChecked())
|
||||||
|
return;
|
||||||
|
|
||||||
|
static QMap<QString, QString> oppositeDirections = QMap<QString, QString>({
|
||||||
|
{"up", "down"}, {"right", "left"}, {"down", "up"}, {"left", "right"}});
|
||||||
|
QString oppositeDirection = oppositeDirections.value(originalDirection);
|
||||||
|
|
||||||
|
// Find the matching connection in the connected map.
|
||||||
|
QMap<QString, Map*> *mapcache = project->map_cache;
|
||||||
|
Connection* mirrorConnection = NULL;
|
||||||
|
Map* otherMap = project->getMap(originalMapName);
|
||||||
|
for (Connection* conn : otherMap->connections) {
|
||||||
|
if (conn->direction == oppositeDirection && conn->map_name == map->name) {
|
||||||
|
mirrorConnection = conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDelete) {
|
||||||
|
if (mirrorConnection) {
|
||||||
|
otherMap->connections.removeOne(mirrorConnection);
|
||||||
|
delete mirrorConnection;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connection->direction != originalDirection || connection->map_name != originalMapName) {
|
||||||
|
if (mirrorConnection) {
|
||||||
|
otherMap->connections.removeOne(mirrorConnection);
|
||||||
|
delete mirrorConnection;
|
||||||
|
mirrorConnection = NULL;
|
||||||
|
otherMap = project->getMap(connection->map_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new mirrored connection, if a matching one doesn't already exist.
|
||||||
|
if (!mirrorConnection) {
|
||||||
|
mirrorConnection = new Connection;
|
||||||
|
mirrorConnection->direction = oppositeDirections.value(connection->direction);
|
||||||
|
mirrorConnection->map_name = map->name;
|
||||||
|
otherMap->connections.append(mirrorConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
mirrorConnection->offset = QString::number(-connection->offset.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::removeCurrentConnection() {
|
void Editor::removeCurrentConnection() {
|
||||||
|
@ -575,6 +658,8 @@ void Editor::removeCurrentConnection() {
|
||||||
|
|
||||||
map->connections.removeOne(selected_connection_item->connection);
|
map->connections.removeOne(selected_connection_item->connection);
|
||||||
connection_edit_items.removeOne(selected_connection_item);
|
connection_edit_items.removeOne(selected_connection_item);
|
||||||
|
removeMirroredConnection(selected_connection_item->connection);
|
||||||
|
|
||||||
scene->removeItem(selected_connection_item);
|
scene->removeItem(selected_connection_item);
|
||||||
delete selected_connection_item;
|
delete selected_connection_item;
|
||||||
selected_connection_item = NULL;
|
selected_connection_item = NULL;
|
||||||
|
@ -751,8 +836,8 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
|
||||||
y = initialY;
|
y = initialY;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit connectionMoved(newOffset);
|
|
||||||
connection->offset = QString::number(newOffset);
|
connection->offset = QString::number(newOffset);
|
||||||
|
emit connectionMoved(connection);
|
||||||
return QPointF(x, y);
|
return QPointF(x, y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
11
editor.h
11
editor.h
|
@ -48,6 +48,7 @@ public:
|
||||||
void setEditingObjects();
|
void setEditingObjects();
|
||||||
void setEditingConnections();
|
void setEditingConnections();
|
||||||
void setCurrentConnectionDirection(QString curDirection);
|
void setCurrentConnectionDirection(QString curDirection);
|
||||||
|
void updateCurrentConnectionDirection(QString curDirection);
|
||||||
void setConnectionsVisibility(bool visible);
|
void setConnectionsVisibility(bool visible);
|
||||||
void updateConnectionOffset(int offset);
|
void updateConnectionOffset(int offset);
|
||||||
void setConnectionMap(QString mapName);
|
void setConnectionMap(QString mapName);
|
||||||
|
@ -101,11 +102,17 @@ private:
|
||||||
void populateConnectionMapPickers();
|
void populateConnectionMapPickers();
|
||||||
void setDiveEmergeControls();
|
void setDiveEmergeControls();
|
||||||
void updateDiveEmergeMap(QString mapName, QString direction);
|
void updateDiveEmergeMap(QString mapName, QString direction);
|
||||||
|
void onConnectionOffsetChanged(int newOffset);
|
||||||
|
void removeMirroredConnection(Connection*);
|
||||||
|
void updateMirroredConnectionOffset(Connection*);
|
||||||
|
void updateMirroredConnectionDirection(Connection*, QString);
|
||||||
|
void updateMirroredConnectionMap(Connection*, QString);
|
||||||
|
void updateMirroredConnection(Connection*, QString, QString, bool isDelete = false);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
void mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item);
|
||||||
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
void mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixmapItem *item);
|
||||||
void onConnectionOffsetChanged(int newOffset);
|
void onConnectionMoved(Connection*);
|
||||||
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
|
void onConnectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||||
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
void onConnectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
||||||
void onConnectionDirectionChanged(QString newDirection);
|
void onConnectionDirectionChanged(QString newDirection);
|
||||||
|
@ -310,7 +317,7 @@ protected:
|
||||||
signals:
|
signals:
|
||||||
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
void connectionItemSelected(ConnectionPixmapItem* connectionItem);
|
||||||
void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
void connectionItemDoubleClicked(ConnectionPixmapItem* connectionItem);
|
||||||
void connectionMoved(int offset);
|
void connectionMoved(Connection*);
|
||||||
};
|
};
|
||||||
|
|
||||||
class MetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
|
class MetatilesPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
|
|
|
@ -775,7 +775,7 @@ void MainWindow::on_action_Export_Map_Image_triggered()
|
||||||
|
|
||||||
void MainWindow::on_comboBox_ConnectionDirection_currentIndexChanged(const QString &direction)
|
void MainWindow::on_comboBox_ConnectionDirection_currentIndexChanged(const QString &direction)
|
||||||
{
|
{
|
||||||
editor->setCurrentConnectionDirection(direction);
|
editor->updateCurrentConnectionDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_spinBox_ConnectionOffset_valueChanged(int offset)
|
void MainWindow::on_spinBox_ConnectionOffset_valueChanged(int offset)
|
||||||
|
|
|
@ -1326,6 +1326,38 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_11">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Maximum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBox_MirrorConnections">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Mirror</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_9">
|
<spacer name="horizontalSpacer_9">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -39,7 +39,8 @@ Map* Project::loadMap(QString map_name) {
|
||||||
Map *map;
|
Map *map;
|
||||||
if (map_cache->contains(map_name)) {
|
if (map_cache->contains(map_name)) {
|
||||||
map = map_cache->value(map_name);
|
map = map_cache->value(map_name);
|
||||||
if (map->hasUnsavedChanges()) {
|
// TODO: uncomment when undo/redo history is fully implemented for all actions.
|
||||||
|
if (true/*map->hasUnsavedChanges()*/) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1260,7 +1261,6 @@ void Project::loadObjectPixmaps(QList<Event*> objects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_type == "object") {
|
if (event_type == "object") {
|
||||||
|
|
||||||
int sprite_id = constants.value(object->get("sprite"));
|
int sprite_id = constants.value(object->get("sprite"));
|
||||||
|
|
||||||
QString info_label = pointers.value(sprite_id).replace("&", "");
|
QString info_label = pointers.value(sprite_id).replace("&", "");
|
||||||
|
|
Loading…
Reference in a new issue