mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 17:54:42 +00:00
added online support
This commit is contained in:
parent
78d5f8c2c2
commit
700eaf9529
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
6
SnakeClient/SnakeApp/back-end/settings.cpp
Normal file
6
SnakeClient/SnakeApp/back-end/settings.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "settings.h"
|
||||
|
||||
QSettings *Settings::instans() {
|
||||
static QSettings* data = new QSettings();
|
||||
return data;
|
||||
}
|
19
SnakeClient/SnakeApp/back-end/settings.h
Normal file
19
SnakeClient/SnakeApp/back-end/settings.h
Normal 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
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user