Add PluginArgs for plugin system
This commit is contained in:
parent
6aab7bf2f2
commit
bc69e67a5b
@ -26,6 +26,7 @@ mkdir -p $buildDir
|
|||||||
pushd $buildDir
|
pushd $buildDir
|
||||||
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||||
-DCMAKE_INSTALL_PREFIX="$distDir" \
|
-DCMAKE_INSTALL_PREFIX="$distDir" \
|
||||||
|
-DCMAKE_INSTALL_RPATH="$project/dist/${TARGET}-${BUILD_TYPE}/lib/nostalgia" \
|
||||||
$buildTypeArgs \
|
$buildTypeArgs \
|
||||||
$toolchain \
|
$toolchain \
|
||||||
$project
|
$project
|
||||||
|
@ -17,7 +17,8 @@ const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName";
|
|||||||
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
|
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
|
||||||
const QString ImportTilesheetWizardPage::BPP = "bpp";
|
const QString ImportTilesheetWizardPage::BPP = "bpp";
|
||||||
|
|
||||||
ImportTilesheetWizardPage::ImportTilesheetWizardPage() {
|
ImportTilesheetWizardPage::ImportTilesheetWizardPage(studio::PluginArgs args) {
|
||||||
|
m_project = args.project;
|
||||||
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) {
|
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) {
|
||||||
auto importPath = field(IMPORT_PATH).toString();
|
auto importPath = field(IMPORT_PATH).toString();
|
||||||
if (QFile(importPath).exists()) {
|
if (QFile(importPath).exists()) {
|
||||||
@ -37,12 +38,17 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage() {
|
|||||||
int ImportTilesheetWizardPage::accept() {
|
int ImportTilesheetWizardPage::accept() {
|
||||||
auto tilesheetName = field(TILESHEET_NAME).toString();
|
auto tilesheetName = field(TILESHEET_NAME).toString();
|
||||||
auto importPath = field(IMPORT_PATH).toString();
|
auto importPath = field(IMPORT_PATH).toString();
|
||||||
if (QFile(importPath).exists()) {
|
QFile importFile(importPath);
|
||||||
return 0;
|
if (importFile.exists()) {
|
||||||
|
return importImage(importFile, field(TILESHEET_NAME).toString());
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ImportTilesheetWizardPage::importImage(QFile &src, QString tilesetName) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,15 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage {
|
|||||||
static const QString TILESHEET_NAME;
|
static const QString TILESHEET_NAME;
|
||||||
static const QString IMPORT_PATH;
|
static const QString IMPORT_PATH;
|
||||||
static const QString BPP;
|
static const QString BPP;
|
||||||
|
studio::Project *m_project = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImportTilesheetWizardPage();
|
ImportTilesheetWizardPage(studio::PluginArgs args);
|
||||||
|
|
||||||
int accept();
|
int accept();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int importImage(QFile &src, QString dest);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nostalgia/studio/studio.hpp>
|
|
||||||
|
|
||||||
#include "import_tilesheet_wizard.hpp"
|
#include "import_tilesheet_wizard.hpp"
|
||||||
|
|
||||||
#include "plugin.hpp"
|
#include "plugin.hpp"
|
||||||
@ -18,14 +16,19 @@ namespace nostalgia {
|
|||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
Plugin::Plugin() {
|
Plugin::Plugin() {
|
||||||
addImportWizard(
|
}
|
||||||
tr("Tile Sheet"),
|
|
||||||
[]() {
|
QVector<studio::WizardMaker> Plugin::importWizards(studio::PluginArgs args) {
|
||||||
QVector<QWizardPage*> pgs;
|
return {
|
||||||
pgs.push_back(new ImportTilesheetWizardPage());
|
{
|
||||||
return pgs;
|
tr("Tile Sheet"),
|
||||||
|
[args]() {
|
||||||
|
QVector<QWizardPage*> pgs;
|
||||||
|
pgs.push_back(new ImportTilesheetWizardPage(args));
|
||||||
|
return pgs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ class Plugin: public QObject, studio::Plugin {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Plugin();
|
Plugin();
|
||||||
|
|
||||||
|
QVector<studio::WizardMaker> importWizards(studio::PluginArgs args) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,16 +15,12 @@ void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> m
|
|||||||
m_newWizards.push_back({name, make});
|
m_newWizards.push_back({name, make});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make) {
|
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
|
||||||
m_importWizards.push_back({name, make});
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<WizardMaker> Plugin::newWizards() {
|
QVector<WizardMaker> Plugin::importWizards(PluginArgs) {
|
||||||
return m_newWizards;
|
return {};
|
||||||
}
|
|
||||||
|
|
||||||
QVector<WizardMaker> Plugin::importWizards() {
|
|
||||||
return m_importWizards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,20 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QSharedPointer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QWizardPage>
|
#include <QWizardPage>
|
||||||
|
|
||||||
|
#include "project.hpp"
|
||||||
|
|
||||||
namespace nostalgia {
|
namespace nostalgia {
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
|
struct PluginArgs {
|
||||||
|
Project *project = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
struct WizardMaker {
|
struct WizardMaker {
|
||||||
QString name;
|
QString name;
|
||||||
std::function<QVector<QWizardPage*>()> make;
|
std::function<QVector<QWizardPage*>()> make;
|
||||||
@ -25,16 +33,15 @@ struct WizardMaker {
|
|||||||
class Plugin {
|
class Plugin {
|
||||||
private:
|
private:
|
||||||
QVector<WizardMaker> m_newWizards;
|
QVector<WizardMaker> m_newWizards;
|
||||||
QVector<WizardMaker> m_importWizards;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
void addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||||
|
|
||||||
void addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
void addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||||
|
|
||||||
QVector<WizardMaker> newWizards();
|
virtual QVector<WizardMaker> newWizards(PluginArgs);
|
||||||
|
|
||||||
QVector<WizardMaker> importWizards();
|
virtual QVector<WizardMaker> importWizards(PluginArgs);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -218,9 +218,13 @@ int MainWindow::writeState(QString path) {
|
|||||||
|
|
||||||
int MainWindow::openProject(QString projectPath) {
|
int MainWindow::openProject(QString projectPath) {
|
||||||
auto err = closeProject();
|
auto err = closeProject();
|
||||||
auto project = QSharedPointer<Project>(new Project(projectPath));
|
auto project = new Project(projectPath);
|
||||||
err |= project->open();
|
err |= project->open();
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
|
if (m_project) {
|
||||||
|
delete m_project;
|
||||||
|
m_project = nullptr;
|
||||||
|
}
|
||||||
m_project = project;
|
m_project = project;
|
||||||
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
|
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
|
||||||
m_importAction->setEnabled(true);
|
m_importAction->setEnabled(true);
|
||||||
@ -231,7 +235,10 @@ int MainWindow::openProject(QString projectPath) {
|
|||||||
|
|
||||||
int MainWindow::closeProject() {
|
int MainWindow::closeProject() {
|
||||||
auto err = 0;
|
auto err = 0;
|
||||||
m_project = QSharedPointer<Project>(nullptr);
|
if (m_project) {
|
||||||
|
delete m_project;
|
||||||
|
m_project = nullptr;
|
||||||
|
}
|
||||||
if (m_projectExplorer->model()) {
|
if (m_projectExplorer->model()) {
|
||||||
delete m_projectExplorer->model();
|
delete m_projectExplorer->model();
|
||||||
}
|
}
|
||||||
@ -315,8 +322,10 @@ void MainWindow::showImportWizard() {
|
|||||||
auto ws = new WizardSelect();
|
auto ws = new WizardSelect();
|
||||||
wizard.addPage(ws);
|
wizard.addPage(ws);
|
||||||
|
|
||||||
|
PluginArgs args;
|
||||||
|
args.project = m_project;
|
||||||
for (auto p : m_plugins) {
|
for (auto p : m_plugins) {
|
||||||
for (auto w : p->importWizards()) {
|
for (auto w : p->importWizards(args)) {
|
||||||
ws->addOption(w.name, w.make);
|
ws->addOption(w.name, w.make);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ class MainWindow: public QMainWindow {
|
|||||||
QString m_profilePath;
|
QString m_profilePath;
|
||||||
NostalgiaStudioState m_state;
|
NostalgiaStudioState m_state;
|
||||||
QAction *m_importAction = nullptr;
|
QAction *m_importAction = nullptr;
|
||||||
QSharedPointer<Project> m_project;
|
Project *m_project = nullptr;
|
||||||
QPointer<QMenu> m_viewMenu;
|
QPointer<QMenu> m_viewMenu;
|
||||||
QVector<std::function<void()>> m_cleanupTasks;
|
QVector<std::function<void()>> m_cleanupTasks;
|
||||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||||
|
Loading…
Reference in New Issue
Block a user