diff --git a/QcookieClicker.pro b/QcookieClicker.pro index b2ebf38..0816d86 100644 --- a/QcookieClicker.pro +++ b/QcookieClicker.pro @@ -13,9 +13,13 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - main.cpp + sources/main.cpp \ + sources/appsettings.cpp -RESOURCES += qml.qrc \ +HEADERS += \ + headers/appsettings.h + +RESOURCES += qml/qml.qrc \ shared/shared.qrc # Additional import path used to resolve QML modules in Qt Creator's code model diff --git a/QcookieClicker.pro.user b/QcookieClicker.pro.user index 1a1ab49..4238654 100644 --- a/QcookieClicker.pro.user +++ b/QcookieClicker.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 2 + 0 ProjectExplorer.Project.EditorSettings @@ -61,6 +61,258 @@ ProjectExplorer.Project.Target.0 + + Desktop Qt 5.11.3 GCC 64bit + Desktop Qt 5.11.3 GCC 64bit + qt.qt5.5113.gcc_64_kit + 0 + 0 + 0 + + /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + QcookieClicker + QcookieClicker2 + Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/Documents/git/qcookieclicker/QcookieClicker.pro + QcookieClicker.pro + + 3768 + false + true + true + false + false + true + + /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 Android for armeabi-v7a (Clang Qt 5.11.3 for Android ARMv7) Android for armeabi-v7a (Clang Qt 5.11.3 for Android ARMv7) @@ -351,7 +603,7 @@ 0 - QcookieClicker + Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/QcookieClicker/QcookieClicker.pro @@ -366,7 +618,7 @@ - ProjectExplorer.Project.Target.1 + ProjectExplorer.Project.Target.2 Android for x86 (Clang Qt 5.11.3 for Android x86) Android for x86 (Clang Qt 5.11.3 for Android x86) @@ -660,7 +912,7 @@ 0 - QcookieClicker + Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/QcookieClicker/QcookieClicker.pro @@ -674,258 +926,6 @@ 1 - - ProjectExplorer.Project.Target.2 - - Desktop Qt 5.11.3 GCC 64bit - Desktop Qt 5.11.3 GCC 64bit - qt.qt5.5113.gcc_64_kit - 0 - 0 - 0 - - /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy Configuration - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - QcookieClicker - - Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/QcookieClicker/QcookieClicker.pro - QcookieClicker.pro - - 3768 - false - true - true - false - false - true - - /home/dorian/build-QcookieClicker-Desktop_Qt_5_11_3_GCC_64bit-Debug - - 1 - - ProjectExplorer.Project.TargetCount 3 diff --git a/headers/appsettings.h b/headers/appsettings.h new file mode 100644 index 0000000..144d49c --- /dev/null +++ b/headers/appsettings.h @@ -0,0 +1,49 @@ +#ifndef APPSETTINGS_H +#define APPSETTINGS_H + +#include +#include +#include +#include + +class AppSettings : public QObject +{ + Q_OBJECT + + Q_PROPERTY(NOTIFY themeChanged) + +public: + explicit AppSettings(QObject *parent = nullptr); + // This is the Constructor of the AppSettings class + + ~AppSettings(); + // This is the Destructor of the AppSettings class + +private: + QSettings *settingsManager; + // QSettings object which cares about our settings.ini file + + QSettings *themeSettingsManager; + // QSettings object which cares about the themes + +signals: + void themeChanged(); + +public slots: + Q_INVOKABLE QString read(const QString &key); + // function to read values from the settings file + + Q_INVOKABLE void write(const QString &key, const QVariant &value); + // function to write values to the settings file + + Q_INVOKABLE void setDefault(const QString &key, const QVariant &defaultValue); + // function to create a key (/ setting) with a default value if it hasnt been ceated yet + + Q_INVOKABLE QString theme(QString key); + // function to get style settings from a theme file + + Q_INVOKABLE void reloadTheme(); + // function to reload the theme and tell all child that it has changed +}; + +#endif // APPSETTINGS_H diff --git a/main.qml b/main.qml deleted file mode 100644 index 13bf0ed..0000000 --- a/main.qml +++ /dev/null @@ -1,57 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Window 2.2 -import QtQuick.Controls 2.4 - -Window { - visible: true - width: 640 - height: 480 - title: "QcookieClicker" - - Page { - id: app - - property int level: 0 - - anchors.fill: parent - - Label { - id: levelLa - - anchors { - top: parent.top - horizontalCenter: parent.horizontalCenter - topMargin: 20 - } - - font.pixelSize: 30 - - text: app.level - } - - Button { - id: cookieBt - - anchors.centerIn: parent - - height: parent.height * 0.3 - width: height - - scale: pressed ? 0.8:1 - - background: Image { - source: "qrc:/icons/cookie.png" - } - - onClicked: { - app.level = app.level + 1 - } - - Behavior on scale { - NumberAnimation { - duration: 100 - } - } - } - } -} diff --git a/qml/ShopPopup.qml b/qml/ShopPopup.qml new file mode 100644 index 0000000..9fde9f1 --- /dev/null +++ b/qml/ShopPopup.qml @@ -0,0 +1,55 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 + +Popup { + id: control + + modal: true + + height: 300 + + Rectangle { + id: contentRect + + height: parent.height + + width: topImg.width * 0.836 + anchors.horizontalCenter: parent.horizontalCenter + + color: "white" + + + } + + Image { + id: topImg + + anchors { + bottom: contentRect.top + bottomMargin: -height * 0.22 + } + source: "qrc:/graphics/shopTop.png" + fillMode: Image.PreserveAspectFit + width: parent.width + } + + Image { + id: bottomImg + + anchors { + top: contentRect.bottom + topMargin: -height * 0.33 + } + + source: "qrc:/graphics/shopBottom.png" + fillMode: Image.PreserveAspectFit + width: parent.width + } + + + background: Rectangle { + color: "transparent" + } + + +} diff --git a/qml/components/GameButton.qml b/qml/components/GameButton.qml new file mode 100644 index 0000000..4817fd7 --- /dev/null +++ b/qml/components/GameButton.qml @@ -0,0 +1,22 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 + +Button { + id: control + + property string imageSrc: "" + + width: height + + scale: pressed ? 0.8:1 + + background: Image { + source: control.imageSrc + } + + Behavior on scale { + NumberAnimation { + duration: 100 + } + } +} diff --git a/qml/main.qml b/qml/main.qml new file mode 100644 index 0000000..050a91c --- /dev/null +++ b/qml/main.qml @@ -0,0 +1,91 @@ +import QtQuick 2.9 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.4 + +import com.itsblue.qcookieclicker 1.0 + +import "./components" + +Window { + visible: true + width: 540 + height: 960 + title: "QcookieClicker" + + Page { + id: app + + property int level: settings.read("score") + + anchors.fill: parent + + AppSettings { + id: settings + } + + Label { + id: levelLa + + anchors { + top: parent.top + horizontalCenter: parent.horizontalCenter + topMargin: 20 + } + + font.pixelSize: 30 + + text: app.level + } + + GameButton { + id: cookieBt + + imageSrc: "qrc:/icons/cookie.png" + + anchors.centerIn: parent + + height: parent.width * 0.6 + + onClicked: { + settings.write("score", parseInt(settings.read("score")) + 1) + app.level = settings.read("score") + } + } + + Row { + id: menuRo + + anchors { + bottom: parent.bottom + bottomMargin: parent.height * 0.025 + horizontalCenter: parent.horizontalCenter + } + + height: parent.height * 0.1 + + GameButton { + id: shopBt + + imageSrc: "qrc:/icons/shop.png" + + height: parent.height + + onClicked: { + shopPu.open() + } + } + } + + ShopPopup { + id: shopPu + + x: ( parent.width - width ) / 2 + y: ( parent.height - height ) / 2 + + width: parent.width * 0.8 + + } + + + } +} diff --git a/qml.qrc b/qml/qml.qrc similarity index 51% rename from qml.qrc rename to qml/qml.qrc index 5f6483a..44fdff8 100644 --- a/qml.qrc +++ b/qml/qml.qrc @@ -1,5 +1,7 @@ main.qml + components/GameButton.qml + ShopPopup.qml diff --git a/shared/graphics/shopBottom.png b/shared/graphics/shopBottom.png new file mode 100644 index 0000000..564eb90 Binary files /dev/null and b/shared/graphics/shopBottom.png differ diff --git a/shared/graphics/shopTop.png b/shared/graphics/shopTop.png new file mode 100644 index 0000000..7832263 Binary files /dev/null and b/shared/graphics/shopTop.png differ diff --git a/shared/icons/shop.png b/shared/icons/shop.png new file mode 100644 index 0000000..8b7a549 Binary files /dev/null and b/shared/icons/shop.png differ diff --git a/shared/shared.qrc b/shared/shared.qrc index 300ac4b..ebef114 100644 --- a/shared/shared.qrc +++ b/shared/shared.qrc @@ -1,5 +1,8 @@ icons/cookie.png + icons/shop.png + graphics/shopTop.png + graphics/shopBottom.png diff --git a/shared/shop.xcf b/shared/shop.xcf new file mode 100644 index 0000000..94948db Binary files /dev/null and b/shared/shop.xcf differ diff --git a/sources/appsettings.cpp b/sources/appsettings.cpp new file mode 100644 index 0000000..46a781d --- /dev/null +++ b/sources/appsettings.cpp @@ -0,0 +1,90 @@ +#include "headers/appsettings.h" + +AppSettings::AppSettings(QObject* parent) + :QObject(parent) +{ + // This is the Constructor of the AppSettings class + + // get writable path to store the settings.ini file + QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + + qDebug() << "app settings path: " << path; + + // create or open the settings.ini file + this->settingsManager = new QSettings(path+"/settings.ini", QSettings::IniFormat); + + // set the values to their defaults if they haven't been created yet + this->setDefault("score", "0"); + + // create or open the settings.ini file + this->themeSettingsManager = new QSettings(":/themes/" + this->read("theme") + ".ini", QSettings::IniFormat); +} + +QString AppSettings::read(const QString &key) +{ + // function to read values from the settings file + + // open the value-group + this->settingsManager->beginGroup("AppSettings"); + // read the value + QString value = this->settingsManager->value(key , false).toString(); + // close the value-group + this->settingsManager->endGroup(); + // return the value + return(value); +} + +void AppSettings::write(const QString &key, const QVariant &value) +{ + // function to write values to the settings file + + // open the value-group + this->settingsManager->beginGroup("AppSettings"); + // write the value + this->settingsManager->setValue(key, value); + // close the value-group + this->settingsManager->endGroup(); +} + +QString AppSettings::theme(QString key) +{ + // function to get style settings from a theme file + + // open the value-group + this->themeSettingsManager->beginGroup("ClickGameTheme"); + // read the value + QString value = this->themeSettingsManager->value(key , false).toString(); + // close the value-group + this->themeSettingsManager->endGroup(); + // return the value + return(value); +} + +void AppSettings::setDefault(const QString &key, const QVariant &defaultValue) +{ + // function to create a key (/ setting) with a default value if it hasnt been ceated yet + + // read the current value + QString value = this->read(key); + if(value == "false"){ + // if it is nor defined yet, the read function will return "false" (as a string) + // -> if that is the case -> create the key with the default value + this->write(key, defaultValue); + } + +} + +void AppSettings::reloadTheme() +{ + delete this->themeSettingsManager; + this->themeSettingsManager = new QSettings(":/themes/" + this->read("theme") + ".ini", QSettings::IniFormat); + emit this->themeChanged(); +} + +AppSettings::~AppSettings() +{ + // This is the Destructor of the AppSettings class + + // delete the settings manager + delete settingsManager; +} diff --git a/main.cpp b/sources/main.cpp similarity index 75% rename from main.cpp rename to sources/main.cpp index 6333b85..144a8df 100644 --- a/main.cpp +++ b/sources/main.cpp @@ -1,12 +1,16 @@ #include #include +#include "headers/appsettings.h" + int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); + qmlRegisterType("com.itsblue.qcookieclicker", 1, 0, "AppSettings"); + QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty())