From 880dabade39adc9c28fb37500d9f05168191827e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Feb 2023 13:15:02 -0500 Subject: [PATCH] Add script action warning --- include/config.h | 4 ++++ src/config.cpp | 12 ++++++++++++ src/scriptapi/scripting.cpp | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index 27beb112..24d88a1e 100644 --- a/include/config.h +++ b/include/config.h @@ -62,6 +62,7 @@ public: this->textEditorOpenFolder = ""; this->textEditorGotoLine = ""; this->warnScriptLoad = true; + this->warnScriptAction = true; } void setRecentProject(QString project); void setReopenOnLaunch(bool enabled); @@ -80,6 +81,7 @@ public: void setMonitorFiles(bool monitor); void setTilesetCheckerboardFill(bool checkerboard); void setWarnScriptLoad(bool enabled); + void setWarnScriptAction(bool enabled); void setTheme(QString theme); void setTextEditorOpenFolder(const QString &command); void setTextEditorGotoLine(const QString &command); @@ -100,6 +102,7 @@ public: bool getMonitorFiles(); bool getTilesetCheckerboardFill(); bool getWarnScriptLoad(); + bool getWarnScriptAction(); QString getTheme(); QString getTextEditorOpenFolder(); QString getTextEditorGotoLine(); @@ -136,6 +139,7 @@ private: bool monitorFiles; bool tilesetCheckerboardFill; bool warnScriptLoad; + bool warnScriptAction; QString theme; QString textEditorOpenFolder; QString textEditorGotoLine; diff --git a/src/config.cpp b/src/config.cpp index 780e0389..a7269026 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -242,6 +242,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->tilesetCheckerboardFill = getConfigBool(key, value); } else if (key == "warn_script_load") { this->warnScriptLoad = getConfigBool(key, value); + } else if (key == "warn_script_action") { + this->warnScriptAction = getConfigBool(key, value); } else if (key == "theme") { this->theme = value; } else if (key == "text_editor_open_directory") { @@ -278,6 +280,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("monitor_files", this->monitorFiles ? "1" : "0"); map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0"); map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0"); + map.insert("warn_script_action", this->warnScriptAction ? "1" : "0"); map.insert("theme", this->theme); map.insert("text_editor_open_directory", this->textEditorOpenFolder); map.insert("text_editor_goto_line", this->textEditorGotoLine); @@ -337,6 +340,11 @@ void PorymapConfig::setWarnScriptLoad(bool enabled) { this->save(); } +void PorymapConfig::setWarnScriptAction(bool enabled) { + this->warnScriptAction = enabled; + this->save(); +} + void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { this->mainWindowGeometry = mainWindowGeometry_; @@ -498,6 +506,10 @@ bool PorymapConfig::getWarnScriptLoad() { return this->warnScriptLoad; } +bool PorymapConfig::getWarnScriptAction() { + return this->warnScriptAction; +} + QString PorymapConfig::getTheme() { return this->theme; } diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index a534c2e5..2680dc83 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -57,7 +57,6 @@ void Scripting::loadModules(QStringList moduleFiles) { messageBox.setDetailedText(getMostRecentError()); messageBox.setIcon(QMessageBox::Warning); messageBox.addButton(QMessageBox::Ok); - messageBox.setDefaultButton(QMessageBox::Ok); QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); messageBox.setCheckBox(checkbox); QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { @@ -159,8 +158,22 @@ void Scripting::invokeAction(QString actionName) { QJSValue result = callbackFunction.call(QJSValueList()); if (tryErrorJS(result)) continue; } - if (!foundFunction) + if (!foundFunction) { logError(QString("Unknown custom script function '%1'").arg(functionName)); + if (porymapConfig.getWarnScriptAction()) { + QMessageBox messageBox(instance->mainWindow); + messageBox.setText("Failed to run custom action"); + messageBox.setInformativeText(getMostRecentError()); + messageBox.setIcon(QMessageBox::Warning); + messageBox.addButton(QMessageBox::Ok); + QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); + messageBox.setCheckBox(checkbox); + QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { + porymapConfig.setWarnScriptAction(static_cast(state) != Qt::CheckState::Checked); + }); + messageBox.exec(); + } + } } void Scripting::cb_ProjectOpened(QString projectPath) {