diff --git a/src/activities/numeration_weights_integer/NumberWeightDragElement.qml b/src/activities/numeration_weights_integer/NumberWeightDragElement.qml index 9e5f1cba1..3072e6228 100644 --- a/src/activities/numeration_weights_integer/NumberWeightDragElement.qml +++ b/src/activities/numeration_weights_integer/NumberWeightDragElement.qml @@ -1,107 +1,107 @@ /* GCompris - NumberWeightDragElement.qml * * Copyright (C) 2019 Emmanuel Charruau * * 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.6 import GCompris 1.0 //? import "../../core" import "numeration_weights_integer.js" as Activity Rectangle { id: numberWeightDragElement property int lastX property int lastY property string imageName property string name property bool canDrag: true property string caption property string src property int weightValue property bool selected // callback defined in each numberWeightDragElement called when we release the element in background //? property var releaseElement: null //? width: parent.width - parent.width/5 height: parent.height / 15 color: "transparent" border.color: "red" border.width: selected === true ? 1 : 0 Drag.active: numberWeightDragElementMouseArea.drag.active src: "resource/images/" + imageName Image { id: numberWeightDragElementImage sourceSize.width: parent.width sourceSize.height: parent.height source: imageName !== "" ? numberWeightDragElement.src : "" anchors.fill: parent //number of available items GCText { id: numberWeightDragElementCaption anchors.fill: parent anchors.margins: 10 fontSizeMode: Text.Fit color: "white" verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter text: numberWeightDragElement.caption } } MouseArea { id: numberWeightDragElementMouseArea anchors.fill: parent onPressed: { //set the initial position numberWeightDragElement.lastX = numberWeightDragElement.x numberWeightDragElement.lastY = numberWeightDragElement.y } onPositionChanged: { - Activity.unselectAllNumberWeightDragElement() + Activity.unselectAllNumberWeightDragElement() } onClicked: { Activity.selectNumberWeightDragElement(index) } drag.target: numberWeightDragElement drag.axis: numberWeightDragElement.x < parent.width ? Drag.XAxis : Drag.XAndYAxis Drag.hotSpot.x: width Drag.hotSpot.y: height onReleased: { parent.Drag.drop() //set the element to its initial coordinates numberWeightDragElement.x = numberWeightDragElement.lastX numberWeightDragElement.y = numberWeightDragElement.lastY } } } diff --git a/src/activities/numeration_weights_integer/NumberWeightHeaderElement.qml b/src/activities/numeration_weights_integer/NumberWeightHeaderElement.qml index 80615e8cc..49da48767 100644 --- a/src/activities/numeration_weights_integer/NumberWeightHeaderElement.qml +++ b/src/activities/numeration_weights_integer/NumberWeightHeaderElement.qml @@ -1,115 +1,115 @@ /* GCompris - NumberWeightHeaderElement.qml * * Copyright (C) 2019 Emmanuel Charruau * * 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.6 import GCompris 1.0 import "../../core" import "numeration_weights_integer.js" as Activity Rectangle { id: numberWeightHeaderElement property string defaultColor: "darkred" property string overlapColor: "blue" color: "darkred" radius: 0.2 anchors.top: parent.top //? property int lastX property int lastY property Item dragParent property alias textAlias: numberWeightHeaderCaption.text border.color: "red" border.width: 0 DropArea { id: numberWeightsHeaderDropArea anchors.fill: parent keys: "numberWeightHeaderKey" onEntered: { numberWeightHeaderElement.color = overlapColor } onExited: { numberWeightHeaderElement.color = defaultColor } onDropped: { numberWeightHeaderElement.color = defaultColor numberWeightHeaderCaption.text = drag.source.caption } Image { id: numberWeightHeaderImage anchors.fill: parent - sourceSize.width: parent.width //? + sourceSize.width: parent.width sourceSize.height: parent.height GCText { id: numberClassElementCaption anchors.fill: parent anchors.bottom: parent.bottom fontSizeMode: Text.Fit color: "white" verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter } } } GCText { id: numberWeightHeaderCaption anchors.fill: parent anchors.margins: 10 //find a way to fit the text without truncating it fontSizeMode: Text.Fit color: "white" verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter wrapMode: TextEdit.WordWrap text: qsTr("Drag column weight here.") } MouseArea { anchors.fill: parent onClicked: { if (numberWeightHeaderImage.status === Image.Ready) { Activity.removeNumberWeightComponent(numberWeightImageTile) } else { if (Activity.selectedNumberWeightDragElementIndex !== -1) { if (numberWeightDragListModel.get(Activity.selectedNumberWeightDragElementIndex).dragkeys === "numberWeightHeaderKey") { numberWeightHeaderImage.source = numberWeightDragListModel.get(Activity.selectedNumberWeightDragElementIndex).imageName numberWeightHeaderCaption.text = numberWeightDragListModel.get(Activity.selectedNumberWeightDragElementIndex).caption } } } } } } diff --git a/src/activities/numeration_weights_integer/numeration_weights_integer.js b/src/activities/numeration_weights_integer/numeration_weights_integer.js index e7b191279..daef6891b 100644 --- a/src/activities/numeration_weights_integer/numeration_weights_integer.js +++ b/src/activities/numeration_weights_integer/numeration_weights_integer.js @@ -1,537 +1,556 @@ /* GCompris - numeration.js * * Copyright (C) 2019 Emmanuel Charruau * * 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.6 as Quick var currentLevel = 0 var numberOfLevel = 0 //? var items var numbersToConvert = [] var scorePercentage = 0 var scorePourcentageStep = 0 var numbersToConvertIndex = 0 var selectedNumberWeightDragElementIndex = -1 var numberHasADecimalPart = false var fullClassNamesConstantArray = ["Decimal Part","Unit class","Thousand class","Million class","Milliard class"] var classNamesUsedArray var numberClassesObj = { "Decimal Part": { name: qsTr("Decimal Part"), color: "black", dragkeys: "NumberClassKey"}, "Unit class": { name: qsTr("Unit class"), color: "black", dragkeys: "NumberClassKey"}, "Thousand class": { name: qsTr("Thousand class"), color: "black", dragkeys: "NumberClassKey"}, "Million class": { name: qsTr("Million class"), color: "black", dragkeys: "NumberClassKey"}, "Milliard class": { name: qsTr("Milliard class"), color: "black", dragkeys: "NumberClassKey"} } var numberWeightsColumnsArray = ["HundredColumn","TenColumn","UnitColumn"] var numberWeightComponentConstantArray = ["UnitColumn","TenColumn","HundredColumn","Unit","Ten","Hundred","Thousand","TenThousand", "OneHundredThousand","OneMillion","TenMillion","OneHundredMillion", "OneMilliard","TenMilliard","OneHundredMilliard"] var numberWeightDragArray = { "UnitColumn": { name: qsTr("Unit"), caption: "Unit", imageName: "", weightValue: "1", dragkeys: "numberWeightHeaderKey", color: "lightskyblue", selected: false }, "TenColumn": { name: qsTr("Ten"), caption: "Ten", imageName: "", weightValue: "10", dragkeys: "numberWeightHeaderKey", color: "lightskyblue", selected: false }, "HundredColumn": { name: qsTr("Hundred"), caption: "Hundred", imageName: "", weightValue: "100", dragkeys: "numberWeightHeaderKey", color: "lightskyblue", selected: false }, "Unit": { name: qsTr("Unit"), caption: "", imageName: "unit.svg", weightValue: "1", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "Ten": { name: qsTr("Unit"), caption: "", imageName: "ten.svg", weightValue: "10", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "Hundred": { name: qsTr("Unit"), caption: "", imageName: "hundred.svg", weightValue: "100", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "Thousand": { name: qsTr("Unit"), caption: "1000", imageName: "weightCaption.svg", weightValue: "1000", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "TenThousand": { name: qsTr("Unit"), caption: "10 000", imageName: "weightCaption.svg", weightValue: "10000", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "OneHundredThousand": { name: qsTr("Unit"), caption: "100 000", imageName: "weightCaption.svg", weightValue: "100000", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "OneMillion": { name: qsTr("Unit"), caption: "1 000 000", imageName: "weightCaption.svg", weightValue: "1000000", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "TenMillion": { name: qsTr("Unit"), caption: "10 000 000", imageName: "weightCaption.svg", weightValue: "10000000", dragkeys: "numberWeightKey", color: "transparent", selected: false }, "OneHundredMillion": { name: qsTr("Unit"), caption: "1000 000 000", imageName: "weightCaption.svg", weightValue: "100000000", dragkeys: "numberWeightKey", color: "transparent" , selected: false }, "OneMilliard": { name: qsTr("Unit"), caption: "1 000 000 000", imageName: "weightCaption.svg", weightValue: "1000000000", dragkeys: "numberWeightKey", color: "transparent" , selected: false }, "TenMilliard": { name: qsTr("Unit"), caption: "10 000 000 000", imageName: "weightCaption.svg", weightValue: "10000000000", dragkeys: "numberWeightKey", color: "transparent" , selected: false }, "OneHundredMilliard": { name: qsTr("Unit"), caption: "100 000 000 000", imageName: "weightCaption.svg", weightValue: "100000000000", dragkeys: "numberWeightKey", color: "transparent" , selected: false } } // for what is used name in numberWeightDragArray ? //? var numberClassTypeColumnsArray = ["Integer Part","Decimal Part"] function removeClassInNumberClassesArray(className) { console.log(numberClassesArray) var index = numberClassesArray.indexOf(className); if (index > -1) { numberClassesArray.splice(index, 1); } console.log(numberClassesArray) } function removeClassInNumberClassesArray() { numberClassesArray.pop(numberClass) } function setNumberWeightHeader(numberWeightImageTile,imageName,caption,weightValue) { if ( imageName !== "") { numberWeightImageTile.source = "qrc:/gcompris/src/activities/numeration_weights_integer/resource/images/" + imageName } numberWeightImageTile.caption = caption numberWeightImageTile.weightValue = weightValue } function setNumberWeightComponent(numberWeightImageTile,imageName,caption,weightValue) { if ( imageName !== "") { numberWeightImageTile.source = "qrc:/gcompris/src/activities/numeration_weights_integer/resource/images/" + imageName numberWeightImageTile.caption = caption numberWeightImageTile.weightValue = weightValue } } function removeNumberWeightComponent(numberWeightImageTile) { numberWeightImageTile.source = "" numberWeightImageTile.caption = "" numberWeightImageTile.weightValue = "" numberWeightImageTile.border.color = "black" } function resetNumerationTable() { for (var i = 0; i=0; i--,classNamesUsedIndex++) { if (items.numberClassListModel.get(i).name === classNamesUsedArray[classNamesUsedIndex]) { items.numberClassListModel.setProperty(i, "misplaced", false) } else { items.numberClassListModel.setProperty(i, "misplaced", true) allClassesColumnsInRightPositions = false } } return allClassesColumnsInRightPositions } function expectedAndEnteredValuesAreEquals() { var enteredValue = readNumerationTableEnteredValue() console.log("enteredValue/parseInt(numbersToConvert[numbersToConvertIndex],10)",enteredValue + "/" + parseInt(numbersToConvert[numbersToConvertIndex],10)) //test if entered value is equal to number expected if (enteredValue === parseInt(numbersToConvert[numbersToConvertIndex],10)) { console.log("enteredValue/parseInt(numbersToConvert[numbersToConvertIndex],10)",enteredValue + "/" + parseInt(numbersToConvert[numbersToConvertIndex],10)) return true } else { return false } } function checkEnteredValue() { var _expectedAndEnteredValuesAreEquals = expectedAndEnteredValuesAreEquals() if (_expectedAndEnteredValuesAreEquals) { return true } else { return false } } function evaluateAndDisplayProgresses(correctAnswer) { if (correctAnswer) { items.bonus.good("flower") console.log("1///////////////scorePercentage",scorePercentage) scorePercentage = scorePercentage + scorePourcentageStep //? console.log("2///////////////scorePercentage",scorePercentage) items.progressBar.value = scorePercentage if (scorePercentage > 97) { nextLevel() } numbersToConvertIndex++ items.numberToConvertRectangle.text = numbersToConvert[numbersToConvertIndex] + console.log("numbersToConvert: " + numbersToConvert) + console.log("Index of numbersToConvert: " + numbersToConvertIndex) return } else { items.bonus.bad("flower") scorePercentage = scorePercentage - (2 * scorePourcentageStep) if (scorePercentage < 0) scorePercentage = 0 items.progressBar.value = scorePercentage var numbersToConvertIndexPlus4 = numbersToConvertIndex + 4 //we insert here an random additional value, otherwise there could be an overflow when adding the 2 values //inserted when the user makes an error and that we are at the end of the array if (numbersToConvertIndexPlus4 -1 > numbersToConvert.length ) { var randomValueToInsert = numbersToConvert[Math.floor(Math.random() * numbersToConvert.length)] numbersToConvert.push(randomValueToInsert) } //when user makes an error, the given error is inserted twice, one time to find the good result, a second time to be sure that the answer is understood numbersToConvert.splice(numbersToConvertIndex+1, 0, numbersToConvert[numbersToConvertIndex]); numbersToConvert.splice(numbersToConvertIndex+3, 0, numbersToConvert[numbersToConvertIndex]); numbersToConvertIndex++ //? how can we catch here the stop signal to wait a little bit before to go to next question ? + console.log("numbersToConvert: " + numbersToConvert) + console.log("Index of numbersToConvert: " + numbersToConvertIndex) items.numberToConvertRectangle.text = numbersToConvert[numbersToConvertIndex] } } function start(items_) { items = items_ currentLevel = 0 classNamesUsedArray = setClassNamesUsedArray(fullClassNamesConstantArray) numberHasADecimalPart = hasNumberADecimalPart() setNumberClassTypeListModel() updateIntegerAndDecimalHeaderWidth() setNumberClassDragListModel(fullClassNamesConstantArray) setNumberWeightDragListModel(numberWeightComponentConstantArray) initLevel() numberOfLevel = items.levels.length // ? } function setNumberClassTypeListModel() { items.numberClassTypeModel.append({"numberClassType": "Integer Part", "numberClassTypeHeaderWidth": 0}) if (hasNumberADecimalPart()) { addDecimalHeaderToNumberClassTypeModel() } } function setClassNamesUsedArray(fullClassNamesArray) { var smallerNumberClass = items.levels[currentLevel].smallerNumberClass var biggerNumberClass = items.levels[currentLevel].biggerNumberClass if (!isClassNamePresentInfullClassNamesArray(fullClassNamesArray, smallerNumberClass)) { return fullClassNamesConstantArray } if (!isClassNamePresentInfullClassNamesArray(fullClassNamesArray, biggerNumberClass)) { return fullClassNamesConstantArray } return fullClassNamesArray.slice(fullClassNamesArray.indexOf(smallerNumberClass),fullClassNamesArray.indexOf(biggerNumberClass)+1) } function isClassNamePresentInfullClassNamesArray(fullClassNamesArray, className) { if (fullClassNamesArray.indexOf(className) !== -1) { return true } else { items.warningRectangle.text = qsTr("The class name \"" + className + "\" is not present in the available list: \"" + fullClassNamesArray+ "\". Check your configuration file (lower case or uppercase error?).") items.warningRectangle.show() return false } } function hasNumberADecimalPart() { for (var i=0; i * * Authors: * Emmanuel Charruau * * 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.6 import GCompris 1.0 import "../../../../core" Dataset { objective: qsTr("Drag the different numbers weights to obtain a number between 1 and 99.") difficulty: 1 data: [ { "level" : "1", "objective" : qsTr("Drag the number weights in the right cells to create numbers up to 9"), //possible smallerNumberClass are "Decimal Part","Unit class","Thousand class","Million class","Milliard class" "smallerNumberClass": "Unit class", //"smallerNumberClass": "Decimal Part", "biggerNumberClass": "Milliard class", "numbers" : [ "4", "1", - "5", - "6", - "8", - "2", - "9", - "3", - "7", - "10" + "5" +// "6", +// "8", +// "2", +// "9", +// "3", +// "7", +// "10" ] }, { "level" : "2", "objective" : qsTr("Drag the number weights in the right cells to create numbers up to 20."), "numbers" : [ "14", "2", "11", "2", "7", "18", "5", "19", "13", "20" ] }, { "level" : "3", "objective" : qsTr("Drag the number weights in the right cells to create numbers up to 40"), "numbers" : [ "14", "2", "22", "2", "37", "38", "5", "29", "13", "40" ] }, { "level" : "4", "objective" : qsTr("Drag the number weights in the right cells to create numbers up to 60"), "numbers" : [ "54", "23", "22", "2", "43", "57", "5", "39", "53", "60" ] }, { "level" : "5", "objective" : qsTr("Drag the number weights in the right cells to create numbers up to 99"), "numbers" : [ "64", "13", "82", "92", "44", "77", "85", "9", "53", "99" ] } ] }