added language setting, version variable etc.
This commit is contained in:
parent
0b0690d162
commit
194054e6fd
@ -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}\"
|
||||
|
@ -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
|
||||
|
||||
|
Binary file not shown.
0
fonts/DroidSansFallback.ttf
Executable file → Normal file
0
fonts/DroidSansFallback.ttf
Executable file → Normal file
5
main.cpp
5
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")));
|
||||
|
127
qml/main.qml
127
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("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("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();
|
||||
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("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("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("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version 0.1</p><p>2014 Qiaoyong Zhong</p>")
|
||||
text: qsTr("<p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version " + settings.getVersion() + "</p><p>2014 Qiaoyong Zhong <solary.sh@gmail.com></p>")
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -9,103 +9,128 @@
|
||||
<translation>2048游戏</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="22"/>
|
||||
<location filename="../qml/main.qml" line="24"/>
|
||||
<source>File</source>
|
||||
<translation>文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="24"/>
|
||||
<location filename="../qml/main.qml" line="230"/>
|
||||
<location filename="../qml/main.qml" line="26"/>
|
||||
<location filename="../qml/main.qml" line="264"/>
|
||||
<source>New Game</source>
|
||||
<translation>新游戏</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="29"/>
|
||||
<location filename="../qml/main.qml" line="31"/>
|
||||
<source>Exit</source>
|
||||
<translation>退出</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="36"/>
|
||||
<location filename="../qml/main.qml" line="38"/>
|
||||
<source>Settings</source>
|
||||
<translation>设置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="38"/>
|
||||
<location filename="../qml/main.qml" line="40"/>
|
||||
<source>Labeling</source>
|
||||
<translation>标签系统</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="42"/>
|
||||
<source>2048</source>
|
||||
<translation>2048</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="50"/>
|
||||
<location filename="../qml/main.qml" line="54"/>
|
||||
<source>Degree</source>
|
||||
<translation>学位</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="62"/>
|
||||
<location filename="../qml/main.qml" line="66"/>
|
||||
<source>Military Rank</source>
|
||||
<translation>军衔</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="74"/>
|
||||
<location filename="../qml/main.qml" line="78"/>
|
||||
<source>PRC</source>
|
||||
<translation>天朝</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="89"/>
|
||||
<location filename="../qml/main.qml" line="91"/>
|
||||
<source>Language</source>
|
||||
<translation>语言</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="93"/>
|
||||
<source>English</source>
|
||||
<translation>英语</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="105"/>
|
||||
<source>Simplified Chinese</source>
|
||||
<translation>简体中文</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="121"/>
|
||||
<source>Help</source>
|
||||
<translation>帮助</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="91"/>
|
||||
<location filename="../qml/main.qml" line="123"/>
|
||||
<source>About</source>
|
||||
<translation>关于</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="95"/>
|
||||
<location filename="../qml/main.qml" line="127"/>
|
||||
<source>About Qt</source>
|
||||
<translation>关于Qt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="151"/>
|
||||
<location filename="../qml/main.qml" line="185"/>
|
||||
<source>SCORE</source>
|
||||
<translation>得分</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="151"/>
|
||||
<location filename="../qml/main.qml" line="185"/>
|
||||
<source>BEST</source>
|
||||
<translation>最高分</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="211"/>
|
||||
<location filename="../qml/main.qml" line="245"/>
|
||||
<source>Join the numbers and get to the <b>2048 tile</b>!</source>
|
||||
<translation>把相同的数字相加,得到<b>2048</b>!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="268"/>
|
||||
<location filename="../qml/main.qml" line="302"/>
|
||||
<source>Language Setting Hint</source>
|
||||
<translation>语言设置提示</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="303"/>
|
||||
<source>Please restart the program to make the language setting take effect.</source>
|
||||
<translation>为了让语言设置生效,请重启程序。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="309"/>
|
||||
<source>About 2048-Qt</source>
|
||||
<translation>关于2048-Qt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="269"/>
|
||||
<source><p style='font-weight: bold; font-size: 24px'>2048-Qt</p><p>Version 0.1</p><p>2014 Qiaoyong Zhong</p></source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="275"/>
|
||||
<location filename="../qml/main.qml" line="316"/>
|
||||
<source>Game Over</source>
|
||||
<translation>游戏结束</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="276"/>
|
||||
<location filename="../qml/main.qml" line="317"/>
|
||||
<source>Game Over!</source>
|
||||
<translation>游戏结束!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="286"/>
|
||||
<location filename="../qml/main.qml" line="327"/>
|
||||
<source>You Win</source>
|
||||
<translation>你赢了</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/main.qml" line="287"/>
|
||||
<location filename="../qml/main.qml" line="328"/>
|
||||
<source>You win! Continue playing?</source>
|
||||
<translation>你赢了!要继续玩吗?</translation>
|
||||
</message>
|
||||
|
Loading…
x
Reference in New Issue
Block a user