Merge pull request #505 from GriffinRichards/connection-warp

Allow navigating to connected maps from any tab
This commit is contained in:
t 2023-01-16 15:46:49 -05:00 committed by GitHub
commit debf9d99f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 78 deletions

View file

@ -13,6 +13,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d
- Add option to turn off the checkerboard fill for new tilesets. - Add option to turn off the checkerboard fill for new tilesets.
### Changed ### Changed
- Double-clicking on a connecting map on the Map or Events tabs will now open that map.
- Hovering on border metatiles with the mouse will now display their information in the bottom bar. - Hovering on border metatiles with the mouse will now display their information in the bottom bar.
- The last-used directory is now preserved in import/export file dialogs. - The last-used directory is now preserved in import/export file dialogs.

View file

@ -110,8 +110,7 @@ public:
QGraphicsPixmapItem *current_view = nullptr; QGraphicsPixmapItem *current_view = nullptr;
MapPixmapItem *map_item = nullptr; MapPixmapItem *map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = nullptr; ConnectionPixmapItem* selected_connection_item = nullptr;
QList<QGraphicsPixmapItem*> connection_items; QList<ConnectionPixmapItem*> connection_items;
QList<ConnectionPixmapItem*> connection_edit_items;
QGraphicsPathItem *connection_mask = nullptr; QGraphicsPathItem *connection_mask = nullptr;
CollisionPixmapItem *collision_item = nullptr; CollisionPixmapItem *collision_item = nullptr;
QGraphicsItemGroup *events_group = nullptr; QGraphicsItemGroup *events_group = nullptr;
@ -166,7 +165,8 @@ private:
void setBorderItemsVisible(bool, qreal = 1); void setBorderItemsVisible(bool, qreal = 1);
void setConnectionEditControlValues(MapConnection*); void setConnectionEditControlValues(MapConnection*);
void setConnectionEditControlsEnabled(bool); void setConnectionEditControlsEnabled(bool);
void createConnectionItem(MapConnection* connection, bool hide); void setConnectionsEditable(bool);
void createConnectionItem(MapConnection* connection);
void populateConnectionMapPickers(); void populateConnectionMapPickers();
void setDiveEmergeControls(); void setDiveEmergeControls();
void updateDiveEmergeMap(QString mapName, QString direction); void updateDiveEmergeMap(QString mapName, QString direction);

View file

@ -29,6 +29,9 @@ public:
void render(qreal opacity = 1); void render(qreal opacity = 1);
int getMinOffset(); int getMinOffset();
int getMaxOffset(); int getMaxOffset();
void setEditable(bool editable);
bool getEditable();
void updateHighlight(bool selected);
protected: protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);

View file

@ -86,7 +86,6 @@ void Editor::setEditingMap() {
displayMapConnections(); displayMapConnections();
map_item->draw(); map_item->draw();
map_item->setVisible(true); map_item->setVisible(true);
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
} }
if (collision_item) { if (collision_item) {
collision_item->setVisible(false); collision_item->setVisible(false);
@ -95,7 +94,8 @@ void Editor::setEditingMap() {
events_group->setVisible(false); events_group->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(false); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->stopSingleTileMode(); this->cursorMapTileRect->stopSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -108,7 +108,6 @@ void Editor::setEditingCollision() {
displayMapConnections(); displayMapConnections();
collision_item->draw(); collision_item->draw();
collision_item->setVisible(true); collision_item->setVisible(true);
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
} }
if (map_item) { if (map_item) {
map_item->paintingMode = MapPixmapItem::PaintMode::Metatiles; map_item->paintingMode = MapPixmapItem::PaintMode::Metatiles;
@ -118,7 +117,8 @@ void Editor::setEditingCollision() {
events_group->setVisible(false); events_group->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(false); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -135,13 +135,13 @@ void Editor::setEditingObjects() {
displayMapConnections(); displayMapConnections();
map_item->draw(); map_item->draw();
map_item->setVisible(true); map_item->setVisible(true);
setConnectionsVisibility(ui->checkBox_ToggleBorder->isChecked());
} }
if (collision_item) { if (collision_item) {
collision_item->setVisible(false); collision_item->setVisible(false);
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(false); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionsEditable(false);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
@ -172,7 +172,6 @@ void Editor::setEditingConnections() {
map_item->setVisible(true); map_item->setVisible(true);
populateConnectionMapPickers(); populateConnectionMapPickers();
ui->label_NumConnections->setText(QString::number(map->connections.length())); ui->label_NumConnections->setText(QString::number(map->connections.length()));
setConnectionsVisibility(false);
setDiveEmergeControls(); setDiveEmergeControls();
bool controlsEnabled = selected_connection_item != nullptr; bool controlsEnabled = selected_connection_item != nullptr;
setConnectionEditControlsEnabled(controlsEnabled); setConnectionEditControlsEnabled(controlsEnabled);
@ -190,6 +189,7 @@ void Editor::setEditingConnections() {
} }
setBorderItemsVisible(true, 0.4); setBorderItemsVisible(true, 0.4);
setConnectionItemsVisible(true); setConnectionItemsVisible(true);
setConnectionsEditable(true);
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
} }
@ -747,7 +747,7 @@ void Editor::populateConnectionMapPickers() {
} }
void Editor::setConnectionItemsVisible(bool visible) { void Editor::setConnectionItemsVisible(bool visible) {
for (ConnectionPixmapItem* item : connection_edit_items) { for (ConnectionPixmapItem* item : connection_items) {
item->setVisible(visible); item->setVisible(visible);
item->setEnabled(visible); item->setEnabled(visible);
} }
@ -856,26 +856,20 @@ void Editor::setConnectionEditControlsEnabled(bool enabled) {
} }
} }
void Editor::setConnectionsEditable(bool editable) {
for (ConnectionPixmapItem* item : connection_items) {
item->setEditable(editable);
item->updateHighlight(item == selected_connection_item);
}
}
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) { void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
if (!connectionItem) if (!connectionItem)
return; return;
for (ConnectionPixmapItem* item : connection_edit_items) {
bool isSelectedItem = item == connectionItem;
int zValue = isSelectedItem ? 0 : -1;
qreal opacity = isSelectedItem ? 1 : 0.75;
item->setZValue(zValue);
item->render(opacity);
if (isSelectedItem) {
QPixmap pixmap = item->pixmap();
QPainter painter(&pixmap);
painter.setPen(QColor(255, 0, 255));
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
painter.end();
item->setPixmap(pixmap);
}
}
selected_connection_item = connectionItem; selected_connection_item = connectionItem;
for (ConnectionPixmapItem* item : connection_items)
item->updateHighlight(item == selected_connection_item);
setConnectionEditControlsEnabled(true); setConnectionEditControlsEnabled(true);
setConnectionEditControlValues(selected_connection_item->connection); setConnectionEditControlValues(selected_connection_item->connection);
ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset()); ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());
@ -885,7 +879,7 @@ void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
void Editor::setSelectedConnectionFromMap(QString mapName) { void Editor::setSelectedConnectionFromMap(QString mapName) {
// Search for the first connection that connects to the given map map. // Search for the first connection that connects to the given map map.
for (ConnectionPixmapItem* item : connection_edit_items) { for (ConnectionPixmapItem* item : connection_items) {
if (item->connection->map_name == mapName) { if (item->connection->map_name == mapName) {
onConnectionItemSelected(item); onConnectionItemSelected(item);
break; break;
@ -1077,13 +1071,6 @@ QString Editor::getMovementPermissionText(uint16_t collision, uint16_t elevation
return message; return message;
} }
void Editor::setConnectionsVisibility(bool visible) {
for (QGraphicsPixmapItem* item : connection_items) {
item->setVisible(visible);
item->setActive(visible);
}
}
bool Editor::setMap(QString map_name) { bool Editor::setMap(QString map_name) {
if (map_name.isEmpty()) { if (map_name.isEmpty()) {
return false; return false;
@ -1528,38 +1515,30 @@ DraggablePixmapItem *Editor::addMapEvent(Event *event) {
} }
void Editor::displayMapConnections() { void Editor::displayMapConnections() {
for (QGraphicsPixmapItem* item : connection_items) { for (ConnectionPixmapItem* item : connection_items) {
if (item->scene()) {
item->scene()->removeItem(item);
}
delete item;
}
connection_items.clear();
for (ConnectionPixmapItem* item : connection_edit_items) {
if (item->scene()) { if (item->scene()) {
item->scene()->removeItem(item); item->scene()->removeItem(item);
} }
delete item; delete item;
} }
selected_connection_item = nullptr; selected_connection_item = nullptr;
connection_edit_items.clear(); connection_items.clear();
for (MapConnection *connection : map->connections) { for (MapConnection *connection : map->connections) {
if (connection->direction == "dive" || connection->direction == "emerge") { if (connection->direction == "dive" || connection->direction == "emerge") {
continue; continue;
} }
createConnectionItem(connection, false); createConnectionItem(connection);
} }
if (!connection_edit_items.empty()) { if (!connection_items.empty()) {
onConnectionItemSelected(connection_edit_items.first()); onConnectionItemSelected(connection_items.first());
} }
maskNonVisibleConnectionTiles(); maskNonVisibleConnectionTiles();
} }
void Editor::createConnectionItem(MapConnection* connection, bool hide) { void Editor::createConnectionItem(MapConnection* connection) {
Map *connected_map = project->getMap(connection->map_name); Map *connected_map = project->getMap(connection->map_name);
if (!connected_map) { if (!connected_map) {
return; return;
@ -1582,26 +1561,15 @@ void Editor::createConnectionItem(MapConnection* connection, bool hide) {
y = offset * 16; y = offset * 16;
} }
QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap); ConnectionPixmapItem *item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
item->setZValue(-1);
item->setX(x); item->setX(x);
item->setY(y); item->setY(y);
item->setZValue(-1);
scene->addItem(item); scene->addItem(item);
connect(item, &ConnectionPixmapItem::connectionMoved, this, &Editor::onConnectionMoved);
connect(item, &ConnectionPixmapItem::connectionItemSelected, this, &Editor::onConnectionItemSelected);
connect(item, &ConnectionPixmapItem::connectionItemDoubleClicked, this, &Editor::onConnectionItemDoubleClicked);
connection_items.append(item); connection_items.append(item);
item->setVisible(!hide);
ConnectionPixmapItem *connection_edit_item = new ConnectionPixmapItem(pixmap, connection, x, y, map->getWidth(), map->getHeight());
connection_edit_item->setX(x);
connection_edit_item->setY(y);
connection_edit_item->setZValue(-1);
scene->addItem(connection_edit_item);
connect(connection_edit_item, &ConnectionPixmapItem::connectionMoved,
this, &Editor::onConnectionMoved);
connect(connection_edit_item, &ConnectionPixmapItem::connectionItemSelected,
this, &Editor::onConnectionItemSelected);
connect(connection_edit_item, &ConnectionPixmapItem::connectionItemDoubleClicked,
this, &Editor::onConnectionItemDoubleClicked);
connection_edit_items.append(connection_edit_item);
} }
// Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE). // Hides connected map tiles that cannot be seen from the current map (beyond BORDER_DISTANCE).
@ -1662,18 +1630,14 @@ void Editor::updateMapBorder() {
} }
void Editor::updateMapConnections() { void Editor::updateMapConnections() {
if (connection_items.size() != connection_edit_items.size())
return;
for (int i = 0; i < connection_items.size(); i++) { for (int i = 0; i < connection_items.size(); i++) {
Map *connected_map = project->getMap(connection_edit_items[i]->connection->map_name); Map *connected_map = project->getMap(connection_items[i]->connection->map_name);
if (!connected_map) if (!connected_map)
continue; continue;
QPixmap pixmap = connected_map->renderConnection(*(connection_edit_items[i]->connection), map->layout); QPixmap pixmap = connected_map->renderConnection(*(connection_items[i]->connection), map->layout);
connection_items[i]->basePixmap = pixmap;
connection_items[i]->setPixmap(pixmap); connection_items[i]->setPixmap(pixmap);
connection_edit_items[i]->basePixmap = pixmap;
connection_edit_items[i]->setPixmap(pixmap);
} }
maskNonVisibleConnectionTiles(); maskNonVisibleConnectionTiles();
@ -1793,8 +1757,8 @@ void Editor::addNewConnection() {
newConnection->offset = 0; newConnection->offset = 0;
newConnection->map_name = defaultMapName; newConnection->map_name = defaultMapName;
map->connections.append(newConnection); map->connections.append(newConnection);
createConnectionItem(newConnection, true); createConnectionItem(newConnection);
onConnectionItemSelected(connection_edit_items.last()); onConnectionItemSelected(connection_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); updateMirroredConnection(newConnection, newConnection->direction, newConnection->map_name);
@ -1866,7 +1830,7 @@ void Editor::removeCurrentConnection() {
return; return;
map->connections.removeOne(selected_connection_item->connection); map->connections.removeOne(selected_connection_item->connection);
connection_edit_items.removeOne(selected_connection_item); connection_items.removeOne(selected_connection_item);
removeMirroredConnection(selected_connection_item->connection); removeMirroredConnection(selected_connection_item->connection);
if (selected_connection_item && selected_connection_item->scene()) { if (selected_connection_item && selected_connection_item->scene()) {
@ -1879,8 +1843,8 @@ void Editor::removeCurrentConnection() {
ui->spinBox_ConnectionOffset->setValue(0); ui->spinBox_ConnectionOffset->setValue(0);
ui->label_NumConnections->setText(QString::number(map->connections.length())); ui->label_NumConnections->setText(QString::number(map->connections.length()));
if (connection_edit_items.length() > 0) { if (connection_items.length() > 0) {
onConnectionItemSelected(connection_edit_items.last()); onConnectionItemSelected(connection_items.last());
} }
} }
@ -1951,7 +1915,7 @@ void Editor::updateSecondaryTileset(QString tilesetLabel, bool forceLoad)
void Editor::toggleBorderVisibility(bool visible, bool enableScriptCallback) void Editor::toggleBorderVisibility(bool visible, bool enableScriptCallback)
{ {
this->setBorderItemsVisible(visible); this->setBorderItemsVisible(visible);
this->setConnectionsVisibility(visible); this->setConnectionItemsVisible(visible);
porymapConfig.setShowBorder(visible); porymapConfig.setShowBorder(visible);
if (enableScriptCallback) if (enableScriptCallback)
Scripting::cb_BorderVisibilityToggled(visible); Scripting::cb_BorderVisibilityToggled(visible);

View file

@ -65,7 +65,34 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
} }
} }
void ConnectionPixmapItem::setEditable(bool editable) {
setFlag(ItemIsMovable, editable);
setFlag(ItemSendsGeometryChanges, editable);
}
bool ConnectionPixmapItem::getEditable() {
return (this->flags() & ItemIsMovable) != 0;
}
void ConnectionPixmapItem::updateHighlight(bool selected) {
bool editable = this->getEditable();
int zValue = (selected || !editable) ? 0 : -1;
qreal opacity = (selected || !editable) ? 1 : 0.75;
this->setZValue(zValue);
this->render(opacity);
if (editable && selected) {
QPixmap pixmap = this->pixmap();
QPainter painter(&pixmap);
painter.setPen(QColor(255, 0, 255));
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
painter.end();
this->setPixmap(pixmap);
}
}
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) { void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
if (!this->getEditable())
return;
emit connectionItemSelected(this); emit connectionItemSelected(this);
} }

View file

@ -393,7 +393,7 @@ QPixmap MapImageExporter::getFormattedMapPixmap(Map *map, bool ignoreBorder) {
if (!this->mode) { if (!this->mode) {
// if showing connections, draw on outside of image // if showing connections, draw on outside of image
QPainter connectionPainter(&pixmap); QPainter connectionPainter(&pixmap);
for (auto connectionItem : editor->connection_edit_items) { for (auto connectionItem : editor->connection_items) {
QString direction = connectionItem->connection->direction; QString direction = connectionItem->connection->direction;
if ((showUpConnections && direction == "up") if ((showUpConnections && direction == "up")
|| (showDownConnections && direction == "down") || (showDownConnections && direction == "down")