diff --git a/src/activities/penalty/Penalty.qml b/src/activities/penalty/Penalty.qml --- a/src/activities/penalty/Penalty.qml +++ b/src/activities/penalty/Penalty.qml @@ -45,6 +45,25 @@ activity.stop.connect(stop) } + function isEnabled (Rectangle) { + var state + if (Rectangle === rectLeft) { state = "LEFT" } + else if (Rectangle === rectTop) { state = "CENTER" } + else { state = "RIGHT" } + + if (items.saveBallState !== "INITIAL") { + if (items.saveBallState !== state) { + return false + } + } + else { + if (ball.x !== items.ballX && ball.y !== items.ballY) { + return false + } + } + return true + } + function changeBallState(saveBallState) { instruction.text = "" @@ -54,13 +73,20 @@ } /* This is a shoot */ - var progress = progressTop - if (saveBallState == "LEFT") { - progress = progressLeft - } - else if(saveBallState == "RIGHT") { - progress = progressRight + var progress = items.progress + if (items.saveBallState === "INITIAL" && progress === undefined) { + items.saveBallState = saveBallState + if (saveBallState === "LEFT") { + progress = progressLeft + } + else if (saveBallState === "RIGHT") { + progress = progressRight + } + else { + progress = progressTop + } } + items.progress = progress if(progress.ratio > 0) { /* Second click, stop animation */ @@ -72,7 +98,7 @@ /* Success or not */ if(progress.ratio < 100) { /* Success */ - ball.state = saveBallState + ball.state = items.saveBallState } else { /* failure */ ball.state = "FAIL" @@ -102,10 +128,12 @@ MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + enabled: { + isEnabled(this.parent) + } + onClicked: { - if(mouse.button) { - changeBallState("LEFT") - } + changeBallState("LEFT") } } } @@ -123,10 +151,12 @@ MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + enabled: { + isEnabled(this.parent) + } + onClicked: { - if(mouse.button) { - changeBallState("CENTER") - } + changeBallState("CENTER") } } } @@ -146,10 +176,12 @@ MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton + enabled: { + isEnabled(this.parent) + } + onClicked: { - if(mouse.button) { - changeBallState("RIGHT") - } + changeBallState("RIGHT") } } } @@ -167,6 +199,10 @@ property alias bonus: bonus property int duration : 0 property int progressBarOpacity : 40 + property string saveBallState: "INITIAL" + property var progress: undefined + property double ballX: ball.parent.width/2 - ball.width/2; + property double ballY: ball.parent.height*0.77 - ball.height/2 } onStart: { Activity.start(items) } @@ -432,9 +468,11 @@ acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton onClicked: { ball.state = "INITIAL" + items.saveBallState = "INITIAL" progressRight.ratio = 0 progressLeft.ratio = 0 progressTop.ratio = 0 + items.progress = undefined } } } diff --git a/src/activities/penalty/penalty.js b/src/activities/penalty/penalty.js --- a/src/activities/penalty/penalty.js +++ b/src/activities/penalty/penalty.js @@ -31,6 +31,7 @@ function start(items_) { items = items_ currentLevel = 0 + initLevel() } @@ -54,9 +55,11 @@ function resetLevel() { items.ball.state = "INITIAL" + items.saveBallState = "INITIAL" items.progressRight.ratio = 0 items.progressLeft.ratio = 0 items.progressTop.ratio = 0 + items.progress = undefined } function nextLevel() {