preserve layout in config
This commit is contained in:
parent
e79b6e2fca
commit
f485ebdd3e
5 changed files with 64 additions and 11 deletions
|
@ -344,12 +344,15 @@ public:
|
||||||
}
|
}
|
||||||
virtual void reset() override {
|
virtual void reset() override {
|
||||||
this->recentMap = QString();
|
this->recentMap = QString();
|
||||||
|
this->recentLayout = QString();
|
||||||
this->useEncounterJson = true;
|
this->useEncounterJson = true;
|
||||||
this->customScripts.clear();
|
this->customScripts.clear();
|
||||||
this->readKeys.clear();
|
this->readKeys.clear();
|
||||||
}
|
}
|
||||||
void setRecentMap(const QString &map);
|
void setRecentMap(const QString &map);
|
||||||
QString getRecentMap();
|
QString getRecentMap();
|
||||||
|
void setRecentLayout(const QString &map);
|
||||||
|
QString getRecentLayout();
|
||||||
void setEncounterJsonActive(bool active);
|
void setEncounterJsonActive(bool active);
|
||||||
bool getEncounterJsonActive();
|
bool getEncounterJsonActive();
|
||||||
void setProjectDir(QString projectDir);
|
void setProjectDir(QString projectDir);
|
||||||
|
@ -371,6 +374,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
QString projectDir;
|
QString projectDir;
|
||||||
QString recentMap;
|
QString recentMap;
|
||||||
|
QString recentLayout;
|
||||||
bool useEncounterJson;
|
bool useEncounterJson;
|
||||||
QMap<QString, bool> customScripts;
|
QMap<QString, bool> customScripts;
|
||||||
QStringList readKeys;
|
QStringList readKeys;
|
||||||
|
|
|
@ -357,10 +357,12 @@ private:
|
||||||
|
|
||||||
bool tilesetNeedsRedraw = false;
|
bool tilesetNeedsRedraw = false;
|
||||||
|
|
||||||
|
bool setDefaultView();
|
||||||
|
bool setRecentView();
|
||||||
bool setLayout(QString layoutId);
|
bool setLayout(QString layoutId);
|
||||||
|
|
||||||
bool setMap(QString, bool scroll = false);
|
bool setMap(QString, bool scroll = false);
|
||||||
void unsetMap();
|
void unsetMap();
|
||||||
|
|
||||||
void redrawMapScene();
|
void redrawMapScene();
|
||||||
void redrawLayoutScene();
|
void redrawLayoutScene();
|
||||||
void refreshMapScene();
|
void refreshMapScene();
|
||||||
|
@ -373,7 +375,9 @@ private:
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
bool openProject(QString dir);
|
bool openProject(QString dir);
|
||||||
QString getDefaultMap();
|
QString getDefaultMap();
|
||||||
void setRecentMap(QString map_name);
|
QString getDefaultLayout();
|
||||||
|
void setRecentMapConfig(QString map_name);
|
||||||
|
void setRecentLayoutConfig(QString layoutId);
|
||||||
|
|
||||||
void updateMapList();
|
void updateMapList();
|
||||||
|
|
||||||
|
|
|
@ -1102,6 +1102,8 @@ QString UserConfig::getConfigFilepath() {
|
||||||
void UserConfig::parseConfigKeyValue(QString key, QString value) {
|
void UserConfig::parseConfigKeyValue(QString key, QString value) {
|
||||||
if (key == "recent_map") {
|
if (key == "recent_map") {
|
||||||
this->recentMap = value;
|
this->recentMap = value;
|
||||||
|
} else if (key == "recent_layout") {
|
||||||
|
this->recentLayout = value;
|
||||||
} else if (key == "use_encounter_json") {
|
} else if (key == "use_encounter_json") {
|
||||||
this->useEncounterJson = getConfigBool(key, value);
|
this->useEncounterJson = getConfigBool(key, value);
|
||||||
} else if (key == "custom_scripts") {
|
} else if (key == "custom_scripts") {
|
||||||
|
@ -1118,6 +1120,7 @@ void UserConfig::setUnreadKeys() {
|
||||||
QMap<QString, QString> UserConfig::getKeyValueMap() {
|
QMap<QString, QString> UserConfig::getKeyValueMap() {
|
||||||
QMap<QString, QString> map;
|
QMap<QString, QString> map;
|
||||||
map.insert("recent_map", this->recentMap);
|
map.insert("recent_map", this->recentMap);
|
||||||
|
map.insert("recent_layout", this->recentLayout);
|
||||||
map.insert("use_encounter_json", QString::number(this->useEncounterJson));
|
map.insert("use_encounter_json", QString::number(this->useEncounterJson));
|
||||||
map.insert("custom_scripts", this->outputCustomScripts());
|
map.insert("custom_scripts", this->outputCustomScripts());
|
||||||
return map;
|
return map;
|
||||||
|
@ -1146,6 +1149,15 @@ QString UserConfig::getRecentMap() {
|
||||||
return this->recentMap;
|
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) {
|
void UserConfig::setEncounterJsonActive(bool active) {
|
||||||
this->useEncounterJson = active;
|
this->useEncounterJson = active;
|
||||||
this->save();
|
this->save();
|
||||||
|
|
|
@ -1164,6 +1164,8 @@ bool Editor::setMap(QString map_name) {
|
||||||
|
|
||||||
bool Editor::setLayout(QString layoutId) {
|
bool Editor::setLayout(QString layoutId) {
|
||||||
//
|
//
|
||||||
|
if (layoutId.isEmpty()) return false;
|
||||||
|
|
||||||
this->layout = this->project->loadLayout(layoutId);
|
this->layout = this->project->loadLayout(layoutId);
|
||||||
|
|
||||||
if (!displayLayout()) {
|
if (!displayLayout()) {
|
||||||
|
|
|
@ -342,8 +342,8 @@ void MainWindow::initMiscHeapObjects() {
|
||||||
// !TODO: scroll view on first showing
|
// !TODO: scroll view on first showing
|
||||||
void MainWindow::initMapSortOrder() {
|
void MainWindow::initMapSortOrder() {
|
||||||
mapSortOrder = porymapConfig.getMapSortOrder();
|
mapSortOrder = porymapConfig.getMapSortOrder();
|
||||||
if (mapSortOrder == MapSortOrder::SortByLayout)
|
// if (mapSortOrder == MapSortOrder::SortByLayout)
|
||||||
mapSortOrder = MapSortOrder::SortByGroup;
|
// mapSortOrder = MapSortOrder::SortByGroup;
|
||||||
|
|
||||||
this->ui->mapListContainer->setCurrentIndex(static_cast<int>(this->mapSortOrder));
|
this->ui->mapListContainer->setCurrentIndex(static_cast<int>(this->mapSortOrder));
|
||||||
}
|
}
|
||||||
|
@ -541,16 +541,13 @@ bool MainWindow::openProject(QString dir) {
|
||||||
this->preferenceEditor->updateFields();
|
this->preferenceEditor->updateFields();
|
||||||
});
|
});
|
||||||
editor->project->set_root(dir);
|
editor->project->set_root(dir);
|
||||||
success = loadDataStructures()
|
success = loadDataStructures() && populateMapList() && setDefaultView();
|
||||||
&& populateMapList()
|
|
||||||
&& setMap(getDefaultMap(), true);
|
|
||||||
} else {
|
} else {
|
||||||
QString open_map = editor->map->name;
|
|
||||||
editor->project->fileWatcher.removePaths(editor->project->fileWatcher.files());
|
editor->project->fileWatcher.removePaths(editor->project->fileWatcher.files());
|
||||||
editor->project->clearLayoutsTable();
|
editor->project->clearLayoutsTable();
|
||||||
editor->project->clearMapCache();
|
editor->project->clearMapCache();
|
||||||
editor->project->clearTilesetCache();
|
editor->project->clearTilesetCache();
|
||||||
success = loadDataStructures() && populateMapList() && setMap(open_map, true);
|
success = loadDataStructures() && populateMapList() && setRecentView();
|
||||||
}
|
}
|
||||||
|
|
||||||
projectOpenFailure = !success;
|
projectOpenFailure = !success;
|
||||||
|
@ -581,6 +578,22 @@ bool MainWindow::isProjectOpen() {
|
||||||
return !projectOpenFailure && editor && editor->project;
|
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() {
|
QString MainWindow::getDefaultMap() {
|
||||||
if (editor && editor->project) {
|
if (editor && editor->project) {
|
||||||
QList<QStringList> names = editor->project->groupedMapNames;
|
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) {
|
QString MainWindow::getExistingDirectory(QString dir) {
|
||||||
return QFileDialog::getExistingDirectory(this, "Open Directory", dir, QFileDialog::ShowDirsOnly);
|
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::layoutChanged, [this]() { onMapChanged(nullptr); });
|
||||||
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
|
connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing);
|
||||||
|
|
||||||
setRecentMap(map_name);
|
setRecentMapConfig(map_name);
|
||||||
updateMapList();
|
updateMapList();
|
||||||
|
|
||||||
Scripting::cb_MapOpened(map_name);
|
Scripting::cb_MapOpened(map_name);
|
||||||
|
@ -741,6 +766,8 @@ bool MainWindow::setLayout(QString layoutId) {
|
||||||
|
|
||||||
updateTilesetEditor();
|
updateTilesetEditor();
|
||||||
|
|
||||||
|
setRecentLayoutConfig(layoutId);
|
||||||
|
|
||||||
return true;
|
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);
|
userConfig.setRecentMap(mapName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setRecentLayoutConfig(QString layoutId) {
|
||||||
|
userConfig.setRecentLayout(layoutId);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::displayMapProperties() {
|
void MainWindow::displayMapProperties() {
|
||||||
// Block signals to the comboboxes while they are being modified
|
// Block signals to the comboboxes while they are being modified
|
||||||
const QSignalBlocker blocker1(ui->comboBox_Song);
|
const QSignalBlocker blocker1(ui->comboBox_Song);
|
||||||
|
|
Loading…
Reference in a new issue