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> <source>Select level</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Store</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PreviewControl</name> <name>PreviewControl</name>
@ -86,9 +90,9 @@
</message> </message>
</context> </context>
<context> <context>
<name>SelectLvlView</name> <name>SelectLevelView</name>
<message> <message>
<source>Start</source> <source>Select</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,19 +22,10 @@ namespace CRAWL {
class Engine; class Engine;
class IWorld; class IWorld;
class WorldViewData;
class MainMenuModel; class MainMenuModel;
class IControl; class IControl;
class Store; 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. * @brief The ClientApp class This is main class of the Game engine.
*/ */
@ -87,8 +78,7 @@ private:
*/ */
void changeLevel(int lvl); void changeLevel(int lvl);
QHash<int, WordlData> _availableLvls; QHash<int, ILevel*> _availableLvls;
MainMenuModel *_menu = nullptr;
Engine *_engine = nullptr; Engine *_engine = nullptr;
}; };

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@
//# //#
#include "engine.h" #include "engine.h"
#include "mainmenumodel.h"
#include <QQmlComponent> #include <QQmlComponent>
#include <Crawl/guiobject.h> #include <Crawl/guiobject.h>
@ -23,14 +24,15 @@ namespace CRAWL {
Engine::Engine(QObject *parent): QObject(parent) { Engine::Engine(QObject *parent): QObject(parent) {
_store = new Store(); _store = new Store();
_storeView = new StoreViewModel;
_currentUser = new User(); _currentUser = new User();
_menu = new MainMenuModel();
} }
Engine::~Engine() { Engine::~Engine() {
stopRenderLoop(); stopRenderLoop();
delete _storeView; delete _menu;
delete _currentUser;
} }
QObject *Engine::scane() { QObject *Engine::scane() {
@ -38,7 +40,6 @@ QObject *Engine::scane() {
} }
void Engine::setLevel(ILevel *world) { void Engine::setLevel(ILevel *world) {
_storeView->setVisible(!world);
if (_currentLevel == world) if (_currentLevel == world)
return ; return ;
@ -166,6 +167,10 @@ void Engine::renderLoop() {
} }
} }
QObject *Engine::menu() const {
return _menu;
}
Store *Engine::store() const { Store *Engine::store() const {
return _store; return _store;
} }
@ -181,13 +186,10 @@ User *Engine::currentUser() const {
return _currentUser; return _currentUser;
} }
QObject *Engine::storeView() const {
return _storeView;
}
void Engine::initStore(const QMultiHash<int, const IItem *> &availabelItems) { void Engine::initStore(const QMultiHash<int, const IItem *> &availabelItems) {
_store->init(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 StartData;
class User; class User;
class StoreViewModel; class StoreViewModel;
class MainMenuModel;
/** /**
* @brief The Engine class * @brief The Engine class
@ -31,9 +32,10 @@ class Engine : public QObject {
Q_PROPERTY(QObject* player READ player NOTIFY playerChanged) Q_PROPERTY(QObject* player READ player NOTIFY playerChanged)
Q_PROPERTY(QObject* world READ world NOTIFY worldChanged) Q_PROPERTY(QObject* world READ world NOTIFY worldChanged)
Q_PROPERTY(QObject* nest READ nest 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* scane READ scane WRITE setScane NOTIFY scaneChanged)
Q_PROPERTY(QObject * menu READ menu NOTIFY menuChanged)
public: public:
Engine(QObject * parent = nullptr); Engine(QObject * parent = nullptr);
@ -104,12 +106,6 @@ public:
*/ */
User *currentUser() const; 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. * @brief initStore This method is wrapper of the Store::init method.
* @param availabelItems This is list of available items. * @param availabelItems This is list of available items.
@ -128,11 +124,19 @@ public:
*/ */
QObject *nest() const ; QObject *nest() const ;
/**
* @brief menu This is a main menu model.
* @return main menu model object.
*/
QObject *menu() const;
signals: signals:
void scaneChanged(); void scaneChanged();
void playerChanged(); void playerChanged();
void worldChanged(); void worldChanged();
void storeViewChanged();
void menuChanged();
private slots: private slots:
/** /**
@ -152,11 +156,11 @@ private:
QObject *_scane = nullptr; QObject *_scane = nullptr;
ILevel* _currentLevel = nullptr; ILevel* _currentLevel = nullptr;
MainMenuModel *_menu = nullptr;
quint64 _oldTimeRender = 0; quint64 _oldTimeRender = 0;
User *_currentUser = nullptr; User *_currentUser = nullptr;
StoreViewModel *_storeView = nullptr;
Store *_store = nullptr; Store *_store = nullptr;
QFuture<void> _renderLoopFuture; QFuture<void> _renderLoopFuture;

View File

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

View File

@ -10,7 +10,6 @@
#include <QObject> #include <QObject>
#include "settings.h" #include "settings.h"
#include "worldviewdata.h"
namespace ViewSolutions { namespace ViewSolutions {
class ListViewModel; class ListViewModel;
@ -19,6 +18,7 @@ class ListViewModel;
namespace CRAWL { namespace CRAWL {
class WorldInfo; class WorldInfo;
class StoreViewModel;
/** /**
* @brief The MainMenuModel class This is main class for controll user interface * @brief The MainMenuModel class This is main class for controll user interface
@ -28,26 +28,35 @@ class MainMenuModel : public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(QObject* userSettingsModel READ userSettingsModel NOTIFY userSettingsModelChanged) 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: public:
MainMenuModel(QObject *ptr = nullptr); MainMenuModel(QObject *ptr = nullptr);
~MainMenuModel();
QObject* userSettingsModel() const; 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: signals:
void userSettingsModelChanged(QObject* userSettingsModel); void userSettingsModelChanged(QObject* userSettingsModel);
void sigLevelChanged(int lvl);
void availableLvlsModelChanged(); void visibleChanged();
void storeViewChanged();
private: private:
Settings *_conf = nullptr; Settings *_conf = nullptr;
QObject* _userSettingsModel = 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; _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) { void StoreViewModel::buy(int item) {
if (_store && getUser()) { if (_store && getUser()) {
_store->buy(*getUser(), item); _store->buy(*getUser(), item);

View File

@ -21,10 +21,6 @@ class User;
class StoreViewModel: public BaseUserListModel class StoreViewModel: public BaseUserListModel
{ {
Q_OBJECT 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: public:
StoreViewModel(); StoreViewModel();
@ -37,18 +33,6 @@ public:
*/ */
void init(Store * store, User* user); 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. * @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. * @param item This is item id that user want to buy.
@ -59,16 +43,9 @@ public:
protected: protected:
const IItem *getItem(int id) const; const IItem *getItem(int id) const;
signals:
/**
* @brief visibleChanged This slot emited when store visibel changed
*/
void visibleChanged();
private: private:
Store *_store = nullptr; 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