Save & restore region map editor geometry & state from config

This commit is contained in:
BigBahss 2020-09-15 19:03:15 -04:00 committed by huderlem
parent 5624de750b
commit daae6fe52b
4 changed files with 34 additions and 1 deletions

View file

@ -52,6 +52,7 @@ public:
void setPrettyCursors(bool enabled);
void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray);
void setTilesetEditorGeometry(QByteArray, QByteArray);
void setRegionMapEditorGeometry(QByteArray, QByteArray);
void setCollisionOpacity(int opacity);
void setMetatilesZoom(int zoom);
void setShowPlayerView(bool enabled);
@ -65,6 +66,7 @@ public:
bool getPrettyCursors();
QMap<QString, QByteArray> getMainGeometry();
QMap<QString, QByteArray> getTilesetEditorGeometry();
QMap<QString, QByteArray> getRegionMapEditorGeometry();
int getCollisionOpacity();
int getMetatilesZoom();
bool getShowPlayerView();
@ -92,6 +94,8 @@ private:
QByteArray mainSplitterState;
QByteArray tilesetEditorGeometry;
QByteArray tilesetEditorState;
QByteArray regionMapEditorGeometry;
QByteArray regionMapEditorState;
int collisionOpacity;
int metatilesZoom;
bool showPlayerView;

View file

@ -141,6 +141,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->tilesetEditorGeometry = bytesFromString(value);
} else if (key == "tileset_editor_state") {
this->tilesetEditorState = bytesFromString(value);
} else if (key == "region_map_editor_geometry") {
this->regionMapEditorGeometry = bytesFromString(value);
} else if (key == "region_map_editor_state") {
this->regionMapEditorState = bytesFromString(value);
} else if (key == "metatiles_zoom") {
bool ok;
this->metatilesZoom = qMax(10, qMin(100, value.toInt(&ok)));
@ -196,6 +200,8 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
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("region_map_editor_geometry", stringFromByteArray(this->regionMapEditorGeometry));
map.insert("region_map_editor_state", stringFromByteArray(this->regionMapEditorState));
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");
@ -264,6 +270,12 @@ void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_,
this->save();
}
void PorymapConfig::setRegionMapEditorGeometry(QByteArray regionMapEditorGeometry_, QByteArray regionMapEditorState_) {
this->regionMapEditorGeometry = regionMapEditorGeometry_;
this->regionMapEditorState = regionMapEditorState_;
this->save();
}
void PorymapConfig::setCollisionOpacity(int opacity) {
this->collisionOpacity = opacity;
// don't auto-save here because this can be called very frequently.
@ -328,6 +340,15 @@ QMap<QString, QByteArray> PorymapConfig::getTilesetEditorGeometry() {
return geometry;
}
QMap<QString, QByteArray> PorymapConfig::getRegionMapEditorGeometry() {
QMap<QString, QByteArray> geometry;
geometry.insert("region_map_editor_geometry", this->regionMapEditorGeometry);
geometry.insert("region_map_editor_state", this->regionMapEditorState);
return geometry;
}
int PorymapConfig::getCollisionOpacity() {
return this->collisionOpacity;
}

View file

@ -2661,7 +2661,10 @@ void MainWindow::on_actionRegion_Map_Editor_triggered() {
return;
}
connect(this->regionMapEditor, &QObject::destroyed, [=](QObject *) { this->regionMapEditor = nullptr; });
this->regionMapEditor->setAttribute(Qt::WA_DeleteOnClose);
logInfo("Restoring region map editor geometry from previous session.");
QMap<QString, QByteArray> geometry = porymapConfig.getRegionMapEditorGeometry();
this->regionMapEditor->restoreGeometry(geometry.value("region_map_editor_geometry"));
this->regionMapEditor->restoreState(geometry.value("region_map_editor_state"));
}
if (!this->regionMapEditor->isVisible()) {

View file

@ -899,6 +899,11 @@ void RegionMapEditor::closeEvent(QCloseEvent *event)
} else {
event->accept();
}
porymapConfig.setRegionMapEditorGeometry(
this->saveGeometry(),
this->saveState()
);
}
void RegionMapEditor::on_verticalSlider_Zoom_Map_Image_valueChanged(int val) {