diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-09-02 03:25:52 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-09-02 03:25:52 (GMT) |
commit | c67b9e5e9925d422dca0c5243f91c3e08fe90304 (patch) | |
tree | 2aaaa2da927318b0a28a8f15cf15a7d90c18a9ff | |
parent | 1ccca16e3e032cb90d09dc4a161fe35114d8360d (diff) | |
download | Qt-c67b9e5e9925d422dca0c5243f91c3e08fe90304.zip Qt-c67b9e5e9925d422dca0c5243f91c3e08fe90304.tar.gz Qt-c67b9e5e9925d422dca0c5243f91c3e08fe90304.tar.bz2 |
SameGame now asks for a name and saves your score.
Included a rewriting of the Dialog item to be half-decent.
Watch http://qtfx-nokia.trolltech.com.au/samegame/scores.php on the
internal network for highscores!
-rw-r--r-- | demos/declarative/samegame/SameGame.qml | 13 | ||||
-rw-r--r-- | demos/declarative/samegame/content/Dialog.qml | 18 | ||||
-rwxr-xr-x | demos/declarative/samegame/content/samegame.js | 12 |
3 files changed, 30 insertions, 13 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index 0da5679..877c1cc 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -34,6 +34,19 @@ Rectangle { } Dialog { id: dialog; anchors.centerIn: parent; z: 21 } + Dialog { + id: scoreName; anchors.centerIn: parent; z: 22; + TextInput { + id: Editor + onAccepted: { + if(scoreName.opacity==1&&Editor.text!="") + sendHighScore(Editor.text); + scoreName.forceClose(); + } + anchors.verticalCenter: parent.verticalCenter + x:160; width: 200; height:20; focus: true + } + } Rectangle { id: ToolBar diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml index 72c7900..401d211 100644 --- a/demos/declarative/samegame/content/Dialog.qml +++ b/demos/declarative/samegame/content/Dialog.qml @@ -2,14 +2,20 @@ import Qt 4.6 Rectangle { id: page + function forceClose() { + page.closed(); + page.opacity = 0; + } + function show(txt) { + MyText.text = txt; + page.opacity = 1; + } + signal closed(); color: "white"; border.width: 1; width: MyText.width + 20; height: 60; - property string text: "Hello World!" opacity: 0 opacity: Behavior { - SequentialAnimation { - NumberAnimation {property: "opacity"; from: 0; duration: 1500 } - NumberAnimation {property: "opacity"; to: 0; duration: 1500 } - } + NumberAnimation { duration: 1000 } } - Text { id: MyText; anchors.centerIn: parent; text: parent.text } + Text { id: MyText; anchors.centerIn: parent; text: "Hello World!" } + MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } } diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index 355dbfd..d890cd2 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -144,10 +144,10 @@ function victoryCheck() gameCanvas.score += 500; //Checks for game over if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ - dialog.text = "Game Over. Your score is " + gameCanvas.score; - dialog.opacity = 1; + dialog.show("Game Over. Your score is " + gameCanvas.score); timer = new Date() - timer; - //if(scoresURL != "") sendHighScore(name); + if(scoresURL != "") + scoreName.show("Please enter your name: "); } } @@ -233,8 +233,7 @@ function tweetHighScore(twitterName, twitterPass) { postman.open("POST", "http://twitter.com/statuses/update.xml", true, twitterName, twitterPass); postman.onreadystatechange = function() { if (postman.readyState == postman.DONE) { - dialog.text = "Your score has been tweeted for you."; - dialog.opacity = 1; + dialog.show("Your score has been tweeted for you."); } } postman.send(postData); @@ -247,8 +246,7 @@ function sendHighScore(name) { postman.open("POST", scoresURL, true); postman.onreadystatechange = function() { if (postman.readyState == postman.DONE) { - dialog.text = "Your score has been uploaded."; - dialog.opacity = 1; + dialog.show("Your score has been uploaded."); } } postman.send(postData); |