Add dive/emerge map overlay

This commit is contained in:
GriffinR 2024-07-24 15:46:20 -04:00
parent c8434c85b3
commit 13252f98f3
8 changed files with 406 additions and 151 deletions

View file

@ -1715,7 +1715,7 @@
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1809,7 +1809,7 @@
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1903,7 +1903,7 @@
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -2003,7 +2003,7 @@
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -2097,7 +2097,7 @@
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -2601,34 +2601,7 @@
</property>
</widget>
</item>
<item row="0" column="4">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="button_OpenEmergeMap">
<property name="toolTip">
<string>Open the selected Emerge Map</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/map_go.ico</normaloff>:/icons/map_go.ico</iconset>
</property>
</widget>
</item>
<item row="0" column="5">
<item row="0" column="7">
<widget class="QCheckBox" name="checkBox_MirrorConnections">
<property name="toolTip">
<string>If enabled, connections will automatically be updated on the connected map.</string>
@ -2641,20 +2614,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="button_OpenDiveMap">
<property name="toolTip">
<string>Open the selected Dive Map</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/map_go.ico</normaloff>:/icons/map_go.ico</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_DiveMap">
<property name="text">
@ -2662,6 +2621,13 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_EmergeMap">
<property name="text">
<string>Emerge Map</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="NoScrollComboBox" name="comboBox_EmergeMap">
<property name="toolTip">
@ -2675,10 +2641,161 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_EmergeMap">
<item row="0" column="6">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="button_OpenDiveMap">
<property name="toolTip">
<string>Open the selected Dive Map</string>
</property>
<property name="text">
<string>Emerge Map</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/map_go.ico</normaloff>:/icons/map_go.ico</iconset>
</property>
</widget>
</item>
<item row="0" column="4" rowspan="2">
<widget class="QGroupBox" name="groupBox_DiveMapOpacity">
<property name="title">
<string>Show Emerge/Dive Maps</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QStackedWidget" name="stackedWidget_DiveMapOpacity">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page_OpacitySeparate">
<layout class="QVBoxLayout" name="verticalLayout_19">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSlider" name="slider_EmergeMapOpacity">
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>90</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="slider_DiveMapOpacity">
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>90</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_OpacityCombined">
<layout class="QVBoxLayout" name="verticalLayout_20">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSlider" name="slider_DiveEmergeMapOpacity">
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>90</number>
</property>
<property name="value">
<number>30</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="button_OpenEmergeMap">
<property name="toolTip">
<string>Open the selected Emerge Map</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/map_go.ico</normaloff>:/icons/map_go.ico</iconset>
</property>
</widget>
</item>
@ -2763,8 +2880,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>365</width>
<height>651</height>
</rect>
</property>
<layout class="QVBoxLayout" name="layout_ConnectionsList">

View file

@ -58,6 +58,10 @@ public:
this->reopenOnLaunch = true;
this->mapSortOrder = MapSortOrder::Group;
this->prettyCursors = true;
this->showDiveEmergeMaps = false;
this->diveEmergeMapOpacity = 30;
this->diveMapOpacity = 15;
this->emergeMapOpacity = 15;
this->collisionOpacity = 50;
this->collisionZoom = 30;
this->metatilesZoom = 30;
@ -103,6 +107,10 @@ public:
bool projectManuallyClosed;
MapSortOrder mapSortOrder;
bool prettyCursors;
bool showDiveEmergeMaps;
int diveEmergeMapOpacity;
int diveMapOpacity;
int emergeMapOpacity;
int collisionOpacity;
int collisionZoom;
int metatilesZoom;

View file

@ -75,10 +75,11 @@ public:
void setEditingConnections();
void setMapEditingButtonsEnabled(bool enabled);
void setConnectionsVisibility(bool visible);
void updateDiveEmergeVisibility();
void addNewConnection();
void addConnection(Map* map, MapConnection* connection);
void removeConnection(Map* map, MapConnection* connection);
void removeConnectionItem(ConnectionPixmapItem* connectionItem, bool removeMirror = true);
void addConnection(Map* map, MapConnection* connection, bool addMirror = true);
void removeConnection(Map* map, MapConnection* connection, bool removeMirror = true);
void removeConnectionItem(ConnectionPixmapItem* connectionItem);
void removeSelectedConnection();
void addNewWildMonGroup(QWidget *window);
void deleteWildMonGroup();
@ -111,6 +112,8 @@ public:
QPointer<MapPixmapItem> map_item = nullptr;
ConnectionPixmapItem* selected_connection_item = nullptr;
QList<ConnectionPixmapItem*> connection_items;
QGraphicsPixmapItem *dive_map_overlay = nullptr;
QGraphicsPixmapItem *emerge_map_overlay = nullptr;
QGraphicsPathItem *connection_mask = nullptr;
QPointer<CollisionPixmapItem> collision_item = nullptr;
QGraphicsItemGroup *events_group = nullptr;
@ -175,6 +178,8 @@ private:
void clearCurrentMetatilesSelection();
void clearMapEvents();
void clearMapConnections();
void clearDiveMap();
void clearEmergeMap();
void clearConnectionMask();
void clearMapBorder();
void clearMapGrid();
@ -186,7 +191,8 @@ private:
void updateConnectionItemPos(ConnectionPixmapItem* connectionItem);
void createConnectionItem(MapConnection* connection);
void addConnectionToList(ConnectionPixmapItem* connection);
void updateDiveEmergeMap(QString mapName, QString direction);
void createDiveEmergeConnection(MapConnection* connection);
void setDiveEmergeMapName(QString mapName, QString direction);
MapConnectionMirror getMirroredConnection(MapConnection*);
void addMirroredConnection(MapConnection*);
void removeMirroredConnection(MapConnection*);

View file

@ -269,6 +269,10 @@ private slots:
void eventTabChanged(int index);
void on_groupBox_DiveMapOpacity_toggled(bool on);
void on_slider_DiveEmergeMapOpacity_valueChanged(int value);
void on_slider_DiveMapOpacity_valueChanged(int value);
void on_slider_EmergeMapOpacity_valueChanged(int value);
void on_horizontalSlider_CollisionTransparency_valueChanged(int value);
void on_toolButton_ExpandAll_clicked();
void on_toolButton_CollapseAll_clicked();

View file

@ -9,10 +9,10 @@ class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
public:
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y)
: QGraphicsPixmapItem(pixmap),
connection(connection)
: QGraphicsPixmapItem(pixmap)
{
this->basePixmap = pixmap;
this->connection = connection;
setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges);
this->initialX = x;
@ -22,7 +22,7 @@ public:
this->setY(y);
}
QPixmap basePixmap;
MapConnection* const connection;
MapConnection* connection;
int initialX;
int initialY;
int initialOffset;

View file

@ -330,6 +330,14 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->mainSplitterState = bytesFromString(value);
} else if (key == "metatiles_splitter_state") {
this->metatilesSplitterState = bytesFromString(value);
} else if (key == "show_dive_emerge_maps") {
this->showDiveEmergeMaps = getConfigBool(key, value);
} else if (key == "dive_emerge_map_opacity") {
this->diveEmergeMapOpacity = getConfigInteger(key, value, 10, 90, 30);
} else if (key == "dive_map_opacity") {
this->diveMapOpacity = getConfigInteger(key, value, 10, 90, 15);
} else if (key == "emerge_map_opacity") {
this->emergeMapOpacity = getConfigInteger(key, value, 10, 90, 15);
} else if (key == "collision_opacity") {
this->collisionOpacity = getConfigInteger(key, value, 0, 100, 50);
} else if (key == "tileset_editor_geometry") {
@ -439,6 +447,10 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("project_settings_editor_state", stringFromByteArray(this->projectSettingsEditorState));
map.insert("custom_scripts_editor_geometry", stringFromByteArray(this->customScriptsEditorGeometry));
map.insert("custom_scripts_editor_state", stringFromByteArray(this->customScriptsEditorState));
map.insert("show_dive_emerge_maps", this->showDiveEmergeMaps ? "1" : "0");
map.insert("dive_emerge_map_opacity", QString::number(this->diveEmergeMapOpacity));
map.insert("dive_map_opacity", QString::number(this->diveMapOpacity));
map.insert("emerge_map_opacity", QString::number(this->emergeMapOpacity));
map.insert("collision_opacity", QString::number(this->collisionOpacity));
map.insert("collision_zoom", QString::number(this->collisionZoom));
map.insert("metatiles_zoom", QString::number(this->metatilesZoom));

View file

@ -725,6 +725,26 @@ void Editor::updateEncounterFields(EncounterFields newFields) {
project->wildMonFields = newFields;
}
void Editor::createConnectionItem(MapConnection* connection) {
if (!connection)
return;
QPixmap pixmap = getConnectionPixmap(*connection);
QPoint pos = calculateConnectionPosition(*connection, pixmap);
ConnectionPixmapItem *item = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y());
item->render();
scene->addItem(item);
connect(item, &ConnectionPixmapItem::selectionChanged, [this, item](bool selected) {
if (selected) setSelectedConnection(item);
});
connect(item, &ConnectionPixmapItem::connectionItemDoubleClicked, [this, item] {
emit this->connectionItemDoubleClicked(item->connection->map_name, map->name);
});
connection_items.append(item);
addConnectionToList(item);
}
void Editor::addConnectionToList(ConnectionPixmapItem * connectionItem) {
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, connectionItem->connection, project->mapNames);
ui->layout_ConnectionsList->insertWidget(ui->layout_ConnectionsList->count() - 1, listItem); // Insert above the vertical spacer
@ -799,25 +819,20 @@ void Editor::addNewConnection() {
newConnection->map_name = defaultMapName;
addConnection(map, newConnection);
setSelectedConnection(connection_items.last());
addMirroredConnection(newConnection);
}
void Editor::addConnection(Map* map, MapConnection * connection) {
void Editor::addConnection(Map* map, MapConnection * connection, bool addMirror) {
if (!map || !connection)
return;
if (addMirror)
addMirroredConnection(connection);
map->connections.append(connection);
if (map == this->map) {
// Adding a connection to the current map, we need to display it visually.
// Note that for the Dive/Emerge combo boxes this is normally redundant
// as the user can only create these by having already set the text,
// *except* in the case where they're connecting a map to itself.
if (connection->direction == "dive") {
const QSignalBlocker blocker(ui->comboBox_DiveMap);
ui->comboBox_DiveMap->setCurrentText(connection->map_name);
} else if (connection->direction == "emerge") {
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
ui->comboBox_EmergeMap->setCurrentText(connection->map_name);
if (connection->direction == "dive" || connection->direction == "emerge") {
createDiveEmergeConnection(connection);
} else {
createConnectionItem(connection);
}
@ -825,19 +840,10 @@ void Editor::addConnection(Map* map, MapConnection * connection) {
emit editedMapData(map);
}
void Editor::removeConnectionItem(ConnectionPixmapItem* connectionItem, bool removeMirror) {
void Editor::removeConnectionItem(ConnectionPixmapItem* connectionItem) {
if (!connectionItem)
return;
if (removeMirror) {
// 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.
// 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).
removeMirroredConnection(connectionItem->connection);
}
removeConnection(map, connectionItem->connection);
connection_items.removeOne(connectionItem);
if (connectionItem->scene())
connectionItem->scene()->removeItem(connectionItem);
@ -847,21 +853,48 @@ void Editor::removeConnectionItem(ConnectionPixmapItem* connectionItem, bool rem
if (!connection_items.isEmpty())
setSelectedConnection(connection_items.first());
}
delete connectionItem;
}
void Editor::removeConnection(Map* map, MapConnection* connection) {
if (!map)
return;
map->connections.removeOne(connection);
delete connection;
emit editedMapData(map);
removeConnection(map, connectionItem->connection);
delete connectionItem;
}
void Editor::removeSelectedConnection() {
removeConnectionItem(selected_connection_item);
}
void Editor::removeConnection(Map* map, MapConnection* connection, bool removeMirror) {
if (!map || !connection)
return;
if (removeMirror)
removeMirroredConnection(connection);
if (map == this->map) {
// The connection to delete is displayed on the currently-opened map, we need to delete it visually as well.
if (connection->direction == "dive") {
clearDiveMap();
} else if (connection->direction == "emerge") {
clearEmergeMap();
} else {
// Find and delete the matching connection graphics.
// If this was called via removeConnectionItem we rely on
// the item having already been removed from this list.
for (auto item :connection_items) {
if (item->connection == connection) {
item->connection = nullptr;
removeConnectionItem(item);
break;
}
}
}
}
map->connections.removeOne(connection);
delete connection;
emit editedMapData(map);
}
MapConnectionMirror Editor::getMirroredConnection(MapConnection* source) {
MapConnectionMirror mirror;
if (!map || !source || !ui->checkBox_MirrorConnections->isChecked())
@ -890,46 +923,58 @@ void Editor::addMirroredConnection(MapConnection* source) {
if (!mirror.map)
return;
mirror.connection = new MapConnection;
mirror.connection = new MapConnection; // TODO: Are we leaking memory here if mirror.connection != nullptr
*mirror.connection = MapConnection::mirror(*source, map->name);
addConnection(mirror.map, mirror.connection);
addConnection(mirror.map, mirror.connection, false);
}
void Editor::removeMirroredConnection(MapConnection* source) {
MapConnectionMirror mirror = getMirroredConnection(source);
if (!mirror.map || !mirror.connection)
return;
removeConnection(mirror.map, mirror.connection, false);
}
if (map == mirror.map) {
// The connection to delete is displayed on the currently-opened map, we need to delete it visually as well.
if (source->direction == "dive") {
const QSignalBlocker blocker(ui->comboBox_DiveMap);
ui->comboBox_DiveMap->setCurrentText("");
} else if (source->direction == "emerge") {
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
ui->comboBox_EmergeMap->setCurrentText("");
} else {
// Find and delete the matching connection graphics
for (auto item :connection_items) {
if (item->connection == mirror.connection) {
removeConnectionItem(item, false);
return;
}
}
}
void Editor::createDiveEmergeConnection(MapConnection* connection) {
if (!connection)
return;
QGraphicsPixmapItem *item;
Map *connectedMap = project->getMap(connection->map_name);
if (!connectedMap || connectedMap == this->map) {
// There's no point in rendering a map on top of itself.
// We create an empty image anyway to allow for changes later.
item = new QGraphicsPixmapItem(QPixmap());
} else {
item = new QGraphicsPixmapItem(connectedMap->render());
}
// TODO: Set pos. In-game, how are diving coordinates converted if the maps are different sizes?
scene->addItem(item);
if (connection->direction == "dive") {
clearDiveMap();
dive_map_overlay = item;
const QSignalBlocker blocker(ui->comboBox_DiveMap);
ui->comboBox_DiveMap->setCurrentText(connection->map_name);
} else if (connection->direction == "emerge") {
clearEmergeMap();
emerge_map_overlay = item;
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
ui->comboBox_EmergeMap->setCurrentText(connection->map_name);
} else {
// Shouldn't happen
scene->removeItem(item);
delete item;
}
removeConnection(mirror.map, mirror.connection);
}
void Editor::updateDiveMap(QString mapName) {
updateDiveEmergeMap(mapName, "dive");
setDiveEmergeMapName(mapName, "dive");
}
void Editor::updateEmergeMap(QString mapName) {
updateDiveEmergeMap(mapName, "emerge");
setDiveEmergeMapName(mapName, "emerge");
}
void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
void Editor::setDiveEmergeMapName(QString mapName, QString direction) {
if (!mapName.isEmpty() && !project->mapNamesToMapConstants.contains(mapName)) {
logError(QString("Invalid %1 connection map name: '%2'").arg(direction).arg(mapName));
return;
@ -944,12 +989,12 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
}
}
// Dive/Emerge maps aren't represented visually (aside from their combo boxes),
// so we have less to do here than a normal connection.
if (connection) {
if (connection->map_name == mapName)
return;
// Update existing connection
if (mapName.isEmpty()) {
removeMirroredConnection(connection);
removeConnection(map, connection);
} else {
setConnectionMap(connection, mapName);
@ -961,7 +1006,24 @@ void Editor::updateDiveEmergeMap(QString mapName, QString direction) {
connection->offset = 0;
connection->map_name = mapName;
addConnection(map, connection);
addMirroredConnection(connection);
}
updateDiveEmergeVisibility();
}
void Editor::updateDiveEmergeVisibility() {
if (dive_map_overlay && emerge_map_overlay) {
// Both connections in use, use separate sliders
ui->stackedWidget_DiveMapOpacity->setCurrentIndex(0);
dive_map_overlay->setOpacity(!porymapConfig.showDiveEmergeMaps ? 0 : static_cast<qreal>(porymapConfig.diveMapOpacity) / 100);
emerge_map_overlay->setOpacity(!porymapConfig.showDiveEmergeMaps ? 0 : static_cast<qreal>(porymapConfig.emergeMapOpacity) / 100);
} else {
// One connection in use (or none), use single slider
ui->stackedWidget_DiveMapOpacity->setCurrentIndex(1);
qreal opacity = !porymapConfig.showDiveEmergeMaps ? 0 : static_cast<qreal>(porymapConfig.diveEmergeMapOpacity) / 100;
if (dive_map_overlay)
dive_map_overlay->setOpacity(opacity);
else if (emerge_map_overlay)
emerge_map_overlay->setOpacity(opacity);
}
}
@ -1040,7 +1102,7 @@ void Editor::updateConnectionItemPos(ConnectionPixmapItem* connectionItem) {
}
void Editor::setConnectionOffset(MapConnection *connection, int offset) {
if (!connection || !map || connection->offset == offset)
if (!connection || !map || connection->offset == offset || !MapConnection::isCardinal(connection->direction))
return;
MapConnectionMirror mirror = getMirroredConnection(connection);
@ -1808,29 +1870,55 @@ void Editor::clearMapConnections() {
}
delete item;
}
selected_connection_item = nullptr;
connection_items.clear();
clearDiveMap();
clearEmergeMap();
selected_connection_item = nullptr;
}
void Editor::clearDiveMap() {
const QSignalBlocker blocker(ui->comboBox_DiveMap);
ui->comboBox_DiveMap->setCurrentText("");
if (dive_map_overlay) {
if (dive_map_overlay->scene()){
dive_map_overlay->scene()->removeItem(dive_map_overlay);
}
delete dive_map_overlay;
dive_map_overlay = nullptr;
}
}
void Editor::clearEmergeMap() {
const QSignalBlocker blocker(ui->comboBox_EmergeMap);
ui->comboBox_EmergeMap->setCurrentText("");
if (emerge_map_overlay) {
if (emerge_map_overlay->scene()){
emerge_map_overlay->scene()->removeItem(emerge_map_overlay);
}
delete emerge_map_overlay;
emerge_map_overlay = nullptr;
}
}
void Editor::displayMapConnections() {
clearMapConnections();
const QSignalBlocker blocker1(ui->comboBox_DiveMap);
const QSignalBlocker blocker2(ui->comboBox_EmergeMap);
ui->comboBox_DiveMap->setCurrentText("");
ui->comboBox_EmergeMap->setCurrentText("");
// 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
// this we won't delete extra diving connections, but we'll only display the first one.
// TODO: Move text check to inside createDiveEmergeConnection?
for (MapConnection *connection : map->connections) {
if (connection->direction == "dive") {
if (ui->comboBox_DiveMap->currentText().isEmpty())
ui->comboBox_DiveMap->setCurrentText(connection->map_name);
createDiveEmergeConnection(connection);
} else if (connection->direction == "emerge") {
if (ui->comboBox_EmergeMap->currentText().isEmpty())
ui->comboBox_EmergeMap->setCurrentText(connection->map_name);
createDiveEmergeConnection(connection);
} else {
// We allow any unknown direction names here. They'll be editable from the list menu.
createConnectionItem(connection);
@ -1839,26 +1927,8 @@ void Editor::displayMapConnections() {
if (!connection_items.empty())
setSelectedConnection(connection_items.first());
}
void Editor::createConnectionItem(MapConnection* connection) {
if (!connection)
return;
QPixmap pixmap = getConnectionPixmap(*connection);
QPoint pos = calculateConnectionPosition(*connection, pixmap);
ConnectionPixmapItem *item = new ConnectionPixmapItem(pixmap, connection, pos.x(), pos.y());
item->render();
scene->addItem(item);
connect(item, &ConnectionPixmapItem::selectionChanged, [this, item](bool selected) {
if (selected) setSelectedConnection(item);
});
connect(item, &ConnectionPixmapItem::connectionItemDoubleClicked, [this, item] {
emit this->connectionItemDoubleClicked(item->connection->map_name, map->name);
});
connection_items.append(item);
addConnectionToList(item);
updateDiveEmergeVisibility();
}
void Editor::clearConnectionMask() {

View file

@ -471,6 +471,13 @@ void MainWindow::applyMapListFilter(QString filterText)
}
void MainWindow::loadUserSettings() {
const QSignalBlocker blocker1(ui->horizontalSlider_CollisionTransparency);
const QSignalBlocker blocker2(ui->slider_DiveEmergeMapOpacity);
const QSignalBlocker blocker3(ui->slider_DiveMapOpacity);
const QSignalBlocker blocker4(ui->slider_EmergeMapOpacity);
const QSignalBlocker blocker5(ui->horizontalSlider_MetatileZoom);
const QSignalBlocker blocker6(ui->horizontalSlider_CollisionZoom);
ui->actionBetter_Cursors->setChecked(porymapConfig.prettyCursors);
this->editor->settings->betterCursors = porymapConfig.prettyCursors;
ui->actionPlayer_View_Rectangle->setChecked(porymapConfig.showPlayerView);
@ -479,17 +486,17 @@ void MainWindow::loadUserSettings() {
this->editor->settings->cursorTileRectEnabled = porymapConfig.showCursorTile;
ui->checkBox_ToggleBorder->setChecked(porymapConfig.showBorder);
ui->checkBox_ToggleGrid->setChecked(porymapConfig.showGrid);
ui->groupBox_DiveMapOpacity->setChecked(porymapConfig.showDiveEmergeMaps);
mapSortOrder = porymapConfig.mapSortOrder;
ui->horizontalSlider_CollisionTransparency->blockSignals(true);
this->editor->collisionOpacity = static_cast<qreal>(porymapConfig.collisionOpacity) / 100;
ui->horizontalSlider_CollisionTransparency->setValue(porymapConfig.collisionOpacity);
ui->horizontalSlider_CollisionTransparency->blockSignals(false);
ui->horizontalSlider_MetatileZoom->blockSignals(true);
ui->slider_DiveEmergeMapOpacity->setValue(porymapConfig.diveEmergeMapOpacity);
ui->slider_DiveMapOpacity->setValue(porymapConfig.diveMapOpacity);
ui->slider_EmergeMapOpacity->setValue(porymapConfig.emergeMapOpacity);
ui->horizontalSlider_MetatileZoom->setValue(porymapConfig.metatilesZoom);
ui->horizontalSlider_MetatileZoom->blockSignals(false);
ui->horizontalSlider_CollisionZoom->blockSignals(true);
ui->horizontalSlider_CollisionZoom->setValue(porymapConfig.collisionZoom);
ui->horizontalSlider_CollisionZoom->blockSignals(false);
setTheme(porymapConfig.theme);
}
@ -2263,6 +2270,37 @@ void MainWindow::eventTabChanged(int index) {
isProgrammaticEventTabChange = false;
}
void MainWindow::on_groupBox_DiveMapOpacity_toggled(bool on) {
// Qt doesn't change the style of disabled sliders, so we do it ourselves
QString stylesheet = on ? "" : "QSlider::groove:horizontal {border: 1px solid #999999; border-radius: 3px; height: 2px; background: #B1B1B1;}"
"QSlider::handle:horizontal {border: 1px solid #444444; border-radius: 3px; width: 10px; height: 9px; margin: -5px -1px; background: #5C5C5C; }";
ui->slider_DiveEmergeMapOpacity->setStyleSheet(stylesheet);
ui->slider_DiveMapOpacity->setStyleSheet(stylesheet);
ui->slider_EmergeMapOpacity->setStyleSheet(stylesheet);
porymapConfig.showDiveEmergeMaps = on;
this->editor->updateDiveEmergeVisibility();
}
// Normally a map only has either a Dive map connection or an Emerge map connection,
// in which case we only show a single opacity slider to modify the one in use.
// If a user has both connections we show two separate opacity sliders so they can
// modify them independently.
void MainWindow::on_slider_DiveEmergeMapOpacity_valueChanged(int value) {
porymapConfig.diveEmergeMapOpacity = value;
this->editor->updateDiveEmergeVisibility();
}
void MainWindow::on_slider_DiveMapOpacity_valueChanged(int value) {
porymapConfig.diveMapOpacity = value;
this->editor->updateDiveEmergeVisibility();
}
void MainWindow::on_slider_EmergeMapOpacity_valueChanged(int value) {
porymapConfig.emergeMapOpacity = value;
this->editor->updateDiveEmergeVisibility();
}
void MainWindow::on_horizontalSlider_CollisionTransparency_valueChanged(int value) {
this->editor->collisionOpacity = static_cast<qreal>(value) / 100;
porymapConfig.collisionOpacity = value;