preserve layout in config

This commit is contained in:
garak 2023-02-22 15:41:29 -05:00
parent e79b6e2fca
commit f485ebdd3e
5 changed files with 64 additions and 11 deletions

View file

@ -344,12 +344,15 @@ public:
}
virtual void reset() override {
this->recentMap = QString();
this->recentLayout = QString();
this->useEncounterJson = true;
this->customScripts.clear();
this->readKeys.clear();
}
void setRecentMap(const QString &map);
QString getRecentMap();
void setRecentLayout(const QString &map);
QString getRecentLayout();
void setEncounterJsonActive(bool active);
bool getEncounterJsonActive();
void setProjectDir(QString projectDir);
@ -371,6 +374,7 @@ protected:
private:
QString projectDir;
QString recentMap;
QString recentLayout;
bool useEncounterJson;
QMap<QString, bool> customScripts;
QStringList readKeys;

View file

@ -357,10 +357,12 @@ private:
bool tilesetNeedsRedraw = false;
bool setDefaultView();
bool setRecentView();
bool setLayout(QString layoutId);
bool setMap(QString, bool scroll = false);
void unsetMap();
void redrawMapScene();
void redrawLayoutScene();
void refreshMapScene();
@ -373,7 +375,9 @@ private:
QString getExistingDirectory(QString);
bool openProject(QString dir);
QString getDefaultMap();
void setRecentMap(QString map_name);
QString getDefaultLayout();
void setRecentMapConfig(QString map_name);
void setRecentLayoutConfig(QString layoutId);
void updateMapList();

View file

@ -1102,6 +1102,8 @@ QString UserConfig::getConfigFilepath() {
void UserConfig::parseConfigKeyValue(QString key, QString value) {
if (key == "recent_map") {
this->recentMap = value;
} else if (key == "recent_layout") {
this->recentLayout = value;
} else if (key == "use_encounter_json") {
this->useEncounterJson = getConfigBool(key, value);
} else if (key == "custom_scripts") {
@ -1118,6 +1120,7 @@ void UserConfig::setUnreadKeys() {
QMap<QString, QString> UserConfig::getKeyValueMap() {
QMap<QString, QString> map;
map.insert("recent_map", this->recentMap);
map.insert("recent_layout", this->recentLayout);
map.insert("use_encounter_json", QString::number(this->useEncounterJson));
map.insert("custom_scripts", this->outputCustomScripts());
return map;
@ -1146,6 +1149,15 @@ QString UserConfig::getRecentMap() {
return this->recentMap;
}
void UserConfig::setRecentLayout(const QString &layout) {
this->recentLayout = layout;
this->save();
}
QString UserConfig::getRecentLayout() {
return this->recentLayout;
}
void UserConfig::setEncounterJsonActive(bool active) {
this->useEncounterJson = active;
this->save();

View file

@ -1164,6 +1164,8 @@ bool Editor::setMap(QString map_name) {
bool Editor::setLayout(QString layoutId) {
//
if (layoutId.isEmpty()) return false;
this->layout = this->project->loadLayout(layoutId);
if (!displayLayout()) {

View file

@ -342,8 +342,8 @@ void MainWindow::initMiscHeapObjects() {
// !TODO: scroll view on first showing
void MainWindow::initMapSortOrder() {
mapSortOrder = porymapConfig.getMapSortOrder();
if (mapSortOrder == MapSortOrder::SortByLayout)
mapSortOrder = MapSortOrder::SortByGroup;
// if (mapSortOrder == MapSortOrder::SortByLayout)
// mapSortOrder = MapSortOrder::SortByGroup;
this->ui->mapListContainer->setCurrentIndex(static_cast<int>(this->mapSortOrder));
}
@ -541,16 +541,13 @@ bool MainWindow::openProject(QString dir) {
this->preferenceEditor->updateFields();
});
editor->project->set_root(dir);
success = loadDataStructures()
&& populateMapList()
&& setMap(getDefaultMap(), true);
success = loadDataStructures() && populateMapList() && setDefaultView();
} else {
QString open_map = editor->map->name;
editor->project->fileWatcher.removePaths(editor->project->fileWatcher.files());
editor->project->clearLayoutsTable();
editor->project->clearMapCache();
editor->project->clearTilesetCache();
success = loadDataStructures() && populateMapList() && setMap(open_map, true);
success = loadDataStructures() && populateMapList() && setRecentView();
}
projectOpenFailure = !success;
@ -581,6 +578,22 @@ bool MainWindow::isProjectOpen() {
return !projectOpenFailure && editor && editor->project;
}
bool MainWindow::setDefaultView() {
if (this->mapSortOrder == MapSortOrder::SortByLayout) {
return setLayout(getDefaultLayout());
} else {
return setMap(getDefaultMap(), true);
}
}
bool MainWindow::setRecentView() {
if (this->mapSortOrder == MapSortOrder::SortByLayout) {
return setLayout(userConfig.getRecentLayout());
} else {
return setMap(userConfig.getRecentMap(), true);
}
}
QString MainWindow::getDefaultMap() {
if (editor && editor->project) {
QList<QStringList> names = editor->project->groupedMapNames;
@ -618,6 +631,18 @@ void MainWindow::openSubWindow(QWidget * window) {
}
}
QString MainWindow::getDefaultLayout() {
if (editor && editor->project) {
QString recentLayout = userConfig.getRecentLayout();
if (!recentLayout.isEmpty() && editor->project->mapLayoutsTable.contains(recentLayout)) {
return recentLayout;
} else if (!editor->project->mapLayoutsTable.isEmpty()) {
return editor->project->mapLayoutsTable.first();
}
}
return QString();
}
QString MainWindow::getExistingDirectory(QString dir) {
return QFileDialog::getExistingDirectory(this, "Open Directory", dir, QFileDialog::ShowDirsOnly);
}
@ -707,7 +732,7 @@ bool MainWindow::setMap(QString map_name, bool scroll) {
connect(editor->layout, &Layout::layoutChanged, [this]() { onMapChanged(nullptr); });
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
setRecentMap(map_name);
setRecentMapConfig(map_name);
updateMapList();
Scripting::cb_MapOpened(map_name);
@ -741,6 +766,8 @@ bool MainWindow::setLayout(QString layoutId) {
updateTilesetEditor();
setRecentLayoutConfig(layoutId);
return true;
}
@ -825,10 +852,14 @@ void MainWindow::openWarpMap(QString map_name, int event_id, Event::Group event_
}
}
void MainWindow::setRecentMap(QString mapName) {
void MainWindow::setRecentMapConfig(QString mapName) {
userConfig.setRecentMap(mapName);
}
void MainWindow::setRecentLayoutConfig(QString layoutId) {
userConfig.setRecentLayout(layoutId);
}
void MainWindow::displayMapProperties() {
// Block signals to the comboboxes while they are being modified
const QSignalBlocker blocker1(ui->comboBox_Song);