select level menu

This commit is contained in:
Andrei Yankovich 2021-06-10 18:07:04 +03:00
parent d7c637f4bf
commit 03abde5ca6
14 changed files with 45 additions and 48 deletions

View File

@ -7,6 +7,9 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setOrganizationName("QuasarApp");
QCoreApplication::setApplicationName("Snake");
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
ClientApp client; ClientApp client;

View File

@ -27,9 +27,11 @@ QByteArray ClientApp::initTheme() {
ClientApp::ClientApp() { ClientApp::ClientApp() {
_engine = new Engine(); _engine = new Engine();
_menu = new MainMenuModel();
} }
ClientApp::~ClientApp() { ClientApp::~ClientApp() {
delete _menu;
delete _engine; delete _engine;
for (const auto& item : qAsConst(_availableLvls)) { for (const auto& item : qAsConst(_availableLvls)) {
@ -57,16 +59,20 @@ void ClientApp::initLang() {
void ClientApp::initLvls() { void ClientApp::initLvls() {
auto plugins = availablePlugins(); auto plugins = availablePlugins();
QList<QObject*> _availableWorlds;
for (const auto& lvl: plugins) { for (const auto& lvl: plugins) {
WordlData data; WordlData data;
data.model = PluginLoader::load(lvl.absoluteFilePath()); data.model = PluginLoader::load(lvl.absoluteFilePath());
if (data.model) { if (data.model) {
data.viewModel = new WorldViewData(data.model); data.viewModel = new WorldViewData(data.model);
_availableWorlds.push_back(data.viewModel);
_availableLvls.insert(data.model->name(), data); _availableLvls.insert(data.model->name(), data);
} }
} }
_menu->setAvailableLvls(_availableWorlds);
} }
QList<QFileInfo> ClientApp::availablePlugins() const { QList<QFileInfo> ClientApp::availablePlugins() const {
@ -81,8 +87,6 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", initTheme()); qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", initTheme());
qputenv("QT_QUICK_CONTROLS_STYLE", "Material"); qputenv("QT_QUICK_CONTROLS_STYLE", "Material");
qmlRegisterAnonymousType<MainMenuModel>("MainMenuModel", 1);
auto root = engine->rootContext(); auto root = engine->rootContext();
if (!root) if (!root)
return false; return false;
@ -90,6 +94,8 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
engine->addImageProvider(QLatin1String("userItems"), new ImageProvider()); engine->addImageProvider(QLatin1String("userItems"), new ImageProvider());
root->setContextProperty("engine", QVariant::fromValue(_engine)); root->setContextProperty("engine", QVariant::fromValue(_engine));
root->setContextProperty("mainmenu", QVariant::fromValue(_menu));
initSnakeProjectResources(); initSnakeProjectResources();
initLang(); initLang();
initLvls(); initLvls();

View File

@ -10,6 +10,7 @@ class Engine;
class IWorld; class IWorld;
class WorldViewData; class WorldViewData;
class QQmlApplicationEngine; class QQmlApplicationEngine;
class MainMenuModel;
inline void initSnakeProjectResources() { Q_INIT_RESOURCE(SnakeProject); } inline void initSnakeProjectResources() { Q_INIT_RESOURCE(SnakeProject); }
@ -52,6 +53,7 @@ private:
QList<QFileInfo> availablePlugins() const; QList<QFileInfo> availablePlugins() const;
QHash<QString, WordlData> _availableLvls; QHash<QString, WordlData> _availableLvls;
MainMenuModel *_menu = nullptr;
Engine *_engine = nullptr; Engine *_engine = nullptr;
}; };

View File

@ -34,8 +34,7 @@ Item {
text: qsTr("Play game") text: qsTr("Play game")
onClicked: { onClicked: {
if (model) selectLvl.open()
model.newGame();
} }
} }
@ -90,7 +89,7 @@ Item {
PagePopUp { PagePopUp {
id: selectLvl id: selectLvl
source: SettingsView { source: SelectLvlView {
model: item1.model ? item1.model.availableLvlsModel: null model: item1.model ? item1.model.availableLvlsModel: null
} }

View File

@ -12,9 +12,11 @@ View3D {
property var player: (model)? model.player: null property var player: (model)? model.player: null
property var world: (model)? model.world: null property var world: (model)? model.world: null
property var releativeCameraPosition: (world)? model.cameraReleativePosition: null property var releativeCameraPosition: (world)? model.cameraReleativePosition: null
property bool showMenu: false
property bool isPause: false
onModelChanged: { onModelChanged: {
if (!mainScane) if (!model)
return; return;
model.scane = mainScane model.scane = mainScane
@ -22,9 +24,12 @@ View3D {
PerspectiveCamera { PerspectiveCamera {
id: camera id: camera
position: Qt.vector3d(player.position.x + releativeCameraPosition.x, position: (player)? Qt.vector3d(player.position.x + releativeCameraPosition.x,
player.position.y + releativeCameraPosition.y, player.position.y + releativeCameraPosition.y,
player.position.z + releativeCameraPosition.z) player.position.z + releativeCameraPosition.z)
:
Qt.vector3d(0,0,0)
eulerRotation.z: -90 eulerRotation.z: -90
} }
@ -38,31 +43,13 @@ View3D {
environment: SceneEnvironment { environment: SceneEnvironment {
id: background id: background
clearColor: window.color
backgroundMode: SceneEnvironment.SkyBox backgroundMode: SceneEnvironment.SkyBox
lightProbe: Texture { lightProbe: Texture {
source: model source: (model)? model.hdr: ""
} }
} }
Timer {
id: autoTimer;
repeat: true;
running: showMenu;
interval: 1000
onTriggered: {
interval = Math.random() * 600
scene.model.buttonPress();
}
}
Component.onCompleted: {
updateBackgroundColor(0);
model.handleNewGame();
}
MouseArea { MouseArea {
anchors.fill: parent; anchors.fill: parent;

View File

@ -5,6 +5,8 @@ ListView {
id: root id: root
property string selectedLvl: "" property string selectedLvl: ""
orientation: ListView.Horizontal
clip: true
delegate: ImageView { delegate: ImageView {
property var data : modelData property var data : modelData

View File

@ -20,19 +20,14 @@ ApplicationWindow {
Scene { Scene {
id: scane; id: scane;
model: contr; model: engine;
anchors.fill: parent; anchors.fill: parent;
} }
MainMenu { MainMenu {
model: (contr)? contr.mainMenuModel: null; model: (mainmenu)? mainmenu: null;
anchors.fill: parent; anchors.fill: parent;
visible: scane.showMenu;
onPlayGame: {
contr.showMenu = false;
}
} }

View File

@ -4,7 +4,7 @@
#include <SnakeProject/guiobject.h> #include <SnakeProject/guiobject.h>
#include "SnakeProject/iworld.h" #include "SnakeProject/iworld.h"
Engine::Engine() { Engine::Engine(QObject *parent): QObject(parent) {
} }

View File

@ -20,7 +20,7 @@ class Engine : public QObject {
Q_PROPERTY(QObject* scane READ scane WRITE setScane NOTIFY scaneChanged) Q_PROPERTY(QObject* scane READ scane WRITE setScane NOTIFY scaneChanged)
public: public:
Engine(); Engine(QObject * parent = nullptr);
/** /**
* @brief scane This method return main scane of the game. * @brief scane This method return main scane of the game.

View File

@ -1,6 +1,9 @@
#include "SnakeProject/iworld.h" #include "SnakeProject/iworld.h"
#include "world.h" #include "world.h"
IWorld* instance() { inline void initResources() { Q_INIT_RESOURCE(Empty); }
extern "C" IWorld* instance() {
initResources();
return new World(); return new World();
} }

View File

@ -18,7 +18,7 @@ WorldRule *World::initWorldRules() const {
} }
QString World::initHdrBackGround() const { QString World::initHdrBackGround() const {
return ":/hdr/res/hdr/testHDR.jpg"; return "qrc:/hdr/res/hdr/testHDR.jpg";
} }
QString World::description() const { QString World::description() const {
@ -26,7 +26,7 @@ QString World::description() const {
} }
QString World::imagePreview() const { QString World::imagePreview() const {
return ":/hdr/res/hdr/testHDR.jpg"; return "qrc:/hdr/res/hdr/testHDR.jpg";
} }

View File

@ -6,7 +6,7 @@
//# //#
#include <QtTest> #include <QtTest>
#include "exampletest.h" #include "pluginloadertest.h"
// Use This macros for initialize your own test classes. // Use This macros for initialize your own test classes.
// Check exampletests // Check exampletests
@ -32,7 +32,7 @@ private slots:
// BEGIN TESTS CASES // BEGIN TESTS CASES
TestCase(exampleTest, ExampleTest) TestCase(exampleTest, PluginLoaderTest)
// END TEST CASES // END TEST CASES
private: private:

View File

@ -6,17 +6,17 @@
//# //#
#include "exampletest.h" #include "pluginloadertest.h"
ExampleTest::ExampleTest() { PluginLoaderTest::PluginLoaderTest() {
} }
ExampleTest::~ExampleTest() { PluginLoaderTest::~PluginLoaderTest() {
} }
void ExampleTest::test() { void PluginLoaderTest::test() {
QVERIFY(true); QVERIFY(true);
} }

View File

@ -13,11 +13,11 @@
#include <QtTest> #include <QtTest>
class ExampleTest: public Test, protected TestUtils class PluginLoaderTest: public Test, protected TestUtils
{ {
public: public:
ExampleTest(); PluginLoaderTest();
~ExampleTest(); ~PluginLoaderTest();
void test(); void test();