chenge main menu

This commit is contained in:
Andrei Yankovich 2021-08-15 15:05:40 +03:00
parent 2a376488c8
commit 82c2a7e2ed
28 changed files with 155 additions and 332 deletions

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -73,6 +73,10 @@
<source>Select level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreviewControl</name>
@ -86,9 +90,9 @@
</message>
</context>
<context>
<name>SelectLvlView</name>
<name>SelectLevelView</name>
<message>
<source>Start</source>
<source>Select</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -10,7 +10,6 @@
<file>CrawlModule/Scene.qml</file>
<file>CrawlModule/SettingsView.qml</file>
<file>CrawlModule/SnakeItem.qml</file>
<file>CrawlModule/SelectLvlView.qml</file>
<file>CrawlModule/DefaultMenu.qml</file>
<file>CrawlModule/AbstractMenuView.qml</file>
<file>CrawlModule/Light.qml</file>

View File

@ -39,9 +39,9 @@ QByteArray ClientApp::initTheme() {
ILevel *ClientApp::getLastLevel() {
for (const auto &data : qAsConst(_availableLvls)) {
if (data.model && data.model->world() && _engine->currentUser() &&
_engine->currentUser()->isUnlocked(data.model->world()->itemId())) {
return data.model;
if (data && data->world() && _engine->currentUser() &&
_engine->currentUser()->isUnlocked(data->world()->itemId())) {
return data;
}
}
@ -50,18 +50,13 @@ ILevel *ClientApp::getLastLevel() {
ClientApp::ClientApp() {
_engine = new Engine();
_menu = new MainMenuModel();
connect(_menu, &MainMenuModel::sigLevelChanged, this, &ClientApp::changeLevel);
}
ClientApp::~ClientApp() {
delete _menu;
delete _engine;
for (auto it = _availableLvls.begin(); it != _availableLvls.end(); ++it) {
delete it.value().viewModel;
delete it.value().model;
delete it.value();
}
_availableLvls.clear();
@ -69,15 +64,15 @@ ClientApp::~ClientApp() {
void ClientApp::initStore(QMultiHash<int, const IItem *> & result) {
for (const auto &data : qAsConst(_availableLvls)) {
if (data.model && data.model->world())
result.unite(data.model->world()->childItemsRecursive());
if (data && data->world())
result.unite(data->world()->childItemsRecursive());
}
}
void ClientApp::changeLevel(int lvl) {
WordlData data = _availableLvls.value(lvl);
ILevel* data = _availableLvls.value(lvl, nullptr);
if (!data.model) {
if (!data) {
QuasarAppUtils::Params::log("Failed to start lvl.", QuasarAppUtils::Error);
return;
}
@ -89,7 +84,7 @@ void ClientApp::changeLevel(int lvl) {
return;
}
_engine->setLevel(data.model);
_engine->setLevel(data);
}
bool ClientApp::init(QQmlApplicationEngine *engine) {
@ -104,7 +99,6 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
engine->addImageProvider(QLatin1String("userItems"), new ImageProvider());
root->setContextProperty("engine", QVariant::fromValue(_engine));
root->setContextProperty("mainmenu", QVariant::fromValue(_menu));
qmlRegisterUncreatableMetaObject(
WorldStatus::staticMetaObject,
@ -140,12 +134,7 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
}
void ClientApp::addLvl(ILevel *levelWordl) {
WordlData data;
data.model = levelWordl;
data.viewModel = new WorldViewData(data.model->world());
_availableLvls.insert(data.model->world()->itemId(), data);
_menu->addWorldViewModel(data.viewModel);
_availableLvls.insert(levelWordl->world()->itemId(), levelWordl);
}
}

View File

@ -22,19 +22,10 @@ namespace CRAWL {
class Engine;
class IWorld;
class WorldViewData;
class MainMenuModel;
class IControl;
class Store;
/**
* @brief The WordlData struct simple structure that contains information about world.
*/
struct WordlData {
WorldViewData* viewModel = nullptr;
ILevel * model = nullptr;
};
/**
* @brief The ClientApp class This is main class of the Game engine.
*/
@ -87,8 +78,7 @@ private:
*/
void changeLevel(int lvl);
QHash<int, WordlData> _availableLvls;
MainMenuModel *_menu = nullptr;
QHash<int, ILevel*> _availableLvls;
Engine *_engine = nullptr;
};

View File

@ -41,9 +41,8 @@ ApplicationWindow {
MainMenu {
model: (mainmenu)? mainmenu: null;
model: (mainWindow.model)? mainWindow.model.menu: null;
anchors.fill: parent;
visible: scane.showMenu
}
NotificationServiceView {

View File

@ -11,10 +11,10 @@ import QtQuick.Controls
import QtQuick.Layouts
Item {
id: item1
id: root
property var model: null
visible: true
visible: Boolean(model && model.visible)
z: 1
GridLayout {
@ -35,7 +35,6 @@ Item {
transformOrigin: Item.Center
MainMenuButton {
id: play
text: qsTr("Select level")
@ -45,6 +44,15 @@ Item {
}
}
MainMenuButton {
id: store
text: qsTr("Store")
onClicked: {
storePopUp.open()
}
}
MainMenuButton {
id: settings
text: qsTr("My Settings")
@ -70,7 +78,7 @@ Item {
id: settingsPopUp
source: SettingsView {
id: settingsView
model: item1.model ? item1.model.userSettingsModel: null
model: root.model ? root.model.userSettingsModel: null
}
standardButtons: Dialog.Save | Dialog.Cancel | Dialog.RestoreDefaults
@ -93,19 +101,25 @@ Item {
}
PagePopUp {
id: selectLvl
source: SelectLvlView {
id: storePopUp
source: StoreView {
id: view
model: item1.model ? item1.model.availableLvlsModel: null
model: root.model ? root.model.storeView: null
onStart: {
if (!item1.model)
return;
}
item1.model.newGame(view.selectedLvl)
modal: false;
width: parent.width * 0.8
height: parent.height * 0.8;
}
PagePopUp {
id: selectLvl
source: SelectLevelView {
id: selectLvlView
model: root.model ? root.model.availableLvlsModel: null
selectLvl.close();
}
}
modal: false;

View File

@ -12,7 +12,7 @@ import QtQuick.Controls
import QtQuick.Layouts
AbstractMenuView {
columns: 2
columns: 4
rows: 2
MouseArea {
@ -20,7 +20,7 @@ AbstractMenuView {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.columnSpan: 2
Layout.columnSpan: 4
Layout.rowSpan: 1
onClicked: {

View File

@ -5,14 +5,11 @@ import QtQuick.Controls
import QtQuick.Layouts
import QtQuick3D.Particles3D
// https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject
import engine.worldstatus
View3D {
id: scene;
property var worldModel: null;
property alias showMenu: privateRoot.showMenu
renderMode: View3D.Offscreen
visible: worldModel && worldModel.visible
@ -52,7 +49,6 @@ View3D {
property var releativeCameraPosition: (worldModel)? worldModel.cameraReleativePosition: null
property var gameMenu: null
property bool showMenu: (worldModel)? WorldStatus.Game !== worldModel.worldStatus : false;
function add (cppObjId) {
if (!worldModel) {
@ -144,12 +140,6 @@ View3D {
console.log("Error loading component: " + privateRoot.gameMenuModel.view, comp.errorString());
}
}
function onShowMenuChanged() {
if (privateRoot.gameMenu) {
privateRoot.gameMenu.visible = !showMenu
}
}
}
}
}

View File

@ -7,7 +7,6 @@ import QtQuick.Layouts
Page {
id: store
property var model: null;
visible: model && model.visible
ColumnLayout {
anchors.fill: parent
ListView {

View File

@ -1,61 +0,0 @@
//#
//# Copyright (C) 2021-2021 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
import QtQuick
import ViewSolutionsModule
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
ColumnLayout {
id: root
property alias model: list.model
property string selectedLvl: ""
signal start(var lvlName)
ListView {
id: list
Layout.fillHeight: true
Layout.fillWidth: true
orientation: ListView.Horizontal
clip: true
delegate: ImageView {
property var data : modelData
hoverColor: "#90f6ff"
selectedColor: "#90f6ff"
source: data.image
text: data.name
width: list.height * 1.5
height: list.height * 0.9
selected: selectedLvl === data.name
onClicked: {
selectedLvl = text
}
}
}
Button {
Layout.alignment: Qt.AlignRight
text: qsTr("Start")
enabled: selectedLvl.length
onClicked: {
root.start(selectedLvl)
}
}
}

View File

@ -7,7 +7,6 @@ import QtQuick.Layouts
Page {
id: store
property var model: null;
visible: model && model.visible
ColumnLayout {
anchors.fill: parent
ListView {

View File

@ -6,6 +6,7 @@
//#
#include "engine.h"
#include "mainmenumodel.h"
#include <QQmlComponent>
#include <Crawl/guiobject.h>
@ -23,14 +24,15 @@ namespace CRAWL {
Engine::Engine(QObject *parent): QObject(parent) {
_store = new Store();
_storeView = new StoreViewModel;
_currentUser = new User();
_menu = new MainMenuModel();
}
Engine::~Engine() {
stopRenderLoop();
delete _storeView;
delete _menu;
delete _currentUser;
}
QObject *Engine::scane() {
@ -38,7 +40,6 @@ QObject *Engine::scane() {
}
void Engine::setLevel(ILevel *world) {
_storeView->setVisible(!world);
if (_currentLevel == world)
return ;
@ -166,6 +167,10 @@ void Engine::renderLoop() {
}
}
QObject *Engine::menu() const {
return _menu;
}
Store *Engine::store() const {
return _store;
}
@ -181,13 +186,10 @@ User *Engine::currentUser() const {
return _currentUser;
}
QObject *Engine::storeView() const {
return _storeView;
}
void Engine::initStore(const QMultiHash<int, const IItem *> &availabelItems) {
_store->init(availabelItems);
_storeView->init(_store, _currentUser);
static_cast<StoreViewModel*>(_menu->storeView())->init(_store, _currentUser);
}
}

View File

@ -21,6 +21,7 @@ class Store;
class StartData;
class User;
class StoreViewModel;
class MainMenuModel;
/**
* @brief The Engine class
@ -31,9 +32,10 @@ class Engine : public QObject {
Q_PROPERTY(QObject* player READ player NOTIFY playerChanged)
Q_PROPERTY(QObject* world READ world NOTIFY worldChanged)
Q_PROPERTY(QObject* nest READ nest NOTIFY worldChanged)
Q_PROPERTY(QObject* storeView READ storeView NOTIFY storeViewChanged)
Q_PROPERTY(QObject* scane READ scane WRITE setScane NOTIFY scaneChanged)
Q_PROPERTY(QObject * menu READ menu NOTIFY menuChanged)
public:
Engine(QObject * parent = nullptr);
@ -104,12 +106,6 @@ public:
*/
User *currentUser() const;
/**
* @brief storeView This method return pointer to store view model
* @return pointer to store view model
*/
QObject *storeView() const;
/**
* @brief initStore This method is wrapper of the Store::init method.
* @param availabelItems This is list of available items.
@ -128,11 +124,19 @@ public:
*/
QObject *nest() const ;
/**
* @brief menu This is a main menu model.
* @return main menu model object.
*/
QObject *menu() const;
signals:
void scaneChanged();
void playerChanged();
void worldChanged();
void storeViewChanged();
void menuChanged();
private slots:
/**
@ -152,11 +156,11 @@ private:
QObject *_scane = nullptr;
ILevel* _currentLevel = nullptr;
MainMenuModel *_menu = nullptr;
quint64 _oldTimeRender = 0;
User *_currentUser = nullptr;
StoreViewModel *_storeView = nullptr;
Store *_store = nullptr;
QFuture<void> _renderLoopFuture;

View File

@ -8,6 +8,7 @@
#include <listviewmodel.h>
#include "mainmenumodel.h"
#include "settingsviewmodel.h"
#include "storeviewmodel.h"
#include <quasarapp.h>
@ -17,28 +18,30 @@ MainMenuModel::MainMenuModel(QObject *ptr): QObject (ptr) {
_conf = QuasarAppUtils::Settings::instance();
_userSettingsModel = new SettingsViewModel(this);
_availableLvlsModel = new ViewSolutions::ListViewModel(this);
_storeView = new StoreViewModel();
}
MainMenuModel::~MainMenuModel() {
delete _storeView;
}
QObject *MainMenuModel::userSettingsModel() const {
return _userSettingsModel;
}
QObject *MainMenuModel::availableLvlsModel() const {
return _availableLvlsModel;
bool MainMenuModel::getVisible() const {
return visible;
}
void MainMenuModel::addWorldViewModel(QObject * data) {
_availableLvlsModel->addSource(data);
void MainMenuModel::setVisible(bool newVisible) {
if (visible == newVisible)
return;
visible = newVisible;
emit visibleChanged();
}
void MainMenuModel::setAvailableLvls(const QList<QObject*> &newData) {
_availableLvlsModel->setSource(newData);
}
void MainMenuModel::changeLevel(int lvl) {
emit sigLevelChanged(lvl);
QObject *MainMenuModel::storeView() const {
return _storeView;
}
}

View File

@ -10,7 +10,6 @@
#include <QObject>
#include "settings.h"
#include "worldviewdata.h"
namespace ViewSolutions {
class ListViewModel;
@ -19,6 +18,7 @@ class ListViewModel;
namespace CRAWL {
class WorldInfo;
class StoreViewModel;
/**
* @brief The MainMenuModel class This is main class for controll user interface
@ -28,26 +28,35 @@ class MainMenuModel : public QObject
Q_OBJECT
Q_PROPERTY(QObject* userSettingsModel READ userSettingsModel NOTIFY userSettingsModelChanged)
Q_PROPERTY(QObject * availableLvlsModel READ availableLvlsModel NOTIFY availableLvlsModelChanged)
Q_PROPERTY(bool visible READ getVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(QObject * storeView READ storeView NOTIFY storeViewChanged)
public:
MainMenuModel(QObject *ptr = nullptr);
~MainMenuModel();
QObject* userSettingsModel() const;
QObject* availableLvlsModel() const;
void addWorldViewModel(QObject *);
void setAvailableLvls(const QList<QObject *> &newData);
Q_INVOKABLE void changeLevel(int lvl);
bool getVisible() const;
void setVisible(bool newVisible);
/**
* @brief storeView This method return pointer to store view model
* @return pointer to store view model
*/
QObject *storeView() const;
signals:
void userSettingsModelChanged(QObject* userSettingsModel);
void sigLevelChanged(int lvl);
void availableLvlsModelChanged();
void visibleChanged();
void storeViewChanged();
private:
Settings *_conf = nullptr;
QObject* _userSettingsModel = nullptr;
ViewSolutions::ListViewModel *_availableLvlsModel = nullptr;
bool visible = true;
StoreViewModel *_storeView = nullptr;
};

View File

@ -16,17 +16,6 @@ void StoreViewModel::init(Store *store, User *user) {
_store = store;
}
bool StoreViewModel::visible() const {
return _visible;
}
void StoreViewModel::setVisible(bool newVisible) {
if (_visible == newVisible)
return;
_visible = newVisible;
emit visibleChanged();
}
void StoreViewModel::buy(int item) {
if (_store && getUser()) {
_store->buy(*getUser(), item);

View File

@ -21,10 +21,6 @@ class User;
class StoreViewModel: public BaseUserListModel
{
Q_OBJECT
/**
* @brief visible If you sets thsis proprtye to false then store view qml view will be hide.
*/
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
public:
StoreViewModel();
@ -37,18 +33,6 @@ public:
*/
void init(Store * store, User* user);
/**
* @brief visible This method return true if the store view is visible.
* @return true if the store view is visible.
*/
bool visible() const;
/**
* @brief setVisible This method chnge the visible state of the qml view of store.
* @param newVisible This is new value of the qml-store visible
*/
void setVisible(bool newVisible);
/**
* @brief buy This is qml method for receive signal from view about buying item.
* @param item This is item id that user want to buy.
@ -59,16 +43,9 @@ public:
protected:
const IItem *getItem(int id) const;
signals:
/**
* @brief visibleChanged This slot emited when store visibel changed
*/
void visibleChanged();
private:
Store *_store = nullptr;
bool _visible = false;
};
}

View File

@ -1,67 +0,0 @@
//#
//# Copyright (C) 2021-2021 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#include "worldviewdata.h"
#include "Crawl/iworld.h"
namespace CRAWL {
WorldViewData::WorldViewData(const IWorld *data) {
setWorldObject(data);
}
QString WorldViewData::name() const {
if (_worldObject) {
return _worldObject->itemName();
}
return "";
}
QString WorldViewData::desc() const {
if (_worldObject) {
return _worldObject->description();
}
return "";
}
int WorldViewData::cost() const {
if (_worldObject) {
return _worldObject->cost();
}
return 0;
}
bool WorldViewData::unlocked() const {
return m_unlocked || !cost();
}
void WorldViewData::setUnlocked(bool newUnlocked) {
if (m_unlocked == newUnlocked)
return;
m_unlocked = newUnlocked;
emit unlockedChanged();
}
QString WorldViewData::image() const {
if (_worldObject) {
return _worldObject->image();
}
return "";
}
void WorldViewData::setWorldObject(const IWorld *newWorldObject) {
if (_worldObject == newWorldObject)
return;
_worldObject = newWorldObject;
emit dataChanged();
}
}

View File

@ -1,52 +0,0 @@
//#
//# Copyright (C) 2021-2021 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#
#ifndef WORLDVIEWDATA_H
#define WORLDVIEWDATA_H
#include <QObject>
namespace CRAWL {
class IWorld;
/**
* @brief The WorldViewData class Simaple class for view world status in gui interface.
*/
class WorldViewData: public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY dataChanged)
Q_PROPERTY(QString desc READ desc NOTIFY dataChanged)
Q_PROPERTY(int cost READ cost NOTIFY dataChanged)
Q_PROPERTY(bool unlocked READ unlocked WRITE setUnlocked NOTIFY unlockedChanged)
Q_PROPERTY(QString image READ image NOTIFY dataChanged)
public:
WorldViewData(const IWorld * data);
QString name() const;
QString desc() const;
int cost() const;
bool unlocked() const;
void setUnlocked(bool newUnlocked);
QString image() const;
void setWorldObject(const IWorld *newWorldObject);
private:
bool m_unlocked;
const IWorld* _worldObject = nullptr;
signals:
void dataChanged();
void unlockedChanged();
};
}
#endif // WORLDVIEWDATA_H