Add new World wizard
This commit is contained in:
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user