Skip unnecessary dive map rendering, fix rendering small connections
This commit is contained in:
parent
63b77a1fdc
commit
0b800c1201
5 changed files with 41 additions and 20 deletions
|
@ -78,6 +78,7 @@ public:
|
|||
void setMapEditingButtonsEnabled(bool enabled);
|
||||
void setConnectionsVisibility(bool visible);
|
||||
void updateDivingMapsVisibility();
|
||||
void displayDivingConnections();
|
||||
void addConnection(MapConnection* connection);
|
||||
void removeConnection(MapConnection* connection);
|
||||
void removeSelectedConnection();
|
||||
|
|
|
@ -13,7 +13,6 @@ public:
|
|||
: QGraphicsPixmapItem(getBasePixmap(connection))
|
||||
{
|
||||
m_connection = connection;
|
||||
setZValue(2);
|
||||
|
||||
// Update pixmap if the connected map is swapped.
|
||||
connect(m_connection, &MapConnection::targetMapNameChanged, this, &DivingMapPixmapItem::updatePixmap);
|
||||
|
|
|
@ -216,23 +216,29 @@ QPixmap Map::renderBorder(bool ignoreCache) {
|
|||
}
|
||||
|
||||
QPixmap Map::renderConnection(const QString &direction, MapLayout * fromLayout) {
|
||||
if (direction == "dive" || direction == "emerge")
|
||||
return render(true);
|
||||
|
||||
if (!MapConnection::isCardinal(direction))
|
||||
return QPixmap();
|
||||
|
||||
// Cardinal connections are rendered within the bounds of the border draw distance,
|
||||
// and we need to render the nearest segment of the map.
|
||||
// Dive/Emerge maps are rendered normally, but within the bounds of their parent map.
|
||||
int x = 0, y = 0, w = getWidth(), h = getHeight();
|
||||
if (direction == "up") {
|
||||
y = getHeight() - BORDER_DISTANCE;
|
||||
h = BORDER_DISTANCE;
|
||||
h = qMin(h, BORDER_DISTANCE);
|
||||
y = getHeight() - h;
|
||||
} else if (direction == "down") {
|
||||
h = BORDER_DISTANCE;
|
||||
h = qMin(h, BORDER_DISTANCE);
|
||||
} else if (direction == "left") {
|
||||
x = getWidth() - BORDER_DISTANCE;
|
||||
w = BORDER_DISTANCE;
|
||||
w = qMin(w, BORDER_DISTANCE);
|
||||
x = getWidth() - w;
|
||||
} else if (direction == "right") {
|
||||
w = BORDER_DISTANCE;
|
||||
w = qMin(w, BORDER_DISTANCE);
|
||||
} else if (MapConnection::isDiving(direction)) {
|
||||
if (fromLayout) {
|
||||
w = qMin(w, fromLayout->getWidth());
|
||||
h = qMin(h, fromLayout->getHeight());
|
||||
fromLayout = nullptr; // This would be used for palettes later, but we want our own palettes, not the parent's.
|
||||
}
|
||||
} else {
|
||||
// Unknown direction
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
render(true, fromLayout, QRect(x, y, w, h));
|
||||
|
|
|
@ -737,10 +737,6 @@ void Editor::displayConnection(MapConnection* connection) {
|
|||
if (!connection)
|
||||
return;
|
||||
|
||||
// It's possible for a map connection to be displayed repeatedly if it's being
|
||||
// updated by mirroring and the target map is changing to/from the current map.
|
||||
connection->disconnect();
|
||||
|
||||
if (MapConnection::isDiving(connection->direction())) {
|
||||
displayDivingConnection(connection);
|
||||
return;
|
||||
|
@ -758,6 +754,10 @@ void Editor::displayConnection(MapConnection* connection) {
|
|||
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, pixmapItem->connection, project->mapNames);
|
||||
ui->layout_ConnectionsList->insertWidget(ui->layout_ConnectionsList->count() - 1, listItem); // Insert above the vertical spacer
|
||||
|
||||
// It's possible for a map connection to be displayed repeatedly if it's being
|
||||
// updated by mirroring and the target map is changing to/from the current map.
|
||||
connection->disconnect();
|
||||
|
||||
// Double clicking the list item or pixmap opens the connected map
|
||||
connect(listItem, &ConnectionsListItem::doubleClicked, this, &Editor::onMapConnectionDoubleClicked);
|
||||
connect(pixmapItem, &ConnectionPixmapItem::connectionItemDoubleClicked, this, &Editor::onMapConnectionDoubleClicked);
|
||||
|
@ -871,6 +871,14 @@ void Editor::removeConnectionPixmap(MapConnection* connection) {
|
|||
delete pixmapItem;
|
||||
}
|
||||
|
||||
void Editor::displayDivingConnections() {
|
||||
if (!this->map)
|
||||
return;
|
||||
|
||||
for (auto connection : this->map->getConnections())
|
||||
displayDivingConnection(connection);
|
||||
}
|
||||
|
||||
void Editor::displayDivingConnection(MapConnection* connection) {
|
||||
if (!connection)
|
||||
return;
|
||||
|
@ -879,6 +887,10 @@ void Editor::displayDivingConnection(MapConnection* connection) {
|
|||
if (!MapConnection::isDiving(direction))
|
||||
return;
|
||||
|
||||
// Save some rendering time if it won't be displayed
|
||||
if (!porymapConfig.showDiveEmergeMaps)
|
||||
return;
|
||||
|
||||
// Note: We only support editing 1 Dive and Emerge connection per map.
|
||||
// In a vanilla game only the first Dive/Emerge connection is considered, so allowing
|
||||
// users to have multiple is likely to lead to confusion. In case users have changed
|
||||
|
@ -890,7 +902,6 @@ void Editor::displayDivingConnection(MapConnection* connection) {
|
|||
auto item = new DivingMapPixmapItem(connection);
|
||||
scene->addItem(item);
|
||||
diving_map_items.insert(direction, item);
|
||||
maskNonVisibleConnectionTiles();
|
||||
|
||||
// Display map name in combo box
|
||||
auto comboBox = (direction == "dive") ? ui->comboBox_DiveMap : ui->comboBox_EmergeMap;
|
||||
|
@ -963,7 +974,6 @@ void Editor::setDivingMapName(QString mapName, QString direction) {
|
|||
addConnection(new MapConnection(mapName, direction));
|
||||
}
|
||||
updateDivingMapsVisibility();
|
||||
maskNonVisibleConnectionTiles();
|
||||
}
|
||||
|
||||
void Editor::updateDivingMapsVisibility() {
|
||||
|
@ -1810,7 +1820,6 @@ void Editor::maskNonVisibleConnectionTiles() {
|
|||
QBrush brush(ui->graphicsView_Map->palette().color(QPalette::Active, QPalette::Base));
|
||||
|
||||
connection_mask = scene->addPath(mask, pen, brush);
|
||||
connection_mask->setZValue(3); // Above diving maps
|
||||
}
|
||||
|
||||
void Editor::clearMapBorder() {
|
||||
|
|
|
@ -2302,6 +2302,12 @@ void MainWindow::setDivingMapsVisible(bool visible) {
|
|||
ui->actionDive_Emerge_Map->setChecked(visible);
|
||||
|
||||
porymapConfig.showDiveEmergeMaps = visible;
|
||||
|
||||
if (visible) {
|
||||
// We skip rendering diving maps if this setting is not enabled,
|
||||
// so when we enable it we need to make sure they've rendered.
|
||||
this->editor->displayDivingConnections();
|
||||
}
|
||||
this->editor->updateDivingMapsVisibility();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue