added online support

This commit is contained in:
Andrei Yankovich 2019-08-05 16:14:29 +03:00
parent 78d5f8c2c2
commit 700eaf9529
7 changed files with 58 additions and 8 deletions

View File

@ -29,6 +29,7 @@ SOURCES += \
back-end/head.cpp \
back-end/imageprovider.cpp \
back-end/itemworld.cpp \
back-end/settings.cpp \
back-end/snake.cpp \
back-end/world.cpp \
back-end/main.cpp
@ -100,5 +101,6 @@ HEADERS += \
back-end/head.h \
back-end/imageprovider.h \
back-end/itemworld.h \
back-end/settings.h \
back-end/snake.h \
back-end/world.h

View File

@ -1,8 +1,16 @@
#include "mainmenumodel.h"
#include "userview.h"
#include <client.h>
#include <back-end/settings.h>
MainMenuModel::MainMenuModel(QObject *ptr): QObject (ptr) {
_userViewModel = new UserView (this);
_conf = Settings::instans();
auto adderss = _conf->value(SERVER_ADDRESS, SERVER_ADDRESS_DEFAULT).toString();
auto port = _conf->value(SERVER_ADDRESS_PORT, SERVER_ADDRESS_DEFAULT_PORT).toInt();
_client = new ClientProtocol::Client(adderss, static_cast<unsigned short>(port), this);
}
QObject *MainMenuModel::userViewModel() const {

View File

@ -2,10 +2,11 @@
#define NETWORKPROFILEMAINMODEL_H
#include <QObject>
#include <QSettings>
class UserView;
namespace ClientProtockol {
namespace ClientProtocol {
class Client;
}
@ -26,9 +27,10 @@ class MainMenuModel : public QObject
private:
UserView* _userViewModel = nullptr;
ClientProtockol::Client *_client = nullptr;
ClientProtocol::Client *_client = nullptr;
OnlineStatus _onlineStatus = ClientIsOffline;
QSettings *_conf = nullptr;
OnlineStatus _onlineStatus;
public:
MainMenuModel(QObject *ptr = nullptr);

View File

@ -0,0 +1,6 @@
#include "settings.h"
QSettings *Settings::instans() {
static QSettings* data = new QSettings();
return data;
}

View File

@ -0,0 +1,19 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QSettings>
#include <config.h>
#define SERVER_ADDRESS "SERVER_ADDRESS"
#define SERVER_ADDRESS_PORT "SERVER_ADDRESS_PORT"
#define SERVER_ADDRESS_DEFAULT "178.124.160.6"
#define SERVER_ADDRESS_DEFAULT_PORT DEFAULT_SNAKE_PORT
class Settings
{
public:
Settings() = delete;
static QSettings *instans();
};
#endif // SETTINGS_H

View File

@ -7,7 +7,7 @@ import QtGraphicalEffects 1.12
Item {
id: element
readonly property int loginStatus : 0
property int loginStatus : 0
readonly property var resultLoginEnum: [
qsTr("Success"), // 0
qsTr("Authorization Required"), // 1
@ -296,7 +296,20 @@ Item {
height: 2 * metrix.controlPtMaterial
width: height
}
Label {
visible: loginStatus === 4
text: qsTr("You need connect to server");
font.pixelSize: height / 10;
anchors.fill: parent;
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
background: FrameView {
anchors.fill: parent
}
}
}

View File

@ -6,16 +6,15 @@ import QtQuick.Layouts 1.3
Item {
id: item1
property var model: null
property bool online: (model)? model.online: false
property bool login: (model)? model.login: false
readonly property int onlineStatus: (model)? model.onlineStatus: false
visible: true
z: 1
signal playGame();
onLoginChanged: {
if (!login) {
onOnlineStatusChanged: {
if (onlineStatus !== 4) {
loginPopUp._show();
}
}
@ -110,6 +109,7 @@ Item {
id: loginPopUp
source: LoginView {
id: loginView
loginStatus: onlineStatus
}
visible: true;