Add new World wizard

This commit is contained in:
Gary Talent 2017-12-20 22:41:14 -06:00
parent 2edee450aa
commit 4e50d80f5f
31 changed files with 415 additions and 94 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ media_header.txt
studio_state.json studio_state.json
CMakeLists.txt.user CMakeLists.txt.user
Session.vim Session.vim
ROM.oxfs

View File

@ -22,7 +22,7 @@ endif()
add_definitions( add_definitions(
-std=c++14 -std=c++14
-fdiagnostics-color #-fdiagnostics-color
-Wall -Wall
-Wsign-compare -Wsign-compare
) )

View File

@ -71,6 +71,11 @@ debug:
${ENV_RUN} ./scripts/setup_build ${HOST_ENV} debug ${ENV_RUN} ./scripts/setup_build ${HOST_ENV} debug
${ENV_RUN} rm -f build/current ${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: windows:
${ENV_RUN} rm -rf build/windows ${ENV_RUN} rm -rf build/windows
${ENV_RUN} ./scripts/setup_build windows ${ENV_RUN} ./scripts/setup_build windows

View File

@ -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),) ifneq ($(shell which gmake),)
MAKE="gmake" MAKE="gmake"
@ -26,6 +26,11 @@ native_debug_build:
${MAKE} -C ${HOST_ENV}-debug ${ARGS}; \ ${MAKE} -C ${HOST_ENV}-debug ${ARGS}; \
fi fi
native_asan_build:
@if [ -d ${HOST_ENV}-asan ]; then \
${MAKE} -C ${HOST_ENV}-asan ${ARGS}; \
fi
windows_release: windows_release:
@if [ -d windows-release ]; then \ @if [ -d windows-release ]; then \
${MAKE} -C windows-release ${ARGS}; \ ${MAKE} -C windows-release ${ARGS}; \

View File

@ -17,8 +17,10 @@ elif [[ $TARGET == gba ]]; then
toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DNOSTALGIA_BUILD_TYPE=GBA -DOX_USE_STDLIB=OFF" toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DNOSTALGIA_BUILD_TYPE=GBA -DOX_USE_STDLIB=OFF"
fi fi
if [[ $BUILD_TYPE == debug ]]; then if [[ $BUILD_TYPE == asan ]]; then
buildTypeArgs="-DUSE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug" buildTypeArgs="-DUSE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug"
elif [[ $BUILD_TYPE == debug ]]; then
buildTypeArgs="-DCMAKE_BUILD_TYPE=Debug"
elif [[ $BUILD_TYPE == release ]]; then elif [[ $BUILD_TYPE == release ]]; then
buildTypeArgs="-DCMAKE_BUILD_TYPE=Release" buildTypeArgs="-DCMAKE_BUILD_TYPE=Release"
fi fi

View File

@ -3,6 +3,7 @@
if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA") if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA")
find_package(Qt5Widgets) find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
endif() endif()
#project packages #project packages

View File

@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 2.8.11)
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native") if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_library( add_library(

View File

@ -18,7 +18,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(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) { 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()) {
@ -53,9 +54,9 @@ int ImportTilesheetWizardPage::importImage(QFile &srcFile, QString tilesheetName
srcFile.open(QIODevice::ReadOnly); srcFile.open(QIODevice::ReadOnly);
if (srcFile.read((char*) buff, buffSize) > 0) { if (srcFile.read((char*) buff, buffSize) > 0) {
int err = 0; int err = 0;
m_project->mkdir(TILESHEET_DIR); m_ctx->project->mkdir(TILESHEET_DIR);
err |= m_project->write(TILESHEET_DIR + tilesheetName, buff, buffSize); err |= m_ctx->project->write(TILESHEET_DIR + tilesheetName, buff, buffSize);
err |= m_project->saveRomFs(); err |= m_ctx->project->saveRomFs();
return err; return err;
} else { } else {
return 1; return 1;

View File

@ -19,10 +19,10 @@ 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; const studio::Context *m_ctx = nullptr;
public: public:
ImportTilesheetWizardPage(studio::PluginArgs args); ImportTilesheetWizardPage(const studio::Context *args);
int accept(); int accept();

View File

@ -18,7 +18,7 @@ namespace core {
Plugin::Plugin() { Plugin::Plugin() {
} }
QVector<studio::WizardMaker> Plugin::importWizards(studio::PluginArgs args) { QVector<studio::WizardMaker> Plugin::importWizards(const studio::Context *args) {
return { return {
{ {
tr("Tile Sheet"), tr("Tile Sheet"),

View File

@ -23,7 +23,7 @@ class Plugin: public QObject, studio::Plugin {
public: public:
Plugin(); Plugin();
QVector<studio::WizardMaker> importWizards(studio::PluginArgs args) override; QVector<studio::WizardMaker> importWizards(const studio::Context *args) override;
}; };
} }

View File

@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8.11)
project(nostalgia-studio) project(nostalgia-studio)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_executable( add_executable(
nostalgia-studio nostalgia-studio

View File

@ -11,17 +11,17 @@
namespace nostalgia { namespace nostalgia {
namespace studio { namespace studio {
void Plugin::addNewWizard(QString name, std::function<QVector<QWizardPage*>()> make) { QVector<WizardMaker> Plugin::newWizards(const Context *ctx) {
m_newWizards.push_back({name, make});
}
QVector<WizardMaker> Plugin::newWizards(PluginArgs) {
return {}; return {};
} }
QVector<WizardMaker> Plugin::importWizards(PluginArgs) { QVector<WizardMaker> Plugin::importWizards(const Context *ctx) {
return {}; return {};
} }
QWidget *Plugin::makeEditor(QString path, const Context *ctx) {
return nullptr;
}
} }
} }

View File

@ -21,27 +21,30 @@
namespace nostalgia { namespace nostalgia {
namespace studio { namespace studio {
struct PluginArgs { struct Context {
Project *&project; QWidget *tabParent = nullptr;
const Project *project = nullptr;
}; };
struct WizardMaker { struct WizardMaker {
QString name; QString name;
std::function<QVector<QWizardPage*>()> make; std::function<QVector<QWizardPage*>()> make;
std::function<int(QWizard*)> onAccept;
};
struct EditorMaker {
virtual QWidget *make(QString path, const Context *ctx) = 0;
}; };
class Plugin { class Plugin {
private:
QVector<WizardMaker> m_newWizards;
public: 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);
}; };
} }

View File

@ -65,7 +65,7 @@ int Project::openRomFs() {
} }
} }
int Project::saveRomFs() { int Project::saveRomFs() const {
int err = 0; int err = 0;
QFile file(m_path + ROM_FILE); QFile file(m_path + ROM_FILE);
err |= file.open(QIODevice::WriteOnly) == false; err |= file.open(QIODevice::WriteOnly) == false;
@ -78,17 +78,21 @@ FileSystem *Project::romFs() {
return m_fs; return m_fs;
} }
int Project::mkdir(QString path) { int Project::mkdir(QString path) const {
auto err = m_fs->mkdir(path.toUtf8().data()); auto err = m_fs->mkdir(path.toUtf8().data());
emit updated(path); emit updated(path);
return err; 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); auto err = m_fs->write(path.toUtf8().data(), buff, buffLen);
emit updated(path); emit updated(path);
return err; return err;
} }
ox::FileStat Project::stat(QString path) const {
return m_fs->stat(path.toUtf8().data());
}
} }
} }

View File

@ -33,16 +33,19 @@ class Project: public QObject {
int openRomFs(); int openRomFs();
int saveRomFs(); int saveRomFs() const;
ox::FileSystem *romFs(); 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: signals:
void updated(QString path); void updated(QString path) const;
}; };
} }

View File

@ -7,6 +7,7 @@
*/ */
#include <QComboBox> #include <QComboBox>
#include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
@ -14,6 +15,7 @@
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "plugin.hpp"
#include "wizard.hpp" #include "wizard.hpp"
namespace nostalgia { namespace nostalgia {
@ -43,9 +45,9 @@ void WizardSelect::initializePage() {
emit completeChanged(); emit completeChanged();
} }
void WizardSelect::addOption(QString name, function<QVector<QWizardPage*>()> makePage) { void WizardSelect::addOption(WizardMaker wm) {
m_options[name] = makePage; m_options[wm.name] = {wm.make, wm.onAccept};
m_listWidget->addItem(name); m_listWidget->addItem(wm.name);
} }
bool WizardSelect::isComplete() const { bool WizardSelect::isComplete() const {
@ -53,18 +55,21 @@ bool WizardSelect::isComplete() const {
} }
void WizardSelect::itemSelected(int row) { void WizardSelect::itemSelected(int row) {
if (row > -1) { auto w = dynamic_cast<Wizard*>(wizard());
auto w = wizard(); if (w and row > -1) {
// remove other pages
if (nextId() > -1) { while (nextId() > -1) {
w->removePage(nextId()); w->removePage(nextId());
} }
auto selected = m_listWidget->currentItem()->text(); auto selected = m_listWidget->currentItem()->text();
if (m_options.contains(selected)) { 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->addPage(p);
} }
w->setAccept(o.onAccept);
// for some reason the continue button only appears correctly after remove runs // for some reason the continue button only appears correctly after remove runs
w->removePage(w->addPage(new QWizardPage())); w->removePage(w->addPage(new QWizardPage()));
} }
@ -313,7 +318,7 @@ void WizardFormPage::showValidationError(QString msg) {
// set message // set message
if (msg != "") { if (msg != "") {
m_errorMsg->setText(tr("Error: ") + msg); m_errorMsg->setText(msg);
} else { } else {
m_errorMsg->setText(""); m_errorMsg->setText("");
} }
@ -325,7 +330,7 @@ Wizard::Wizard(QString windowTitle, QWidget *parent): QWizard(parent) {
setModal(true); setModal(true);
} }
void Wizard::setAccept(std::function<int()> acceptFunc) { void Wizard::setAccept(std::function<int(QWizard*)> acceptFunc) {
m_acceptFunc = acceptFunc; m_acceptFunc = acceptFunc;
} }
@ -333,7 +338,7 @@ void Wizard::accept() {
auto page = dynamic_cast<WizardFormPage*>(currentPage()); auto page = dynamic_cast<WizardFormPage*>(currentPage());
if (page != nullptr && page->accept() == 0) { if (page != nullptr && page->accept() == 0) {
QDialog::accept(); QDialog::accept();
} else if (m_acceptFunc != nullptr && m_acceptFunc() == 0) { } else if (m_acceptFunc != nullptr && m_acceptFunc(this) == 0) {
QDialog::accept(); QDialog::accept();
} }
} }

View File

@ -22,18 +22,25 @@
namespace nostalgia { namespace nostalgia {
namespace studio { namespace studio {
class WizardMaker;
class WizardSelect: public QWizardPage { class WizardSelect: public QWizardPage {
Q_OBJECT Q_OBJECT
private: 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; QListWidget *m_listWidget = nullptr;
bool m_complete = false; bool m_complete = false;
public: public:
WizardSelect(); WizardSelect();
void addOption(QString name, std::function<QVector<QWizardPage*>()> makePage); void addOption(WizardMaker wm);
void initializePage() override; void initializePage() override;
@ -109,12 +116,12 @@ class WizardConclusionPage: public QWizardPage {
class Wizard: public QWizard { class Wizard: public QWizard {
Q_OBJECT Q_OBJECT
private: private:
std::function<int()> m_acceptFunc; std::function<int(QWizard*)> m_acceptFunc;
public: public:
Wizard(QString windowTitle, QWidget *parent = 0); Wizard(QString windowTitle, QWidget *parent = 0);
void setAccept(std::function<int()> acceptFunc); void setAccept(std::function<int(QWizard*)> acceptFunc);
void accept(); void accept();
}; };

View File

@ -91,6 +91,8 @@ void MainWindow::loadPlugins() {
delete loader; delete loader;
}); });
m_plugins.push_back(plugin); m_plugins.push_back(plugin);
} else {
qInfo() << loader->errorString();
} }
} }
} }
@ -232,14 +234,14 @@ int MainWindow::openProject(QString projectPath) {
auto project = new Project(projectPath); auto project = new Project(projectPath);
err |= project->openRomFs(); err |= project->openRomFs();
if (err == 0) { if (err == 0) {
if (m_project) { if (m_ctx.project) {
delete m_project; delete m_ctx.project;
m_project = nullptr; m_ctx.project = nullptr;
} }
m_project = project; m_ctx.project = project;
m_oxfsView = new OxFSModel(m_project->romFs()); m_oxfsView = new OxFSModel(project->romFs());
m_projectExplorer->setModel(m_oxfsView); 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_importAction->setEnabled(true);
m_state.projectPath = projectPath; m_state.projectPath = projectPath;
} }
@ -248,11 +250,11 @@ int MainWindow::openProject(QString projectPath) {
int MainWindow::closeProject() { int MainWindow::closeProject() {
auto err = 0; auto err = 0;
if (m_project) { if (m_ctx.project) {
disconnect(m_project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString))); disconnect(m_ctx.project, SIGNAL(updated(QString)), m_oxfsView, SLOT(updateFile(QString)));
delete m_project; delete m_ctx.project;
m_project = nullptr; m_ctx.project = nullptr;
delete m_oxfsView; delete m_oxfsView;
m_oxfsView = nullptr; m_oxfsView = nullptr;
@ -293,7 +295,12 @@ void MainWindow::showNewWizard() {
Wizard wizard(tr("New...")); Wizard wizard(tr("New..."));
auto ws = new WizardSelect(); auto ws = new WizardSelect();
wizard.addPage(ws); wizard.addPage(ws);
ws->addOption(tr("Project"),
// add new project wizard
ws->addOption(
WizardMaker {
tr("Project"),
[&wizard, PROJECT_NAME, PROJECT_PATH]() { [&wizard, PROJECT_NAME, PROJECT_PATH]() {
QVector<QWizardPage*> pgs; QVector<QWizardPage*> pgs;
auto pg = new WizardFormPage(); auto pg = new WizardFormPage();
@ -310,14 +317,13 @@ void MainWindow::showNewWizard() {
); );
pg->addPathBrowse(tr("Project &Path:"), PROJECT_PATH + "*", QDir::homePath(), QFileDialog::Directory); pg->addPathBrowse(tr("Project &Path:"), PROJECT_PATH + "*", QDir::homePath(), QFileDialog::Directory);
pgs.push_back(pg); pgs.push_back(pg);
pgs.push_back(new WizardConclusionPage(tr("Creating project: ") + "%1/%2", {PROJECT_PATH, PROJECT_NAME})); pgs.push_back(new WizardConclusionPage(tr("Creating project: %1/%2"), {PROJECT_PATH, PROJECT_NAME}));
return pgs; return pgs;
} },
);
wizard.setAccept([this, &wizard, ws, PROJECT_NAME, PROJECT_PATH]() -> int { [this, PROJECT_NAME, PROJECT_PATH](QWizard *wizard) {
auto projectName = wizard.field(PROJECT_NAME).toString(); auto projectName = wizard->field(PROJECT_NAME).toString();
auto projectPath = wizard.field(PROJECT_PATH).toString(); auto projectPath = wizard->field(PROJECT_PATH).toString();
if (QDir(projectPath).exists()) { if (QDir(projectPath).exists()) {
auto path = projectPath + "/" + projectName; auto path = projectPath + "/" + projectName;
if (!QDir(path).exists()) { if (!QDir(path).exists()) {
@ -331,7 +337,16 @@ void MainWindow::showNewWizard() {
return 2; return 2;
} }
} }
}
); );
// add plugin options
for (auto p : m_plugins) {
for (auto w : p->newWizards(&m_ctx)) {
ws->addOption(w);
}
}
wizard.show(); wizard.show();
wizard.exec(); wizard.exec();
} }
@ -344,12 +359,9 @@ void MainWindow::showImportWizard() {
auto ws = new WizardSelect(); auto ws = new WizardSelect();
wizard.addPage(ws); wizard.addPage(ws);
PluginArgs args {
.project = m_project
};
for (auto p : m_plugins) { for (auto p : m_plugins) {
for (auto w : p->importWizards(args)) { for (auto w : p->importWizards(&m_ctx)) {
ws->addOption(w.name, w.make); ws->addOption(w);
} }
} }

View File

@ -87,14 +87,14 @@ class MainWindow: public QMainWindow {
NostalgiaStudioProfile m_profile; NostalgiaStudioProfile m_profile;
NostalgiaStudioState m_state; NostalgiaStudioState m_state;
QAction *m_importAction = nullptr; QAction *m_importAction = nullptr;
Project *m_project = nullptr; Context m_ctx;
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;
QTreeView *m_projectExplorer = nullptr; QTreeView *m_projectExplorer = nullptr;
QVector<Plugin*> m_plugins; QVector<Plugin*> m_plugins;
QPointer<OxFSModel> m_oxfsView = nullptr; QPointer<OxFSModel> m_oxfsView = nullptr;
QTabBar *m_tabbar; QTabBar *m_tabbar = nullptr;
public: public:
MainWindow(QString profilePath); MainWindow(QString profilePath);

View File

@ -5,6 +5,10 @@
{ {
"dir": "../lib/nostalgia", "dir": "../lib/nostalgia",
"lib_name": "NostalgiaCore-Studio" "lib_name": "NostalgiaCore-Studio"
},
{
"dir": "../lib/nostalgia",
"lib_name": "NostalgiaWorld-Studio"
} }
] ]
} }

View File

@ -11,3 +11,7 @@ install(
DESTINATION DESTINATION
include/nostalgia/world include/nostalgia/world
) )
if(NOSTALGIA_BUILD_TYPE STREQUAL "Native")
add_subdirectory(studio)
endif()

View 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
)

View 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/";
}
}

View 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;
}
}

View 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;
}
}
);
}
}
}

View 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);
};
}
}

View File

@ -0,0 +1,13 @@
#include "worldeditor.hpp"
namespace nostalgia {
namespace world {
using namespace studio;
WorldEditor::WorldEditor(QString path, const Context *ctx) {
}
}
}

View 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);
};
}
}

View 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;
}
}
}
}

View 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;
};
}
}