Add PluginArgs for plugin system

This commit is contained in:
Gary Talent 2017-05-21 00:15:47 -05:00
parent 6aab7bf2f2
commit bc69e67a5b
9 changed files with 56 additions and 28 deletions

View File

@ -26,6 +26,7 @@ mkdir -p $buildDir
pushd $buildDir
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_INSTALL_PREFIX="$distDir" \
-DCMAKE_INSTALL_RPATH="$project/dist/${TARGET}-${BUILD_TYPE}/lib/nostalgia" \
$buildTypeArgs \
$toolchain \
$project

View File

@ -17,7 +17,8 @@ const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName";
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
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) {
auto importPath = field(IMPORT_PATH).toString();
if (QFile(importPath).exists()) {
@ -37,12 +38,17 @@ ImportTilesheetWizardPage::ImportTilesheetWizardPage() {
int ImportTilesheetWizardPage::accept() {
auto tilesheetName = field(TILESHEET_NAME).toString();
auto importPath = field(IMPORT_PATH).toString();
if (QFile(importPath).exists()) {
return 0;
QFile importFile(importPath);
if (importFile.exists()) {
return importImage(importFile, field(TILESHEET_NAME).toString());
} else {
return 1;
}
}
int ImportTilesheetWizardPage::importImage(QFile &src, QString tilesetName) {
return 1;
}
}
}

View File

@ -18,11 +18,15 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage {
static const QString TILESHEET_NAME;
static const QString IMPORT_PATH;
static const QString BPP;
studio::Project *m_project = nullptr;
public:
ImportTilesheetWizardPage();
ImportTilesheetWizardPage(studio::PluginArgs args);
int accept();
private:
int importImage(QFile &src, QString dest);
};
}

View File

@ -6,8 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <nostalgia/studio/studio.hpp>
#include "import_tilesheet_wizard.hpp"
#include "plugin.hpp"
@ -18,14 +16,19 @@ namespace nostalgia {
namespace core {
Plugin::Plugin() {
addImportWizard(
tr("Tile Sheet"),
[]() {
QVector<QWizardPage*> pgs;
pgs.push_back(new ImportTilesheetWizardPage());
return pgs;
}
QVector<studio::WizardMaker> Plugin::importWizards(studio::PluginArgs args) {
return {
{
tr("Tile Sheet"),
[args]() {
QVector<QWizardPage*> pgs;
pgs.push_back(new ImportTilesheetWizardPage(args));
return pgs;
}
}
);
};
}
}

View File

@ -22,6 +22,8 @@ class Plugin: public QObject, studio::Plugin {
public:
Plugin();
QVector<studio::WizardMaker> importWizards(studio::PluginArgs args) override;
};
}

View File

@ -15,16 +15,12 @@ void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> m
m_newWizards.push_back({name, make});
}
void Plugin::addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make) {
m_importWizards.push_back({name, make});
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
return {};
}
QVector<WizardMaker> Plugin::newWizards() {
return m_newWizards;
}
QVector<WizardMaker> Plugin::importWizards() {
return m_importWizards;
QVector<WizardMaker> Plugin::importWizards(PluginArgs) {
return {};
}
}

View File

@ -11,12 +11,20 @@
#include <functional>
#include <QMainWindow>
#include <QPointer>
#include <QSharedPointer>
#include <QVector>
#include <QWizardPage>
#include "project.hpp"
namespace nostalgia {
namespace studio {
struct PluginArgs {
Project *project = nullptr;
};
struct WizardMaker {
QString name;
std::function<QVector<QWizardPage*>()> make;
@ -25,16 +33,15 @@ struct WizardMaker {
class Plugin {
private:
QVector<WizardMaker> m_newWizards;
QVector<WizardMaker> m_importWizards;
public:
void addNewWizard(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);
};
}

View File

@ -218,9 +218,13 @@ int MainWindow::writeState(QString path) {
int MainWindow::openProject(QString projectPath) {
auto err = closeProject();
auto project = QSharedPointer<Project>(new Project(projectPath));
auto project = new Project(projectPath);
err |= project->open();
if (err == 0) {
if (m_project) {
delete m_project;
m_project = nullptr;
}
m_project = project;
m_projectExplorer->setModel(new OxFSModel(m_project->romFS()));
m_importAction->setEnabled(true);
@ -231,7 +235,10 @@ int MainWindow::openProject(QString projectPath) {
int MainWindow::closeProject() {
auto err = 0;
m_project = QSharedPointer<Project>(nullptr);
if (m_project) {
delete m_project;
m_project = nullptr;
}
if (m_projectExplorer->model()) {
delete m_projectExplorer->model();
}
@ -315,8 +322,10 @@ void MainWindow::showImportWizard() {
auto ws = new WizardSelect();
wizard.addPage(ws);
PluginArgs args;
args.project = m_project;
for (auto p : m_plugins) {
for (auto w : p->importWizards()) {
for (auto w : p->importWizards(args)) {
ws->addOption(w.name, w.make);
}
}

View File

@ -82,7 +82,7 @@ class MainWindow: public QMainWindow {
QString m_profilePath;
NostalgiaStudioState m_state;
QAction *m_importAction = nullptr;
QSharedPointer<Project> m_project;
Project *m_project = nullptr;
QPointer<QMenu> m_viewMenu;
QVector<std::function<void()>> m_cleanupTasks;
QVector<QPointer<QDockWidget>> m_dockWidgets;