diff --git a/2048-qt.pro b/2048-qt.pro index 5c7ec04..49bee4d 100644 --- a/2048-qt.pro +++ b/2048-qt.pro @@ -31,4 +31,7 @@ HEADERS += \ TRANSLATIONS = ts/2048-qt_zh_CN.ts -VERSION = 0.1.0 +VERSION = 0.1.1 + +VERSTR = '\\"$${VERSION}\\"' +DEFINES += VER=\"$${VERSTR}\" diff --git a/README.md b/README.md index b46a2c6..c4ac6da 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt. - PRC (天朝) - Multi-language support, currently - English - - Chinese + - Simplified Chinese ## Screenshots @@ -25,13 +25,15 @@ A clone of [2048](https://github.com/gabrielecirulli/2048), implemented in Qt. ## Downloads +Check https://github.com/xiaoyong/2048-Qt/releases for compiled binary executable files. + ### Windows -Check https://github.com/xiaoyong/2048-Qt/releases for compiled binary files. All required Qt libraries have been packed into one .exe file. +All required Qt libraries have been packed into one .exe file. So it should work out of the box. ### Linux -The [bin/](https://github.com/xiaoyong/2048-Qt/tree/master/bin) directory contains the compiled binary file for 64-bit Linux. To run it, the Qt libraries (version >= 5.2.1) are required and should be installed on you system. +The Qt libraries (version >= 5.2.1) are required. Make sure that they are installed on you system. ## Todo diff --git a/bin/2048-qt-linux-x86_64 b/bin/2048-qt-linux-x86_64 deleted file mode 100755 index ebd74ad..0000000 Binary files a/bin/2048-qt-linux-x86_64 and /dev/null differ diff --git a/fonts/DroidSansFallback.ttf b/fonts/DroidSansFallback.ttf old mode 100755 new mode 100644 diff --git a/main.cpp b/main.cpp index 02e100b..985bf46 100644 --- a/main.cpp +++ b/main.cpp @@ -9,9 +9,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + Settings settings(0, "xiaoyong", "2048-Qt"); + settings.setVersion(QString(VER)); // Localization - QString locale = QLocale::system().name(); + QString locale = settings.value("language", QLocale::system().name()).toString(); QString tsFile = "2048-qt_" + locale; QTranslator translator; @@ -29,7 +31,6 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("myClass", &myClass); // Access C++ object "settings" from QML as "settings" - Settings settings(0, "xiaoyong", "2048-Qt"); engine.rootContext()->setContextProperty("settings", &settings); engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); diff --git a/qml/main.qml b/qml/main.qml index bbddac4..03c97b8 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -16,7 +16,9 @@ ApplicationWindow { x: (Screen.width - width) / 2 y: (Screen.height - height) / 2 - ExclusiveGroup { id: labelSettingsGroup } + ExclusiveGroup { id: labelSettingsGroup } + ExclusiveGroup { id: languageSettingsGroup } + menuBar: MenuBar { Menu { title: qsTr("File") @@ -34,51 +36,81 @@ ApplicationWindow { Menu { title: qsTr("Settings") - MenuItem { - text: qsTr("2048") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[0] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[0]) { - MyScript.label = MyScript.labelOptions[0]; - MyScript.startupFunction(); + Menu { + title: qsTr("Labeling") + MenuItem { + text: qsTr("2048") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[0] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[0]) { + MyScript.label = MyScript.labelOptions[0]; + MyScript.startupFunction(); + } } } - } - MenuItem { - text: qsTr("Degree") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[1] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[1]) { - MyScript.label = MyScript.labelOptions[1]; - MyScript.startupFunction(); + MenuItem { + text: qsTr("Degree") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[1] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[1]) { + MyScript.label = MyScript.labelOptions[1]; + MyScript.startupFunction(); + } } } - } - MenuItem { - text: qsTr("Military Rank") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[2] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[2]) { - MyScript.label = MyScript.labelOptions[2]; - MyScript.startupFunction(); + MenuItem { + text: qsTr("Military Rank") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[2] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[2]) { + MyScript.label = MyScript.labelOptions[2]; + MyScript.startupFunction(); + } + } + } + MenuItem { + text: qsTr("PRC") + checkable: true + exclusiveGroup: labelSettingsGroup + checked: MyScript.label === MyScript.labelOptions[3] ? true : false + onTriggered: { + if (MyScript.label !== MyScript.labelOptions[3]) { + MyScript.label = MyScript.labelOptions[3]; + MyScript.startupFunction(); + } } } } - MenuItem { - text: qsTr("PRC") - checkable: true - exclusiveGroup: labelSettingsGroup - checked: MyScript.label === MyScript.labelOptions[3] ? true : false - onTriggered: { - if (MyScript.label !== MyScript.labelOptions[3]) { - MyScript.label = MyScript.labelOptions[3]; - MyScript.startupFunction(); + Menu { + title: qsTr("Language") + MenuItem { + text: qsTr("English") + checkable: true + exclusiveGroup: languageSettingsGroup + checked: settings.value("language", "en_US") === "en_US" ? true : false + onTriggered: { + if (settings.value("language", "en_US") !== "en_US") { + settings.setValue("language", "en_US"); + changeLanguageDialog.open(); + } + } + } + MenuItem { + text: qsTr("Simplified Chinese") + checkable: true + exclusiveGroup: languageSettingsGroup + checked: settings.value("language", "en_US") === "zh_CN" ? true : false + onTriggered: { + if (settings.value("language", "en_US") !== "zh_CN") { + settings.setValue("language", "zh_CN"); + changeLanguageDialog.open(); + } } } } @@ -152,7 +184,7 @@ ApplicationWindow { Text { text: (index == 0) ? qsTr("SCORE") : qsTr("BEST") anchors.horizontalCenter: parent.horizontalCenter - y: 7 + y: 6 font.family: localFont.name font.pixelSize: 13 color: helper.myColors.fglight @@ -160,7 +192,7 @@ ApplicationWindow { Text { text: scoreText anchors.horizontalCenter: parent.horizontalCenter - y: 25 + y: 22 font.family: localFont.name font.pixelSize: 25 font.bold: true @@ -265,10 +297,17 @@ ApplicationWindow { } } + MessageDialog { + id: changeLanguageDialog + title: qsTr("Language Setting Hint") + text: qsTr("Please restart the program to make the language setting take effect.") + standardButtons: StandardButton.Ok + } + MessageDialog { id: aboutDialog title: qsTr("About 2048-Qt") - text: qsTr("

2048-Qt

Version 0.1

2014 Qiaoyong Zhong

") + text: qsTr("

2048-Qt

Version " + settings.getVersion() + "

2014 Qiaoyong Zhong <solary.sh@gmail.com>

") standardButtons: StandardButton.Ok } diff --git a/settings.cpp b/settings.cpp index 5af4579..5f4ba7b 100644 --- a/settings.cpp +++ b/settings.cpp @@ -15,3 +15,11 @@ void Settings::setValue(const QString &key, const QVariant &value) { QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { return settings_->value(key, defaultValue); } + +void Settings::setVersion(QString version) { + appVersion = version; +} + +QString Settings::getVersion() { + return appVersion; +} diff --git a/settings.h b/settings.h index f39763c..57c5d2f 100644 --- a/settings.h +++ b/settings.h @@ -13,6 +13,9 @@ public: Q_INVOKABLE void setValue(const QString &key, const QVariant &value); Q_INVOKABLE QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; + Q_INVOKABLE QString getVersion(); + + void setVersion(const QString version); signals: @@ -20,7 +23,7 @@ public slots: private: QSettings *settings_; - + QString appVersion; }; #endif // SETTINGS_H diff --git a/ts/2048-qt_zh_CN.qm b/ts/2048-qt_zh_CN.qm index 13f2374..308189d 100644 Binary files a/ts/2048-qt_zh_CN.qm and b/ts/2048-qt_zh_CN.qm differ diff --git a/ts/2048-qt_zh_CN.ts b/ts/2048-qt_zh_CN.ts index 55eea72..3695eea 100644 --- a/ts/2048-qt_zh_CN.ts +++ b/ts/2048-qt_zh_CN.ts @@ -9,103 +9,128 @@ 2048游戏 - + File 文件 - - + + New Game 新游戏 - + Exit 退出 - + Settings 设置 - + + Labeling + 标签系统 + + + 2048 2048 - + Degree 学位 - + Military Rank 军衔 - + PRC 天朝 - + + Language + 语言 + + + + English + 英语 + + + + Simplified Chinese + 简体中文 + + + Help 帮助 - + About 关于 - + About Qt 关于Qt - + SCORE 得分 - + BEST 最高分 - + Join the numbers and get to the <b>2048 tile</b>! 把相同的数字相加,得到<b>2048</b>! - - About 2048-Qt - 关于2048-Qt + + Language Setting Hint + 语言设置提示 + + + + Please restart the program to make the language setting take effect. + 为了让语言设置生效,请重启程序。 - - <p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version 0.1</p><p>2014 Qiaoyong Zhong</p> - + + About 2048-Qt + 关于2048-Qt - + Game Over 游戏结束 - + Game Over! 游戏结束! - + You Win 你赢了 - + You win! Continue playing? 你赢了!要继续玩吗?