More map connection bug fixes
This commit is contained in:
parent
96b5fb1617
commit
9ca5f6bc15
4 changed files with 34 additions and 43 deletions
|
@ -175,9 +175,9 @@ private:
|
||||||
void createConnectionItem(MapConnection* connection);
|
void createConnectionItem(MapConnection* connection);
|
||||||
void addConnectionToList(ConnectionPixmapItem* connection);
|
void addConnectionToList(ConnectionPixmapItem* connection);
|
||||||
void updateDiveEmergeMap(QString mapName, QString direction);
|
void updateDiveEmergeMap(QString mapName, QString direction);
|
||||||
MapConnectionMirror getMirroredConnection(const MapConnection&);
|
MapConnectionMirror getMirroredConnection(MapConnection*);
|
||||||
void addMirroredConnection(const MapConnection&);
|
void addMirroredConnection(MapConnection*);
|
||||||
void removeMirroredConnection(const MapConnection&);
|
void removeMirroredConnection(MapConnection*);
|
||||||
void updateEncounterFields(EncounterFields newFields);
|
void updateEncounterFields(EncounterFields newFields);
|
||||||
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
|
QString getMovementPermissionText(uint16_t collision, uint16_t elevation);
|
||||||
QString getMetatileDisplayMessage(uint16_t metatileId);
|
QString getMetatileDisplayMessage(uint16_t metatileId);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
|
class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y, int baseMapWidth, int baseMapHeight)
|
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y)
|
||||||
: QGraphicsPixmapItem(pixmap),
|
: QGraphicsPixmapItem(pixmap),
|
||||||
connection(connection)
|
connection(connection)
|
||||||
{
|
{
|
||||||
|
@ -18,16 +18,14 @@ public:
|
||||||
this->initialX = x;
|
this->initialX = x;
|
||||||
this->initialY = y;
|
this->initialY = y;
|
||||||
this->initialOffset = connection->offset;
|
this->initialOffset = connection->offset;
|
||||||
this->baseMapWidth = baseMapWidth;
|
this->setX(x);
|
||||||
this->baseMapHeight = baseMapHeight;
|
this->setY(y);
|
||||||
}
|
}
|
||||||
QPixmap basePixmap;
|
QPixmap basePixmap;
|
||||||
MapConnection* const connection;
|
MapConnection* const connection;
|
||||||
int initialX;
|
int initialX;
|
||||||
int initialY;
|
int initialY;
|
||||||
int initialOffset;
|
int initialOffset;
|
||||||
int baseMapWidth;
|
|
||||||
int baseMapHeight;
|
|
||||||
|
|
||||||
void setEditable(bool editable);
|
void setEditable(bool editable);
|
||||||
bool getEditable();
|
bool getEditable();
|
||||||
|
|
|
@ -12,8 +12,6 @@ MapConnection MapConnection::mirror(const MapConnection &source, const QString &
|
||||||
{"dive", "emerge"}, {"emerge", "dive"}
|
{"dive", "emerge"}, {"emerge", "dive"}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Allowing editing unknown directions is a can of worms.
|
|
||||||
// Specifically a self-connection with an empty direction and an offset of 0 can be identified as its own mirror
|
|
||||||
MapConnection mirror;
|
MapConnection mirror;
|
||||||
mirror.direction = oppositeDirections.value(source.direction/*, source.direction*/);
|
mirror.direction = oppositeDirections.value(source.direction/*, source.direction*/);
|
||||||
mirror.map_name = mapName;
|
mirror.map_name = mapName;
|
||||||
|
|
|
@ -791,7 +791,7 @@ void Editor::addNewConnection() {
|
||||||
newConnection->map_name = defaultMapName;
|
newConnection->map_name = defaultMapName;
|
||||||
addConnection(map, newConnection);
|
addConnection(map, newConnection);
|
||||||
setSelectedConnection(connection_items.last());
|
setSelectedConnection(connection_items.last());
|
||||||
addMirroredConnection(*newConnection);
|
addMirroredConnection(newConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::addConnection(Map* map, MapConnection * connection) {
|
void Editor::addConnection(Map* map, MapConnection * connection) {
|
||||||
|
@ -821,16 +821,14 @@ void Editor::removeConnectionItem(ConnectionPixmapItem* connectionItem, bool rem
|
||||||
if (!connectionItem)
|
if (!connectionItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (connectionItem->connection) {
|
if (removeMirror) {
|
||||||
if (removeMirror) {
|
// If a map is connected to itself and we delete the connection then this function
|
||||||
// If a map is connected to itself and we delete the connection then this function
|
// will be called twice, once for the target of the delete and once for its mirror.
|
||||||
// will be called twice, once for the target of the delete and once for its mirror.
|
// We only want to try deleting the mirror once, on the first call (because the mirror
|
||||||
// We only want to try deleting the mirror once, on the first call (because the mirror
|
// of the mirror is the original target again, and we already deleted it).
|
||||||
// of the mirror is the original target again, and we already deleted it).
|
removeMirroredConnection(connectionItem->connection);
|
||||||
removeMirroredConnection(*connectionItem->connection);
|
|
||||||
}
|
|
||||||
removeConnection(map, connectionItem->connection);
|
|
||||||
}
|
}
|
||||||
|
removeConnection(map, connectionItem->connection);
|
||||||
|
|
||||||
connection_items.removeOne(connectionItem);
|
connection_items.removeOne(connectionItem);
|
||||||
if (connectionItem->scene())
|
if (connectionItem->scene())
|
||||||
|
@ -856,22 +854,22 @@ void Editor::removeSelectedConnection() {
|
||||||
removeConnectionItem(selected_connection_item);
|
removeConnectionItem(selected_connection_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapConnectionMirror Editor::getMirroredConnection(const MapConnection &source) {
|
MapConnectionMirror Editor::getMirroredConnection(MapConnection* source) {
|
||||||
MapConnectionMirror mirror;
|
MapConnectionMirror mirror;
|
||||||
if (!map || !ui->checkBox_MirrorConnections->isChecked())
|
if (!map || !source || !ui->checkBox_MirrorConnections->isChecked())
|
||||||
return mirror;
|
return mirror;
|
||||||
|
|
||||||
// Note: It's possible (and ok) for mirror.map == this->map
|
// Note: It's possible (and ok) for mirror.map == this->map
|
||||||
mirror.map = project->getMap(source.map_name);
|
mirror.map = project->getMap(source->map_name);
|
||||||
if (!mirror.map)
|
if (!mirror.map)
|
||||||
return mirror;
|
return mirror;
|
||||||
|
|
||||||
// Find the matching connection in the connected map.
|
// Find the matching connection in the connected map.
|
||||||
// Note: There is no strict source -> mirror pairing, i.e. we are not guaranteed
|
// Note: There is no strict source -> mirror pairing, i.e. we are not guaranteed
|
||||||
// to always get the same MapConnection if there are multiple identical copies.
|
// to always get the same MapConnection if there are multiple identical copies.
|
||||||
MapConnection target = MapConnection::mirror(source, map->name);
|
MapConnection target = MapConnection::mirror(*source, map->name);
|
||||||
for (auto connection : mirror.map->connections) {
|
for (auto connection : mirror.map->connections) {
|
||||||
if (*connection == target) {
|
if (*connection == target && connection != source) {
|
||||||
mirror.connection = connection;
|
mirror.connection = connection;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -879,27 +877,27 @@ MapConnectionMirror Editor::getMirroredConnection(const MapConnection &source) {
|
||||||
return mirror;
|
return mirror;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::addMirroredConnection(const MapConnection &source) {
|
void Editor::addMirroredConnection(MapConnection* source) {
|
||||||
MapConnectionMirror mirror = getMirroredConnection(source);
|
MapConnectionMirror mirror = getMirroredConnection(source);
|
||||||
if (!mirror.map)
|
if (!mirror.map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mirror.connection = new MapConnection;
|
mirror.connection = new MapConnection;
|
||||||
*mirror.connection = MapConnection::mirror(source, map->name);
|
*mirror.connection = MapConnection::mirror(*source, map->name);
|
||||||
addConnection(mirror.map, mirror.connection);
|
addConnection(mirror.map, mirror.connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::removeMirroredConnection(const MapConnection &source) {
|
void Editor::removeMirroredConnection(MapConnection* source) {
|
||||||
MapConnectionMirror mirror = getMirroredConnection(source);
|
MapConnectionMirror mirror = getMirroredConnection(source);
|
||||||
if (!mirror.map || !mirror.connection)
|
if (!mirror.map || !mirror.connection)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (map == mirror.map) {
|
if (map == mirror.map) {
|
||||||
// The connection to delete is displayed on the currently-opened map, we need to delete it visually as well.
|
// The connection to delete is displayed on the currently-opened map, we need to delete it visually as well.
|
||||||
if (source.direction == "dive") {
|
if (source->direction == "dive") {
|
||||||
const QSignalBlocker blocker(ui->comboBox_DiveMap);
|
const QSignalBlocker blocker(ui->comboBox_DiveMap);
|
||||||
ui->comboBox_DiveMap->setCurrentText("");
|
ui->comboBox_DiveMap->setCurrentText("");
|
||||||
} else if (source.direction == "emerge") {
|
} else if (source->direction == "emerge") {
|
||||||
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
|
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
|
||||||
ui->comboBox_EmergeMap->setCurrentText("");
|
ui->comboBox_EmergeMap->setCurrentText("");
|
||||||
} else {
|
} else {
|
||||||
|
@ -943,7 +941,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
// Update existing connection
|
// Update existing connection
|
||||||
if (mapName.isEmpty()) {
|
if (mapName.isEmpty()) {
|
||||||
removeMirroredConnection(*connection);
|
removeMirroredConnection(connection);
|
||||||
removeConnection(map, connection);
|
removeConnection(map, connection);
|
||||||
} else {
|
} else {
|
||||||
setConnectionMap(connection, mapName);
|
setConnectionMap(connection, mapName);
|
||||||
|
@ -955,7 +953,7 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
|
||||||
connection->offset = 0;
|
connection->offset = 0;
|
||||||
connection->map_name = mapName;
|
connection->map_name = mapName;
|
||||||
addConnection(map, connection);
|
addConnection(map, connection);
|
||||||
addMirroredConnection(*connection);
|
addMirroredConnection(connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1037,7 +1035,7 @@ void Editor::setConnectionOffset(MapConnection *connection, int offset) {
|
||||||
if (!connection || !map || connection->offset == offset)
|
if (!connection || !map || connection->offset == offset)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MapConnectionMirror mirror = getMirroredConnection(*connection);
|
MapConnectionMirror mirror = getMirroredConnection(connection);
|
||||||
if (mirror.connection && mirror.map) {
|
if (mirror.connection && mirror.map) {
|
||||||
mirror.connection->offset = -offset;
|
mirror.connection->offset = -offset;
|
||||||
if (mirror.map != map) {
|
if (mirror.map != map) {
|
||||||
|
@ -1071,9 +1069,9 @@ void Editor::setConnectionMap(MapConnection *connection, const QString &mapName)
|
||||||
if (!connection || !map || connection->map_name == mapName)
|
if (!connection || !map || connection->map_name == mapName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
removeMirroredConnection(*connection);
|
removeMirroredConnection(connection);
|
||||||
connection->map_name = mapName;
|
connection->map_name = mapName;
|
||||||
addMirroredConnection(*connection);
|
addMirroredConnection(connection);
|
||||||
|
|
||||||
emit editedMapData(map);
|
emit editedMapData(map);
|
||||||
}
|
}
|
||||||
|
@ -1083,7 +1081,7 @@ void Editor::setConnectionDirection(MapConnection *connection, const QString &di
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: Lazy
|
// TODO: Lazy
|
||||||
removeMirroredConnection(*connection);
|
removeMirroredConnection(connection);
|
||||||
|
|
||||||
if (MapConnection::isHorizontal(connection->direction) != MapConnection::isHorizontal(direction)
|
if (MapConnection::isHorizontal(connection->direction) != MapConnection::isHorizontal(direction)
|
||||||
|| MapConnection::isVertical(connection->direction) != MapConnection::isVertical(direction)) {
|
|| MapConnection::isVertical(connection->direction) != MapConnection::isVertical(direction)) {
|
||||||
|
@ -1092,7 +1090,7 @@ void Editor::setConnectionDirection(MapConnection *connection, const QString &di
|
||||||
}
|
}
|
||||||
connection->direction = direction;
|
connection->direction = direction;
|
||||||
|
|
||||||
addMirroredConnection(*connection);
|
addMirroredConnection(connection);
|
||||||
|
|
||||||
emit editedMapData(map);
|
emit editedMapData(map);
|
||||||
}
|
}
|
||||||
|
@ -1781,9 +1779,7 @@ void Editor::createConnectionItem(MapConnection* connection) {
|
||||||
return;
|
return;
|
||||||
QPixmap pixmap = getConnectionPixmap(*connection);
|
QPixmap pixmap = getConnectionPixmap(*connection);
|
||||||
QPoint pos = calculateConnectionPosition(*connection, pixmap);
|
QPoint pos = calculateConnectionPosition(*connection, pixmap);
|
||||||
ConnectionPixmapItem *item = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y(), map->getWidth(), map->getHeight());
|
ConnectionPixmapItem *item = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y());
|
||||||
item->setX(pos.x());
|
|
||||||
item->setY(pos.y());
|
|
||||||
item->render();
|
item->render();
|
||||||
scene->addItem(item);
|
scene->addItem(item);
|
||||||
|
|
||||||
|
@ -1860,9 +1856,8 @@ void Editor::updateMapConnections() {
|
||||||
for (auto item : connection_items) {
|
for (auto item : connection_items) {
|
||||||
if (!item->connection)
|
if (!item->connection)
|
||||||
continue;
|
continue;
|
||||||
QPixmap pixmap = getConnectionPixmap(*item->connection);
|
item->basePixmap = getConnectionPixmap(*item->connection);
|
||||||
item->basePixmap = pixmap;
|
item->render();
|
||||||
item->setPixmap(pixmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maskNonVisibleConnectionTiles();
|
maskNonVisibleConnectionTiles();
|
||||||
|
|
Loading…
Reference in a new issue