mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-27 18:24:41 +00:00
remove logic from qml
This commit is contained in:
parent
f0e20ceeb2
commit
4bc2951f0c
@ -17,7 +17,6 @@ class MainMenuModel : public QObject
|
||||
|
||||
Q_PROPERTY(QObject* userViewModel READ userViewModel NOTIFY userViewModelChanged)
|
||||
Q_PROPERTY(QObject* userSettingsModel READ userSettingsModel NOTIFY userSettingsModelChanged)
|
||||
|
||||
Q_PROPERTY(int onlineStatus READ onlineStatus NOTIFY onlineStatusChanged)
|
||||
|
||||
private:
|
||||
@ -36,16 +35,13 @@ public:
|
||||
Q_INVOKABLE void playOffline();
|
||||
Q_INVOKABLE void tryConnect();
|
||||
|
||||
|
||||
public slots:
|
||||
void login(const QString& email, const QString& pass);
|
||||
void registerNewUser(const QString& email, const QString& pass);
|
||||
|
||||
|
||||
signals:
|
||||
void userViewModelChanged(QObject* userViewModel);
|
||||
void newGame();
|
||||
|
||||
void onlinelChanged(bool online);
|
||||
void loginChanged(bool login);
|
||||
void onlineStatusChanged();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "diff.h"
|
||||
#include <lvls.h>
|
||||
#include "ProfileViewItems/mainmenumodel.h"
|
||||
#include <back-end/ProfileViewItems/notificationservice.h>
|
||||
|
||||
Controller::Controller() {
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
@ -63,14 +64,28 @@ void Controller::update() {
|
||||
}
|
||||
|
||||
world.render();
|
||||
|
||||
if(world.isDefiat()) {
|
||||
stopTimer();
|
||||
emit finished(false, lvl, world.getCurrentLong());
|
||||
if (!_showMenu) {
|
||||
setShowMenu(true);
|
||||
}
|
||||
handleNewGame();
|
||||
}
|
||||
|
||||
if (world.isEnd()) {
|
||||
stopTimer();
|
||||
emit finished(true, lvl, world.getCurrentLong());
|
||||
|
||||
if (!_showMenu) {
|
||||
setShowMenu(true);
|
||||
/** TO-DO **/
|
||||
// tr(" Next Lvl!!!"),
|
||||
// tr(QString(" You anblock next lvl (%0)" ).arg(lvl)),
|
||||
// "qrc:/texture/up");
|
||||
NotificationService::getService()->setNotify(
|
||||
QString(" You anblock next lvl (%0)" ).arg(lvl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
long_changed(static_cast<int>(world.getCurrentLong()));
|
||||
@ -124,3 +139,15 @@ void Controller::setPause(bool p){
|
||||
}
|
||||
}
|
||||
|
||||
bool Controller::showMenu() const {
|
||||
return _showMenu;
|
||||
}
|
||||
|
||||
void Controller::setShowMenu(bool showMenu) {
|
||||
if (_showMenu == showMenu)
|
||||
return;
|
||||
|
||||
_showMenu = showMenu;
|
||||
emit showMenuChanged(_showMenu);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ class Controller : public QObject
|
||||
Q_PROPERTY(int long_ READ long_ NOTIFY long_changed)
|
||||
Q_PROPERTY(int generalLong READ generalLong NOTIFY generalLongchanged)
|
||||
Q_PROPERTY(QObject* mainMenuModel READ mainMenuModel NOTIFY mainMenuModelchanged)
|
||||
Q_PROPERTY(bool showMenu READ showMenu WRITE setShowMenu NOTIFY showMenuChanged)
|
||||
|
||||
private:
|
||||
|
||||
@ -27,6 +28,7 @@ private:
|
||||
int lvl = 0;
|
||||
int m_generalLong = 0;
|
||||
bool pause = false;
|
||||
bool _showMenu = true;
|
||||
|
||||
void generateDiff(const QMap<int, GuiObject *> &);
|
||||
|
||||
@ -40,16 +42,14 @@ public:
|
||||
void stopTimer();
|
||||
|
||||
int long_() const;
|
||||
|
||||
int generalLong() const;
|
||||
bool showMenu() const;
|
||||
|
||||
QObject* mainMenuModel() const;
|
||||
|
||||
public slots:
|
||||
void buttonPress();
|
||||
|
||||
void setPause(bool);
|
||||
|
||||
void update();
|
||||
|
||||
/**
|
||||
@ -70,14 +70,9 @@ public slots:
|
||||
*/
|
||||
QObject* getGameObject(int id);
|
||||
|
||||
void setShowMenu(bool showMenu);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief finished - imited when game over or victory
|
||||
* @param victory - flag of vicrory, if it equals false then game over
|
||||
* @param lvl - game over lvl
|
||||
* @param distance - game over distance
|
||||
*/
|
||||
void finished(bool victory, int lvl, double distance);
|
||||
|
||||
/**
|
||||
* @brief gameObjectsChanged
|
||||
@ -87,6 +82,7 @@ signals:
|
||||
void long_changed(int m_long);
|
||||
void generalLongchanged(int generalLong);
|
||||
void mainMenuModelchanged(QObject* mainMenuModel);
|
||||
void showMenuChanged(bool showMenu);
|
||||
};
|
||||
|
||||
#endif // CONTROLLER_H
|
||||
|
@ -25,7 +25,7 @@ Item {
|
||||
|
||||
property var model: null;
|
||||
property var arrayObjects: []
|
||||
property bool showMenu: true
|
||||
property alias showMenu: model.showMenu
|
||||
property bool isPause: false
|
||||
|
||||
function add (cppObjId) {
|
||||
@ -112,29 +112,6 @@ Item {
|
||||
remove(tempDifRem[i]);
|
||||
}
|
||||
}
|
||||
|
||||
onFinished: {
|
||||
|
||||
var isVictory = victory;
|
||||
var gameLvl = lvl + 1;
|
||||
var dist = distance;
|
||||
updateBackgroundColor(gameLvl);
|
||||
|
||||
if (isVictory ) {
|
||||
|
||||
if (!autoTimer.running)
|
||||
// notification.show(qsTr(" Next Lvl!!!"),
|
||||
// qsTr(" You anblock next lvl (" + gameLvl + ")" ),
|
||||
// "qrc:/texture/up");
|
||||
|
||||
model.nextLvl();
|
||||
} else if (autoTimer.running) {
|
||||
model.handleNewGame();
|
||||
} else {
|
||||
showMenu = true;
|
||||
model.handleNewGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -9,8 +9,7 @@ TEMPLATE = app
|
||||
TARGET = serverTests
|
||||
|
||||
SOURCES += \
|
||||
testutils.cpp \
|
||||
tst_testsnakeserver.cpp
|
||||
testutils.cpp
|
||||
|
||||
CONFIG(release, debug|release): {
|
||||
DESTDIR = $$PWD/build/release
|
||||
|
Loading…
x
Reference in New Issue
Block a user