diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-07 06:57:21 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-07 06:57:21 (GMT) |
commit | a3a6e1622149654bc9e244e685e8e7dcbdf966b2 (patch) | |
tree | 1c4fe9feab63839213a0d97e9b24414c9585a227 /demos/declarative/samegame | |
parent | 99573a8e81fcea38c5f68b340068fff266315c03 (diff) | |
parent | 8b0cac9179de4d1cb34b9f17932d34cef3cd4f5b (diff) | |
download | Qt-a3a6e1622149654bc9e244e685e8e7dcbdf966b2.zip Qt-a3a6e1622149654bc9e244e685e8e7dcbdf966b2.tar.gz Qt-a3a6e1622149654bc9e244e685e8e7dcbdf966b2.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into test
Conflicts:
demos/declarative/samegame/content/samegame.js
tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
Diffstat (limited to 'demos/declarative/samegame')
-rw-r--r-- | demos/declarative/samegame/content/Button.qml | 6 | ||||
-rw-r--r-- | demos/declarative/samegame/content/Dialog.qml | 8 | ||||
-rwxr-xr-x | demos/declarative/samegame/content/samegame.js | 26 | ||||
-rw-r--r-- | demos/declarative/samegame/samegame.qml | 29 |
4 files changed, 35 insertions, 34 deletions
diff --git a/demos/declarative/samegame/content/Button.qml b/demos/declarative/samegame/content/Button.qml index 2354218..301124e 100644 --- a/demos/declarative/samegame/content/Button.qml +++ b/demos/declarative/samegame/content/Button.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rectangle { - id: Container + id: container signal clicked property string text: "Button" @@ -17,9 +17,9 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: Container.clicked() } + MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { - id: txtItem; text: Container.text; anchors.centerIn: Container; color: activePalette.buttonText + id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText } } diff --git a/demos/declarative/samegame/content/Dialog.qml b/demos/declarative/samegame/content/Dialog.qml index 401d211..661257b 100644 --- a/demos/declarative/samegame/content/Dialog.qml +++ b/demos/declarative/samegame/content/Dialog.qml @@ -7,15 +7,15 @@ Rectangle { page.opacity = 0; } function show(txt) { - MyText.text = txt; + myText.text = txt; page.opacity = 1; } signal closed(); - color: "white"; border.width: 1; width: MyText.width + 20; height: 60; + color: "white"; border.width: 1; width: myText.width + 20; height: 60; opacity: 0 - opacity: Behavior { + opacity: Behavior { NumberAnimation { duration: 1000 } } - Text { id: MyText; anchors.centerIn: parent; text: "Hello World!" } + 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 7deafde..15bafc4 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -1,8 +1,7 @@ /* This script file handles the game logic */ //Note that X/Y referred to here are in game coordinates -var maxX = 10;//Nums are for tileSize 40 +var maxX = 10;//Nums are for gameCanvas.tileSize 40 var maxY = 15; -var tileSize = 40; var maxIndex = maxX*maxY; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; @@ -35,8 +34,9 @@ function initBoard() board[i].destroy(); } - maxX = Math.floor(gameCanvas.width/tileSize); - maxY = Math.floor(gameCanvas.height/tileSize); + //Calculate board size + maxX = Math.floor(gameCanvas.width/gameCanvas.tileSize); + maxY = Math.floor(gameCanvas.height/gameCanvas.tileSize); maxIndex = maxY*maxX; //Close dialogs @@ -63,8 +63,8 @@ var floodBoard;//Set to 1 if the floodFill reaches off that node //NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope function handleClick(x,y) { - var xIdx = Math.floor(x/tileSize); - var yIdx = Math.floor(y/tileSize); + var xIdx = Math.floor(x/gameCanvas.tileSize); + var yIdx = Math.floor(y/gameCanvas.tileSize); if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; if(board[index(xIdx, yIdx)] == null) @@ -118,7 +118,7 @@ function shuffleDown() }else{ if(fallDist > 0){ var obj = board[index(xIdx,yIdx)]; - obj.targetY += fallDist * tileSize; + obj.targetY += fallDist * gameCanvas.tileSize; board[index(xIdx,yIdx+fallDist)] = obj; board[index(xIdx,yIdx)] = null; } @@ -136,7 +136,7 @@ function shuffleDown() obj = board[index(xIdx,yIdx)]; if(obj == null) continue; - obj.targetX -= fallDist * tileSize; + obj.targetX -= fallDist * gameCanvas.tileSize; board[index(xIdx-fallDist,yIdx)] = obj; board[index(xIdx,yIdx)] = null; } @@ -195,11 +195,11 @@ function createBlock(xIdx,yIdx){ } dynamicObject.type = Math.floor(Math.random() * 3); dynamicObject.parent = gameCanvas; - dynamicObject.x = xIdx*tileSize; - dynamicObject.targetX = xIdx*tileSize; - dynamicObject.targetY = yIdx*tileSize; - dynamicObject.width = tileSize; - dynamicObject.height = tileSize; + dynamicObject.x = xIdx*gameCanvas.tileSize; + dynamicObject.targetX = xIdx*gameCanvas.tileSize; + dynamicObject.targetY = yIdx*gameCanvas.tileSize; + dynamicObject.width = gameCanvas.tileSize; + dynamicObject.height = gameCanvas.tileSize; dynamicObject.spawned = true; board[index(xIdx,yIdx)] = dynamicObject; }else{//isError or isLoading diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml index 2d00208..ea7c14c 100644 --- a/demos/declarative/samegame/samegame.qml +++ b/demos/declarative/samegame/samegame.qml @@ -2,15 +2,13 @@ import Qt 4.6 import "content" Rectangle { - id: Screen + id: screen width: 490; height: 720 - Script { source: "content/samegame.js" } - SystemPalette { id: activePalette; colorGroup: Qt.Active } Item { - width: parent.width; anchors.top: parent.top; anchors.bottom: ToolBar.top + width: parent.width; anchors.top: parent.top; anchors.bottom: toolBar.top Image { id: background @@ -21,6 +19,9 @@ Rectangle { Item { id: gameCanvas property int score: 0 + property int tileSize: 40 + + Script { source: "content/samegame.js" } z: 20; anchors.centerIn: parent width: parent.width - (parent.width % getTileSize()); @@ -34,14 +35,14 @@ Rectangle { } Dialog { id: dialog; anchors.centerIn: parent; z: 21 } - Dialog { - id: scoreName; anchors.centerIn: parent; z: 22; + Dialog { + id: scoreName; anchors.centerIn: parent; z: 22; TextInput { - id: Editor - onAccepted: { - if(scoreName.opacity==1&&Editor.text!="") - sendHighScore(Editor.text); - scoreName.forceClose(); + id: editor + onAccepted: { + if(scoreName.opacity==1&&editor.text!="") + sendHighScore(editor.text); + scoreName.forceClose(); } anchors.verticalCenter: parent.verticalCenter width: 72; focus: true @@ -50,10 +51,10 @@ Rectangle { } Rectangle { - id: ToolBar + id: toolBar color: activePalette.window height: 32; width: parent.width - anchors.bottom: Screen.bottom + anchors.bottom: screen.bottom Button { id: btnA; text: "New Game"; onClicked: {initBoard();} @@ -62,7 +63,7 @@ Rectangle { } Text { - id: Score + id: score text: "Score: " + gameCanvas.score; font.bold: true anchors.right: parent.right; anchors.rightMargin: 3 anchors.verticalCenter: parent.verticalCenter |