4
1
mirror of https://github.com/QuasarApp/Snake.git synced 2025-05-06 06:29:47 +00:00

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

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

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

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

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

@ -12,9 +12,11 @@ View3D {
property var player: (model)? model.player: null
property var world: (model)? model.world: null
property var releativeCameraPosition: (world)? model.cameraReleativePosition: null
property bool showMenu: false
property bool isPause: false
onModelChanged: {
if (!mainScane)
if (!model)
return;
model.scane = mainScane
@ -22,9 +24,12 @@ View3D {
PerspectiveCamera {
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.z + releativeCameraPosition.z)
:
Qt.vector3d(0,0,0)
eulerRotation.z: -90
}
@ -38,31 +43,13 @@ View3D {
environment: SceneEnvironment {
id: background
clearColor: window.color
backgroundMode: SceneEnvironment.SkyBox
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 {
anchors.fill: parent;

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

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

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

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

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

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

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

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

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