mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-27 02:04:41 +00:00
ref #30 BIG refactoring
This commit is contained in:
parent
ee5a3be629
commit
af60e3d9b2
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
||||
[submodule "submodules/QuasarAppLib"]
|
||||
path = submodules/QuasarAppLib
|
||||
url = https://github.com/QuasarApp/QuasarAppLib
|
||||
[submodule "submodules/SimpleQmlNotify"]
|
||||
path = submodules/SimpleQmlNotify
|
||||
url = https://github.com/QuasarApp/SimpleQmlNotify.git
|
||||
|
@ -45,6 +45,9 @@ endif()
|
||||
|
||||
# Add sub directories
|
||||
|
||||
add_subdirectory(submodules/QuasarAppLib)
|
||||
add_subdirectory(submodules/SimpleQmlNotify)
|
||||
|
||||
add_subdirectory(src/ClientLib)
|
||||
add_subdirectory(src/Client)
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
set(CURRENT_PROJECT "${PROJECT_NAME}Eaxample")
|
||||
set(CURRENT_PROJECT "${PROJECT_NAME}")
|
||||
|
||||
file(GLOB SOURCE_CPP
|
||||
"*.cpp"
|
||||
@ -33,10 +33,7 @@ else ()
|
||||
add_executable(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC})
|
||||
endif()
|
||||
|
||||
if (${QT_VERSION_MAJOR})
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC Qt${QT_VERSION_MAJOR}::Core)
|
||||
endif()
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME})
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}Core)
|
||||
|
||||
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR})
|
||||
|
@ -1,10 +1,20 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the lgplv3 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 <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include "clientapp.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
QQmlApplicationEngine engine;
|
||||
ClientApp client;
|
||||
|
||||
if (!client.init(&engine)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
set(CURRENT_PROJECT "${PROJECT_NAME}Core")
|
||||
|
||||
add_definitions(-DSnakeProject_LIBRARY)
|
||||
|
||||
@ -13,35 +14,27 @@ add_definitions(-DSnakeProject_LIBRARY)
|
||||
file(GLOB SOURCE_CPP
|
||||
"*SnakeProject/*.cpp"
|
||||
"SnakeProject/Private/*.cpp"
|
||||
"*.qrc"
|
||||
"SnakeProject/*.qrc"
|
||||
"SnakeProject/Private/*.qrc"
|
||||
)
|
||||
|
||||
if (${QT_VERSION_MAJOR})
|
||||
file(GLOB SOURCE_QRC
|
||||
"*.qrc"
|
||||
"SnakeProject/*.qrc"
|
||||
"SnakeProject/Private/*.qrc"
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
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)
|
||||
|
||||
add_library(${CURRENT_PROJECT} ${SOURCE_CPP} ${SOURCE_QRC})
|
||||
|
||||
add_library(${PROJECT_NAME} ${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(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${PRIVATE_INCUDE_DIR})
|
||||
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR})
|
||||
|
||||
set(LANGS ${CMAKE_CURRENT_SOURCE_DIR}/languages/en.ts)
|
||||
|
||||
|
||||
prepareQM(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR} "${LANGS}")
|
||||
prepareQM(${CURRENT_PROJECT} ${CMAKE_CURRENT_SOURCE_DIR} "${LANGS}")
|
||||
|
||||
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "" FORCE)
|
||||
|
||||
|
15
src/ClientLib/SnakeProject/Private/mainmenumodel.cpp
Normal file
15
src/ClientLib/SnakeProject/Private/mainmenumodel.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "mainmenumodel.h"
|
||||
#include "settingsviewmodel.h"
|
||||
|
||||
#include <quasarapp.h>
|
||||
|
||||
MainMenuModel::MainMenuModel(QObject *ptr): QObject (ptr) {
|
||||
|
||||
_conf = QuasarAppUtils::Settings::instance();
|
||||
_userSettingsModel = new SettingsViewModel(this);
|
||||
|
||||
}
|
||||
|
||||
QObject *MainMenuModel::userSettingsModel() const {
|
||||
return _userSettingsModel;
|
||||
}
|
25
src/ClientLib/SnakeProject/Private/mainmenumodel.h
Normal file
25
src/ClientLib/SnakeProject/Private/mainmenumodel.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef NETWORKPROFILEMAINMODEL_H
|
||||
#define NETWORKPROFILEMAINMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
#include "snakeprojectsettings.h"
|
||||
|
||||
|
||||
class MainMenuModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QObject* userSettingsModel READ userSettingsModel NOTIFY userSettingsModelChanged)
|
||||
|
||||
private:
|
||||
Settings *_conf = nullptr;
|
||||
|
||||
public:
|
||||
MainMenuModel(QObject *ptr = nullptr);
|
||||
QObject* userSettingsModel() const;
|
||||
|
||||
signals:
|
||||
void userSettingsModelChanged(QObject* userSettingsModel);
|
||||
};
|
||||
|
||||
#endif // NETWORKPROFILEMAINMODEL_H
|
@ -1,180 +0,0 @@
|
||||
#include "mainclient.h"
|
||||
#include "notificationservice.h"
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
OnlineStatus MainClient::onlineStatus() const {
|
||||
return _onlineStatus;
|
||||
}
|
||||
|
||||
void MainClient::setOnlineStatus(OnlineStatus onlineStatus) {
|
||||
if (_onlineStatus == onlineStatus)
|
||||
return;
|
||||
|
||||
emit sigOnlineStatusChanged(_onlineStatus = onlineStatus);
|
||||
pushNotify(onlineStatus);
|
||||
|
||||
}
|
||||
|
||||
void MainClient::clientStatusChanged() {
|
||||
auto status = OnlineStatus::ClientIsOffline;
|
||||
|
||||
if (isOnline()) {
|
||||
status = OnlineStatus::AuthorizationRequired;
|
||||
}
|
||||
|
||||
if (isLogin()) {
|
||||
status = OnlineStatus::Success;
|
||||
}
|
||||
|
||||
setOnlineStatus(status);
|
||||
}
|
||||
|
||||
void MainClient::pushNotify(OnlineStatus onlineStatus) {
|
||||
|
||||
|
||||
switch (onlineStatus) {
|
||||
|
||||
case OnlineStatus::Success: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login status"), tr("Success")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OnlineStatus::AuthorizationRequired: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login status"), tr("Authorization Required")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OnlineStatus::WaitForAnswer: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login status"), tr("Wait for answer")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OnlineStatus::AuthorizationFail: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login result"), tr("Authorization fail") , "", NotificationData::Error));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OnlineStatus::ClientIsOffline: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login result"), tr("Client is offline"), "", NotificationData::Warning));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case OnlineStatus::OfflineMode: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Login result"), tr("Offline Mode")));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MainClient::handleReceivePackage(ClientProtocol::Command cmd, const QByteArray &obj) {
|
||||
switch (cmd) {
|
||||
|
||||
case ClientProtocol::Command::Player: {
|
||||
auto playerData = QSharedPointer<PlayerClientData>::create();
|
||||
playerData->fromBytes(obj);
|
||||
|
||||
_users [playerData->id()] = playerData;
|
||||
|
||||
if (playerData->id() == _currentUserId) {
|
||||
emit currentUserDataChanged(_users [playerData->id()]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ClientProtocol::Command::BadRequest: {
|
||||
|
||||
NotificationService::getService()->setNotify(
|
||||
NotificationData(tr("Request"), tr("Bad Request"), "",
|
||||
NotificationData::Error));
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
void MainClient::handleLoginChanged(bool logined) {
|
||||
this->setSubscribe(ClientProtocol::Command::Player, logined, _currentUserId);
|
||||
clientStatusChanged();
|
||||
|
||||
}
|
||||
|
||||
void MainClient::handleOnlineChanged(bool) {
|
||||
clientStatusChanged();
|
||||
}
|
||||
|
||||
MainClient::MainClient(const QString &addrress, unsigned short port, QObject *ptr):
|
||||
ClientProtocol::Client (addrress, port, ptr) {
|
||||
|
||||
connect(this, &MainClient::sigIncommingData,
|
||||
this, &MainClient::handleReceivePackage);
|
||||
|
||||
connect(this, &MainClient::onlineChanged,
|
||||
this, &MainClient::handleOnlineChanged);
|
||||
|
||||
connect(this, &MainClient::loginChanged,
|
||||
this, &MainClient::handleLoginChanged);
|
||||
}
|
||||
|
||||
bool MainClient::login(const QString &gmail, const QByteArray &pass, bool) {
|
||||
if (!ClientProtocol::Client::login(gmail, pass)) {
|
||||
setOnlineStatus(OnlineStatus::AuthorizationFail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MainClient::registration(const QString &gmail,
|
||||
const QByteArray &pass) {
|
||||
|
||||
if (!ClientProtocol::Client::registration(gmail, pass)) {
|
||||
setOnlineStatus(OnlineStatus::AuthorizationFail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainClient::playOffline() {
|
||||
if (_onlineStatus == OnlineStatus::ClientIsOffline) {
|
||||
setOnlineStatus(OfflineMode);
|
||||
}
|
||||
}
|
||||
|
||||
void MainClient::tryConnect(const QString &addrress, unsigned short port) {
|
||||
setOnlineStatus(ClientIsOffline);
|
||||
connectToHost(addrress, port);
|
||||
}
|
||||
|
||||
MainClient::~MainClient() {
|
||||
for (auto &i: _users) {
|
||||
i.clear();
|
||||
}
|
||||
_users.clear();
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef MAINCLIENT_H
|
||||
#define MAINCLIENT_H
|
||||
#include <client.h>
|
||||
|
||||
class PlayerClientData;
|
||||
|
||||
enum OnlineStatus: int {
|
||||
Success = 0x0,
|
||||
AuthorizationRequired,
|
||||
WaitForAnswer,
|
||||
AuthorizationFail,
|
||||
ClientIsOffline,
|
||||
OfflineMode
|
||||
};
|
||||
|
||||
class MainClient: public ClientProtocol::Client
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QHash<int, QSharedPointer<PlayerClientData>> _users;
|
||||
OnlineStatus _onlineStatus = ClientIsOffline;
|
||||
|
||||
void setOnlineStatus(OnlineStatus onlineStatus);
|
||||
void clientStatusChanged();
|
||||
void pushNotify(OnlineStatus onlineStatus);
|
||||
|
||||
private slots:
|
||||
void handleReceivePackage(ClientProtocol::Command cmd, const QByteArray& obj);
|
||||
void handleLoginChanged(bool);
|
||||
void handleOnlineChanged(bool);
|
||||
|
||||
public:
|
||||
MainClient(const QString& addrress = LOCAL_SNAKE_SERVER,
|
||||
unsigned short port = DEFAULT_SNAKE_PORT,
|
||||
QObject * ptr = nullptr);
|
||||
bool login(const QString& gmail, const QByteArray &pass, bool registerNewUser = false) override;
|
||||
bool registration(const QString& gmail,
|
||||
const QByteArray &pass) override;
|
||||
void playOffline();
|
||||
void tryConnect(const QString &addrress, unsigned short port);
|
||||
|
||||
~MainClient() override;
|
||||
|
||||
OnlineStatus onlineStatus() const;
|
||||
|
||||
signals:
|
||||
void sigOnlineStatusChanged(OnlineStatus);
|
||||
void currentUserDataChanged(QSharedPointer<PlayerClientData>);
|
||||
};
|
||||
|
||||
#endif // MAINCLIENT_H
|
@ -1,59 +0,0 @@
|
||||
#include "mainmenumodel.h"
|
||||
#include "settingsviewmodel.h"
|
||||
#include "userview.h"
|
||||
|
||||
#include <back-end/settings.h>
|
||||
#include <quasarapp.h>
|
||||
#include "mainclient.h"
|
||||
|
||||
MainMenuModel::MainMenuModel(QObject *ptr): QObject (ptr) {
|
||||
|
||||
if(!ClientProtocol::initClientProtockol()) {
|
||||
QuasarAppUtils::Params::verboseLog("client protockol not inited", QuasarAppUtils::Error);
|
||||
}
|
||||
|
||||
_userViewModel = new UserView (this);
|
||||
_conf = Settings::get();
|
||||
_userSettingsModel = new SettingsViewModel(this);
|
||||
auto adderss = _conf->getValue(SERVER_ADDRESS, SERVER_ADDRESS_DEFAULT).toString();
|
||||
auto port = _conf->getValue(SERVER_ADDRESS_PORT, SERVER_ADDRESS_DEFAULT_PORT).toInt();
|
||||
_client = new MainClient(adderss, static_cast<unsigned short>(port), this);
|
||||
|
||||
connect(_client, &MainClient::sigOnlineStatusChanged,
|
||||
this , &MainMenuModel::onlineStatusChanged);
|
||||
|
||||
connect(_client, &MainClient::currentUserDataChanged,
|
||||
_userViewModel , &UserView::setSource);
|
||||
}
|
||||
|
||||
QObject *MainMenuModel::userViewModel() const {
|
||||
return _userViewModel;
|
||||
}
|
||||
|
||||
int MainMenuModel::onlineStatus() const {
|
||||
return _client->onlineStatus();
|
||||
}
|
||||
|
||||
void MainMenuModel::playOffline() {
|
||||
_client->playOffline();
|
||||
_userViewModel->setOffline(true);
|
||||
}
|
||||
|
||||
void MainMenuModel::tryConnect() {
|
||||
auto adderss = _conf->getValue(SERVER_ADDRESS, SERVER_ADDRESS_DEFAULT).toString();
|
||||
auto port = _conf->getValue(SERVER_ADDRESS_PORT, SERVER_ADDRESS_DEFAULT_PORT).toInt();
|
||||
_client->tryConnect(adderss, static_cast<unsigned short>(port));
|
||||
}
|
||||
|
||||
QObject *MainMenuModel::userSettingsModel() const {
|
||||
return _userSettingsModel;
|
||||
}
|
||||
|
||||
void MainMenuModel::login(const QString &email, const QString &pass) {
|
||||
_client->login(email, pass.toUtf8());
|
||||
}
|
||||
|
||||
void MainMenuModel::registerNewUser(const QString &email,
|
||||
const QString &pass) {
|
||||
_client->registration(email, pass.toUtf8());
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef NETWORKPROFILEMAINMODEL_H
|
||||
#define NETWORKPROFILEMAINMODEL_H
|
||||
|
||||
#include "mainclient.h"
|
||||
|
||||
#include <QObject>
|
||||
#include "./../settings.h"
|
||||
|
||||
class UserView;
|
||||
|
||||
class MainClient;
|
||||
class SettingsViewModel;
|
||||
|
||||
class MainMenuModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
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:
|
||||
UserView* _userViewModel = nullptr;
|
||||
SettingsViewModel* _userSettingsModel = nullptr;
|
||||
MainClient *_client = nullptr;
|
||||
Settings *_conf = nullptr;
|
||||
|
||||
public:
|
||||
MainMenuModel(QObject *ptr = nullptr);
|
||||
|
||||
QObject* userViewModel() const;
|
||||
QObject* userSettingsModel() const;
|
||||
|
||||
int onlineStatus() const;
|
||||
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();
|
||||
void userSettingsModelChanged(QObject* userSettingsModel);
|
||||
};
|
||||
|
||||
#endif // NETWORKPROFILEMAINMODEL_H
|
@ -1,6 +0,0 @@
|
||||
#include "playerclientdata.h"
|
||||
|
||||
PlayerClientData::PlayerClientData()
|
||||
{
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#ifndef PLAYERCLIENTDATA_H
|
||||
#define PLAYERCLIENTDATA_H
|
||||
#include <player.h>
|
||||
|
||||
class PlayerClientData: public ClientProtocol::Player
|
||||
{
|
||||
public:
|
||||
PlayerClientData();
|
||||
};
|
||||
|
||||
#endif // PLAYERCLIENTDATA_H
|
@ -1,78 +0,0 @@
|
||||
#include "userview.h"
|
||||
|
||||
const PlayerClientData *UserView::getSource() const {
|
||||
return _source.data();
|
||||
}
|
||||
|
||||
void UserView::setSource(QSharedPointer<PlayerClientData> data) {
|
||||
|
||||
_offline = data == nullptr;
|
||||
|
||||
if (data->id() != _source->id()) {
|
||||
_source = data;
|
||||
emit sourceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool UserView::offline() const {
|
||||
return _offline;
|
||||
}
|
||||
|
||||
void UserView::setOffline(bool offline) {
|
||||
if (_offline != offline) {
|
||||
emit offlineChanged(_offline = offline);
|
||||
}
|
||||
}
|
||||
|
||||
UserView::UserView(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
QString UserView::name() const {
|
||||
if (!_source) {
|
||||
return tr("Undefined name");
|
||||
}
|
||||
return _source->getName();
|
||||
}
|
||||
|
||||
QString UserView::gmail() const {
|
||||
if (!_source) {
|
||||
return tr("Undefined gmail");
|
||||
}
|
||||
return _source->getGmail();
|
||||
}
|
||||
|
||||
int UserView::money() const {
|
||||
if (!_source) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<int>(_source->getMany());
|
||||
}
|
||||
|
||||
int UserView::record() const {
|
||||
if (!_source) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<int>(_source->getRecord());
|
||||
}
|
||||
|
||||
int UserView::avgRecord() const {
|
||||
if (!_source) {
|
||||
return -1;
|
||||
}
|
||||
return static_cast<int>(_source->getAvgRecord());
|
||||
}
|
||||
|
||||
int UserView::cureentSnake() const {
|
||||
if (!_source) {
|
||||
return -1;
|
||||
}
|
||||
return _source->getCureentSnake();
|
||||
}
|
||||
|
||||
int UserView::id() const {
|
||||
if (!_source) {
|
||||
return -1;
|
||||
}
|
||||
return _source->id();
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#ifndef USERVIEW_H
|
||||
#define USERVIEW_H
|
||||
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class UserView : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString name READ name NOTIFY sourceChanged)
|
||||
Q_PROPERTY(QString gmail READ gmail NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int money READ money NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int record READ record NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int avgRecord READ avgRecord NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int cureentSnake READ cureentSnake NOTIFY sourceChanged)
|
||||
Q_PROPERTY(int id READ id NOTIFY sourceChanged)
|
||||
Q_PROPERTY(bool offline READ offline NOTIFY offlineChanged)
|
||||
|
||||
private:
|
||||
QSharedPointer<PlayerClientData> _source = nullptr;
|
||||
|
||||
bool _offline = false;
|
||||
|
||||
public:
|
||||
explicit UserView(QObject *parent = nullptr);
|
||||
|
||||
QString name() const;
|
||||
QString gmail() const;
|
||||
int money() const;
|
||||
int record() const;
|
||||
int avgRecord() const;
|
||||
int cureentSnake() const;
|
||||
int id() const;
|
||||
|
||||
const PlayerClientData *getSource() const;
|
||||
bool offline() const;
|
||||
void setOffline(bool offline);
|
||||
|
||||
signals:
|
||||
|
||||
void sourceChanged();
|
||||
|
||||
void offlineChanged(bool offline);
|
||||
|
||||
public slots:
|
||||
void setSource(QSharedPointer<PlayerClientData> data);
|
||||
|
||||
};
|
||||
|
||||
#endif // USERVIEW_H
|
@ -1,11 +1,12 @@
|
||||
#include "clientapp.h"
|
||||
#include "imageprovider.h"
|
||||
#include "ProfileViewItems/userview.h"
|
||||
#include "mainmenumodel.h"
|
||||
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <quasarapp.h>
|
||||
|
||||
#include <back-end/ProfileViewItems/mainmenumodel.h>
|
||||
#include <back-end/ProfileViewItems/notificationservice.h>
|
||||
#include <qmlnotifyservice.h>
|
||||
|
||||
QByteArray ClientApp::initTheme() {
|
||||
int themeIndex = Settings::get()->getValue(THEME, THEME_DEFAULT).toInt();
|
||||
@ -23,6 +24,21 @@ ClientApp::ClientApp() {
|
||||
ClientApp::~ClientApp() {
|
||||
}
|
||||
|
||||
void ClientApp::initLang() {
|
||||
QLocale locale = QLocale::system();
|
||||
QString customLanguage = QuasarAppUtils::Params::getArg("lang");
|
||||
if(customLanguage.size()) {
|
||||
locale = QLocale(customLanguage);
|
||||
}
|
||||
|
||||
if(!QuasarAppUtils::Locales::init(locale, {":/languages/languages/",
|
||||
":/credits_languages/",
|
||||
":/qmlNotify_languages/",
|
||||
":/lv_languages/"})){
|
||||
QuasarAppUtils::Params::log("Error load language : " , QuasarAppUtils::Error);
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
|
||||
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", initTheme());
|
||||
@ -40,7 +56,12 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
engine->addImageProvider(QLatin1String("userItems"), new ImageProvider());
|
||||
|
||||
root->setContextProperty("contr", &contr);
|
||||
root->setContextProperty("notificationService", NotificationService::getService());
|
||||
|
||||
initLang();
|
||||
|
||||
if (!QmlNotificationService::init(engine)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
engine->load(QUrl(QStringLiteral("qrc:/front-end/main.qml")));
|
||||
if (engine->rootObjects().isEmpty())
|
||||
|
@ -13,6 +13,8 @@ private:
|
||||
|
||||
QByteArray initTheme();
|
||||
|
||||
void initLang();
|
||||
|
||||
public:
|
||||
ClientApp();
|
||||
~ClientApp();
|
||||
|
@ -1,20 +0,0 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include "clientapp.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
QQmlApplicationEngine engine;
|
||||
ClientApp client;
|
||||
|
||||
if (!client.init(&engine)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
#ifndef SNAKESETTINGS_H
|
||||
#define SNAKESETTINGS_H
|
||||
#include <config.h>
|
||||
#include <quasarapp.h>
|
||||
|
||||
#define SERVER_ADDRESS "SERVER_ADDRESS"
|
@ -101,49 +101,6 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MainClient</name>
|
||||
<message>
|
||||
<source>Login status</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Success</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Authorization Required</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Wait for answer</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Login result</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Authorization fail</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Client is offline</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Offline Mode</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Request</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Bad Request</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MainMenu</name>
|
||||
<message>
|
||||
@ -275,13 +232,5 @@
|
||||
<source>try conect to server </source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Undefined name</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Undefined gmail</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
1
submodules/SimpleQmlNotify
Submodule
1
submodules/SimpleQmlNotify
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 61b683c0591a41394e30d8f1099a856d7f4a552e
|
@ -19,7 +19,7 @@ set(PUBLIC_INCUDE_DIR ${PUBLIC_INCUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/units")
|
||||
|
||||
|
||||
add_executable(${CURRENT_PROJECT} ${SOURCE_CPP})
|
||||
target_link_libraries(${CURRENT_PROJECT} PRIVATE Qt${QT_VERSION_MAJOR}::Test SnakeProject)
|
||||
target_link_libraries(${CURRENT_PROJECT} PRIVATE Qt${QT_VERSION_MAJOR}::Test "${PROJECT_NAME}Core")
|
||||
|
||||
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user