mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
Custom Scripts -> Plugins
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled
This commit is contained in:
27
include/api/pluginsettings.h
Normal file
27
include/api/pluginsettings.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#ifndef PLUGINSETTINGS_H
|
||||
#define PLUGINSETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
// Holds the basic user-provided information about a plugin.
|
||||
struct PluginSettings {
|
||||
QString path;
|
||||
bool enabled = true;
|
||||
|
||||
// Plugins can either be specific to the project, or specific to the user.
|
||||
// This allows projects to send plugin scripts downstream to their users,
|
||||
// while still allowing them to use their own personal plugins.
|
||||
bool userOnly = true;
|
||||
|
||||
static QStringList filter(const QList<PluginSettings>& plugins) {
|
||||
QStringList paths;
|
||||
for (auto& plugin : plugins) {
|
||||
if (plugin.enabled) paths.append(plugin.path);
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PLUGINSETTINGS_H
|
||||
@@ -21,7 +21,7 @@ class MainWindow;
|
||||
#ifdef QT_QML_LIB
|
||||
|
||||
// !! New callback functions or changes to existing callback function names/arguments
|
||||
// should be synced to resources/text/script_template.txt and docsrc/manual/scripting-capabilities.rst
|
||||
// should be synced to resources/text/plugin_template.txt and docsrc/manual/scripting-capabilities.rst
|
||||
class Scripting : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -50,7 +50,8 @@ public:
|
||||
Q_INVOKABLE bool getBorderVisibility();
|
||||
Q_INVOKABLE void setSmartPathsEnabled(bool visible);
|
||||
Q_INVOKABLE bool getSmartPathsEnabled();
|
||||
static Q_INVOKABLE QList<QString> getCustomScripts();
|
||||
static Q_INVOKABLE QList<QString> getPluginScripts();
|
||||
static Q_INVOKABLE QList<QString> getCustomScripts() {return getPluginScripts();} // Alias for backwards-compatibility
|
||||
Q_INVOKABLE QList<int> getMetatileLayerOrder();
|
||||
Q_INVOKABLE void setMetatileLayerOrder(const QList<int> &order);
|
||||
Q_INVOKABLE QList<float> getMetatileLayerOpacity();
|
||||
@@ -196,7 +196,7 @@ public:
|
||||
int metatileSelectorWidth = 8;
|
||||
QStringList globalConstantsFilepaths;
|
||||
QMap<QString,QString> globalConstants;
|
||||
QList<ScriptSettings> customScripts;
|
||||
QList<PluginSettings> plugins;
|
||||
QMap<Event::Group, QString> eventIconPaths;
|
||||
QMap<QString, QString> pokemonIconPaths;
|
||||
QVersionNumber minimumVersion;
|
||||
@@ -248,7 +248,7 @@ public:
|
||||
m_fm->addField(&this->metatileSelectorWidth, "metatile_selector_width", 1, INT_MAX);
|
||||
m_fm->addField(&this->globalConstantsFilepaths, "global_constants_filepaths");
|
||||
m_fm->addField(&this->globalConstants, "global_constants");
|
||||
m_fm->addField(&this->customScripts, "custom_scripts");
|
||||
m_fm->addField(&this->plugins, "plugins");
|
||||
m_fm->addField(&this->eventIconPaths, "event_icon_paths");
|
||||
m_fm->addField(&this->pokemonIconPaths, "pokemon_icon_paths");
|
||||
m_fm->addField(&this->minimumVersion, "minimum_version");
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
QString prefabsFilepath;
|
||||
bool prefabsImportPrompted = false;
|
||||
bool useEncounterJson = true;
|
||||
QList<ScriptSettings> customScripts;
|
||||
QList<PluginSettings> plugins;
|
||||
|
||||
protected:
|
||||
virtual bool parseLegacyKeyValue(const QString& key, const QString& value) override;
|
||||
@@ -32,7 +32,7 @@ protected:
|
||||
m_fm->addField(&this->prefabsFilepath, "prefabs_filepath");
|
||||
m_fm->addField(&this->prefabsImportPrompted, "prefabs_import_prompted");
|
||||
m_fm->addField(&this->useEncounterJson, "use_encounter_json");
|
||||
m_fm->addField(&this->customScripts, "custom_scripts");
|
||||
m_fm->addField(&this->plugins, "plugins");
|
||||
}
|
||||
return m_fm.get();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "magic_enum.hpp"
|
||||
#include "orderedset.h"
|
||||
#include "scriptsettings.h"
|
||||
#include "pluginsettings.h"
|
||||
#include "gridsettings.h"
|
||||
#include "basegame.h"
|
||||
|
||||
@@ -360,16 +360,16 @@ struct Converter<QMargins> : DefaultConverter<QMargins> {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Converter<ScriptSettings> : DefaultConverter<ScriptSettings> {
|
||||
static QJsonValue toJson(const ScriptSettings& value) {
|
||||
struct Converter<PluginSettings> : DefaultConverter<PluginSettings> {
|
||||
static QJsonValue toJson(const PluginSettings& value) {
|
||||
QJsonObject obj;
|
||||
obj["path"] = value.path;
|
||||
obj["enabled"] = value.enabled;
|
||||
return obj;
|
||||
}
|
||||
static ScriptSettings fromJson(const QJsonValue& json, QStringList* errors = nullptr) {
|
||||
static PluginSettings fromJson(const QJsonValue& json, QStringList* errors = nullptr) {
|
||||
const auto obj = Converter<QJsonObject>::fromJson(json, errors);
|
||||
ScriptSettings settings;
|
||||
PluginSettings settings;
|
||||
settings.path = obj.value("path").toString();
|
||||
settings.enabled = obj.value("enabled").toBool();
|
||||
return settings;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef SCRIPTSETTINGS_H
|
||||
#define SCRIPTSETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
// Holds the basic user-provided information about a plug-in script.
|
||||
struct ScriptSettings {
|
||||
QString path;
|
||||
bool enabled = true;
|
||||
|
||||
// Scripts can either be specific to the project, or specific to the user.
|
||||
// This allows projects to send scripts downstream to their users,
|
||||
// while still allowing them to use their own personal scripts.
|
||||
bool userOnly = true;
|
||||
|
||||
static QStringList filter(const QList<ScriptSettings>& scripts) {
|
||||
QStringList paths;
|
||||
for (auto& script : scripts) {
|
||||
if (script.enabled) paths.append(script.path);
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // SCRIPTSETTINGS_H
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "preferenceeditor.h"
|
||||
#include "projectsettingseditor.h"
|
||||
#include "gridsettings.h"
|
||||
#include "customscriptseditor.h"
|
||||
#include "plugineditor.h"
|
||||
#include "wildmonchart.h"
|
||||
#include "wildmonsearch.h"
|
||||
#include "updatepromoter.h"
|
||||
@@ -303,7 +303,7 @@ private slots:
|
||||
void on_actionCheck_for_Updates_triggered();
|
||||
void togglePreferenceSpecificUi();
|
||||
void on_actionProject_Settings_triggered();
|
||||
void on_actionCustom_Scripts_triggered();
|
||||
void on_actionPlugins_triggered();
|
||||
void reloadScriptEngine();
|
||||
void on_actionShow_Grid_triggered();
|
||||
void on_actionGrid_Settings_triggered();
|
||||
@@ -326,7 +326,7 @@ private:
|
||||
QPointer<PreferenceEditor> preferenceEditor = nullptr;
|
||||
QPointer<ProjectSettingsEditor> projectSettingsEditor = nullptr;
|
||||
QPointer<GridSettingsDialog> gridSettingsDialog = nullptr;
|
||||
QPointer<CustomScriptsEditor> customScriptsEditor = nullptr;
|
||||
QPointer<PluginEditor> pluginEditor = nullptr;
|
||||
|
||||
QPointer<FilterChildrenProxyModel> groupListProxyModel = nullptr;
|
||||
QPointer<MapGroupModel> mapGroupModel = nullptr;
|
||||
@@ -454,7 +454,7 @@ private:
|
||||
bool initRegionMapEditor(bool silent = false);
|
||||
bool askToFixRegionMapEditor();
|
||||
void initShortcutsEditor();
|
||||
void initCustomScriptsEditor();
|
||||
void initPluginEditor();
|
||||
void connectSubEditorsToShortcutsEditor();
|
||||
void openProjectSettingsEditor(int tab);
|
||||
bool isProjectOpen();
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
#ifndef CUSTOMSCRIPTSEDITOR_H
|
||||
#define CUSTOMSCRIPTSEDITOR_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QListWidget>
|
||||
#include <QAbstractButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "customscriptslistitem.h"
|
||||
|
||||
namespace Ui {
|
||||
class CustomScriptsEditor;
|
||||
}
|
||||
|
||||
|
||||
class CustomScriptsEditor : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomScriptsEditor(QWidget *parent = nullptr);
|
||||
~CustomScriptsEditor();
|
||||
|
||||
signals:
|
||||
void reloadScriptEngine();
|
||||
|
||||
public slots:
|
||||
void applyUserShortcuts();
|
||||
|
||||
private:
|
||||
Ui::CustomScriptsEditor *ui;
|
||||
|
||||
bool hasUnsavedChanges = false;
|
||||
const QString baseDir;
|
||||
|
||||
void displayScript(const ScriptSettings &settings);
|
||||
void displayNewScript(QString filepath);
|
||||
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 initShortcuts();
|
||||
QObjectList shortcutableObjects() const;
|
||||
void openManual();
|
||||
|
||||
private slots:
|
||||
void dialogButtonClicked(QAbstractButton *button);
|
||||
void createNewScript();
|
||||
void loadScript();
|
||||
bool refreshScripts();
|
||||
void userRefreshScripts();
|
||||
void removeSelectedScripts();
|
||||
void openSelectedScripts();
|
||||
};
|
||||
|
||||
#endif // CUSTOMSCRIPTSEDITOR_H
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifndef CUSTOMSCRIPTSLISTITEM_H
|
||||
#define CUSTOMSCRIPTSLISTITEM_H
|
||||
|
||||
#include <QFrame>
|
||||
#include "scriptsettings.h"
|
||||
|
||||
namespace Ui {
|
||||
class CustomScriptsListItem;
|
||||
}
|
||||
|
||||
class CustomScriptsListItem : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CustomScriptsListItem(QWidget *parent = nullptr);
|
||||
explicit CustomScriptsListItem(const ScriptSettings& settings, QWidget *parent = nullptr);
|
||||
~CustomScriptsListItem();
|
||||
|
||||
void setSettings(const ScriptSettings& settings);
|
||||
ScriptSettings getSettings() const;
|
||||
|
||||
void setPath(const QString& text);
|
||||
QString path() const;
|
||||
|
||||
void setScriptEnabled(bool enabled);
|
||||
bool scriptEnabled() const;
|
||||
|
||||
signals:
|
||||
void clickedChooseScript();
|
||||
void clickedEditScript();
|
||||
void clickedDeleteScript();
|
||||
void toggledEnable(bool checked);
|
||||
void pathEdited(const QString& text);
|
||||
|
||||
private:
|
||||
Ui::CustomScriptsListItem *ui;
|
||||
};
|
||||
|
||||
#endif // CUSTOMSCRIPTSLISTITEM_H
|
||||
63
include/ui/plugineditor.h
Normal file
63
include/ui/plugineditor.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef PLUGINEDITOR_H
|
||||
#define PLUGINEDITOR_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QListWidget>
|
||||
#include <QAbstractButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "pluginlistitem.h"
|
||||
|
||||
namespace Ui {
|
||||
class PluginEditor;
|
||||
}
|
||||
|
||||
|
||||
class PluginEditor : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginEditor(QWidget *parent = nullptr);
|
||||
~PluginEditor();
|
||||
|
||||
signals:
|
||||
void reloadScriptEngine();
|
||||
|
||||
public slots:
|
||||
void applyUserShortcuts();
|
||||
|
||||
private:
|
||||
Ui::PluginEditor *ui;
|
||||
|
||||
bool hasUnsavedChanges = false;
|
||||
const QString baseDir;
|
||||
|
||||
void displayPlugin(const PluginSettings &settings);
|
||||
void displayNewPlugin(QString filepath);
|
||||
QString choosePlugin(QString dir);
|
||||
void removePlugin(QListWidgetItem * item);
|
||||
void replacePlugin(QListWidgetItem * item);
|
||||
void openPlugin(QListWidgetItem * item);
|
||||
QString getPluginFilepath(QListWidgetItem * item, bool absolutePath = true) const;
|
||||
void setPluginFilepath(QListWidgetItem * item, QString filepath) const;
|
||||
bool getPluginEnabled(QListWidgetItem * item) const;
|
||||
void markEdited();
|
||||
int prompt(const QString &text, QMessageBox::StandardButton defaultButton);
|
||||
void save();
|
||||
void closeEvent(QCloseEvent*);
|
||||
void initShortcuts();
|
||||
QObjectList shortcutableObjects() const;
|
||||
void openManual();
|
||||
|
||||
private slots:
|
||||
void dialogButtonClicked(QAbstractButton *button);
|
||||
void createNewPlugin();
|
||||
void loadPlugin();
|
||||
bool refreshPlugins();
|
||||
void userRefreshPlugins();
|
||||
void removeSelectedPlugins();
|
||||
void openSelectedPlugins();
|
||||
};
|
||||
|
||||
#endif // PLUGINEDITOR_H
|
||||
40
include/ui/pluginlistitem.h
Normal file
40
include/ui/pluginlistitem.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef PLUGINLISTITEM_H
|
||||
#define PLUGINLISTITEM_H
|
||||
|
||||
#include <QFrame>
|
||||
#include "pluginsettings.h"
|
||||
|
||||
namespace Ui {
|
||||
class PluginListItem;
|
||||
}
|
||||
|
||||
class PluginListItem : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginListItem(QWidget *parent = nullptr);
|
||||
explicit PluginListItem(const PluginSettings& settings, QWidget *parent = nullptr);
|
||||
~PluginListItem();
|
||||
|
||||
void setSettings(const PluginSettings& settings);
|
||||
PluginSettings getSettings() const;
|
||||
|
||||
void setPath(const QString& text);
|
||||
QString path() const;
|
||||
|
||||
void setPluginEnabled(bool enabled);
|
||||
bool pluginEnabled() const;
|
||||
|
||||
signals:
|
||||
void clickedChoosePlugin();
|
||||
void clickedEditPlugin();
|
||||
void clickedDeletePlugin();
|
||||
void toggledEnable(bool checked);
|
||||
void pathEdited(const QString& text);
|
||||
|
||||
private:
|
||||
Ui::PluginListItem *ui;
|
||||
};
|
||||
|
||||
#endif // PLUGINLISTITEM_H
|
||||
Reference in New Issue
Block a user