diff --git a/src/activities/colors/FindIt.qml b/src/activities/colors/FindIt.qml index ed0fff1e7..22ef6dd55 100644 --- a/src/activities/colors/FindIt.qml +++ b/src/activities/colors/FindIt.qml @@ -1,221 +1,239 @@ /* GCompris - FindIt.qml * * Copyright (C) 2015 Bruno Coudoin * * Original activity in the Gtk+ version of GCompris by * Pascal Georges (pascal.georges1@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 import QtGraphicalEffects 1.0 import GCompris 1.0 import "../../core" import "findit.js" as Activity ActivityBase { id: activity focus: true property var dataset property string backgroundImg property int itemWidth property int itemHeight property string mode: "" onStart: { focus = true; } pageComponent: Image { id: background focus: true fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width source: backgroundImg property bool keyboardMode: false signal start signal stop Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } QtObject { id: items property alias background: background property alias bar: bar - property alias bonus: bonus + property alias bonusTimer: bonusTimer property alias containerModel: containerModel property alias questionItem: questionItem // On startup we want to queue the first sound but not after property bool firstQuestion: true property bool audioOk: false property alias score: score } onStart: Activity.start(items, dataset, mode) onStop: Activity.stop() Keys.onPressed: { if(event.key === Qt.Key_Space) { container.currentItem.select() } } Keys.onReleased: { keyboardMode = true event.accepted = false } Keys.onEnterPressed: container.currentItem.select(); Keys.onReturnPressed: container.currentItem.select(); Keys.onRightPressed: container.moveCurrentIndexRight(); Keys.onLeftPressed: container.moveCurrentIndexLeft(); Keys.onDownPressed: container.moveCurrentIndexDown(); Keys.onUpPressed: container.moveCurrentIndexUp(); ListModel { id: containerModel } GridView { id: container model: containerModel x: background.width * 0.2 y: background.height * 0.2 width: background.width * 0.7 height: background.height * 0.6 interactive: false cellWidth: itemHeight + 10 cellHeight: itemWidth + 10 keyNavigationWraps: true delegate: ColorItem { audioVoices: activity.audioVoices source: model.image audioSrc: model.audio ? model.audio : "" question: model.text sourceSize.height: itemHeight sourceSize.width: itemWidth } add: Transition { PathAnimation { path: Path { PathCurve { x: background.width / 3} PathCurve { y: background.height / 3} PathCurve {} } easing.type: Easing.InOutQuad duration: 2000 } } highlight: Rectangle { width: container.cellWidth - container.spacing height: container.cellHeight - container.spacing color: "#AAFFFFFF" border.width: 3 border.color: "black" visible: background.keyboardMode Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } } Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } } } GCText { id: questionItem anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: 10 fontSize: largeSize font.weight: Font.DemiBold style: Text.Outline styleColor: "black" color: "white" function initQuestion() { text = Activity.getCurrentTextQuestion() if(Activity.getCurrentAudioQuestion()) { if(items.firstQuestion) items.audioOk = activity.audioVoices.append(Activity.getCurrentAudioQuestion()) else items.audioOk = activity.audioVoices.play(Activity.getCurrentAudioQuestion()) items.firstQuestion = false } opacity = 1.0 } onOpacityChanged: opacity == 0 ? initQuestion() : "" Behavior on opacity { PropertyAnimation { duration: 500 } } } DropShadow { anchors.fill: questionItem cached: false horizontalOffset: 3 verticalOffset: 3 radius: 8.0 samples: 16 color: "#80000000" source: questionItem } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } BarButton { id: repeatItem source: "qrc:/gcompris/src/core/resource/bar_repeat.svg"; sourceSize.height: visible ? 80 * ApplicationInfo.ratio : 1 z: bar.z + 1 visible: items.audioOk anchors { bottom: parent.bottom right: parent.right margins: 10 * ApplicationInfo.ratio } onClicked: if (ApplicationSettings.isAudioVoicesEnabled) questionItem.initQuestion() } Score { id: score anchors.bottom: repeatItem.top anchors.right: repeatItem.right anchors.bottomMargin: 30 anchors.margins: 0 } + Timer { + id: bonusTimer + interval: 2000 + property bool win + + function good() { + win = true + start() + } + + function bad() { + win = false + start() + } + + onTriggered: win ? bonus.good("flower") : bonus.bad("flower") + } + Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/colors/findit.js b/src/activities/colors/findit.js index 1e0862111..845979c60 100644 --- a/src/activities/colors/findit.js +++ b/src/activities/colors/findit.js @@ -1,105 +1,105 @@ /* GCompris - findit.js * * Copyright (C) 2015 Bruno Coudoin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ .pragma library .import QtQuick 2.0 as Quick .import "qrc:/gcompris/src/core/core.js" as Core var url = "qrc:/gcompris/src/activities/colors/resource/" var currentLevel var numberOfLevel var items var dataset var currentQuestion function start(items_, dataset_, mode_) { if (mode_ == "Colors") Core.checkForVoices(items_.background); items = items_ dataset = dataset_.get() currentLevel = 0 numberOfLevel = dataset.length items.firstQuestion = true items.audioOk = false items.score.currentSubLevel = 1 initLevel() } function stop() { } function initLevel() { items.bar.level = currentLevel + 1 items.containerModel.clear() currentQuestion = 0 dataset[currentLevel] = Core.shuffle(dataset[currentLevel]) for(var i = 0; i < dataset[currentLevel].length; ++i) { items.containerModel.append(dataset[currentLevel][i]) } items.score.numberOfSubLevels = dataset[currentLevel].length // Shuffle again not to ask the question in the model order dataset[currentLevel] = Core.shuffle(dataset[currentLevel]) initQuestion() } function initQuestion() { // We just set the opacity to 0, the questionItem will then grab // the new question by itself // Need to set opacity to 0.1 before in order to be sure it's changed and trigger the questionItem onOpacityChanged items.questionItem.opacity = 0.1 items.questionItem.opacity = 0 } function nextQuestion() { if(dataset[currentLevel].length <= currentQuestion + 1) { - items.bonus.good("flower") + items.bonusTimer.good() } else { currentQuestion++ items.score.currentSubLevel++ initQuestion() } } function nextLevel() { items.score.currentSubLevel = 1 if(numberOfLevel <= ++currentLevel) { currentLevel = 0 } initLevel(); } function previousLevel() { items.score.currentSubLevel = 1 if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } function getCurrentTextQuestion() { return dataset[currentLevel][currentQuestion].text } function getCurrentAudioQuestion() { return dataset[currentLevel][currentQuestion].audio }