Clean up for new editor windows

This commit is contained in:
GriffinR 2023-09-06 14:45:46 -04:00
parent 2aa18da255
commit 885695e705
9 changed files with 81 additions and 40 deletions

View file

@ -78,7 +78,7 @@
<item>
<widget class="QLabel" name="label_Manual">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Official Documentation: &lt;a href=&quot;https://huderlem.github.io/porymap/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://huderlem.github.io/porymap/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Official Documentation: &lt;a href=&quot;https://huderlem.github.io/porymap/&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;https://huderlem.github.io/porymap/&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>

View file

@ -89,7 +89,7 @@
<item>
<widget class="QLabel" name="label_Manual">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://huderlem.github.io/porymap/manual/scripting-capabilities.html&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;What are custom scripts?&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://huderlem.github.io/porymap/manual/scripting-capabilities.html&quot;&gt;&lt;span style=&quot; text-decoration: underline;&quot;&gt;What are custom scripts?&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>

View file

@ -52,6 +52,9 @@
</item>
<item>
<widget class="QCheckBox" name="checkBox_Enable">
<property name="toolTip">
<string>If unchecked this script will be ignored</string>
</property>
<property name="text">
<string/>
</property>

View file

@ -42,7 +42,7 @@
<item>
<widget class="QCheckBox" name="checkBox_UsePoryscript">
<property name="toolTip">
<string/>
<string>Whether map script files should prefer using .pory</string>
</property>
<property name="text">
<string>Use Poryscript</string>
@ -95,13 +95,14 @@
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="lineEdit_BorderMetatiles"/>
<widget class="QLineEdit" name="lineEdit_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
<property name="text">
<string>Elevation</string>
</property>
@ -131,13 +132,14 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_Elevation"/>
<widget class="QSpinBox" name="spinBox_Elevation">
<property name="toolTip">
<string>The default elevation that will be used to fill new maps</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
<property name="text">
<string>Fill Metatile</string>
</property>
@ -145,9 +147,6 @@
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_BorderMetatiles">
<property name="toolTip">
<string>A comma-separated list of metatile values that will be used to fill new map borders</string>
</property>
<property name="text">
<string>Border Metatiles</string>
</property>
@ -155,6 +154,9 @@
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_FillMetatile">
<property name="toolTip">
<string>The default metatile value that will be used to fill new maps</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
@ -198,13 +200,20 @@
</item>
<item row="1" column="0">
<widget class="QPushButton" name="button_ImportDefaultPrefabs">
<property name="toolTip">
<string>Restore the data in the prefabs file to the version defaults. Will create a new file if one doesn't exist.</string>
</property>
<property name="text">
<string>Import Defaults</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_PrefabsPath"/>
<widget class="QLineEdit" name="lineEdit_PrefabsPath">
<property name="toolTip">
<string>The file that will be used to populate the Prefabs tab</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_PrefabsPath">
@ -301,6 +310,9 @@
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="spinBox_TerrainTypeMask">
<property name="toolTip">
<string>The mask used to read/write Terrain Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
@ -321,9 +333,6 @@
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_TerrainTypeMask">
<property name="toolTip">
<string>The mask used to read/write Terrain Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Terrain Type mask</string>
</property>
@ -351,9 +360,6 @@
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_BehaviorMask">
<property name="toolTip">
<string>The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Behavior mask</string>
</property>
@ -361,6 +367,9 @@
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBox_BehaviorMask">
<property name="toolTip">
<string>The mask used to read/write Metatile Behavior from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
@ -391,6 +400,9 @@
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinBox_EncounterTypeMask">
<property name="toolTip">
<string>The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>
@ -401,9 +413,6 @@
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_EncounterTypeMask">
<property name="toolTip">
<string>The mask used to read/write Encounter Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Encounter Type mask</string>
</property>
@ -411,9 +420,6 @@
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_LayerTypeMask">
<property name="toolTip">
<string>The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="text">
<string>Layer Type mask</string>
</property>
@ -421,6 +427,9 @@
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinBox_LayerTypeMask">
<property name="toolTip">
<string>The mask used to read/write Layer Type from the metatile's attributes data. If 0, this attribute is disabled.</string>
</property>
<property name="prefix">
<string>0x</string>
</property>

View file

@ -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<QString, QByteArray> getPaletteEditorGeometry();
QMap<QString, QByteArray> getRegionMapEditorGeometry();
QMap<QString, QByteArray> getProjectSettingsEditorGeometry();
QMap<QString, QByteArray> 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;

View file

@ -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();

View file

@ -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<QString, QString> 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<QString, QByteArray> PorymapConfig::getProjectSettingsEditorGeometry() {
return geometry;
}
QMap<QString, QByteArray> PorymapConfig::getCustomScriptsEditorGeometry() {
QMap<QString, QByteArray> 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;
}

View file

@ -8,9 +8,6 @@
#include <QDir>
#include <QFileDialog>
// 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<QString, QByteArray> 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()
);
*/
}

View file

@ -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;
}