mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-10 16:39:45 +00:00
ref #30 build successful
This commit is contained in:
parent
af60e3d9b2
commit
8f1df667a7
src
Client
ClientLib
CMakeLists.txt
SnakeProject
Private
networkclient.cppnetworkclient.hnotificationdata.cppnotificationdata.hnotificationservice.cppnotificationservice.hsettingsviewmodel.cpp
clientapp.cppcontroller.cppglobal.hguiobjectfactory.cppmainmenumodel.cppmainmenumodel.hsettings.cppsettings.hsettingsviewmodel.cppsettingsviewmodel.hsnakeprojectsettings.hsnakeutils.h@ -11,20 +11,20 @@ set(CURRENT_PROJECT "${PROJECT_NAME}")
|
||||
|
||||
file(GLOB SOURCE_CPP
|
||||
"*.cpp"
|
||||
"Private/*.cpp"
|
||||
"private/*.cpp"
|
||||
)
|
||||
|
||||
if (${QT_VERSION_MAJOR})
|
||||
file(GLOB SOURCE_QRC
|
||||
"*.qrc"
|
||||
"Private/*.qrc"
|
||||
"private/*.qrc"
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Private")
|
||||
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/private")
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include "clientapp.h"
|
||||
#include <SnakeProject/clientapp.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -13,21 +13,21 @@ add_definitions(-DSnakeProject_LIBRARY)
|
||||
|
||||
file(GLOB SOURCE_CPP
|
||||
"*SnakeProject/*.cpp"
|
||||
"SnakeProject/Private/*.cpp"
|
||||
"SnakeProject/private/*.cpp"
|
||||
"*.qrc"
|
||||
"SnakeProject/*.qrc"
|
||||
"SnakeProject/Private/*.qrc"
|
||||
"SnakeProject/private/*.qrc"
|
||||
)
|
||||
|
||||
set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Private")
|
||||
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/private")
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED)
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick Concurrent REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick Concurrent REQUIRED)
|
||||
|
||||
add_library(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC})
|
||||
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick QuasarApp QmlNotyfyService)
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Concurrent QuasarApp QmlNotyfyService)
|
||||
|
||||
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR})
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include "networkclient.h"
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <updateplayerdata.h>
|
||||
|
||||
int NetworkClient::loginedPlayer() const {
|
||||
return _loginedPlayer;
|
||||
}
|
||||
|
||||
void NetworkClient::handleReceiveData(ClientProtocol::Command cmd,
|
||||
const QByteArray &obj) {
|
||||
|
||||
if (cmd == ClientProtocol::Command::Player) {
|
||||
PlayerClientData data;
|
||||
data.fromBytes(obj);
|
||||
_playersDats[data.id()] = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NetworkClient::NetworkClient() {
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <client.h>
|
||||
|
||||
class NetworkClient : public ClientProtocol::Client
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QHash<int, PlayerClientData> _playersDats;
|
||||
int _loginedPlayer;
|
||||
private slots:
|
||||
void handleReceiveData(ClientProtocol::Command cmd, const QByteArray& obj);
|
||||
public:
|
||||
NetworkClient();
|
||||
int loginedPlayer() const;
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
@ -1,38 +0,0 @@
|
||||
#include "notificationdata.h"
|
||||
|
||||
NotificationData::NotificationData(const QString &title,
|
||||
const QString &text,
|
||||
const QString &img, Type type) {
|
||||
|
||||
_text = text;
|
||||
_title = title;
|
||||
_img = img;
|
||||
_type = type;
|
||||
}
|
||||
|
||||
QString NotificationData::text() const {
|
||||
return _text;
|
||||
}
|
||||
|
||||
QString NotificationData::img() const {
|
||||
return _img;
|
||||
}
|
||||
|
||||
QString NotificationData::title() const {
|
||||
return _title;
|
||||
}
|
||||
|
||||
bool NotificationData::operator ==(const NotificationData &righ) {
|
||||
return _title == righ._title &&
|
||||
_text == righ._text &&
|
||||
_img == righ._img &&
|
||||
_type == righ._type;
|
||||
}
|
||||
|
||||
bool NotificationData::operator !=(const NotificationData &righ) {
|
||||
return !operator==(righ);
|
||||
}
|
||||
|
||||
int NotificationData::type() const {
|
||||
return _type;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#ifndef NOTIFICATIONDATA_H
|
||||
#define NOTIFICATIONDATA_H
|
||||
#include <QObject>
|
||||
|
||||
class NotificationData
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString text READ text)
|
||||
Q_PROPERTY(QString img READ img)
|
||||
Q_PROPERTY(QString title READ title)
|
||||
Q_PROPERTY(int type READ type)
|
||||
|
||||
QString _text;
|
||||
QString _img;
|
||||
QString _title;
|
||||
int _type;
|
||||
|
||||
public:
|
||||
|
||||
enum Type {
|
||||
Normal,
|
||||
Warning = 1,
|
||||
Error = 2,
|
||||
};
|
||||
|
||||
explicit NotificationData(const QString& title = "",
|
||||
const QString& text = "",
|
||||
const QString& img = "",
|
||||
Type type = Type::Normal);
|
||||
|
||||
Q_INVOKABLE QString text() const;
|
||||
Q_INVOKABLE QString img() const;
|
||||
Q_INVOKABLE QString title() const;
|
||||
Q_INVOKABLE int type() const;
|
||||
|
||||
bool operator ==(const NotificationData &righ);
|
||||
bool operator !=(const NotificationData &righ);
|
||||
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONDATA_H
|
@ -1,38 +0,0 @@
|
||||
#include "notificationservice.h"
|
||||
|
||||
NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
|
||||
qRegisterMetaType<NotificationData>("NotificationData");
|
||||
qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
|
||||
|
||||
}
|
||||
|
||||
NotificationData NotificationService::notify() const {
|
||||
return _notify;
|
||||
}
|
||||
|
||||
void NotificationService::setNotify(const NotificationData& notify) {
|
||||
if (_notify != notify)
|
||||
_history.push_back(_notify);
|
||||
|
||||
_notify = notify;
|
||||
|
||||
emit notifyChanged();
|
||||
}
|
||||
|
||||
void NotificationService::setNotify(const QString &title,
|
||||
const QString &text,
|
||||
const QString &img,
|
||||
int type) {
|
||||
|
||||
setNotify(NotificationData(title, text, img,
|
||||
static_cast<NotificationData::Type>(type)));
|
||||
}
|
||||
|
||||
NotificationService *NotificationService::getService() {
|
||||
static auto service = new NotificationService;
|
||||
return service;
|
||||
}
|
||||
|
||||
const QList<NotificationData> &NotificationService::history() const {
|
||||
return _history;
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#ifndef NOTIFICATIONSERVICE_H
|
||||
#define NOTIFICATIONSERVICE_H
|
||||
|
||||
#include "notificationdata.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NotificationService: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
|
||||
Q_PROPERTY(QList<NotificationData> history READ history NOTIFY notifyChanged)
|
||||
|
||||
private:
|
||||
explicit NotificationService(QObject *ptr = nullptr);
|
||||
|
||||
NotificationData _notify;
|
||||
QList<NotificationData> _history;
|
||||
|
||||
public:
|
||||
NotificationData notify() const;
|
||||
void setNotify(const NotificationData ¬ify);
|
||||
Q_INVOKABLE void setNotify(const QString& title = "",
|
||||
const QString& text = "",
|
||||
const QString& img = "",
|
||||
int type = NotificationData::Normal);
|
||||
|
||||
static NotificationService* getService();
|
||||
|
||||
const QList<NotificationData> & history() const;
|
||||
|
||||
signals:
|
||||
void notifyChanged();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // NOTIFICATIONSERVICE_H
|
@ -1,57 +0,0 @@
|
||||
#include "settingsviewmodel.h"
|
||||
#include <QSettings>
|
||||
#include "settings.h"
|
||||
|
||||
void SettingsViewModel::handleValueChanged(QString key, QVariant value) {
|
||||
if (key == SERVER_ADDRESS) {
|
||||
emit hostChanged(value.toString());
|
||||
} else if (key == SERVER_ADDRESS_PORT) {
|
||||
emit portChanged(value.toInt());
|
||||
} else if (key == THEME) {
|
||||
emit themeChanged(value.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
SettingsViewModel::SettingsViewModel(QObject *ptr):
|
||||
QObject (ptr) {
|
||||
_cfg = Settings::get();
|
||||
|
||||
connect(_cfg, &Settings::valueChanged, this , &SettingsViewModel::handleValueChanged);
|
||||
}
|
||||
|
||||
int SettingsViewModel::port() const {
|
||||
return _cfg->getValue(SERVER_ADDRESS_PORT, SERVER_ADDRESS_DEFAULT_PORT).toInt();
|
||||
}
|
||||
|
||||
QString SettingsViewModel::host() const {
|
||||
return _cfg->getValue(SERVER_ADDRESS, SERVER_ADDRESS_DEFAULT).toString();
|
||||
}
|
||||
|
||||
int SettingsViewModel::theme() const {
|
||||
return _cfg->getValue(THEME, THEME_DEFAULT).toInt();
|
||||
}
|
||||
|
||||
void SettingsViewModel::forceUpdate() {
|
||||
emit hostChanged("");
|
||||
emit portChanged(0);
|
||||
emit themeChanged(0);
|
||||
|
||||
}
|
||||
|
||||
void SettingsViewModel::toDefault() {
|
||||
setPort(SERVER_ADDRESS_DEFAULT_PORT);
|
||||
setHost(SERVER_ADDRESS_DEFAULT);
|
||||
setTheme(THEME_DEFAULT);
|
||||
}
|
||||
|
||||
void SettingsViewModel::setPort(int port) {
|
||||
_cfg->setValue(SERVER_ADDRESS_PORT, port);
|
||||
}
|
||||
|
||||
void SettingsViewModel::setHost(const QString& host) {
|
||||
_cfg->setValue(SERVER_ADDRESS, host);
|
||||
}
|
||||
|
||||
void SettingsViewModel::setTheme(int theme) {
|
||||
_cfg->setValue(THEME, theme);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "clientapp.h"
|
||||
#include "imageprovider.h"
|
||||
#include "mainmenumodel.h"
|
||||
#include "SnakeProject/mainmenumodel.h"
|
||||
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
@ -9,7 +9,7 @@
|
||||
#include <qmlnotifyservice.h>
|
||||
|
||||
QByteArray ClientApp::initTheme() {
|
||||
int themeIndex = Settings::get()->getValue(THEME, THEME_DEFAULT).toInt();
|
||||
int themeIndex = Settings::instance()->getValue(THEME, THEME_DEFAULT).toInt();
|
||||
|
||||
switch (themeIndex) {
|
||||
case 1: return "Dark";
|
||||
@ -46,7 +46,6 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
qmlRegisterType <GuiObject> ();
|
||||
qmlRegisterType <Diff> ();
|
||||
qmlRegisterType <MainMenuModel> ();
|
||||
qmlRegisterType <UserView> ();
|
||||
|
||||
auto root = engine->rootContext();
|
||||
if (!root)
|
||||
|
@ -2,9 +2,9 @@
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include "diff.h"
|
||||
#include <lvls.h>
|
||||
#include "ProfileViewItems/mainmenumodel.h"
|
||||
#include <back-end/ProfileViewItems/notificationservice.h>
|
||||
#include "lvls.h"
|
||||
#include "mainmenumodel.h"
|
||||
#include "qmlnotifyservice.h"
|
||||
|
||||
Controller::Controller() {
|
||||
srand(static_cast<unsigned int>(time(nullptr)));
|
||||
@ -78,11 +78,13 @@ void Controller::update() {
|
||||
|
||||
if (!_showMenu) {
|
||||
|
||||
NotificationData notify(tr(" Next Lvl!!!"),
|
||||
tr(" You anblock next lvl (%0)" ).arg(lvl),
|
||||
"qrc:/texture/up");
|
||||
|
||||
NotificationService::getService()->setNotify(notify);
|
||||
if (auto service = QmlNotificationService::NotificationService::getService()) {
|
||||
QmlNotificationService::NotificationData notify(tr(" Next Lvl!!!"),
|
||||
tr(" You anblock next lvl (%0)" ).arg(lvl),
|
||||
"qrc:/texture/up");
|
||||
service->setNotify(notify);
|
||||
}
|
||||
}
|
||||
|
||||
nextLvl();
|
||||
|
12
src/ClientLib/SnakeProject/global.h
Normal file
12
src/ClientLib/SnakeProject/global.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef SNAKEPROJECT_GLOBAL_H
|
||||
#define SNAKEPROJECT_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(SnakeProject_LIBRARY)
|
||||
# define SNAKEPROJECT_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define SNAKEPROJECT_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // QTSECRET_GLOBAL_H
|
@ -1,6 +1,6 @@
|
||||
#include "guiobjectfactory.h"
|
||||
#include "box.h"
|
||||
#include <snakeutils.h>
|
||||
#include "snakeutils.h"
|
||||
#include "head.h"
|
||||
#include "background.h"
|
||||
#include "backgrounditem.h"
|
||||
|
0
src/ClientLib/SnakeProject/Private/mainmenumodel.cpp → src/ClientLib/SnakeProject/mainmenumodel.cpp
0
src/ClientLib/SnakeProject/Private/mainmenumodel.cpp → src/ClientLib/SnakeProject/mainmenumodel.cpp
@ -2,7 +2,7 @@
|
||||
#define NETWORKPROFILEMAINMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include "snakeprojectsettings.h"
|
||||
#include "SnakeProject/settings.h"
|
||||
|
||||
|
||||
class MainMenuModel : public QObject
|
||||
@ -13,6 +13,7 @@ class MainMenuModel : public QObject
|
||||
|
||||
private:
|
||||
Settings *_conf = nullptr;
|
||||
QObject* _userSettingsModel = nullptr;
|
||||
|
||||
public:
|
||||
MainMenuModel(QObject *ptr = nullptr);
|
||||
@ -20,6 +21,7 @@ public:
|
||||
|
||||
signals:
|
||||
void userSettingsModelChanged(QObject* userSettingsModel);
|
||||
void newGame();
|
||||
};
|
||||
|
||||
#endif // NETWORKPROFILEMAINMODEL_H
|
11
src/ClientLib/SnakeProject/settings.h
Normal file
11
src/ClientLib/SnakeProject/settings.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef SNAKESETTINGS_H
|
||||
#define SNAKESETTINGS_H
|
||||
#include <quasarapp.h>
|
||||
|
||||
#define THEME "THEME_GUI"
|
||||
|
||||
#define THEME_DEFAULT 0
|
||||
|
||||
using Settings = QuasarAppUtils::Settings;
|
||||
|
||||
#endif // SNAKESETTINGS_H
|
32
src/ClientLib/SnakeProject/settingsviewmodel.cpp
Normal file
32
src/ClientLib/SnakeProject/settingsviewmodel.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "settingsviewmodel.h"
|
||||
#include <QSettings>
|
||||
#include "settings.h"
|
||||
|
||||
void SettingsViewModel::handleValueChanged(QString key, QVariant value) {
|
||||
if (key == THEME) {
|
||||
emit themeChanged(value.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
SettingsViewModel::SettingsViewModel(QObject *ptr):
|
||||
QObject (ptr) {
|
||||
_cfg = Settings::instance();
|
||||
|
||||
connect(_cfg, &Settings::valueChanged, this , &SettingsViewModel::handleValueChanged);
|
||||
}
|
||||
|
||||
int SettingsViewModel::theme() const {
|
||||
return _cfg->getValue(THEME, THEME_DEFAULT).toInt();
|
||||
}
|
||||
|
||||
void SettingsViewModel::forceUpdate() {
|
||||
emit themeChanged(0);
|
||||
}
|
||||
|
||||
void SettingsViewModel::toDefault() {
|
||||
setTheme(THEME_DEFAULT);
|
||||
}
|
||||
|
||||
void SettingsViewModel::setTheme(int theme) {
|
||||
_cfg->setValue(THEME, theme);
|
||||
}
|
@ -2,14 +2,12 @@
|
||||
#define SETTINGSVIEWMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include "./../settings.h"
|
||||
#include "SnakeProject/settings.h"
|
||||
|
||||
|
||||
class SettingsViewModel: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
|
||||
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
|
||||
Q_PROPERTY(int theme READ theme WRITE setTheme NOTIFY themeChanged)
|
||||
|
||||
private:
|
||||
@ -20,8 +18,6 @@ private slots:
|
||||
|
||||
public:
|
||||
SettingsViewModel(QObject* ptr = nullptr);
|
||||
int port() const;
|
||||
QString host() const;
|
||||
int theme() const;
|
||||
|
||||
Q_INVOKABLE void forceUpdate();
|
||||
@ -29,13 +25,9 @@ public:
|
||||
|
||||
|
||||
public slots:
|
||||
void setPort(int port);
|
||||
void setHost(const QString &host);
|
||||
void setTheme(int theme);
|
||||
|
||||
signals:
|
||||
void portChanged(int port);
|
||||
void hostChanged(const QString &host);
|
||||
void themeChanged(int theme);
|
||||
};
|
||||
|
@ -1,16 +0,0 @@
|
||||
#ifndef SNAKESETTINGS_H
|
||||
#define SNAKESETTINGS_H
|
||||
#include <quasarapp.h>
|
||||
|
||||
#define SERVER_ADDRESS "SERVER_ADDRESS"
|
||||
#define SERVER_ADDRESS_PORT "SERVER_ADDRESS_PORT"
|
||||
#define THEME "THEME_GUI"
|
||||
|
||||
#define SERVER_ADDRESS_DEFAULT "quasarapp.ddns.net"
|
||||
//#define SERVER_ADDRESS_DEFAULT "127.0.0.1"
|
||||
#define SERVER_ADDRESS_DEFAULT_PORT DEFAULT_SNAKE_PORT
|
||||
#define THEME_DEFAULT 0
|
||||
|
||||
using Settings = QuasarAppUtils::Settings;
|
||||
|
||||
#endif // SNAKESETTINGS_H
|
@ -1,7 +1,7 @@
|
||||
#ifndef SNAKEUTILS_H
|
||||
#define SNAKEUTILS_H
|
||||
|
||||
|
||||
#include "SnakeProject/global.h"
|
||||
#include <QMap>
|
||||
#include <QPoint>
|
||||
#include <QVariant>
|
||||
@ -17,4 +17,4 @@
|
||||
typedef QMap<QString, int> WorldRules;
|
||||
|
||||
|
||||
#endif // SNAKEUTILS_H
|
||||
#endif // SNAKEUTILS_Hм.
|
||||
|
Loading…
x
Reference in New Issue
Block a user