Save & restore tileset editor geometry & state from config
This commit is contained in:
parent
1ea50d7955
commit
5624de750b
4 changed files with 55 additions and 22 deletions
|
@ -50,7 +50,8 @@ public:
|
|||
void setRecentMap(QString map);
|
||||
void setMapSortOrder(MapSortOrder order);
|
||||
void setPrettyCursors(bool enabled);
|
||||
void setGeometry(QByteArray, QByteArray, QByteArray, QByteArray);
|
||||
void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray);
|
||||
void setTilesetEditorGeometry(QByteArray, QByteArray);
|
||||
void setCollisionOpacity(int opacity);
|
||||
void setMetatilesZoom(int zoom);
|
||||
void setShowPlayerView(bool enabled);
|
||||
|
@ -62,7 +63,8 @@ public:
|
|||
QString getRecentMap();
|
||||
MapSortOrder getMapSortOrder();
|
||||
bool getPrettyCursors();
|
||||
QMap<QString, QByteArray> getGeometry();
|
||||
QMap<QString, QByteArray> getMainGeometry();
|
||||
QMap<QString, QByteArray> getTilesetEditorGeometry();
|
||||
int getCollisionOpacity();
|
||||
int getMetatilesZoom();
|
||||
bool getShowPlayerView();
|
||||
|
@ -83,11 +85,13 @@ private:
|
|||
QByteArray bytesFromString(QString);
|
||||
MapSortOrder mapSortOrder;
|
||||
bool prettyCursors;
|
||||
QByteArray windowGeometry;
|
||||
QByteArray windowState;
|
||||
QByteArray mainWindowGeometry;
|
||||
QByteArray mainWindowState;
|
||||
QByteArray mapSplitterState;
|
||||
QByteArray eventsSlpitterState;
|
||||
QByteArray mainSplitterState;
|
||||
QByteArray tilesetEditorGeometry;
|
||||
QByteArray tilesetEditorState;
|
||||
int collisionOpacity;
|
||||
int metatilesZoom;
|
||||
bool showPlayerView;
|
||||
|
|
|
@ -122,10 +122,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
|||
this->mapSortOrder = MapSortOrder::Group;
|
||||
logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value));
|
||||
}
|
||||
} else if (key == "window_geometry") {
|
||||
this->windowGeometry = bytesFromString(value);
|
||||
} else if (key == "window_state") {
|
||||
this->windowState = bytesFromString(value);
|
||||
} else if (key == "main_window_geometry") {
|
||||
this->mainWindowGeometry = bytesFromString(value);
|
||||
} else if (key == "main_window_state") {
|
||||
this->mainWindowState = bytesFromString(value);
|
||||
} else if (key == "map_splitter_state") {
|
||||
this->mapSplitterState = bytesFromString(value);
|
||||
} else if (key == "main_splitter_state") {
|
||||
|
@ -137,6 +137,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
|
|||
logWarn(QString("Invalid config value for collision_opacity: '%1'. Must be an integer.").arg(value));
|
||||
this->collisionOpacity = 50;
|
||||
}
|
||||
} else if (key == "tileset_editor_geometry") {
|
||||
this->tilesetEditorGeometry = bytesFromString(value);
|
||||
} else if (key == "tileset_editor_state") {
|
||||
this->tilesetEditorState = bytesFromString(value);
|
||||
} else if (key == "metatiles_zoom") {
|
||||
bool ok;
|
||||
this->metatilesZoom = qMax(10, qMin(100, value.toInt(&ok)));
|
||||
|
@ -186,10 +190,12 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
|
|||
map.insert("recent_map", this->recentMap);
|
||||
map.insert("pretty_cursors", this->prettyCursors ? "1" : "0");
|
||||
map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder));
|
||||
map.insert("window_geometry", stringFromByteArray(this->windowGeometry));
|
||||
map.insert("window_state", stringFromByteArray(this->windowState));
|
||||
map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry));
|
||||
map.insert("main_window_state", stringFromByteArray(this->mainWindowState));
|
||||
map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState));
|
||||
map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState));
|
||||
map.insert("tileset_editor_geometry", stringFromByteArray(this->tilesetEditorGeometry));
|
||||
map.insert("tileset_editor_state", stringFromByteArray(this->tilesetEditorState));
|
||||
map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity));
|
||||
map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom));
|
||||
map.insert("show_player_view", this->showPlayerView ? "1" : "0");
|
||||
|
@ -243,15 +249,21 @@ void PorymapConfig::setMonitorFiles(bool monitor) {
|
|||
this->save();
|
||||
}
|
||||
|
||||
void PorymapConfig::setGeometry(QByteArray windowGeometry_, QByteArray windowState_,
|
||||
void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_,
|
||||
QByteArray mapSplitterState_, QByteArray mainSplitterState_) {
|
||||
this->windowGeometry = windowGeometry_;
|
||||
this->windowState = windowState_;
|
||||
this->mainWindowGeometry = mainWindowGeometry_;
|
||||
this->mainWindowState = mainWindowState_;
|
||||
this->mapSplitterState = mapSplitterState_;
|
||||
this->mainSplitterState = mainSplitterState_;
|
||||
this->save();
|
||||
}
|
||||
|
||||
void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_, QByteArray tilesetEditorState_) {
|
||||
this->tilesetEditorGeometry = tilesetEditorGeometry_;
|
||||
this->tilesetEditorState = tilesetEditorState_;
|
||||
this->save();
|
||||
}
|
||||
|
||||
void PorymapConfig::setCollisionOpacity(int opacity) {
|
||||
this->collisionOpacity = opacity;
|
||||
// don't auto-save here because this can be called very frequently.
|
||||
|
@ -296,17 +308,26 @@ bool PorymapConfig::getPrettyCursors() {
|
|||
return this->prettyCursors;
|
||||
}
|
||||
|
||||
QMap<QString, QByteArray> PorymapConfig::getGeometry() {
|
||||
QMap<QString, QByteArray> PorymapConfig::getMainGeometry() {
|
||||
QMap<QString, QByteArray> geometry;
|
||||
|
||||
geometry.insert("window_geometry", this->windowGeometry);
|
||||
geometry.insert("window_state", this->windowState);
|
||||
geometry.insert("main_window_geometry", this->mainWindowGeometry);
|
||||
geometry.insert("main_window_state", this->mainWindowState);
|
||||
geometry.insert("map_splitter_state", this->mapSplitterState);
|
||||
geometry.insert("main_splitter_state", this->mainSplitterState);
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
QMap<QString, QByteArray> PorymapConfig::getTilesetEditorGeometry() {
|
||||
QMap<QString, QByteArray> geometry;
|
||||
|
||||
geometry.insert("tileset_editor_geometry", this->tilesetEditorGeometry);
|
||||
geometry.insert("tileset_editor_state", this->tilesetEditorState);
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
int PorymapConfig::getCollisionOpacity() {
|
||||
return this->collisionOpacity;
|
||||
}
|
||||
|
|
|
@ -350,10 +350,10 @@ void MainWindow::loadUserSettings() {
|
|||
}
|
||||
|
||||
void MainWindow::restoreWindowState() {
|
||||
logInfo("Restoring window geometry from previous session.");
|
||||
QMap<QString, QByteArray> geometry = porymapConfig.getGeometry();
|
||||
this->restoreGeometry(geometry.value("window_geometry"));
|
||||
this->restoreState(geometry.value("window_state"));
|
||||
logInfo("Restoring main window geometry from previous session.");
|
||||
QMap<QString, QByteArray> geometry = porymapConfig.getMainGeometry();
|
||||
this->restoreGeometry(geometry.value("main_window_geometry"));
|
||||
this->restoreState(geometry.value("main_window_state"));
|
||||
this->ui->splitter_map->restoreState(geometry.value("map_splitter_state"));
|
||||
this->ui->splitter_main->restoreState(geometry.value("main_splitter_state"));
|
||||
}
|
||||
|
@ -2518,7 +2518,10 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
|||
this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this);
|
||||
connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString)));
|
||||
connect(this->tilesetEditor, &QObject::destroyed, [=](QObject *) { this->tilesetEditor = nullptr; });
|
||||
this->tilesetEditor->setAttribute(Qt::WA_DeleteOnClose);
|
||||
logInfo("Restoring tileset editor geometry from previous session.");
|
||||
QMap<QString, QByteArray> geometry = porymapConfig.getTilesetEditorGeometry();
|
||||
this->tilesetEditor->restoreGeometry(geometry.value("tileset_editor_geometry"));
|
||||
this->tilesetEditor->restoreState(geometry.value("tileset_editor_state"));
|
||||
}
|
||||
|
||||
if (!this->tilesetEditor->isVisible()) {
|
||||
|
@ -2697,7 +2700,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||
}
|
||||
}
|
||||
|
||||
porymapConfig.setGeometry(
|
||||
porymapConfig.setMainGeometry(
|
||||
this->saveGeometry(),
|
||||
this->saveState(),
|
||||
this->ui->splitter_map->saveState(),
|
||||
|
|
|
@ -606,6 +606,11 @@ void TilesetEditor::closeEvent(QCloseEvent *event)
|
|||
} else {
|
||||
event->accept();
|
||||
}
|
||||
|
||||
porymapConfig.setTilesetEditorGeometry(
|
||||
this->saveGeometry(),
|
||||
this->saveState()
|
||||
);
|
||||
}
|
||||
|
||||
void TilesetEditor::on_actionChange_Metatiles_Count_triggered()
|
||||
|
|
Loading…
Reference in a new issue