reopen porymap on layout view when applicable

This commit is contained in:
garak 2024-03-28 10:21:35 -04:00
parent 6520189352
commit 70c6e414f1
2 changed files with 24 additions and 1 deletions

View file

@ -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();

View file

@ -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() {