4
0
mirror of https://github.com/QuasarApp/Hanoi-Towers.git synced 2025-05-15 10:59:33 +00:00

simple fixes

This commit is contained in:
Andrei Yankovich 2019-11-12 20:13:09 +03:00
parent 8c301da917
commit a3c9853ee6
7 changed files with 55 additions and 26 deletions

@ -19,6 +19,7 @@ BackEnd::BackEnd():
{
_settings = QuasarAppUtils::Settings::get();
_profile = _settings->getStrValue(CURRENT_PROFILE_KEY, DEFAULT_USER);
init();
}
void BackEnd::reset(){
@ -32,13 +33,15 @@ void BackEnd::reset(){
item->deleteLater();
}
_profileList.clear();
_profile = addProfile(DEFAULT_USER, false)->name();
emit profileListChanged();
}
bool BackEnd::init() {
void BackEnd::init() {
QFile f(MAIN_SETINGS_FILE);
if(f.exists() && f.open(QIODevice::ReadOnly)){
if(f.open(QIODevice::ReadOnly)){
QDataStream stream(&f);
unsigned char dataVersion;
@ -48,7 +51,10 @@ bool BackEnd::init() {
stream >> _profileList;
stream >> _profile;
f.close();
if (_profileList.isEmpty()) {
_profile = addProfile(DEFAULT_USER, false)->name();
}
} else {
unsigned short lvl;
bool isFirstStart, _animation, _randomColor;
@ -63,20 +69,20 @@ bool BackEnd::init() {
setAnimation(_animation);
setRandomColor(_randomColor);
setRandomColor(isFirstStart);
setShowHelp(isFirstStart);
auto profile = addProfile(DEFAULT_USER, false);
static_cast<GameState*>((profile->
gameState()))->saveLvl(
static_cast<short>(lvl));
emit firstChanged();
}
f.close();
return true;
} else {
reset();
}
return false;
}
ProfileData* BackEnd::addProfile(const QString &userName, bool isOnlineuser) {
@ -85,7 +91,7 @@ ProfileData* BackEnd::addProfile(const QString &userName, bool isOnlineuser) {
return profile;
}
profile = new ProfileData();
profile = new ProfileData(userName);
connect(profile, &ProfileData::onlineRequest,
this, &BackEnd::handleOnlineRequest);

@ -25,7 +25,7 @@ class BackEnd: public QObject
private:
bool init();
void init();
ProfileData *addProfile(const QString& userName, bool isOnlineuser);
void saveLocalData() const;

@ -7,6 +7,9 @@ Item {
readonly property int headerSize: Utils.headerFontSize(Screen.pixelDensity);
readonly property int buttonsWidth: Utils.dp(Screen.pixelDensity, 80)
readonly property int buttonsHeight: Utils.dp(Screen.pixelDensity, 40)
readonly property int smallbuttonsSize: Utils.dp(Screen.pixelDensity, 40)
readonly property int popUpWidth: Utils.dp(Screen.pixelDensity, 150)
readonly property int popUpHeight: Utils.dp(Screen.pixelDensity, 80)
readonly property string buttonsTextColor: Utils.textColor()

@ -2,27 +2,46 @@ import QtQuick 2.13
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.13
import QtQuick.Controls.Material 2.13
import "./../base" as Base
RowLayout {
Item {
property string name: ""
property bool online: false
property string record: "0"
property int recordLength: 0
Switch {
text: qsTr("Online user")
position: online
}
RowLayout {
anchors.fill: parent
TextField {
Layout.fillWidth: true
text: name
}
Base.Theme{
id: theme;
}
Text {
text: record
Layout.minimumWidth: recordLength
Switch {
text: qsTr("Online user")
position: online
}
TextField {
Layout.fillWidth: true
readOnly: true;
text: name
}
Text {
text: record
Layout.minimumWidth: recordLength - deleteUser.width
}
Base.BaseButton {
id: deleteUser;
text: "X"
Layout.maximumHeight: theme.smallbuttonsSize
Layout.maximumWidth: theme.smallbuttonsSize
}
}
}

@ -20,7 +20,7 @@ Item {
Base.BaseText {
Layout.alignment: Qt.AlignCenter
text: qsTr("Profiles");
text: qsTr("Profiles") + " (" + backEnd.profile + ")";
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: theme.headerSize;
@ -93,7 +93,7 @@ Item {
online: backEnd.isOnline(modelData)
record: backEnd.record(modelData)
width: listView.width
recordLength: button.width
recordLength: button.width - gridLayout.rowSpacing
}
}

@ -17,8 +17,9 @@ void ProfileData::handleServerResponce(const NetworkProtocol::UserData& data) {
}
}
ProfileData::ProfileData():
ProfileData::ProfileData(const QString &name):
QObject(nullptr) {
_userData.setName(name);
}
ProfileData::~ProfileData() = default;

@ -21,7 +21,7 @@ private slots:
void handleServerResponce(const NetworkProtocol::UserData &data);
public:
ProfileData();
ProfileData(const QString& name);
~ProfileData() override;
Q_INVOKABLE QObject* gameState();