mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-08 07:29:45 +00:00
select level menu
This commit is contained in:
parent
d7c637f4bf
commit
03abde5ca6
@ -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;
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
@ -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);
|
||||||
}
|
}
|
@ -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();
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user