Add new World wizard
This commit is contained in:
parent
2edee450aa
commit
4e50d80f5f
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ media_header.txt
|
||||
studio_state.json
|
||||
CMakeLists.txt.user
|
||||
Session.vim
|
||||
ROM.oxfs
|
||||
|
@ -22,7 +22,7 @@ endif()
|
||||
|
||||
add_definitions(
|
||||
-std=c++14
|
||||
-fdiagnostics-color
|
||||
#-fdiagnostics-color
|
||||
-Wall
|
||||
-Wsign-compare
|
||||
)
|
||||
|
5
Makefile
5
Makefile
@ -71,6 +71,11 @@ debug:
|
||||
${ENV_RUN} ./scripts/setup_build ${HOST_ENV} debug
|
||||
${ENV_RUN} rm -f build/current
|
||||
|
||||
asan:
|
||||
${ENV_RUN} rm -rf build/${HOST_ENV}-asan
|
||||
${ENV_RUN} ./scripts/setup_build ${HOST_ENV} asan
|
||||
${ENV_RUN} rm -f build/current
|
||||
|
||||
windows:
|
||||
${ENV_RUN} rm -rf build/windows
|
||||
${ENV_RUN} ./scripts/setup_build windows
|
||||
|
@ -1,4 +1,4 @@
|
||||
all: gba_build gba_debug_build native_build native_debug_build windows_release windows_debug
|
||||
all: gba_build gba_debug_build native_build native_debug_build native_asan_build windows_release windows_debug
|
||||
|
||||
ifneq ($(shell which gmake),)
|
||||
MAKE="gmake"
|
||||
@ -26,6 +26,11 @@ native_debug_build:
|
||||
${MAKE} -C ${HOST_ENV}-debug ${ARGS}; \
|
||||
fi
|
||||
|
||||
native_asan_build:
|
||||
@if [ -d ${HOST_ENV}-asan ]; then \
|
||||
${MAKE} -C ${HOST_ENV}-asan ${ARGS}; \
|
||||
fi
|
||||
|
||||
windows_release:
|
||||
@if [ -d windows-release ]; then \
|
||||
${MAKE} -C windows-release ${ARGS}; \
|
||||
|
@ -17,8 +17,10 @@ elif [[ $TARGET == gba ]]; then
|
||||
toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DNOSTALGIA_BUILD_TYPE=GBA -DOX_USE_STDLIB=OFF"
|
||||
fi
|
||||
|
||||
if [[ $BUILD_TYPE == debug ]]; then
|
||||
if [[ $BUILD_TYPE == asan ]]; then
|
||||
buildTypeArgs="-DUSE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug"
|
||||
elif [[ $BUILD_TYPE == debug ]]; then
|
||||
buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug"
|
||||
elif [[ $BUILD_TYPE == release ]]; then
|
||||
buildTypeArgs="-DCMAKE_BUILD_TYPE=Release"
|
||||
fi
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA")
|
||||
find_package(Qt5Widgets)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
endif()
|
||||
|
||||
#project packages
|
||||
|
@ -1,4 +1,3 @@
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
|
||||
add_library(
|
||||
|
@ -18,7 +18,8 @@ const QString ImportTilesheetWizardPage::TILESHEET_NAME = "projectName";
|
||||
const QString ImportTilesheetWizardPage::IMPORT_PATH = "projectPath";
|
||||
const QString ImportTilesheetWizardPage::BPP = "bpp";
|
||||
|
||||
ImportTilesheetWizardPage::ImportTilesheetWizardPage(studio::PluginArgs args): m_project(args.project) {
|
||||
ImportTilesheetWizardPage::ImportTilesheetWizardPage(const studio::Context *ctx) {
|
||||
m_ctx = ctx;
|
||||
addLineEdit(tr("&Tile Sheet Name:"), TILESHEET_NAME + "*", "", [this](QString) {
|
||||
auto importPath = field(IMPORT_PATH).toString();
|
||||
if (QFile(importPath).exists()) {
|
||||
@ -53,9 +54,9 @@ int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName
|
||||
srcFile.open(QIODevice::ReadOnly);
|
||||
if (srcFile.read((char*) buff, buffSize) > 0) {
|
||||
int err = 0;
|
||||
m_project->mkdir(TILESHEET_DIR);
|
||||
err |= m_project->write(TILESHEET_DIR + tilesheetName, buff, buffSize);
|
||||
err |= m_project->saveRomFs();
|
||||
m_ctx->project->mkdir(TILESHEET_DIR);
|
||||
err |= m_ctx->project->write(TILESHEET_DIR + tilesheetName, buff, buffSize);
|
||||
err |= m_ctx->project->saveRomFs();
|
||||
return err;
|
||||
} else {
|
||||
return 1;
|
||||
|
@ -19,10 +19,10 @@ class ImportTilesheetWizardPage: public studio::WizardFormPage {
|
||||
static const QString TILESHEET_NAME;
|
||||
static const QString IMPORT_PATH;
|
||||
static const QString BPP;
|
||||
studio::Project *&m_project;
|
||||
const studio::Context *m_ctx = nullptr;
|
||||
|
||||
public:
|
||||
ImportTilesheetWizardPage(studio::PluginArgs args);
|
||||
ImportTilesheetWizardPage(const studio::Context *args);
|
||||
|
||||
int accept();
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace core {
|
||||
Plugin::Plugin() {
|
||||
}
|
||||
|
||||
QVector<studio::WizardMaker> Plugin::importWizards(studio::PluginArgs args) {
|
||||
QVector<studio::WizardMaker> Plugin::importWizards(const studio::Context *args) {
|
||||
return {
|
||||
{
|
||||
tr("Tile Sheet"),
|
||||
|
@ -23,7 +23,7 @@ class Plugin: public QObject, studio::Plugin {
|
||||
public:
|
||||
Plugin();
|
||||
|
||||
QVector<studio::WizardMaker> importWizards(studio::PluginArgs args) override;
|
||||
QVector<studio::WizardMaker> importWizards(const studio::Context *args) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8.11)
|
||||
project(nostalgia-studio)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_executable(
|
||||
nostalgia-studio
|
||||
|
@ -11,17 +11,17 @@
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make) {
|
||||
m_newWizards.push_back({name, make});
|
||||
}
|
||||
|
||||
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
|
||||
QVector<WizardMaker> Plugin::newWizards(const Context *ctx) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QVector<WizardMaker> Plugin::importWizards(PluginArgs) {
|
||||
QVector<WizardMaker> Plugin::importWizards(const Context *ctx) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QWidget *Plugin::makeEditor(QString path, const Context *ctx) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,27 +21,30 @@
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
struct PluginArgs {
|
||||
Project *&project;
|
||||
struct Context {
|
||||
QWidget *tabParent = nullptr;
|
||||
const Project *project = nullptr;
|
||||
};
|
||||
|
||||
struct WizardMaker {
|
||||
QString name;
|
||||
std::function<QVector<QWizardPage*>()> make;
|
||||
std::function<int(QWizard*)> onAccept;
|
||||
};
|
||||
|
||||
struct EditorMaker {
|
||||
virtual QWidget *make(QString path, const Context *ctx) = 0;
|
||||
};
|
||||
|
||||
class Plugin {
|
||||
private:
|
||||
QVector<WizardMaker> m_newWizards;
|
||||
|
||||
public:
|
||||
void addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||
virtual QVector<WizardMaker> newWizards(const Context *ctx);
|
||||
|
||||
void addImportWizard(QString name, std::function<QVector<QWizardPage*>()> make);
|
||||
virtual QVector<WizardMaker> importWizards(const Context *ctx);
|
||||
|
||||
virtual QVector<WizardMaker> newWizards(PluginArgs);
|
||||
virtual QWidget *makeEditor(QString path, const Context *ctx);
|
||||
|
||||
virtual QVector<WizardMaker> importWizards(PluginArgs);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ int Project::openRomFs() {
|
||||
}
|
||||
}
|
||||
|
||||
int Project::saveRomFs() {
|
||||
int Project::saveRomFs() const {
|
||||
int err = 0;
|
||||
QFile file(m_path + ROM_FILE);
|
||||
err |= file.open(QIODevice::WriteOnly) == false;
|
||||
@ -78,17 +78,21 @@ FileSystem *Project::romFs() {
|
||||
return m_fs;
|
||||
}
|
||||
|
||||
int Project::mkdir(QString path) {
|
||||
int Project::mkdir(QString path) const {
|
||||
auto err = m_fs->mkdir(path.toUtf8().data());
|
||||
emit updated(path);
|
||||
return err;
|
||||
}
|
||||
|
||||
int Project::write(QString path, uint8_t *buff, size_t buffLen) {
|
||||
int Project::write(QString path, uint8_t *buff, size_t buffLen) const {
|
||||
auto err = m_fs->write(path.toUtf8().data(), buff, buffLen);
|
||||
emit updated(path);
|
||||
return err;
|
||||
}
|
||||
|
||||
ox::FileStat Project::stat(QString path) const {
|
||||
return m_fs->stat(path.toUtf8().data());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -33,16 +33,19 @@ class Project: public QObject {
|
||||
|
||||
int openRomFs();
|
||||
|
||||
int saveRomFs();
|
||||
int saveRomFs() const;
|
||||
|
||||
ox::FileSystem *romFs();
|
||||
|
||||
int mkdir(QString path);
|
||||
int mkdir(QString path) const;
|
||||
|
||||
int write(QString path, uint8_t *buff, size_t buffLen);
|
||||
int write(QString path, uint8_t *buff, size_t buffLen) const;
|
||||
|
||||
ox::FileStat stat(QString path) const;
|
||||
|
||||
signals:
|
||||
void updated(QString path);
|
||||
void updated(QString path) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@ -14,6 +15,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "plugin.hpp"
|
||||
#include "wizard.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
@ -43,9 +45,9 @@ void WizardSelect::initializePage() {
|
||||
emit completeChanged();
|
||||
}
|
||||
|
||||
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) {
|
||||
m_options[name] = makePage;
|
||||
m_listWidget->addItem(name);
|
||||
void WizardSelect::addOption(WizardMaker wm) {
|
||||
m_options[wm.name] = {wm.make, wm.onAccept};
|
||||
m_listWidget->addItem(wm.name);
|
||||
}
|
||||
|
||||
bool WizardSelect::isComplete() const {
|
||||
@ -53,18 +55,21 @@ bool WizardSelect::isComplete() const {
|
||||
}
|
||||
|
||||
void WizardSelect::itemSelected(int row) {
|
||||
if (row > -1) {
|
||||
auto w = wizard();
|
||||
|
||||
if (nextId() > -1) {
|
||||
auto w = dynamic_cast<Wizard*>(wizard());
|
||||
if (w and row > -1) {
|
||||
// remove other pages
|
||||
while (nextId() > -1) {
|
||||
w->removePage(nextId());
|
||||
}
|
||||
|
||||
auto selected = m_listWidget->currentItem()->text();
|
||||
if (m_options.contains(selected)) {
|
||||
for (auto p : m_options[selected]()) {
|
||||
auto &o = m_options[selected];
|
||||
for (auto p : o.make()) {
|
||||
w->addPage(p);
|
||||
}
|
||||
w->setAccept(o.onAccept);
|
||||
|
||||
// for some reason the continue button only appears correctly after remove runs
|
||||
w->removePage(w->addPage(new QWizardPage()));
|
||||
}
|
||||
@ -313,7 +318,7 @@ void WizardFormPage::showValidationError(QString msg) {
|
||||
|
||||
// set message
|
||||
if (msg != "") {
|
||||
m_errorMsg->setText(tr("Error: ") + msg);
|
||||
m_errorMsg->setText(msg);
|
||||
} else {
|
||||
m_errorMsg->setText("");
|
||||
}
|
||||
@ -325,7 +330,7 @@ Wizard::Wizard(QString windowTitle, QWidget *parent): QWizard(parent) {
|
||||
setModal(true);
|
||||
}
|
||||
|
||||
void Wizard::setAccept(std::function<int()> acceptFunc) {
|
||||
void Wizard::setAccept(std::function<int(QWizard*)> acceptFunc) {
|
||||
m_acceptFunc = acceptFunc;
|
||||
}
|
||||
|
||||
@ -333,7 +338,7 @@ void Wizard::accept() {
|
||||
auto page = dynamic_cast<WizardFormPage*>(currentPage());
|
||||
if (page != nullptr && page->accept() == 0) {
|
||||
QDialog::accept();
|
||||
} else if (m_acceptFunc != nullptr && m_acceptFunc() == 0) {
|
||||
} else if (m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
|
||||
QDialog::accept();
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,25 @@
|
||||
namespace nostalgia {
|
||||
namespace studio {
|
||||
|
||||
class WizardMaker;
|
||||
|
||||
class WizardSelect: public QWizardPage {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QMap<QString, std::function<QVector<QWizardPage*>()>> m_options;
|
||||
struct WizardFuncs {
|
||||
std::function<QVector<QWizardPage*>()> make;
|
||||
std::function<int(QWizard*)> onAccept;
|
||||
};
|
||||
|
||||
QHash<QString, WizardFuncs> m_options;
|
||||
QListWidget *m_listWidget = nullptr;
|
||||
bool m_complete = false;
|
||||
|
||||
public:
|
||||
WizardSelect();
|
||||
|
||||
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage);
|
||||
void addOption(WizardMaker wm);
|
||||
|
||||
void initializePage() override;
|
||||
|
||||
@ -109,12 +116,12 @@ class WizardConclusionPage: public QWizardPage {
|
||||
class Wizard: public QWizard {
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::function<int()> m_acceptFunc;
|
||||
std::function<int(QWizard*)> m_acceptFunc;
|
||||
|
||||
public:
|
||||
Wizard(QString windowTitle, QWidget *parent = 0);
|
||||
|
||||
void setAccept(std::function<int()> acceptFunc);
|
||||
void setAccept(std::function<int(QWizard*)> acceptFunc);
|
||||
|
||||
void accept();
|
||||
};
|
||||
|
@ -91,6 +91,8 @@ void MainWindow::loadPlugins() {
|
||||
delete loader;
|
||||
});
|
||||
m_plugins.push_back(plugin);
|
||||
} else {
|
||||
qInfo() << loader->errorString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,14 +234,14 @@ int MainWindow::openProject(QString projectPath) {
|
||||
auto project = new Project(projectPath);
|
||||
err |= project->openRomFs();
|
||||
if (err == 0) {
|
||||
if (m_project) {
|
||||
delete m_project;
|
||||
m_project = nullptr;
|
||||
if (m_ctx.project) {
|
||||
delete m_ctx.project;
|
||||
m_ctx.project = nullptr;
|
||||
}
|
||||
m_project = project;
|
||||
m_oxfsView = new OxFSModel(m_project->romFs());
|
||||
m_ctx.project = project;
|
||||
m_oxfsView = new OxFSModel(project->romFs());
|
||||
m_projectExplorer->setModel(m_oxfsView);
|
||||
connect(m_project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
|
||||
connect(m_ctx.project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
|
||||
m_importAction->setEnabled(true);
|
||||
m_state.projectPath = projectPath;
|
||||
}
|
||||
@ -248,11 +250,11 @@ int MainWindow::openProject(QString projectPath) {
|
||||
|
||||
int MainWindow::closeProject() {
|
||||
auto err = 0;
|
||||
if (m_project) {
|
||||
disconnect(m_project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
|
||||
if (m_ctx.project) {
|
||||
disconnect(m_ctx.project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
|
||||
|
||||
delete m_project;
|
||||
m_project = nullptr;
|
||||
delete m_ctx.project;
|
||||
m_ctx.project = nullptr;
|
||||
|
||||
delete m_oxfsView;
|
||||
m_oxfsView = nullptr;
|
||||
@ -293,45 +295,58 @@ void MainWindow::showNewWizard() {
|
||||
Wizard wizard(tr("New..."));
|
||||
auto ws = new WizardSelect();
|
||||
wizard.addPage(ws);
|
||||
ws->addOption(tr("Project"),
|
||||
[&wizard, PROJECT_NAME, PROJECT_PATH]() {
|
||||
QVector<QWizardPage*> pgs;
|
||||
auto pg = new WizardFormPage();
|
||||
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*", "", [PROJECT_PATH, pg, &wizard](QString projectName) {
|
||||
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
||||
|
||||
// add new project wizard
|
||||
ws->addOption(
|
||||
WizardMaker {
|
||||
tr("Project"),
|
||||
|
||||
[&wizard, PROJECT_NAME, PROJECT_PATH]() {
|
||||
QVector<QWizardPage*> pgs;
|
||||
auto pg = new WizardFormPage();
|
||||
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*", "", [PROJECT_PATH, pg, &wizard](QString projectName) {
|
||||
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
||||
auto path = projectPath + "/" + projectName;
|
||||
if (!QDir(path).exists()) {
|
||||
return 0;
|
||||
} else {
|
||||
pg->showValidationError(tr("This project directory already exists."));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
pg->addPathBrowse(tr("Project &Path:"), PROJECT_PATH + "*", QDir::homePath(), QFileDialog::Directory);
|
||||
pgs.push_back(pg);
|
||||
pgs.push_back(new WizardConclusionPage(tr("Creating project: %1/%2"), {PROJECT_PATH, PROJECT_NAME}));
|
||||
return pgs;
|
||||
},
|
||||
|
||||
[this, PROJECT_NAME, PROJECT_PATH](QWizard *wizard) {
|
||||
auto projectName = wizard->field(PROJECT_NAME).toString();
|
||||
auto projectPath = wizard->field(PROJECT_PATH).toString();
|
||||
if (QDir(projectPath).exists()) {
|
||||
auto path = projectPath + "/" + projectName;
|
||||
if (!QDir(path).exists()) {
|
||||
Project(path).create();
|
||||
openProject(path);
|
||||
return 0;
|
||||
} else {
|
||||
pg->showValidationError(tr("This project directory already exists."));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
pg->addPathBrowse(tr("Project &Path:"), PROJECT_PATH + "*", QDir::homePath(), QFileDialog::Directory);
|
||||
pgs.push_back(pg);
|
||||
pgs.push_back(new WizardConclusionPage(tr("Creating project: ") + "%1/%2", {PROJECT_PATH, PROJECT_NAME}));
|
||||
|
||||
return pgs;
|
||||
}
|
||||
);
|
||||
wizard.setAccept([this, &wizard, ws, PROJECT_NAME, PROJECT_PATH]() -> int {
|
||||
auto projectName = wizard.field(PROJECT_NAME).toString();
|
||||
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
||||
if (QDir(projectPath).exists()) {
|
||||
auto path = projectPath + "/" + projectName;
|
||||
if (!QDir(path).exists()) {
|
||||
Project(path).create();
|
||||
openProject(path);
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// add plugin options
|
||||
for (auto p : m_plugins) {
|
||||
for (auto w : p->newWizards(&m_ctx)) {
|
||||
ws->addOption(w);
|
||||
}
|
||||
}
|
||||
|
||||
wizard.show();
|
||||
wizard.exec();
|
||||
}
|
||||
@ -344,12 +359,9 @@ void MainWindow::showImportWizard() {
|
||||
auto ws = new WizardSelect();
|
||||
wizard.addPage(ws);
|
||||
|
||||
PluginArgs args {
|
||||
.project = m_project
|
||||
};
|
||||
for (auto p : m_plugins) {
|
||||
for (auto w : p->importWizards(args)) {
|
||||
ws->addOption(w.name, w.make);
|
||||
for (auto w : p->importWizards(&m_ctx)) {
|
||||
ws->addOption(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,14 +87,14 @@ class MainWindow: public QMainWindow {
|
||||
NostalgiaStudioProfile m_profile;
|
||||
NostalgiaStudioState m_state;
|
||||
QAction *m_importAction = nullptr;
|
||||
Project *m_project = nullptr;
|
||||
Context m_ctx;
|
||||
QPointer<QMenu> m_viewMenu;
|
||||
QVector<std::function<void()>> m_cleanupTasks;
|
||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||
QTreeView *m_projectExplorer = nullptr;
|
||||
QVector<Plugin*> m_plugins;
|
||||
QPointer<OxFSModel> m_oxfsView = nullptr;
|
||||
QTabBar *m_tabbar;
|
||||
QTabBar *m_tabbar = nullptr;
|
||||
|
||||
public:
|
||||
MainWindow(QString profilePath);
|
||||
|
@ -5,6 +5,10 @@
|
||||
{
|
||||
"dir": "../lib/nostalgia",
|
||||
"lib_name": "NostalgiaCore-Studio"
|
||||
},
|
||||
{
|
||||
"dir": "../lib/nostalgia",
|
||||
"lib_name": "NostalgiaWorld-Studio"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -11,3 +11,7 @@ install(
|
||||
DESTINATION
|
||||
include/nostalgia/world
|
||||
)
|
||||
|
||||
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
|
||||
add_subdirectory(studio)
|
||||
endif()
|
||||
|
24
src/nostalgia/world/studio/CMakeLists.txt
Normal file
24
src/nostalgia/world/studio/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
add_library(
|
||||
NostalgiaWorld-Studio SHARED
|
||||
consts.cpp
|
||||
newworldwizard.cpp
|
||||
worldstudioplugin.cpp
|
||||
worldeditor.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
NostalgiaWorld-Studio
|
||||
Qt5::Core
|
||||
Qt5::Widgets
|
||||
NostalgiaStudio
|
||||
OxFS
|
||||
OxStd
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
NostalgiaWorld-Studio
|
||||
LIBRARY DESTINATION
|
||||
${NOSTALGIA_DIST_PLUGIN}/nostalgia
|
||||
)
|
17
src/nostalgia/world/studio/consts.cpp
Normal file
17
src/nostalgia/world/studio/consts.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "consts.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
QString PATH_ZONES = "/World/Zones/";
|
||||
|
||||
}
|
||||
}
|
19
src/nostalgia/world/studio/consts.hpp
Normal file
19
src/nostalgia/world/studio/consts.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
extern QString PATH_ZONES;
|
||||
|
||||
}
|
||||
}
|
59
src/nostalgia/world/studio/newworldwizard.cpp
Normal file
59
src/nostalgia/world/studio/newworldwizard.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "newworldwizard.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
using namespace studio;
|
||||
|
||||
const QString NewWorldWizard::FIELD_WORLD_PATH = "World.WorldPath";
|
||||
const QString NewWorldWizard::FIELD_WIDTH = "World.Width";
|
||||
const QString NewWorldWizard::FIELD_HEIGHT = "World.Height";
|
||||
|
||||
NewWorldWizard::NewWorldWizard(const Context *ctx) {
|
||||
addLineEdit(tr("&Name:"), FIELD_WORLD_PATH, "", [this, ctx](QString worldName) {
|
||||
worldName = PATH_ZONES + worldName;
|
||||
if (ctx->project->stat(worldName).inode == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
this->showValidationError(tr("World already exists: %1").arg(worldName));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
addLineEdit(tr("&Width:"), FIELD_WIDTH, "", [this, ctx](QString widthStr) {
|
||||
bool ok = false;
|
||||
widthStr.toInt(&ok);
|
||||
if (ok) {
|
||||
return 0;
|
||||
} else {
|
||||
this->showValidationError(tr("Invalid width: \"%1\"").arg(widthStr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
addLineEdit(tr("&Height:"), FIELD_HEIGHT, "", [this, ctx](QString widthStr) {
|
||||
bool ok = false;
|
||||
widthStr.toInt(&ok);
|
||||
if (ok) {
|
||||
return 0;
|
||||
} else {
|
||||
this->showValidationError(tr("Invalid height: \"%1\"").arg(widthStr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
src/nostalgia/world/studio/newworldwizard.hpp
Normal file
29
src/nostalgia/world/studio/newworldwizard.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPluginLoader>
|
||||
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
struct NewWorldWizard: public studio::WizardFormPage {
|
||||
|
||||
static const QString FIELD_WORLD_PATH;
|
||||
static const QString FIELD_WIDTH;
|
||||
static const QString FIELD_HEIGHT;
|
||||
|
||||
NewWorldWizard(const studio::Context *ctx);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
13
src/nostalgia/world/studio/worldeditor.cpp
Normal file
13
src/nostalgia/world/studio/worldeditor.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#include "worldeditor.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
using namespace studio;
|
||||
|
||||
WorldEditor::WorldEditor(QString path, const Context *ctx) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
24
src/nostalgia/world/studio/worldeditor.hpp
Normal file
24
src/nostalgia/world/studio/worldeditor.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
class WorldEditor: public QWidget {
|
||||
|
||||
public:
|
||||
WorldEditor(QString path, const studio::Context *ctx);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
50
src/nostalgia/world/studio/worldstudioplugin.cpp
Normal file
50
src/nostalgia/world/studio/worldstudioplugin.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <nostalgia/world/world.hpp>
|
||||
|
||||
#include "consts.hpp"
|
||||
#include "newworldwizard.hpp"
|
||||
#include "worldeditor.hpp"
|
||||
|
||||
#include "worldstudioplugin.hpp"
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
using namespace studio;
|
||||
|
||||
QVector<WizardMaker> WorldEditorPlugin::newWizards(const Context *ctx) {
|
||||
return {
|
||||
{
|
||||
tr("Zone"),
|
||||
[ctx]() -> QVector<QWizardPage*> {
|
||||
return {new NewWorldWizard(ctx)};
|
||||
},
|
||||
[ctx](QWizard *w) {
|
||||
w->field(NewWorldWizard::FIELD_WORLD_PATH).toString();
|
||||
w->field(NewWorldWizard::FIELD_WIDTH).toInt();
|
||||
w->field(NewWorldWizard::FIELD_HEIGHT).toInt();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
QWidget *WorldEditorPlugin::makeEditor(QString path, const Context *ctx) {
|
||||
if (path.startsWith(PATH_ZONES)) {
|
||||
return new WorldEditor(path, ctx);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
src/nostalgia/world/studio/worldstudioplugin.hpp
Normal file
31
src/nostalgia/world/studio/worldstudioplugin.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2016-2017 gtalent2@gmail.com
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QPluginLoader>
|
||||
|
||||
#include <nostalgia/studio/studio.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
namespace world {
|
||||
|
||||
class WorldEditorPlugin: public QObject, public studio::Plugin {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "net.drinkingtea.nostalgia.studio.Plugin")
|
||||
Q_INTERFACES(nostalgia::studio::Plugin)
|
||||
|
||||
public:
|
||||
QVector<studio::WizardMaker> newWizards(const studio::Context *ctx) override;
|
||||
|
||||
QWidget *makeEditor(QString path, const studio::Context *ctx) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user