diff --git a/src/activities/activities.txt b/src/activities/activities.txt index 25ffbeab8..a2e4412cc 100644 --- a/src/activities/activities.txt +++ b/src/activities/activities.txt @@ -1,126 +1,127 @@ # The list of activities that will be loaded at GCompris start. # Keep it sorted advanced_colors algebra_by algebra_div algebra_minus algebra_plus algorithm align4 align4-2players +alphabetical_order alphabet-sequence babymatch babyshapes baby_wordprocessor balancebox ballcatch braille_alphabets braille_fun canal_lock chess chess_2players chess_partyend chronos clickanddraw clickgame click_on_letter click_on_letter_up clockgame color_mix color_mix_light colors details drawnumber enumerate erase erase_2clic erase_clic explore_farm_animals explore_monuments explore_world_animals explore_world_music fifteen followline football geo-country geography gletters gnumch-equality gnumch-factors gnumch-inequality gnumch-multiples gnumch-primes graph-coloring guessnumber hangman hanoi hanoi_real hexagon imagename instruments intro_gravity land_safe lang leftright lightsoff louis-braille magic-hat-minus magic-hat-plus maze mazeinvisible mazerelative melody memory memory-enumerate memory-math-add memory-math-add-minus memory-math-add-minus-mult-div memory-math-add-minus-mult-div-tux memory-math-add-minus-tux memory-math-add-tux memory-math-div memory-math-div-tux memory-math-minus memory-math-minus-tux memory-math-mult memory-math-mult-div memory-math-mult-div-tux memory-math-mult-tux memory-sound memory-sound-tux memory-tux memory-wordnumber mining missing-letter money money_back money_back_cents money_cents mosaic numbers-odd-even paintings penalty photo_hunter planegame readingh readingv redraw redraw_symmetrical renewable_energy reversecount roman_numerals scalesboard scalesboard_weight scalesboard_weight_avoirdupois simplepaint smallnumbers smallnumbers2 sudoku superbrain tangram target tic_tac_toe tic_tac_toe_2players traffic watercycle wordsgame diff --git a/src/activities/alphabetical_order/ActivityInfo.qml b/src/activities/alphabetical_order/ActivityInfo.qml new file mode 100644 index 000000000..c830f0db6 --- /dev/null +++ b/src/activities/alphabetical_order/ActivityInfo.qml @@ -0,0 +1,35 @@ +/* GCompris - ActivityInfo.qml + * + * Copyright (C) 2016 Stefan Toncu + * + * 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 GCompris 1.0 + +ActivityInfo { + name: "alphabetical_order/AlphabeticalOrder.qml" + difficulty: 2 + icon: "alphabetical_order/alphabetical_order.svg" + author: "Stefan Toncu <stefan.toncu29@gmail.com>" + demo: true + title: qsTr("Alphabetical order") + description: qsTr("Reorder the letters by their alphabetical position") + //intro: "put here in comment the text for the intro voice" + goal: "" + prerequisite: "" + manual: qsTr("Drag the missing letters to their right place.") + credit: "" + section: "reading" + createdInVersion: 7000 +} diff --git a/src/activities/alphabetical_order/AlphabeticalOrder.qml b/src/activities/alphabetical_order/AlphabeticalOrder.qml new file mode 100644 index 000000000..b8d4a58bd --- /dev/null +++ b/src/activities/alphabetical_order/AlphabeticalOrder.qml @@ -0,0 +1,342 @@ +/* GCompris - alphabetical_order.qml + * + * Copyright (C) 2016 Stefan Toncu + * + * 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 "../../core" +import "alphabetical_order.js" as Activity + + + +ActivityBase { + id: activity + + onStart: focus = true + onStop: {} + + pageComponent: Rectangle { + id: background + anchors.fill: parent + color: "#ABCDEF" + + signal start + signal stop + + + // system locale by default + property string locale: "system" + + Component.onCompleted: { + activity.start.connect(start) + activity.stop.connect(stop) + } + + // Add here the QML items you need to access in javascript + QtObject { + id: items + property Item main: activity.main + property alias background: background + property alias bar: bar + property alias bonus: bonus + property var missingLetters + property alias listModel: listModel + property alias listModel2: listModel2 + property alias repeater: repeater + property alias solutionRepeater: solutionRepeater + property alias locale: background.locale + } + + onStart: { Activity.start(items) } + onStop: { Activity.stop() } + + onFocusChanged: { + if(focus) { + Activity.focusTextInput() + } + } + + ListModel { + id: listModel + } + + ListModel { + id: listModel2 + } + + + Rectangle { + id: board + width: parent.width * 0.7 + height: parent.height * 0.7 + anchors.centerIn: parent + color: "lightblue" + + Flow { + id: guessArea + width: parent.width + height: parent.height / 2.1 + + Repeater { + id: repeater + + model: listModel + + GCText { + id: letter + text: listModel.get(index) ? listModel.get(index).letter : "" + fontSize: hugeSize + + property var _x + property var _y + + + MouseArea { + anchors.fill: parent + drag.target: parent + onPressed: { + letter._x = letter.x + letter._y = letter.y + } + onReleased: { +// var alph = ['c','b','a'] +// print("alph b: ",alph) +// ApplicationInfo.localeSort(alph) +// print("alph a: ",alph) + + /* use mouse's coordinates (x and y) to compare to the "guessArea"'s repeater items */ + var modified = mapToItem(background,mouse.x,mouse.y) + + //search through the "repeater"'s items to find if THIS item can replace it + for (var i=0; i guess.x && modified.x < guess.x + item.width && + modified.y > guess.y - item.height && modified.y < guess.y + item.height * 2) { + var textAux = items.listModel.get(i).letter + items.listModel.setProperty(i,"letter",letter.text) + items.listModel.setProperty(index,"letter",textAux) + break + } + } + + //search through the "solutionRepeater"'s items to find if THIS item can replace it + for (i=0; i guess1.x && modified.x < guess1.x + item1.width && + modified.y > guess1.y - item1.height && modified.y < guess1.y + item1.height * 2) { + var textAux1 = items.listModel2.get(i).letter + items.listModel2.setProperty(i,"letter",letter.text) + items.listModel.setProperty(index,"letter",textAux1) + break + } + } + + letter.x = letter._x + letter.y = letter._y + + if (Activity.checkCorectness()) { + bonus.good("tux") + } + + } + } + } + } + } + + Flow { + id: solutionArea + + width: parent.width + height: parent.height / 2.1 + + anchors.top: guessArea.bottom + + Repeater { + id: solutionRepeater + model: listModel2 +// model: items.missingLetters + + GCText { + id: missingLetter +// text: items.missingLetters[index] + text: listModel2.get(index) ? listModel2.get(index).letter : "" + fontSize: hugeSize + + property var _x + property var _y + + + MouseArea { + anchors.fill: parent + drag.target: parent + onPressed: { + missingLetter._x = missingLetter.x + missingLetter._y = missingLetter.y + } + + onReleased: { + /* use mouse's coordinates (x and y) to compare to the "guessArea"'s repeater items */ + var modified = mapToItem(background,mouse.x,mouse.y) + + //search through the "repeater"'s items to find if THIS item should replace it + for (var i=0; i guess.x && modified.x < guess.x + item.width && + modified.y > guess.y && modified.y < guess.y + item.height) { +// print("belongs to: ",i) + var textAux = items.listModel.get(i).letter + + if (textAux == '_') { + items.listModel.setProperty(i,"letter",missingLetter.text) + items.listModel2.setProperty(index,"letter",'') + } else { + + items.listModel.setProperty(i,"letter",missingLetter.text) + items.listModel2.setProperty(index,"letter",textAux) + } + break + } + } + + missingLetter.x = missingLetter._x + missingLetter.y = missingLetter._y + + if (Activity.checkCorectness()) { + bonus.good("tux") + } + } + } + } + } + } + } + + + 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") + } + } +/* TODO handle this: + GCDialogCheckBox { + id: uppercaseBox + width: 250 * ApplicationInfo.ratio + text: qsTr("Uppercase only mode") + checked: true + onCheckedChanged: { + print("uppercase changed") + } + } +*/ + } + } + } + + 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: dialogHelp + onClose: home() + } + + Bar { + id: bar + content: BarEnumContent { value: help | home | level | config } + onHelpClicked: { + displayDialog(dialogHelp) + } + onPreviousLevelClicked: Activity.previousLevel() + onNextLevelClicked: Activity.nextLevel() + onHomeClicked: activity.home() + onConfigClicked: { + dialogActivityConfig.active = true + dialogActivityConfig.setDefaultValues() + displayDialog(dialogActivityConfig) + } + } + + Bonus { + id: bonus + Component.onCompleted: win.connect(Activity.nextLevel) + } + } + +} diff --git a/src/activities/alphabetical_order/CMakeLists.txt b/src/activities/alphabetical_order/CMakeLists.txt new file mode 100644 index 000000000..58a1a46cb --- /dev/null +++ b/src/activities/alphabetical_order/CMakeLists.txt @@ -0,0 +1 @@ +GCOMPRIS_ADD_RCC(activities/alphabetical_order *.qml *.svg *.js resource/*) diff --git a/src/activities/alphabetical_order/alphabetical_order.js b/src/activities/alphabetical_order/alphabetical_order.js new file mode 100644 index 000000000..2f7c38849 --- /dev/null +++ b/src/activities/alphabetical_order/alphabetical_order.js @@ -0,0 +1,177 @@ +/* GCompris - alphabetical_order.js + * + * Copyright (C) 2016 Stefan Toncu + * + * 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 currentLevel = 0 +var numberOfLevel = 4 +var items +var alphabet = ['a','b','c','d','e','f','g','h','i', + 'j','k','l','m','n','o','p','q','r', + 's','t','u','v','w','x','y','z'] +var solution + +function start(items_) { + items = items_ + currentLevel = 0 + initLevel() +} + +function stop() { +} + +function initLevel() { + items.bar.level = currentLevel + 1 + init() +} + +function init() { + + + print("localeee: ", items.locale) + // ['a','b','c','d'] + solution = getSolution(alphabet, 5) + + // 3 1 5 2 4 + var numbers = getNumbers(5) + + // ['a','_','c','_'] + var model = solution.slice() + // ['b', 'd'] + var modelAux = [] + for (var i = 0; i < 2; i++) { + model[numbers[i]] = '_' + modelAux[i] = solution[numbers[i]] + } + + //debugging +// print(solution) +// print("numbers: ", numbers) +// print("solution: ",solution) +// print("model: ",model) +// print("modelAux: ",modelAux) + + items.listModel.clear() + items.listModel2.clear() + + for (i = 0; i < modelAux.length; i++) { + items.listModel2.append({"letter": modelAux[i]}) + } + + for (i = 0; i < model.length; i++) { + items.listModel.append({"letter": model[i]}) + } +} + +function sortNumber(a,b) { + return a - b; +} + +function getNumbers(len) { + var numbers = [] + for (var i = 0; i < len; i++) { + numbers[i] = i + } + numbers = Core.shuffle(numbers) + + return numbers +} + +function getSolution(alphabet, noOfLetters) { + var solution = [] + var aux = getNumbers(alphabet.length) + //"noOfLetters" numbers sorted of "alphabet.length" numbers shuffeled +// print("generate", aux) + + var generate = [] + for (var i = 0; i < noOfLetters; i++) { + generate[i] = aux[i] + } + generate.sort(sortNumber) + + + for (i = 0; i < noOfLetters; i++) { + solution[i] = alphabet[generate[i]] + } + + return solution +} + +function getModel(alphabet, noOfLetters) { + var model + + for (var i = 0; i < noOfLetters; i++) { + + } + return model +} + +/* Receives the model (what the player has to complete) +and the solution (how the result should look like) +and returns the missing letters from the model +(the letters from bottom, which the user will place on top) */ +function missingLetters(model,solution) { + var missingLetters = [] + for (var i=0; i false + if (nr !== items.listModel.count) + return false + + for (var i = 0; i < nr; i++) + if (solution[i]!==items.listModel.get(i).letter) + return false // the letters are different at index i -> false + + return true +} + +function nextLevel() { + if(numberOfLevel <= ++currentLevel ) { + currentLevel = 0 + } + initLevel(); +} + +function previousLevel() { + if(--currentLevel < 0) { + currentLevel = numberOfLevel - 1 + } + initLevel(); +} + +function focusTextInput() { + if (!GCompris.ApplicationInfo.isMobile && items && items.textinput) + items.textinput.forceActiveFocus(); +} diff --git a/src/activities/alphabetical_order/alphabetical_order.svg b/src/activities/alphabetical_order/alphabetical_order.svg new file mode 100644 index 000000000..a7df1975a --- /dev/null +++ b/src/activities/alphabetical_order/alphabetical_order.svg @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + 2010-04-21T04:22:19 + A blackboard with stand, chalk, eraser and a few letters written, all in slight perspective. Drawn in Inkscape. + https://openclipart.org/detail/49381/blackboard-with-stand-and-letters-by-j_alves + + + J_Alves + + + + + blackboard + chalk + chalkboard + education + letters + school + stand + + + + + + + + + + + diff --git a/src/activities/alphabetical_order/resource/alphabeticalOrder1.svg b/src/activities/alphabetical_order/resource/alphabeticalOrder1.svg new file mode 100644 index 000000000..3ee8053ed --- /dev/null +++ b/src/activities/alphabetical_order/resource/alphabeticalOrder1.svg @@ -0,0 +1,418 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + 2010-04-21T04:22:19 + A blackboard with stand, chalk, eraser and a few letters written, all in slight perspective. Drawn in Inkscape. + https://openclipart.org/detail/49381/blackboard-with-stand-and-letters-by-j_alves + + + J_Alves + + + + + blackboard + chalk + chalkboard + education + letters + school + stand + + + + + + + + + + + diff --git a/src/activities/alphabetical_order/resource/blackboard-w-letters.svg b/src/activities/alphabetical_order/resource/blackboard-w-letters.svg new file mode 100644 index 000000000..8009dd0b5 --- /dev/null +++ b/src/activities/alphabetical_order/resource/blackboard-w-letters.svg @@ -0,0 +1,329 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + Blackboard with Letters + 2010-04-21T03:53:49 + A blackboard, with eraser, chalk and some drawn letters. Drawn in Inkscape. + https://openclipart.org/detail/49369/blackboard-with-letters-by-j_alves + + + J_Alves + + + + + blackboard + chalk + chalkboard + education + school + + + + + + + + + + + diff --git a/src/activities/alphabetical_order/resource/blackboard-with-standletters.svg b/src/activities/alphabetical_order/resource/blackboard-with-standletters.svg new file mode 100644 index 000000000..1872d7756 --- /dev/null +++ b/src/activities/alphabetical_order/resource/blackboard-with-standletters.svg @@ -0,0 +1,364 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + Blackboard with Stand and Letters + 2010-04-21T04:22:19 + A blackboard with stand, chalk, eraser and a few letters written, all in slight perspective. Drawn in Inkscape. + https://openclipart.org/detail/49381/blackboard-with-stand-and-letters-by-j_alves + + + J_Alves + + + + + blackboard + chalk + chalkboard + education + letters + school + stand + + + + + + + + + + + diff --git a/src/activities/alphabetical_order/resource/readme b/src/activities/alphabetical_order/resource/readme new file mode 100644 index 000000000..2135a784f --- /dev/null +++ b/src/activities/alphabetical_order/resource/readme @@ -0,0 +1,8 @@ +blackboard: https://openclipart.org/detail/49381/blackboard-with-stand-and-letters +blackboard_front: https://openclipart.org/detail/49369/blackboard-with-letters + +A: https://openclipart.org/detail/193272/a +B: https://openclipart.org/detail/193303/b +C: https://openclipart.org/detail/193305/c + +https://openclipart.org/search/?query=letters&page=19