Add buttons to open Dive/Emerge maps

This commit is contained in:
GriffinR 2024-06-28 22:01:13 -04:00
parent db35ec2c79
commit 391285aee8
6 changed files with 92 additions and 83 deletions

View file

@ -992,7 +992,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<width>91</width>
<height>74</height>
</rect>
</property>
@ -1193,7 +1193,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<width>91</width>
<height>512</height>
</rect>
</property>
@ -1413,8 +1413,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>444</height>
<width>93</width>
<height>460</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
@ -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">
@ -2588,7 +2588,7 @@
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="3">
<item row="0" column="4">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -2601,7 +2601,7 @@
</property>
</spacer>
</item>
<item row="0" column="4">
<item row="0" column="5">
<widget class="QCheckBox" name="checkBox_MirrorConnections">
<property name="toolTip">
<string>If enabled, connections will automatically be updated on the connected map.</string>
@ -2614,41 +2614,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_EmergeMap">
<property name="text">
<string>Emerge Map</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_DiveMap">
<property name="text">
<string>Dive Map</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="NoScrollComboBox" name="comboBox_DiveMap">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Destination map name when using &lt;span style=&quot; font-weight:600;&quot;&gt;Dive&lt;/span&gt;. If empty, no such connection will exist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="NoScrollComboBox" name="comboBox_EmergeMap">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Destination map name when emerging using &lt;span style=&quot; font-weight:600;&quot;&gt;Dive&lt;/span&gt;. If empty, no such connection will exist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QToolButton" name="button_OpenDiveMap">
<property name="toolTip">
<string>Open the selected Dive Map</string>
@ -2662,7 +2628,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="0" column="0">
<widget class="QToolButton" name="button_OpenEmergeMap">
<property name="toolTip">
<string>Open the selected Emerge Map</string>
@ -2676,6 +2642,40 @@
</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="1" column="1">
<widget class="QLabel" name="label_DiveMap">
<property name="text">
<string>Dive Map</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="NoScrollComboBox" name="comboBox_DiveMap">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Destination map name when using &lt;span style=&quot; font-weight:600;&quot;&gt;Dive&lt;/span&gt;. If empty, no such connection will exist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="NoScrollComboBox" name="comboBox_EmergeMap">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Destination map name when emerging using &lt;span style=&quot; font-weight:600;&quot;&gt;Dive&lt;/span&gt;. If empty, no such connection will exist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View file

@ -248,6 +248,8 @@ private slots:
void on_comboBox_ConnectedMap_currentTextChanged(const QString &mapName);
void on_pushButton_AddConnection_clicked();
void on_pushButton_RemoveConnection_clicked();
void on_button_OpenDiveMap_clicked();
void on_button_OpenEmergeMap_clicked();
void on_comboBox_DiveMap_currentTextChanged(const QString &mapName);
void on_comboBox_EmergeMap_currentTextChanged(const QString &mapName);
void on_comboBox_PrimaryTileset_currentTextChanged(const QString &arg1);
@ -342,6 +344,7 @@ private:
bool tilesetNeedsRedraw = false;
bool userSetMap(QString, bool scrollTreeView = false);
bool setMap(QString, bool scrollTreeView = false);
void redrawMapScene();
void refreshMapScene();

View file

@ -119,6 +119,7 @@ public:
bool readMapGroups();
Map* addNewMapToGroup(QString, int, Map*, bool, bool);
QString getNewMapName();
bool isExistingMapName(const QString&);
QString getProjectTitle();
QString readMapLayoutId(QString map_name);

View file

@ -763,7 +763,7 @@ void Editor::populateConnectionsList() {
addConnectionToList(item->connection);
}
// TODO: Vertical scrolling
// TODO: Don't allow splitter resizing to shrink list items to the point where horizontal scroll is needed
void Editor::addConnectionToList(const MapConnection * connection) {
ConnectionsListItem *listItem = new ConnectionsListItem(ui->scrollAreaContents_ConnectionsList, project->mapNames);
listItem->populate(connection);

View file

@ -718,6 +718,21 @@ void MainWindow::on_action_Reload_Project_triggered() {
openProject(editor->project->root);
}
// setMap, but with a visible error message in case of failure.
// Use when the user is specifically requesting a map to open.
bool MainWindow::userSetMap(QString map_name, bool scrollTreeView) {
if (!setMap(map_name, scrollTreeView)) {
QMessageBox msgBox(this);
QString errorMsg = QString("There was an error opening map %1. Please see %2 for full error details.\n\n%3")
.arg(map_name)
.arg(getLogPath())
.arg(getMostRecentError());
msgBox.critical(nullptr, "Error Opening Map", errorMsg);
return false;
}
return true;
}
bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
logInfo(QString("Setting map to '%1'").arg(map_name));
if (map_name.isEmpty()) {
@ -810,15 +825,8 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
}
// Open the destination map.
if (!setMap(map_name, true)) {
QMessageBox msgBox(this);
QString errorMsg = QString("There was an error opening map %1. Please see %2 for full error details.\n\n%3")
.arg(map_name)
.arg(getLogPath())
.arg(getMostRecentError());
msgBox.critical(nullptr, "Error Opening Map", errorMsg);
if (!userSetMap(map_name, true))
return;
}
// Select the target event.
int index = event_id - Event::getIndexOffset(event_group);
@ -1468,17 +1476,8 @@ void MainWindow::currentMetatilesSelectionChanged() {
void MainWindow::on_mapList_activated(const QModelIndex &index)
{
QVariant data = index.data(Qt::UserRole);
if (index.data(MapListUserRoles::TypeRole) == "map_name" && !data.isNull()) {
QString mapName = data.toString();
if (!setMap(mapName)) {
QMessageBox msgBox(this);
QString errorMsg = QString("There was an error opening map %1. Please see %2 for full error details.\n\n%3")
.arg(mapName)
.arg(getLogPath())
.arg(getMostRecentError());
msgBox.critical(nullptr, "Error Opening Map", errorMsg);
}
}
if (index.data(MapListUserRoles::TypeRole) == "map_name" && !data.isNull())
userSetMap(data.toString());
}
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
@ -2421,15 +2420,7 @@ void MainWindow::clickToolButtonFromEditMode(QString editMode) {
}
void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {
if (!setMap(mapName, true)) {
QMessageBox msgBox(this);
QString errorMsg = QString("There was an error opening map %1. Please see %2 for full error details.\n\n%3")
.arg(mapName)
.arg(getLogPath())
.arg(getMostRecentError());
msgBox.critical(nullptr, "Error Opening Map", errorMsg);
return;
}
if (userSetMap(mapName, true))
editor->setSelectedConnectionFromMap(fromMapName);
}
@ -2592,17 +2583,27 @@ void MainWindow::on_pushButton_ConfigureEncountersJSON_clicked() {
editor->configureEncounterJSON(this);
}
void MainWindow::on_comboBox_DiveMap_currentTextChanged(const QString &mapName)
{
if (mapName.isEmpty() || editor->project->mapNames.contains(mapName)) {
void MainWindow::on_button_OpenDiveMap_clicked() {
const QString mapName = ui->comboBox_DiveMap->currentText();
if (editor->project->isExistingMapName(mapName))
userSetMap(mapName, true);
}
void MainWindow::on_button_OpenEmergeMap_clicked() {
const QString mapName = ui->comboBox_EmergeMap->currentText();
if (editor->project->isExistingMapName(mapName))
userSetMap(mapName, true);
}
void MainWindow::on_comboBox_DiveMap_currentTextChanged(const QString &mapName) {
if (editor->project->isExistingMapName(mapName)) {
editor->updateDiveMap(mapName);
markMapEdited();
}
}
void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName)
{
if (mapName.isEmpty() || editor->project->mapNames.contains(mapName)) {
void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName) {
if (editor->project->isExistingMapName(mapName)) {
editor->updateEmergeMap(mapName);
markMapEdited();
}

View file

@ -1800,6 +1800,10 @@ QString Project::getNewMapName() {
return newMapName;
}
bool Project::isExistingMapName(const QString &mapName) {
return !mapName.isEmpty() && mapName != DYNAMIC_MAP_NAME && this->mapNames.contains(mapName);
}
Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) {
Project::DataQualifiers qualifiers;