Add new World wizard

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

View File

@@ -11,3 +11,7 @@ install(
DESTINATION
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;
};
}
}