diff --git a/.gitignore b/.gitignore index 84bece3a..2189a168 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ media_header.txt studio_state.json CMakeLists.txt.user Session.vim +ROM.oxfs diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d1fdc64..c84d01d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ endif() add_definitions( -std=c++14 - -fdiagnostics-color + #-fdiagnostics-color -Wall -Wsign-compare ) diff --git a/Makefile b/Makefile index 0669d375..fe537bf9 100644 --- a/Makefile +++ b/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 diff --git a/build/Makefile b/build/Makefile index a79652c6..05a1aa2a 100644 --- a/build/Makefile +++ b/build/Makefile @@ -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}; \ diff --git a/scripts/setup_build b/scripts/setup_build index e78c9297..34192f96 100755 --- a/scripts/setup_build +++ b/scripts/setup_build @@ -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 diff --git a/src/nostalgia/CMakeLists.txt b/src/nostalgia/CMakeLists.txt index e6b7c37b..4953afa3 100644 --- a/src/nostalgia/CMakeLists.txt +++ b/src/nostalgia/CMakeLists.txt @@ -3,6 +3,7 @@ if(NOT NOSTALGIA_BUILD_TYPE STREQUAL "GBA") find_package(Qt5Widgets) + set(CMAKE_AUTOMOC ON) endif() #project packages diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index 33624e90..075d418f 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required(VERSION 2.8.11) if(NOSTALGIA_BUILD_TYPE STREQUAL "Native") add_library( diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp index db8a00c8..12842f54 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp @@ -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; diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp index 2b1848ab..1e03b4e7 100644 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp +++ b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp @@ -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(); diff --git a/src/nostalgia/core/studio/plugin.cpp b/src/nostalgia/core/studio/plugin.cpp index 30dc4d56..bd2491f3 100644 --- a/src/nostalgia/core/studio/plugin.cpp +++ b/src/nostalgia/core/studio/plugin.cpp @@ -18,7 +18,7 @@ namespace core { Plugin::Plugin() { } -QVector Plugin::importWizards(studio::PluginArgs args) { +QVector Plugin::importWizards(const studio::Context *args) { return { { tr("Tile Sheet"), diff --git a/src/nostalgia/core/studio/plugin.hpp b/src/nostalgia/core/studio/plugin.hpp index 0aa8956d..51a8f4e9 100644 --- a/src/nostalgia/core/studio/plugin.hpp +++ b/src/nostalgia/core/studio/plugin.hpp @@ -23,7 +23,7 @@ class Plugin: public QObject, studio::Plugin { public: Plugin(); - QVector importWizards(studio::PluginArgs args) override; + QVector importWizards(const studio::Context *args) override; }; } diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index 09539e52..789f6566 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -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 diff --git a/src/nostalgia/studio/lib/plugin.cpp b/src/nostalgia/studio/lib/plugin.cpp index 86b55a5b..0822b69f 100644 --- a/src/nostalgia/studio/lib/plugin.cpp +++ b/src/nostalgia/studio/lib/plugin.cpp @@ -11,17 +11,17 @@ namespace nostalgia { namespace studio { -void Plugin::addNewWizard(QString name, std::function()> make) { - m_newWizards.push_back({name, make}); -} - -QVector Plugin::newWizards(PluginArgs) { +QVector Plugin::newWizards(const Context *ctx) { return {}; } -QVector Plugin::importWizards(PluginArgs) { +QVector Plugin::importWizards(const Context *ctx) { return {}; } +QWidget *Plugin::makeEditor(QString path, const Context *ctx) { + return nullptr; +} + } } diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index ba76d076..82f6268c 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -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()> make; + std::function onAccept; +}; + +struct EditorMaker { + virtual QWidget *make(QString path, const Context *ctx) = 0; }; class Plugin { - private: - QVector m_newWizards; public: - void addNewWizard(QString name, std::function()> make); + virtual QVector newWizards(const Context *ctx); - void addImportWizard(QString name, std::function()> make); + virtual QVector importWizards(const Context *ctx); - virtual QVector newWizards(PluginArgs); + virtual QWidget *makeEditor(QString path, const Context *ctx); - virtual QVector importWizards(PluginArgs); }; } diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index eac65663..99072c94 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -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()); +} + } } diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 6badbcf8..6fd2e928 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -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; + }; } diff --git a/src/nostalgia/studio/lib/wizard.cpp b/src/nostalgia/studio/lib/wizard.cpp index 076be095..af6f59fa 100644 --- a/src/nostalgia/studio/lib/wizard.cpp +++ b/src/nostalgia/studio/lib/wizard.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include +#include "plugin.hpp" #include "wizard.hpp" namespace nostalgia { @@ -43,9 +45,9 @@ void WizardSelect::initializePage() { emit completeChanged(); } -void WizardSelect::addOption(QString name, function()> 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()); + 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 acceptFunc) { +void Wizard::setAccept(std::function acceptFunc) { m_acceptFunc = acceptFunc; } @@ -333,7 +338,7 @@ void Wizard::accept() { auto page = dynamic_cast(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(); } } diff --git a/src/nostalgia/studio/lib/wizard.hpp b/src/nostalgia/studio/lib/wizard.hpp index 014457bd..088bd320 100644 --- a/src/nostalgia/studio/lib/wizard.hpp +++ b/src/nostalgia/studio/lib/wizard.hpp @@ -22,18 +22,25 @@ namespace nostalgia { namespace studio { +class WizardMaker; + class WizardSelect: public QWizardPage { Q_OBJECT private: - QMap()>> m_options; + struct WizardFuncs { + std::function()> make; + std::function onAccept; + }; + + QHash m_options; QListWidget *m_listWidget = nullptr; bool m_complete = false; public: WizardSelect(); - void addOption(QString name, std::function()> 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 m_acceptFunc; + std::function m_acceptFunc; public: Wizard(QString windowTitle, QWidget *parent = 0); - void setAccept(std::function acceptFunc); + void setAccept(std::function acceptFunc); void accept(); }; diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 5a3fe395..22bd6902 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -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 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 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); } } diff --git a/src/nostalgia/studio/mainwindow.hpp b/src/nostalgia/studio/mainwindow.hpp index d68fbfd0..6b613fda 100644 --- a/src/nostalgia/studio/mainwindow.hpp +++ b/src/nostalgia/studio/mainwindow.hpp @@ -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 m_viewMenu; QVector> m_cleanupTasks; QVector> m_dockWidgets; QTreeView *m_projectExplorer = nullptr; QVector m_plugins; QPointer m_oxfsView = nullptr; - QTabBar *m_tabbar; + QTabBar *m_tabbar = nullptr; public: MainWindow(QString profilePath); diff --git a/src/nostalgia/studio/nostalgia-studio.json b/src/nostalgia/studio/nostalgia-studio.json index c3f94f4a..0328a1ea 100644 --- a/src/nostalgia/studio/nostalgia-studio.json +++ b/src/nostalgia/studio/nostalgia-studio.json @@ -5,6 +5,10 @@ { "dir": "../lib/nostalgia", "lib_name": "NostalgiaCore-Studio" + }, + { + "dir": "../lib/nostalgia", + "lib_name": "NostalgiaWorld-Studio" } ] } diff --git a/src/nostalgia/world/CMakeLists.txt b/src/nostalgia/world/CMakeLists.txt index 6990a21b..c2285a49 100644 --- a/src/nostalgia/world/CMakeLists.txt +++ b/src/nostalgia/world/CMakeLists.txt @@ -11,3 +11,7 @@ install( DESTINATION include/nostalgia/world ) + +if(NOSTALGIA_BUILD_TYPE STREQUAL "Native") + add_subdirectory(studio) +endif() diff --git a/src/nostalgia/world/studio/CMakeLists.txt b/src/nostalgia/world/studio/CMakeLists.txt new file mode 100644 index 00000000..dcfbc011 --- /dev/null +++ b/src/nostalgia/world/studio/CMakeLists.txt @@ -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 +) diff --git a/src/nostalgia/world/studio/consts.cpp b/src/nostalgia/world/studio/consts.cpp new file mode 100644 index 00000000..7b549f59 --- /dev/null +++ b/src/nostalgia/world/studio/consts.cpp @@ -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/"; + +} +} diff --git a/src/nostalgia/world/studio/consts.hpp b/src/nostalgia/world/studio/consts.hpp new file mode 100644 index 00000000..c94d449f --- /dev/null +++ b/src/nostalgia/world/studio/consts.hpp @@ -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 + +namespace nostalgia { +namespace world { + +extern QString PATH_ZONES; + +} +} diff --git a/src/nostalgia/world/studio/newworldwizard.cpp b/src/nostalgia/world/studio/newworldwizard.cpp new file mode 100644 index 00000000..308d7aac --- /dev/null +++ b/src/nostalgia/world/studio/newworldwizard.cpp @@ -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 + +#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; + } + } + ); +} + +} +} diff --git a/src/nostalgia/world/studio/newworldwizard.hpp b/src/nostalgia/world/studio/newworldwizard.hpp new file mode 100644 index 00000000..38d3c340 --- /dev/null +++ b/src/nostalgia/world/studio/newworldwizard.hpp @@ -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 + +#include + +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); + +}; + +} +} diff --git a/src/nostalgia/world/studio/worldeditor.cpp b/src/nostalgia/world/studio/worldeditor.cpp new file mode 100644 index 00000000..3730cb74 --- /dev/null +++ b/src/nostalgia/world/studio/worldeditor.cpp @@ -0,0 +1,13 @@ + +#include "worldeditor.hpp" + +namespace nostalgia { +namespace world { + +using namespace studio; + +WorldEditor::WorldEditor(QString path, const Context *ctx) { +} + +} +} diff --git a/src/nostalgia/world/studio/worldeditor.hpp b/src/nostalgia/world/studio/worldeditor.hpp new file mode 100644 index 00000000..ee3c3ab3 --- /dev/null +++ b/src/nostalgia/world/studio/worldeditor.hpp @@ -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 + +namespace nostalgia { +namespace world { + +class WorldEditor: public QWidget { + + public: + WorldEditor(QString path, const studio::Context *ctx); + +}; + +} +} diff --git a/src/nostalgia/world/studio/worldstudioplugin.cpp b/src/nostalgia/world/studio/worldstudioplugin.cpp new file mode 100644 index 00000000..7fd716f2 --- /dev/null +++ b/src/nostalgia/world/studio/worldstudioplugin.cpp @@ -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 + +#include + +#include "consts.hpp" +#include "newworldwizard.hpp" +#include "worldeditor.hpp" + +#include "worldstudioplugin.hpp" + +namespace nostalgia { +namespace world { + +using namespace studio; + +QVector WorldEditorPlugin::newWizards(const Context *ctx) { + return { + { + tr("Zone"), + [ctx]() -> QVector { + 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; + } +} + +} +} diff --git a/src/nostalgia/world/studio/worldstudioplugin.hpp b/src/nostalgia/world/studio/worldstudioplugin.hpp new file mode 100644 index 00000000..442fc80e --- /dev/null +++ b/src/nostalgia/world/studio/worldstudioplugin.hpp @@ -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 + +#include + +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 newWizards(const studio::Context *ctx) override; + + QWidget *makeEditor(QString path, const studio::Context *ctx) override; + +}; + +} +}