Warning, /education/gcompris/src/activities/penalty/Penalty.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - Penalty.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Stephane Mankowski <stephane@mankowski.fr>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Stephane Mankowski <stephane@mankowski.fr> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013 
0014 import "../../core"
0015 import "penalty.js" as Activity
0016 
0017 ActivityBase {
0018     id: activity
0019 
0020     onStart: focus = true
0021     onStop: {}
0022 
0023     pageComponent: Image {
0024         id: background
0025         source: Activity.url + "penalty_bg.svg"
0026         sourceSize.width: parent.width
0027         fillMode: Image.Stretch
0028         anchors.fill: parent
0029         signal start
0030         signal stop
0031 
0032         Component.onCompleted: {
0033             activity.start.connect(start)
0034             activity.stop.connect(stop)
0035         }
0036 
0037         // To enable tapping/clicking on left side of goal
0038         GoalZone {
0039             id: rectLeft
0040             state: "LEFT"
0041             progress: progressLeft
0042             anchors.right: player.left
0043             anchors.leftMargin: parent.width * 0.08
0044             anchors.bottomMargin: parent.height * 0.45
0045         }
0046 
0047         // To enable tapping/clicking on top of goal
0048         GoalZone {
0049             id: rectTop
0050             state: "CENTER"
0051             progress: progressTop
0052             anchors.left: player.left
0053             anchors.right: player.right
0054             anchors.bottom: player.top
0055         }
0056 
0057         // To enable tapping/clicking on right side of goal
0058         GoalZone {
0059             id: rectRight
0060             state: "RIGHT"
0061             progress: progressRight
0062             anchors.left: player.right
0063             anchors.rightMargin: parent.width * 0.06
0064             anchors.bottomMargin: parent.height * 0.45
0065         }
0066 
0067         // Add here the QML items you need to access in javascript
0068         QtObject {
0069             id: items
0070             property Item main: activity.main
0071             property alias background: background
0072             property int currentLevel: activity.currentLevel
0073             property alias ball: ball
0074             property alias progressLeft: progressLeft
0075             property alias progressRight: progressRight
0076             property alias progressTop: progressTop
0077             property alias bonus: bonus
0078             property int duration: 0
0079             property int progressBarOpacity: 40
0080             property string saveBallState: "INITIAL"
0081             property double ballX: ball.parent.width/2 - ball.width/2
0082             property double ballY: ball.parent.height*0.77 - ball.height/2
0083         }
0084 
0085         onStart: { Activity.start(items) }
0086         onStop: {
0087             timerBonus.stop()
0088             Activity.stop()
0089         }
0090 
0091         /* Instruction */
0092         Item {
0093             id: instruction
0094             z: 99
0095             anchors {
0096                 top: parent.top
0097                 topMargin: 10
0098                 horizontalCenter: parent.horizontalCenter
0099             }
0100             width: parent.width * 0.9
0101             property alias text: instructionTxt.text
0102             visible: bar.level === 1 && text != ""
0103 
0104             GCText {
0105                 id: instructionTxt
0106                 anchors {
0107                     horizontalCenter: parent.horizontalCenter
0108                 }
0109                 fontSize: mediumSize
0110                 color: "white"
0111                 style: Text.Outline
0112                 styleColor: "black"
0113                 horizontalAlignment: Text.AlignHCenter
0114                 width: parent.width
0115                 wrapMode: TextEdit.WordWrap
0116                 z: 2
0117             }
0118 
0119             Rectangle {
0120                 anchors.fill: instructionTxt
0121                 z: 1
0122                 opacity: 0.8
0123                 radius: 10
0124                 border.width: 2
0125                 border.color: "black"
0126                 gradient: Gradient {
0127                     GradientStop { position: 0.0; color: "#000" }
0128                     GradientStop { position: 0.9; color: "#666" }
0129                     GradientStop { position: 1.0; color: "#AAA" }
0130                 }
0131             }
0132         }
0133 
0134 
0135         /* The progress bars */
0136         Progress {
0137             id: progressLeft
0138             anchors.left: parent.left
0139             anchors.leftMargin: parent.width / parent.implicitWidth * 62
0140         }
0141 
0142         Progress {
0143             id: progressRight
0144             anchors.right: parent.right
0145             anchors.rightMargin: parent.width/parent.implicitWidth * 50
0146         }
0147 
0148         Progress {
0149             id: progressTop
0150             anchors.topMargin: parent.width / parent.implicitWidth * 40
0151             anchors.horizontalCenter: parent.horizontalCenter
0152             width: parent.height / parent.implicitHeight * 20
0153             height: ratio / 100 * parent.width / parent.implicitWidth * 100
0154         }
0155 
0156         /* The player */
0157         Image {
0158             id: player
0159             source: Activity.url + "penalty_player.svg"
0160             fillMode: Image.PreserveAspectFit
0161             anchors.centerIn: parent
0162             sourceSize.width: 154 * ApplicationInfo.ratio
0163         }
0164 
0165         /* The 2 click icon */
0166         Image {
0167             source: Activity.url + "click_icon.svg"
0168             sourceSize.width: 90 * ApplicationInfo.ratio
0169             anchors.bottom: bar.top
0170             anchors.right: parent.right
0171             anchors.bottomMargin: 10 * ApplicationInfo.ratio
0172             anchors.rightMargin: 10 * ApplicationInfo.ratio
0173         }
0174 
0175         /* The spot under the ball */
0176         Rectangle {
0177             radius: 100 * ApplicationInfo.ratio
0178             color: "white"
0179             width: 50 * ApplicationInfo.ratio
0180             height: 33 * ApplicationInfo.ratio
0181             x: parent.width / 2 - width / 2
0182             y: parent.height * 0.77 + width - height / 2
0183             border.width: 1
0184             border.color: "#b4b4b4"
0185         }
0186 
0187         /* The ball */
0188         Image {
0189             id: ball
0190             source: Activity.url + "penalty_ball.svg"
0191             fillMode: Image.PreserveAspectFit
0192             sourceSize.width: 100 * ApplicationInfo.ratio
0193 
0194             Behavior on x { PropertyAnimation {easing.type: Easing.OutQuad; duration:  1000} }
0195             Behavior on y { PropertyAnimation {easing.type: Easing.OutQuad; duration:  1000} }
0196             Behavior on sourceSize.width { PropertyAnimation {easing.type: Easing.OutQuad; duration: 1000} }
0197 
0198             state: "INITIAL"
0199             states: [
0200                 State {
0201                     name: "INITIAL"
0202                     PropertyChanges {
0203                         target: ball;
0204                         sourceSize.width: 100 * ApplicationInfo.ratio
0205                         x: parent.width/2 - width/2;
0206                         y: parent.height*0.77 - height/2
0207                     }
0208                     PropertyChanges {
0209                         target: instruction
0210                         text: qsTr("Double click or double tap on the side of the goal you want to put the ball in.")
0211                     }
0212                 },
0213                 State {
0214                     name: "RIGHT"
0215                     PropertyChanges {
0216                         target: ball
0217                         sourceSize.width: 75 * ApplicationInfo.ratio
0218                         x: background.width * 0.7
0219                         y: background.height * 0.3
0220                     }
0221                 },
0222                 State {
0223                     name: "LEFT"
0224                     PropertyChanges {
0225                         target: ball
0226                         sourceSize.width: 75 * ApplicationInfo.ratio
0227                         x: background.width * 0.2
0228                         y: background.height * 0.3
0229                     }
0230                 },
0231                 State {
0232                     name: "CENTER"
0233                     PropertyChanges {
0234                         target: ball;
0235                         sourceSize.width: 75 * ApplicationInfo.ratio
0236                         x: parent.width/2 - width/2;
0237                         y: background.height * 0.1
0238                     }
0239                 },
0240                 State {
0241                     name: "FAIL"
0242                     PropertyChanges {
0243                         target: ball
0244                         sourceSize.width: 75 * ApplicationInfo.ratio
0245                         x: parent.width/2 - width/2
0246                         y: player.y + player.height / 2
0247                     }
0248                     PropertyChanges {
0249                         target: instruction
0250                         text: qsTr("Click or tap on the ball to bring it back to its initial position.")
0251                     }
0252                 }
0253             ]
0254 
0255             MouseArea {
0256                 anchors.fill: parent
0257                 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButton
0258                 onClicked: {
0259                     Activity.resetLevel()
0260                 }
0261             }
0262         }
0263 
0264         Timer {
0265             id: timerBonus
0266             interval: 1500
0267             onTriggered: {
0268                 if (ball.state == "FAIL" || ball.state == "INITIAL") {
0269                     bonus.bad("smiley")
0270                     ball.state = "FAIL"
0271                 } else {
0272                     bonus.good("smiley")
0273                 }
0274             }
0275         }
0276 
0277         DialogHelp {
0278             id: dialogHelp
0279             onClose: home()
0280         }
0281 
0282         Bar {
0283             id: bar
0284             level: items.currentLevel + 1
0285             content: BarEnumContent { value: help | home | level }
0286             onHelpClicked: {
0287                 displayDialog(dialogHelp)
0288             }
0289             onPreviousLevelClicked: Activity.previousLevel()
0290             onNextLevelClicked: Activity.nextLevel()
0291             onHomeClicked: activity.home()
0292         }
0293 
0294         Bonus {
0295             id: bonus
0296             winSound: "qrc:/gcompris/src/activities/ballcatch/resource/tuxok.wav"
0297             looseSound: "qrc:/gcompris/src/activities/ballcatch/resource/youcannot.wav"
0298             Component.onCompleted: {
0299                 win.connect(Activity.nextLevel)
0300             }
0301         }
0302     }
0303 
0304 }