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

0001 /* GCompris - FollowLine.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
0008  *   Timothée Giet <animtim@gmail.com> (Gameplay refactoring and improvements)
0009  *
0010  *   SPDX-License-Identifier: GPL-3.0-or-later
0011  */
0012 import QtQuick 2.12
0013 import GCompris 1.0
0014 
0015 import "../../core"
0016 import "followline.js" as Activity
0017 
0018 ActivityBase {
0019     id: activity
0020 
0021     onStart: focus = true
0022     onStop: {}
0023 
0024     pageComponent: Image {
0025         id: background
0026         source: Activity.url + "background.svg"
0027         fillMode: Image.PreserveAspectCrop
0028         sourceSize.width: width
0029         sourceSize.height: height
0030 
0031         signal start
0032         signal stop
0033 
0034         Component.onCompleted: {
0035             activity.start.connect(start)
0036             activity.stop.connect(stop)
0037         }
0038 
0039         // Add here the QML items you need to access in javascript
0040         QtObject {
0041             id: items
0042             property alias background: background
0043             property GCSfx audioEffects: activity.audioEffects
0044             property alias fireman: fireman
0045             property alias lineArea: lineArea
0046             property alias fire: fire
0047             property alias lineBrokenTimer: lineBrokenTimer
0048             property int currentLevel: activity.currentLevel
0049             property alias bonus: bonus
0050             property int currentLock: 0
0051             property int lastLock: 0
0052             property bool verticalLayout: lineArea.height > lineArea.width
0053         }
0054 
0055         onHeightChanged: Activity.initLevel()
0056         onWidthChanged: Activity.initLevel()
0057 
0058         onStart: { Activity.start(items) }
0059         onStop: { Activity.stop() }
0060 
0061         Image {
0062             id: fireman
0063             source: Activity.url + "fireman.svg"
0064             sourceSize.width: 182 * ApplicationInfo.ratio
0065             anchors {
0066                 left: parent.left
0067                 verticalCenter: parent.verticalCenter
0068                 verticalCenterOffset: - height / 10
0069             }
0070         }
0071 
0072         Image {
0073             id: fire
0074             source: Activity.url + "fire.svg"
0075             sourceSize.width: 90 * ApplicationInfo.ratio
0076             anchors {
0077                 right: parent.right
0078                 bottom: bar.top
0079             }
0080 
0081             Image {
0082                 id: fireflame
0083                 source: Activity.url + "fire_flame.svg"
0084                 sourceSize.width: 90 * ApplicationInfo.ratio
0085                 anchors {
0086                     fill: parent
0087                 }
0088                 Behavior on opacity { NumberAnimation { duration: 2000 } }
0089                 onOpacityChanged: if(opacity == 0) Activity.nextLevel()
0090             }
0091         }
0092 
0093         Image {
0094             id: water
0095             source: Activity.url + "water_spot.svg"
0096             sourceSize.width: 148 * ApplicationInfo.ratio
0097             z: 200
0098             opacity: 0
0099             anchors {
0100                 right: parent.right
0101                 bottom: fire.top
0102                 bottomMargin: - fire.height / 2
0103             }
0104             Behavior on opacity { NumberAnimation { duration: 500 } }
0105         }
0106 
0107         DialogHelp {
0108             id: dialogHelp
0109             onClose: home()
0110         }
0111 
0112         function win() {
0113             fireflame.opacity = 0
0114             water.opacity = 1
0115         }
0116 
0117         Bar {
0118             id: bar
0119             level: items.currentLevel + 1
0120             content: BarEnumContent { value: help | home | level }
0121             onHelpClicked: displayDialog(dialogHelp)
0122             onPreviousLevelClicked: Activity.previousLevel()
0123             onNextLevelClicked: Activity.nextLevel()
0124             onHomeClicked: activity.home()
0125             onLevelChanged: {
0126                 fireflame.opacity = 1
0127                 water.opacity = 0
0128             }
0129         }
0130 
0131         Bonus {
0132             id: bonus
0133             Component.onCompleted: win.connect(Activity.nextLevel)
0134         }
0135 
0136         MouseArea {
0137             anchors.fill: parent
0138             enabled: !ApplicationInfo.isMobile
0139             hoverEnabled: true
0140             onPositionChanged: items.currentLock > 0 && water.opacity === 0 ?
0141                                    lineBrokenTimer.start() : false
0142         }
0143 
0144         Item {
0145             id: lineArea
0146             anchors.top: fireman.top
0147             anchors.left: fireman.right
0148             anchors.bottom: fire.top
0149             anchors.right: fire.left
0150 
0151             MultiPointTouchArea {
0152                 anchors.fill: parent
0153                 maximumTouchPoints: 1
0154                 enabled: ApplicationInfo.isMobile && water.opacity === 0
0155                 z: 1000
0156                 onTouchUpdated: {
0157                     for(var i in touchPoints) {
0158                         var touch = touchPoints[i]
0159                         var part = lineArea.childAt(touch.x, touch.y)
0160                         if(part && part.isPart) {
0161                             if(items.currentLock <= part.index && !Activity.movedOut) {
0162                                 items.currentLock = part.index
0163                                 if(items.currentLock >= items.lastLock) {
0164                                     background.win()
0165                                     activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/water.wav")
0166                                 } else {
0167                                     Activity.playAudioFx()
0168                                 }
0169                             } else if(items.currentLock >= part.index && Activity.movedOut) {
0170                                 lineBrokenTimer.stop();
0171                                 Activity.movedOut = false;
0172                             }
0173                         } else {
0174                             lineBrokenTimer.start()
0175                         }
0176                     }
0177                 }
0178                 onReleased: if(water.opacity === 0) lineBrokenTimer.start()
0179             }
0180         }
0181 
0182         Timer {
0183             id: lineBrokenTimer
0184             interval: 20
0185             onTriggered: {
0186                 if(items.currentLock > 0 && water.opacity === 0) {
0187                     Activity.cursorMovedOut();
0188                     restart();
0189                 }
0190             }
0191         }
0192     }
0193 
0194 }