diff --git a/include/mainwindow.h b/include/mainwindow.h index 04c04cef..177196bb 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -387,6 +387,7 @@ private: void setRecentMapConfig(QString map_name); void setRecentLayoutConfig(QString layoutId); bool setInitialMap(); + bool setInitialLayout(); void setRecentMap(QString map_name); QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); void refreshRecentProjectsMenu(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4ff36eef..842f9fb3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -617,7 +617,7 @@ bool MainWindow::openProject(const QString &dir, bool initial) { this->projectOpenFailure = !(loadDataStructures() && populateMapList() - && setInitialMap()); + && (this->mapSortOrder == MapSortOrder::SortByLayout ? setInitialLayout() : setInitialMap())); if (this->projectOpenFailure) { this->statusBar()->showMessage(QString("Failed to open %1").arg(projectString)); @@ -713,6 +713,26 @@ bool MainWindow::setInitialMap() { return false; } +bool MainWindow::setInitialLayout() { + QStringList names; + if (editor && editor->project) + names = editor->project->mapLayoutsTable; + + // Try to set most recently-opened layout, if it's still in the list. + QString recentLayout = userConfig.getRecentLayout(); + if (!recentLayout.isEmpty() && names.contains(recentLayout) && setLayout(recentLayout)) + return true; + + // Failing that, try loading maps in the map list sequentially. + for (auto name : names) { + if (name != recentLayout && setLayout(name)) + return true; + } + + logError("Failed to load any layouts."); + return false; +} + void MainWindow::refreshRecentProjectsMenu() { ui->menuOpen_Recent_Project->clear(); QStringList recentProjects = porymapConfig.getRecentProjects(); @@ -980,10 +1000,12 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_ void MainWindow::setRecentMapConfig(QString mapName) { userConfig.setRecentMap(mapName); + userConfig.setRecentLayout(""); } void MainWindow::setRecentLayoutConfig(QString layoutId) { userConfig.setRecentLayout(layoutId); + userConfig.setRecentMap(""); } void MainWindow::displayMapProperties() {