diff --git a/src/activities/letter-in-word/Card.qml b/src/activities/letter-in-word/Card.qml index ec5619fbb..21109d5cc 100644 --- a/src/activities/letter-in-word/Card.qml +++ b/src/activities/letter-in-word/Card.qml @@ -1,224 +1,224 @@ /* GCompris - Card.qml * * Copyright (C) 2016 Akshat Tandon * * Authors: * Akshat Tandon * * 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 GCompris 1.0 import QtGraphicalEffects 1.0 import "../../core" import "letter-in-word.js" as Activity Item { id: cardItem Image{ id: wordPic sourceSize.width: cardItem.width -6 sourceSize.height: cardItem.width -5 fillMode: Image.PreserveAspectFit source: imgurl z:-5 Image { id: cardImage anchors.top:parent.bottom anchors.topMargin: -30 * ApplicationInfo.ratio sourceSize.width: cardItem.width - 10 fillMode: Image.PreserveAspectFit source: Activity.url + "images/cloud.svg" z: (state == 'scaled') ? 1 : -1 /*ListView{ //anchors.horizontalCenter:parent.horizontalCenter //anchors.verticalCenter: parent.verticalCenter model:components delegate:GCText { //id: textbox z: 11 //anchors.horizontalCenter:cardImage.horizontalCenter //anchors.verticalCenter: cardImage.verticalCenter text: font.pointSize: NaN // need to clear font.pointSize explicitly font.pixelSize: spelling.length > 5 ? cardImage.width * 0.23 : cardImage.width * 0.30 font.bold: true style: Text.Outline styleColor: "#2a2a2a" color: "white" } }*/ Row{ anchors.verticalCenter: cardImage.verticalCenter Repeater{ //anchors.verticalCenter: cardImage.verticalCenter model: components GCText { id: textbox z: 11 //anchors.horizontalCenter:cardImage.horizontalCenter //anchors.verticalCenter: cardImage.verticalCenter text: textdata font.pointSize: NaN // need to clear font.pointSize explicitly font.pixelSize: spelling.length > 5 ? cardImage.width * 0.23 : cardImage.width * 0.30 font.bold: true style: Text.Outline styleColor: "#2a2a2a" color: selected && textdata.length == 1 && textdata == Activity.currentLetter ? "green" : "white" } } } /* DropShadow { anchors.fill: textbox cached: false horizontalOffset: 1 verticalOffset: 1 radius: 3 samples: 16 color: "#422a2a2a" source: textbox }*/ ParticleSystemStarLoader { id: particle clip: false } states: State { name: "scaled"; when: mouseArea.containsMouse PropertyChanges { target: cardItem scale: /*carriageImage.scale * */ 1.2 z: 2} } transitions: Transition { NumberAnimation { properties: "scale"; easing.type: Easing.OutCubic } } SequentialAnimation { id: successAnimation running: selected loops: Animation.Infinite NumberAnimation { target: cardImage easing.type: Easing.InOutQuad property: "rotation" to: 20; duration: 500 } NumberAnimation { target: cardImage easing.type: Easing.InOutQuad property: "rotation"; to: -20 duration: 500 } } SequentialAnimation { id: failureAnimation NumberAnimation { target: colorCardImage property: "opacity" to: 1; duration: 400 } NumberAnimation { target: colorCardImage property: "opacity" to: 0; duration: 200 } } NumberAnimation { id: rotationStop running: !selected target: cardImage property: "rotation" to: 0 duration: 500 easing.type: Easing.InOutQuad } MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: ApplicationInfo.isMobile ? false : true onClicked: { if (Activity.checkWord(index)) { successAnimation.restart(); particle.burst(30) components.clear(); var tempword; var j = 0; for(var i = 0; i < spelling.length; i++){ if(spelling.charAt(i) == Activity.currentLetter){ tempword = spelling.substring(j,i); if(i!=j){ - console.log(tempword) + //console.log(tempword) components.append({"textdata": tempword}) } components.append({"textdata": Activity.currentLetter}); - console.log(Activity.currentLetter) + //console.log(Activity.currentLetter) //console.log('qwe:') //console.log(tempword) j = i + 1; } } if(j < spelling.length){ tempword = spelling.substring(j, spelling.length); components.append({"textdata": tempword}) - console.log(tempword) + //console.log(tempword) //console.log(tempword) //console.log(componenetsArr.length) } - console.log('*/*/') - console.log(components.length) + //console.log('*/*/') + //console.log(components.length) } else { failureAnimation.restart() } } } } Colorize { id: colorCardImage z: 5 anchors.fill: cardImage source: cardImage hue: 0.0 saturation: 1 opacity: 0 } } } diff --git a/src/activities/letter-in-word/LetterInWord.qml b/src/activities/letter-in-word/LetterInWord.qml index 722e6bcb6..2bd2e16c7 100644 --- a/src/activities/letter-in-word/LetterInWord.qml +++ b/src/activities/letter-in-word/LetterInWord.qml @@ -1,289 +1,291 @@ /* GCompris - LetterInWord.qml * * Copyright (C) 2014 Holger Kaelberer * 2016 Akshat Tandon * * Authors: * Holger Kaelberer (Click on Letter - Qt Quick port) * Akshat Tandon (Modifications to Click on Letter code * to make Letter in which word activity) * * 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 "letter-in-word.js" as Activity import "qrc:/gcompris/src/core/core.js" as Core ActivityBase { id: activity focus: true onStart: focus = true pageComponent: Image { id: background source: Activity.url + "images/background.svg" sourceSize.width: parent.width fillMode: Image.PreserveAspectCrop focus: true // system locale by default property string locale: "system" signal start signal stop signal voiceError Component.onCompleted: { dialogActivityConfig.getInitialConfiguration() activity.start.connect(start) activity.stop.connect(stop) } QtObject { id: items property Item main: activity.main property alias bar: bar property alias wordsModel: wordsModel property GCAudio audioVoices: activity.audioVoices property alias parser: parser property alias animateX: animateX property alias repeatItem: repeatItem property alias score: score property alias bonus: bonus property alias locale: background.locale property string question } onVoiceError: { repeatItem.visible = false } onStart: { activity.audioVoices.error.connect(voiceError) Activity.start(items); } onStop: Activity.stop() DialogActivityConfig { id: dialogActivityConfig currentActivity: activity content: Component { Item { property alias localeBox: localeBox height: column.height property alias availableLangs: langs.languages LanguageList { id: langs } Column { id: column spacing: 10 width: parent.width Flow { spacing: 5 width: dialogActivityConfig.width GCComboBox { id: localeBox model: langs.languages background: dialogActivityConfig label: qsTr("Select your locale") } } } } } onClose: home() onLoadData: { if(dataToSave && dataToSave["locale"]) { background.locale = dataToSave["locale"]; } } onSaveData: { var oldLocale = background.locale; var newLocale = dialogActivityConfig.configItem.availableLangs[dialogActivityConfig.loader.item.localeBox.currentIndex].locale; // Remove .UTF-8 if(newLocale.indexOf('.') != -1) { newLocale = newLocale.substring(0, newLocale.indexOf('.')) } dataToSave = {"locale": newLocale } background.locale = newLocale; // Restart the activity with new information if(oldLocale !== newLocale) { background.stop(); background.start(); } } function setDefaultValues() { var localeUtf8 = background.locale; if(background.locale != "system") { localeUtf8 += ".UTF-8"; } for(var i = 0 ; i < dialogActivityConfig.configItem.availableLangs.length ; i ++) { if(dialogActivityConfig.configItem.availableLangs[i].locale === localeUtf8) { dialogActivityConfig.loader.item.localeBox.currentIndex = i; break; } } } } DialogHelp { id: dialogHelpLeftRight onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level | config } onHelpClicked: { displayDialog(dialogHelpLeftRight) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: home() onConfigClicked: { dialogActivityConfig.active = true dialogActivityConfig.setDefaultValues() displayDialog(dialogActivityConfig) } } Score { id: score anchors.top: parent.top anchors.topMargin: 10 * ApplicationInfo.ratio anchors.left: parent.left anchors.leftMargin: 10 * ApplicationInfo.ratio anchors.bottom: undefined anchors.right: undefined } Bonus { id: bonus interval: 1000 Component.onCompleted: { win.connect(Activity.nextSubLevel); loose.connect(Activity.incorrectSelection); } } BarButton { id: repeatItem source: "qrc:/gcompris/src/core/resource/bar_repeat.svg"; sourceSize.width: 80 * ApplicationInfo.ratio anchors { top: parent.top right: parent.right margins: 10 } onClicked:{ Activity.playLetter(Activity.currentLetter); animateX.restart(); } } Item { id: planeText width: plane.width height: plane.height x: - width anchors.top: parent.top anchors.topMargin: 5 * ApplicationInfo.ratio Image { id: plane anchors.centerIn: planeText anchors.top: parent.top source: Activity.url + "images/plane.svg" sourceSize.height: 90 * ApplicationInfo.ratio } GCText { id: questionItem anchors.right: planeText.right anchors.rightMargin: 2 * plane.width / 3 anchors.verticalCenter: planeText.verticalCenter anchors.bottomMargin: 10 * ApplicationInfo.ratio fontSize: hugeSize font.weight: Font.DemiBold color: "#2a2a2a" text: items.question } PropertyAnimation { id: animateX target: planeText properties: "x" from: - planeText.width - to: background.width - duration: 11000 - easing.type: Easing.OutInCirc + //to:background.width/2 - planeText.width/2 + to: bar.level <= 2 ? background.width/4 : background.width + duration: bar.level <= 2 ? 5500: 11000 + //easing.type: Easing.OutQuad + easing.type: bar.level <= 2 ? Easing.OutQuad: Easing.OutInCirc } } ListModel { id: wordsModel } property int itemWidth: Math.min(parent.width / 7.5, parent.height / 5) property int itemHeight: itemWidth * 1.11 GridView { id: wordsView anchors.bottom: bar.top anchors.left: parent.left anchors.right: parent.right anchors.top: planeText.bottom anchors.topMargin: 10 * ApplicationInfo.ratio anchors.leftMargin: 5 * ApplicationInfo.ratio anchors.rightMargin: 5 * ApplicationInfo.ratio anchors.bottomMargin: 5 * ApplicationInfo.ratio cellWidth: itemWidth cellHeight: itemHeight clip: false interactive: false //verticalLayoutDirection: GridView.BottomToTop layoutDirection: Qt.LeftToRight model: wordsModel delegate: Card{ width: background.itemWidth } } JsonParser { id: parser onError: console.error("Click_on_letter: Error parsing JSON: " + msg); } } } diff --git a/src/activities/letter-in-word/letter-in-word.js b/src/activities/letter-in-word/letter-in-word.js index 1305779cd..d5b561034 100644 --- a/src/activities/letter-in-word/letter-in-word.js +++ b/src/activities/letter-in-word/letter-in-word.js @@ -1,336 +1,338 @@ /* GCompris - letter-in-word.js * * Copyright (C) 2014 Holger Kaelberer * 2016 Akshat Tandon * * Authors: * Holger Kaelberer (Qt Quick port of click-on-letter) * Akshat Tandon * * 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 GCompris 1.0 as GCompris //for ApplicationInfo .import "qrc:/gcompris/src/core/core.js" as Core .import "qrc:/gcompris/src/activities/lang/lang_api.js" as Lang var url = "qrc:/gcompris/src/activities/letter-in-word/resource/" var defaultLevelsFile = ":/gcompris/src/activities/letter-in-word/resource/levels/levels-en.json"; var maxLettersPerLine = 6; var levels; var currentLevel; var maxLevel; var currentSubLevel; var currentLetter; var maxSubLevel; var level; var questions; var words; var items; var dataset = null; var frequency; var incorrectFlag = false; function start(_items) { Core.checkForVoices(_items.main); items = _items; // register the voices for the locale var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale) GCompris.DownloadManager.updateResource(GCompris.DownloadManager.getVoicesResourceForLocale(locale)) loadDataset(); //console.log('Dataset:') //console.log(dataset); levels = Lang.getAllLessons(dataset) currentLevel = 0; currentSubLevel = 0; maxLevel = levels.length; //console.log('Max num of levels') //console.log(maxLevel); initLevel(); } function loadDataset() { var resourceUrl = "qrc:/gcompris/src/activities/lang/resource/" var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale) dataset = Lang.load(items.parser, resourceUrl, GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json", "content-"+ locale +".json") //console.log('** Came here') // If dataset is empty, we try to load from short locale // and if not present again, we switch to default one var localeUnderscoreIndex = locale.indexOf('_') if(!dataset) { var localeShort; // We will first look again for locale xx (without _XX if exist) if(localeUnderscoreIndex > 0) { localeShort = locale.substring(0, localeUnderscoreIndex) } else { localeShort = locale; } dataset = Lang.load(items.parser, resourceUrl, GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json", "content-"+localeShort+ ".json") } //console.log('** Came here 2') if(!dataset) { // English fallback dataset = Lang.load(items.parser, resourceUrl, GCompris.ApplicationSettings.wordset ? "words.json" : "words_sample.json", "content-en.json") } //console.log('** Came here 3') } function stop() { items.animateX.stop() } function shuffleString(s) { var a = s; var n = a.length; for(var i = n-1; i>0; i--) { var j = Math.floor(Math.random() * (i + 1)); var tmp = a[i]; a[i] = a[j]; a[j] = tmp; } return a.join(""); } function initLevel() { + //console.log("**********Current level: " + currentLevel) var componentsArr; items.bar.level = currentLevel + 1; if (currentSubLevel == 0 && !incorrectFlag) { level = levels[currentLevel]; words = Lang.getLessonWords(dataset, level); Core.shuffle(words); var limit = Math.min(13, words.length) words = words.slice(0,limit) frequency = calculateFrequency(); var tempQuestions = generateQuestions(); maxSubLevel = tempQuestions.length; items.score.numberOfSubLevels = maxSubLevel; items.score.currentSubLevel = 1; questions = shuffleString(tempQuestions); items.wordsModel.clear(); for (var i = 0; i < words.length; i++) { componentsArr = []; componentsArr.push({"textdata": words[i].translatedTxt}); //console.log(componentsArr.length) items.wordsModel.append({ "spelling": words[i].translatedTxt, "imgurl": words[i].image, "selected": false, "components": componentsArr }); } } else { items.score.currentSubLevel = currentSubLevel + 1; } incorrectFlag = false; for(var i = 0; i < words.length; i++){ items.wordsModel.setProperty(i, "selected", false); } var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale); currentLetter = questions[currentSubLevel]; items.question = currentLetter - if(currentLevel <= 2){ - items.animateX.restart(); - } + items.animateX.restart(); + //if(currentLevel <= 2){ + + //} if (GCompris.ApplicationSettings.isAudioVoicesEnabled && GCompris.DownloadManager.haveLocalResource( GCompris.DownloadManager.getVoicesResourceForLocale(locale))) { items.audioVoices.silence(100) playLetter(currentLetter) items.repeatItem.visible = true } else { // no sound -> show question items.repeatItem.visible = false } } function calculateFrequency(){ var freq = []; for(var i = 0; i < words.length; i++){ var currentWord = words[i].translatedTxt; for(var j = 0; j < currentWord.length; j++){ var character = currentWord.charAt(j); if(freq[character]){ freq[character]++; } else{ freq[character] = 1; } } } /* for(var i in freq){ console.log(i) console.log(freq[i]) }*/ return freq; } function generateQuestions(){ var freqArr = []; var ques = []; for(var character in frequency){ //console.log('calc freq') //console.log(character) //console.log(frequency[character]) freqArr.push([character, frequency[character]]); } freqArr.sort(function(a, b) {return b[1] - a[1]}); /* for(var i = 0; i < freqArr.length; i++){ console.log('freq arr') console.log(freqArr[i][0]) console.log(freqArr[i][1]) }*/ var limit = Math.min(10, freqArr.length); //console.log(freqArr.length) //console.log(limit) for(var i = 0; i < limit; i++){ ques.push(freqArr[i][0]) } /*for(var i = 0; i < ques.length; i++){ console.log('bablu') console.log(ques[i]) }*/ return ques; } function playLetter(letter) { var locale = GCompris.ApplicationInfo.getVoicesLocale(items.locale) items.audioVoices.append(GCompris.ApplicationInfo.getAudioFilePath("voices-$CA/"+locale+"/alphabet/" + Core.getSoundFilenamForChar(letter))) } function nextLevel() { items.audioVoices.clearQueue() if(maxLevel <= ++currentLevel ) { currentLevel = 0 } currentSubLevel = 0; initLevel(); } function previousLevel() { items.audioVoices.clearQueue() if(--currentLevel < 0) { currentLevel = maxLevel - 1 } currentSubLevel = 0; initLevel(); } function nextSubLevel() { if( ++currentSubLevel >= maxSubLevel) { currentSubLevel = 0 nextLevel() } initLevel(); } function checkAnswer() { var checkFlag = false; var modelEntry; for(var i = 0; i < words.length; i++){ modelEntry = items.wordsModel.get(i); for(var j = 0; j < modelEntry.spelling.length; j++){ if(currentLetter == modelEntry.spelling.charAt(j) && modelEntry.selected == false){ checkFlag = true; break; } } } if(checkFlag == false){ items.bonus.good("flower"); } } function checkWord(index) { var checkFlag = false; var modelEntry = items.wordsModel.get(index); for(var i = 0; i < modelEntry.spelling.length; i++){ if(currentLetter == modelEntry.spelling.charAt(i)){ items.wordsModel.setProperty(index, "selected", true); checkAnswer(); checkFlag = true; break; } } if(checkFlag == true){ //items.wordsModel.setProperty(index, "components", componenetsArr) //items.wordsModel.setProperty(index, "imgurl","qrc:/gcompris/src/activities/lang/resource/words_sample/one.png") /*for(var i = 0; i < componenetsArr.length; i++){ console.log(componenetsArr[i].textdata) }*/ return true; } else{ items.bonus.bad("flower"); return false; } } function incorrectSelection(){ //console.log('Entered /*******************************'); //console.log(typeof(questions)) //console.log('Before') //console.log(questions) incorrectFlag = true; var quesLen = questions.length; questions = questions.slice(0,currentSubLevel) + questions.slice(currentSubLevel+1,quesLen) + questions.charAt(currentSubLevel); //console.log('After') //console.log(questions); currentSubLevel--; nextSubLevel(); //console.log('Exited /*******************************'); }