From 885695e7051f2fca313acd56b9d430ca226c94df Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 6 Sep 2023 14:45:46 -0400 Subject: [PATCH] Clean up for new editor windows --- forms/aboutporymap.ui | 2 +- forms/customscriptseditor.ui | 2 +- forms/customscriptslistitem.ui | 3 ++ forms/projectsettingseditor.ui | 59 ++++++++++++++++++-------------- include/config.h | 4 +++ include/ui/customscriptseditor.h | 4 +-- src/config.cpp | 21 ++++++++++++ src/ui/customscriptseditor.cpp | 17 +++++---- src/ui/projectsettingseditor.cpp | 9 +++-- 9 files changed, 81 insertions(+), 40 deletions(-) diff --git a/forms/aboutporymap.ui b/forms/aboutporymap.ui index 546d0817..26fd3f0a 100644 --- a/forms/aboutporymap.ui +++ b/forms/aboutporymap.ui @@ -78,7 +78,7 @@ - <html><head/><body><p>Official Documentation: <a href="https://huderlem.github.io/porymap/"><span style=" text-decoration: underline; color:#0000ff;">https://huderlem.github.io/porymap/</span></a></p></body></html> + <html><head/><body><p>Official Documentation: <a href="https://huderlem.github.io/porymap/"><span style=" text-decoration: underline;">https://huderlem.github.io/porymap/</span></a></p></body></html> Qt::AlignCenter diff --git a/forms/customscriptseditor.ui b/forms/customscriptseditor.ui index 12acb332..8166ed8d 100644 --- a/forms/customscriptseditor.ui +++ b/forms/customscriptseditor.ui @@ -89,7 +89,7 @@ - <html><head/><body><p><a href="https://huderlem.github.io/porymap/manual/scripting-capabilities.html"><span style=" text-decoration: underline; color:#0000ff;">What are custom scripts?</span></a></p></body></html> + <html><head/><body><p><a href="https://huderlem.github.io/porymap/manual/scripting-capabilities.html"><span style=" text-decoration: underline;">What are custom scripts?</span></a></p></body></html> true diff --git a/forms/customscriptslistitem.ui b/forms/customscriptslistitem.ui index c6040aa1..7c7e8794 100644 --- a/forms/customscriptslistitem.ui +++ b/forms/customscriptslistitem.ui @@ -52,6 +52,9 @@ + + If unchecked this script will be ignored + diff --git a/forms/projectsettingseditor.ui b/forms/projectsettingseditor.ui index f2e86018..78f9e61a 100644 --- a/forms/projectsettingseditor.ui +++ b/forms/projectsettingseditor.ui @@ -42,7 +42,7 @@ - + Whether map script files should prefer using .pory Use Poryscript @@ -95,13 +95,14 @@ - + + + A comma-separated list of metatile values that will be used to fill new map borders + + - - The default elevation that will be used to fill new maps - Elevation @@ -131,13 +132,14 @@ - + + + The default elevation that will be used to fill new maps + + - - The default metatile value that will be used to fill new maps - Fill Metatile @@ -145,9 +147,6 @@ - - A comma-separated list of metatile values that will be used to fill new map borders - Border Metatiles @@ -155,6 +154,9 @@ + + The default metatile value that will be used to fill new maps + 0x @@ -198,13 +200,20 @@ + + Restore the data in the prefabs file to the version defaults. Will create a new file if one doesn't exist. + Import Defaults - + + + The file that will be used to populate the Prefabs tab + + @@ -301,6 +310,9 @@ + + The mask used to read/write Terrain Type from the metatile's attributes data. If 0, this attribute is disabled. + 0x @@ -321,9 +333,6 @@ - - The mask used to read/write Terrain Type from the metatile's attributes data. If 0, this attribute is disabled. - Terrain Type mask @@ -351,9 +360,6 @@ - - The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled. - Behavior mask @@ -361,6 +367,9 @@ + + The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled. + 0x @@ -391,6 +400,9 @@ + + The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled. + 0x @@ -401,9 +413,6 @@ - - The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled. - Encounter Type mask @@ -411,9 +420,6 @@ - - The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled. - Layer Type mask @@ -421,6 +427,9 @@ + + The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled. + 0x diff --git a/include/config.h b/include/config.h index 8ce5e2d2..11d503a5 100644 --- a/include/config.h +++ b/include/config.h @@ -74,6 +74,7 @@ public: void setPaletteEditorGeometry(QByteArray, QByteArray); void setRegionMapEditorGeometry(QByteArray, QByteArray); void setProjectSettingsEditorGeometry(QByteArray, QByteArray); + void setCustomScriptsEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); void setMetatilesZoom(int zoom); void setShowPlayerView(bool enabled); @@ -95,6 +96,7 @@ public: QMap getPaletteEditorGeometry(); QMap getRegionMapEditorGeometry(); QMap getProjectSettingsEditorGeometry(); + QMap getCustomScriptsEditorGeometry(); int getCollisionOpacity(); int getMetatilesZoom(); bool getShowPlayerView(); @@ -133,6 +135,8 @@ private: QByteArray regionMapEditorState; QByteArray projectSettingsEditorGeometry; QByteArray projectSettingsEditorState; + QByteArray customScriptsEditorGeometry; + QByteArray customScriptsEditorState; int collisionOpacity; int metatilesZoom; bool showPlayerView; diff --git a/include/ui/customscriptseditor.h b/include/ui/customscriptseditor.h index a2482fc3..fd92b306 100644 --- a/include/ui/customscriptseditor.h +++ b/include/ui/customscriptseditor.h @@ -33,19 +33,17 @@ private: void displayScript(const QString &filepath, bool enabled); QString chooseScript(QString dir); - void removeScript(QListWidgetItem * item); void replaceScript(QListWidgetItem * item); void openScript(QListWidgetItem * item); QString getScriptFilepath(QListWidgetItem * item, bool absolutePath = true) const; void setScriptFilepath(QListWidgetItem * item, QString filepath) const; bool getScriptEnabled(QListWidgetItem * item) const; - void markEdited(); int prompt(const QString &text, QMessageBox::StandardButton defaultButton); void save(); void closeEvent(QCloseEvent*); - + void restoreWindowState(); void initShortcuts(); QObjectList shortcutableObjects() const; void applyUserShortcuts(); diff --git a/src/config.cpp b/src/config.cpp index 6e2193f2..6bfd50a9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -238,6 +238,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->projectSettingsEditorGeometry = bytesFromString(value); } else if (key == "project_settings_editor_state") { this->projectSettingsEditorState = bytesFromString(value); + } else if (key == "custom_scripts_editor_geometry") { + this->customScriptsEditorGeometry = bytesFromString(value); + } else if (key == "custom_scripts_editor_state") { + this->customScriptsEditorState = bytesFromString(value); } else if (key == "metatiles_zoom") { this->metatilesZoom = getConfigInteger(key, value, 10, 100, 30); } else if (key == "show_player_view") { @@ -286,6 +290,8 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("region_map_editor_state", stringFromByteArray(this->regionMapEditorState)); map.insert("project_settings_editor_geometry", stringFromByteArray(this->projectSettingsEditorGeometry)); map.insert("project_settings_editor_state", stringFromByteArray(this->projectSettingsEditorState)); + map.insert("custom_scripts_editor_geometry", stringFromByteArray(this->customScriptsEditorGeometry)); + map.insert("custom_scripts_editor_state", stringFromByteArray(this->customScriptsEditorState)); 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"); @@ -382,6 +388,12 @@ void PorymapConfig::setProjectSettingsEditorGeometry(QByteArray projectSettingsE this->save(); } +void PorymapConfig::setCustomScriptsEditorGeometry(QByteArray customScriptsEditorGeometry_, QByteArray customScriptsEditorState_) { + this->customScriptsEditorGeometry = customScriptsEditorGeometry_; + this->customScriptsEditorState = customScriptsEditorState_; + this->save(); +} + void PorymapConfig::setCollisionOpacity(int opacity) { this->collisionOpacity = opacity; // don't auto-save here because this can be called very frequently. @@ -494,6 +506,15 @@ QMap PorymapConfig::getProjectSettingsEditorGeometry() { return geometry; } +QMap PorymapConfig::getCustomScriptsEditorGeometry() { + QMap geometry; + + geometry.insert("custom_scripts_editor_geometry", this->customScriptsEditorGeometry); + geometry.insert("custom_scripts_editor_state", this->customScriptsEditorState); + + return geometry; +} + int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } diff --git a/src/ui/customscriptseditor.cpp b/src/ui/customscriptseditor.cpp index d2ad791d..addb443c 100644 --- a/src/ui/customscriptseditor.cpp +++ b/src/ui/customscriptseditor.cpp @@ -8,9 +8,6 @@ #include #include -// TODO: Better URL colors on dark themes -// TODO: Save window state - CustomScriptsEditor::CustomScriptsEditor(QWidget *parent) : QMainWindow(parent), ui(new Ui::CustomScriptsEditor), @@ -33,6 +30,7 @@ CustomScriptsEditor::CustomScriptsEditor(QWidget *parent) : connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &CustomScriptsEditor::dialogButtonClicked); this->initShortcuts(); + this->restoreWindowState(); } CustomScriptsEditor::~CustomScriptsEditor() @@ -90,6 +88,13 @@ void CustomScriptsEditor::applyUserShortcuts() { shortcut->setKeys(shortcutsConfig.userShortcuts(shortcut)); } +void CustomScriptsEditor::restoreWindowState() { + logInfo("Restoring custom scripts editor geometry from previous session."); + const QMap geometry = porymapConfig.getCustomScriptsEditorGeometry(); + this->restoreGeometry(geometry.value("custom_scripts_editor_geometry")); + this->restoreState(geometry.value("custom_scripts_editor_state")); +} + void CustomScriptsEditor::displayScript(const QString &filepath, bool enabled) { auto item = new QListWidgetItem(); auto widget = new CustomScriptsListItem(); @@ -243,11 +248,9 @@ void CustomScriptsEditor::closeEvent(QCloseEvent* event) { if (result == QMessageBox::Yes) this->save(); } -/* - // TODO - porymapConfig.setProjectSettingsEditorGeometry( + + porymapConfig.setCustomScriptsEditorGeometry( this->saveGeometry(), this->saveState() ); -*/ } diff --git a/src/ui/projectsettingseditor.cpp b/src/ui/projectsettingseditor.cpp index bf8d17ae..9318838c 100644 --- a/src/ui/projectsettingseditor.cpp +++ b/src/ui/projectsettingseditor.cpp @@ -29,8 +29,6 @@ ProjectSettingsEditor::~ProjectSettingsEditor() delete ui; } -// TODO: Move tool tips to editable areas - void ProjectSettingsEditor::connectSignals() { connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &ProjectSettingsEditor::dialogButtonClicked); connect(ui->button_ChoosePrefabs, &QAbstractButton::clicked, this, &ProjectSettingsEditor::choosePrefabsFileClicked); @@ -178,7 +176,7 @@ void ProjectSettingsEditor::save() { this->projectNeedsReload = true; } -// TODO: If the selected file is in the project directory use a relative path +// Pick a file to use as the new prefabs file path void ProjectSettingsEditor::choosePrefabsFileClicked(bool) { QString startPath = this->project->importExportPath; QFileInfo fileInfo(ui->lineEdit_PrefabsPath->text()); @@ -190,6 +188,11 @@ void ProjectSettingsEditor::choosePrefabsFileClicked(bool) { if (filepath.isEmpty()) return; this->project->setImportExportPath(filepath); + + // Display relative path if this file is in the project folder + const QString projectDir = projectConfig.getProjectDir() + QDir::separator(); + if (filepath.startsWith(projectDir)) + filepath.remove(0, projectDir.length()); ui->lineEdit_PrefabsPath->setText(filepath); this->hasUnsavedChanges = true; }