diff --git a/src/activities/activities.txt b/src/activities/activities.txt index c22240b9f..7ea282681 100644 --- a/src/activities/activities.txt +++ b/src/activities/activities.txt @@ -1,131 +1,132 @@ # 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 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 crane details drawletters 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 letter-in-word 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 nine_men_morris nine_men_morris_2players numbers-odd-even paintings penalty photo_hunter planegame readingh readingv redraw redraw_symmetrical renewable_energy reversecount roman_numerals scalesboard scalesboard_weight scalesboard_weight_avoirdupois +share simplepaint smallnumbers smallnumbers2 sudoku superbrain tangram target tic_tac_toe tic_tac_toe_2players traffic watercycle wordsgame diff --git a/src/activities/share/ActivityInfo.qml b/src/activities/share/ActivityInfo.qml new file mode 100644 index 000000000..da1eb06db --- /dev/null +++ b/src/activities/share/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: "share/Share.qml" + difficulty: 2 + icon: "share/share.svg" + author: "Stefan Toncu <stefan.toncu29@gmail.com>" + demo: true + title: qsTr("Share the candies") + description: qsTr("Try to split the candies to a given number of children") + //intro: "put here in comment the text for the intro voice" + goal: qsTr("Learn the division of numbers") + prerequisite: qsTr("Know how to count") + manual: qsTr("Follow the instructions shown on the screen: first, drag the given number of boys/girls to the middle, then drag candies to each child's rectangle.") + credit: "" + section: "math" + createdInVersion: 7000 +} diff --git a/src/activities/share/CMakeLists.txt b/src/activities/share/CMakeLists.txt new file mode 100644 index 000000000..ea9805dc9 --- /dev/null +++ b/src/activities/share/CMakeLists.txt @@ -0,0 +1 @@ +GCOMPRIS_ADD_RCC(activities/share *.qml *.svg *.js resource/*) diff --git a/src/activities/share/DropChild.qml b/src/activities/share/DropChild.qml new file mode 100644 index 000000000..5665ad0f0 --- /dev/null +++ b/src/activities/share/DropChild.qml @@ -0,0 +1,229 @@ +/* GCompris - DropChild.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" + +Rectangle { + id: dropChild + width: items.cellSize * 3 + height: items.cellSize * 4.5 + color: "transparent" + radius: 0.2 + z: 5 + + property string name + property alias childImage: childImage + property alias area: area + property int indexS: index + + Image { + id: childImage + sourceSize.width: items.cellSize * 1.5 * 0.7 + sourceSize.height: items.cellSize * 1.5 - 5 + anchors.bottom: area.top + anchors.left: parent.left + anchors.leftMargin: 20 + source: "resource/images/" + name + ".svg" + } + + //displays the number of candies each child has + GCText { + id: candyCount + anchors.bottom: area.top + anchors.right: parent.right + anchors.rightMargin: 20 + + //"listModel.get(index) ? ... " because of an error received at startup of each level + text: (listModel.get(index) && background.showCount) ? listModel.get(index).countS : "" + + } + + Rectangle { + id: area + width: items.cellSize * 3 + height: items.cellSize * 3 + anchors.bottom: parent.bottom + radius: width * 0.07 + + color: "#cfecf0" + + property var childCoordinate: repeater_drop_areas.mapToItem(background, dropChild.x, dropChild.y) + property var candyCoord: candyWidget.mapToItem(background, candyWidget.element.x, candyWidget.element.y) + + opacity: candyCoord.x > childCoordinate.x && + candyCoord.y > childCoordinate.y + childImage.height && + candyCoord.x < childCoordinate.x + childCoordinate.width && + candyCoord.y < childCoordinate.y + childCoordinate.height ? 0.5 : 1 + + MouseArea { + anchors.fill: parent + + onClicked: { + if (items.acceptCandy) + ////////////////////// START of EASY mode + if (background.easyMode) { + if (background.currentCandies < items.totalCandies) { + if (listModel.get(index).countS + 1 <= 8) { + //add candies in the first rectangle + listModel.setProperty(index,"countS",listModel.get(index).countS+1) + //the current number of candies increases + background.currentCandies ++ + //on the last one, the candy image from top goes away (destroy) + if (background.currentCandies === items.totalCandies) { + background.resetCandy() + candyWidget.element.opacity = 0.6 + } + //show the basket if there is a rest + if (background.rest!=0 && background.basketShown() === false) + items.basketWidget.element.opacity = 1 + } else print("onclidked else: ", listModel.get(index).countS+1 + " -------------> NO MORE") + } + else { + background.resetCandy() + candyWidget.element.opacity = 0.6 + } + + ////////////////////// END of EASY mode + } else { + if (background.currentCandies < items.candyWidget.total) { + if (listModel.get(index).countS + 1 <= 8) { + //add candies in the first rectangle + listModel.setProperty(index,"countS",listModel.get(index).countS+1) + //the current number of candies increases + background.currentCandies ++ + + //show the basket if there is a rest + if (background.rest!=0 && background.basketShown() === false) + items.basketWidget.element.opacity = 1 + + if (background.currentCandies + 1 === items.candyWidget.total) { + background.resetCandy() + } + } else { + background.wrongMove.fadeInOut.start() + print("onclidked else: ", listModel.get(index).countS+1 + " -------------> NO MORE") + } + } + } + /////////////////// END of HARD mode + } + } + + + Flow { + id: candy_drop_area + spacing: 5 + width: parent.width + height: parent.height + + Repeater { + id: repeater_candy_drop_area + model: countS + + Image { + id: candyArea + sourceSize.width: items.cellSize * 0.7 + sourceSize.height: items.cellSize * 1.5 + source: "resource/images/candy.svg" + + property int lastX + property int lastY + + MouseArea { + anchors.fill: parent + + //enables dragging the candie after placed + drag.target: parent + + onPressed: { + instruction.hide() + //set the initial position + candyArea.lastX = candyArea.x + candyArea.lastY = candyArea.y + //move this rectangle/grid on top of everything + dropChild.z++ + grid.z++ + + print("new dropChild.z " + dropChild.z + " grid.z " + grid.z) + } + + onReleased: { + //move this rectangle/grid to its previous state + dropChild.z-- + grid.z-- + + print("orig dropChild.z " + dropChild.z + " grid.z " + grid.z) + + //check where the candy is being dropped + for (var i=0; i childCoordinate.x && + candyCoordinate.x < childCoordinate.x + currentChild.area.width && + candyCoordinate.y > childCoordinate.y + currentChild.childImage.height && + candyCoordinate.y < childCoordinate.y + currentChild.childImage.height + currentChild.area.height) { + //add the candy to the "i"th recthangle + listModel.setProperty(i, "countS", listModel.get(i).countS + 1) + //remove the candy from current rectangle + listModel.setProperty(rect2.indexS, "countS", listModel.get(rect2.indexS).countS - 1); + break; + } + } + else { + //check if the user wants to put back the candy to the leftWidget + if (candyCoordinate.x > 0 && candyCoordinate.x < wid.width && + candyCoordinate.y > 0 && candyCoordinate.y < wid.height) { + //restore the candy to the leftWidget + background.currentCandies-- + candyWidget.element.opacity = 1 + items.candyWidget.canDrag = true + //remove the candy from current rectangle + listModel.setProperty(rect2.indexS, "countS", listModel.get(rect2.indexS).countS - 1); + break; + } + } + } + + //restore the candy to its initial position + candyArea.x = candyArea.lastX + candyArea.y = candyArea.lastY + } + + //when clicked, it will restore the candy + onClicked: { + background.currentCandies-- + candyWidget.element.opacity = 1 + items.candyWidget.canDrag = true + listModel.setProperty(rect2.indexS, "countS", listModel.get(rect2.indexS).countS - 1); + } + } + } + } + } + } +} diff --git a/src/activities/share/Share.qml b/src/activities/share/Share.qml new file mode 100644 index 000000000..4e6c7200e --- /dev/null +++ b/src/activities/share/Share.qml @@ -0,0 +1,458 @@ +/* GCompris - share.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 "share.js" as Activity + +ActivityBase { + id: activity + + onStart: focus = true + onStop: {} + + // TODO: handle Qt 5.7 listModel bug + + pageComponent: Rectangle { + id: background + anchors.fill: parent + color: "#ffffb3" + signal start + signal stop + + 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 alias instruction: instruction + property int currentSubLevel: 0 + property int nbSubLevel + property alias listModel: listModel + property bool acceptCandy: false + property alias dataset: dataset + property alias girlWidget: girlWidget + property alias boyWidget: boyWidget + property alias candyWidget: candyWidget + property alias basketWidget: basketWidget + property alias leftWidget: leftWidget + property int totalBoys + property int totalGirls + property int totalCandies + property int totalChildren: totalBoys + totalGirls + property int barHeightAddon: ApplicationSettings.isBarHidden ? 1 : 3 + property int cellSize: Math.min(background.width / 11 , background.height / (9 + barHeightAddon)) + } + + Loader { + id: dataset + asynchronous: false + } + + onStart: { Activity.start(items) } + onStop: { Activity.stop() } + + property bool vert: background.width > background.height + property int currentBoys: 0 + property int currentGirls: 0 + property int currentCandies: 0 + property int rest + property int placedInGirls + property int placedInBoys + property bool showCount: true + property bool easyMode: false + property alias wrongMove: wrongMove + property bool finished: false + + //returns true if the x and y is in the "dest" area + function contains(x,y,dest) { + return (x > dest.x && x < dest.x + dest.width && + y > dest.y && y < dest.y + dest.height) + } + + //stop the candy rotation + function resetCandy() { + items.acceptCandy = false; + candyWidget.element.rotation = 0 + } + + //searches in the board for the basket; if it exists, returns true + function basketShown() { + for (var i=0; i= items.totalChildren) { + for (var i=0; i bad + bonus.bad("flower") + } + + //center zone + Rectangle { + id: grid + z: 4 + + //map the coordinates from widgets to grid + property var boy: leftWidget.mapFromItem(boyWidget, boyWidget.element.x, boyWidget.element.y) + property var girl: leftWidget.mapFromItem(girlWidget, girlWidget.element.x, girlWidget.element.y) + property var basket: leftWidget.mapFromItem(basketWidget, basketWidget.element.x, basketWidget.element.y) + + //show that the widget can be dropped here + color: background.contains(boy.x, boy.y, grid) || + background.contains(girl.x, girl.y, grid) || + background.contains(basket.x, basket.y, grid) ? "pink" : "transparent" + + anchors { + top: background.vert ? parent.top : leftWidget.bottom + left: background.vert ? leftWidget.right : parent.left + topMargin: 20 + leftMargin: 20 + } + + width: background.vert ? + background.width - leftWidget.width - 40 : background.width - 40 + height: ApplicationSettings.isBarHidden ? + background.height : background.vert ? + background.height - (bar.height * 1.1) : + background.height - (bar.height * 1.1) - leftWidget.height + + //shows/hides the Instruction + MouseArea { + anchors.fill: parent + onClicked: (instruction.opacity === 0) ? + instruction.show() : instruction.hide() + } + + ListModel { + id: listModel + } + + Flow { + id: drop_areas + spacing: 10 + + width: parent.width + height: parent.height + + Repeater { + id: repeater_drop_areas + model: listModel + + DropChild { + id: rect2 + //"nameS" from listModel + name: nameS + } + } + } + } + + //instruction rectangle + Rectangle { + id: instruction + anchors.fill: instructionTxt + opacity: 0.8 + radius: 10 + border.width: 2 + z: 10 + border.color: "black" + gradient: Gradient { + GradientStop { position: 0.0; color: "#000" } + GradientStop { position: 0.9; color: "#666" } + GradientStop { position: 1.0; color: "#AAA" } + } + + property alias text: instructionTxt.text + + Behavior on opacity { PropertyAnimation { duration: 200 } } + + function show() { + if(text) + opacity = 1 + } + function hide() { + opacity = 0 + } + } + + //instruction for playing the game + GCText { + id: instructionTxt + anchors { + top: background.vert ? parent.top : leftWidget.bottom + topMargin: -10 + horizontalCenter: grid.horizontalCenter + } + opacity: instruction.opacity + z: instruction.z + fontSize: background.vert ? regularSize : smallSize + color: "white" + style: Text.Outline + styleColor: "black" + horizontalAlignment: Text.AlignHCenter + width: Math.max(Math.min(parent.width * 0.8, text.length * 8), parent.width * 0.3) + wrapMode: TextEdit.WordWrap + } + + //left widget, with girl/boy/candy/basket widgets in a grid + Rectangle { + id: leftWidget + width: background.vert ? + items.cellSize * 1.74 : background.width + height: background.vert ? + background.height : items.cellSize * 1.74 + color: "#FFFF42" + border.color: "#FFD85F" + border.width: 4 + z: 4 + + //grid with ok button and images of a boy, a girl, a candy and a basket + Grid { + id: view + x: 10 + y: 10 + + width: background.vert ? leftWidget.width : 3 * bar.height + height: background.vert ? background.height - 2 * bar.height : bar.height + spacing: 10 + columns: background.vert ? 1 : 5 + + //ok button + Image { + id: okButton + source:"qrc:/gcompris/src/core/resource/bar_ok.svg" + sourceSize.width: items.cellSize * 1.5 + fillMode: Image.PreserveAspectFit + + MouseArea { + id: mouseArea + anchors.fill: parent + enabled: background.finished ? false : true + onPressed: okButton.opacity = 0.6 + onReleased: okButton.opacity = 1 + onClicked: background.check() + + } + } + + WidgetOption { + id: girlWidget + src: "resource/images/girl.svg" + name: "girl" + total: items.totalGirls + current: background.currentGirls + } + + WidgetOption { + id: boyWidget + src: "resource/images/boy.svg" + name: "boy" + total: items.totalBoys + current: background.currentBoys + } + + WidgetOption { + id: candyWidget + src: "resource/images/candy.svg" + name: "candy" + total: background.easyMode ? items.totalCandies : 8 * items.totalChildren + 1 + current: background.currentCandies + + //swing animation for candies + SequentialAnimation { + id: anim + running: items.acceptCandy ? true : false + loops: Animation.Infinite + NumberAnimation { + target: candyWidget.element + property: "rotation" + from: -10; to: 10 + duration: 400 + Math.floor(Math.random() * 400) + easing.type: Easing.InOutQuad + } + NumberAnimation { + target: candyWidget.element + property: "rotation" + from: 10; to: -10 + duration: 400 + Math.floor(Math.random() * 400) + easing.type: Easing.InOutQuad + } + } + } + + WidgetOption { + id: basketWidget + src: "resource/images/basket.svg" + name: "basket" + element { + opacity: 0 + Behavior on opacity { PropertyAnimation { duration: 500 } } + } + } + } + } + + // show message warning for placing too many candies in one area + Rectangle { + id: wrongMove + anchors.fill: wrongMoveText + z: 5 + color: "#FFFF42" + radius: width / height * 10 + opacity: 0 + + property alias fadeInOut: fadeInOut + + SequentialAnimation { + id: fadeInOut + PropertyAction { target: wrongMove; property: "z"; value: 5 } + NumberAnimation { target: wrongMove; property: "opacity"; to: 1; duration: 300 } + NumberAnimation { target: wrongMove; property: "opacity"; to: 1; duration: 500 } + NumberAnimation { target: wrongMove; property: "opacity"; to: 0; duration: 200 } + PropertyAction { target: wrongMove; property: "z"; value: -5 } + } + } + + GCText { + id: wrongMoveText + anchors.horizontalCenter: grid.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + fontSize: background.vert ? hugeSize : largeSize + opacity: wrongMove.opacity + z: wrongMove.z + color: "#404040" + text: qsTr(" Too many candies!! ") + } + + DialogActivityConfig { + id: dialogActivityConfig + currentActivity: activity + content: Component { + Item { + height: column.height + + Column { + id: column + spacing: 10 + width: parent.width + + GCDialogCheckBox { + id: easyModeBox + width: 250 * ApplicationInfo.ratio + text: qsTr("Easy mode") + checked: background.easyMode + onCheckedChanged: { + background.easyMode = checked + if (checked == false) + candyWidget.element.opacity = 1 + else Activity.reloadRandom() + print("easyModeBox: ",checked) + } + } + } + } + } + + onClose: home() + } + + //bar buttons + DialogHelp { + id: dialogHelp + onClose: home() + } + + Bar { + id: bar + content: BarEnumContent { value: help | home | level | reload | config} + onHelpClicked: { + displayDialog(dialogHelp) + } + onPreviousLevelClicked: Activity.previousLevel() + onNextLevelClicked: Activity.nextLevel() + onHomeClicked: activity.home() + onReloadClicked: Activity.reloadRandom() + onConfigClicked: { + dialogActivityConfig.active = true + displayDialog(dialogActivityConfig) + } + } + + Bonus { + id: bonus + Component.onCompleted: { + win.connect(Activity.nextSubLevel) + } + onStop: background.finished = false + } + + Score { + anchors { + bottom: parent.bottom + bottomMargin: 10 * ApplicationInfo.ratio + right: parent.right + rightMargin: 10 * ApplicationInfo.ratio + top: undefined + left: undefined + } + numberOfSubLevels: items.nbSubLevel + currentSubLevel: items.currentSubLevel + 1 + } + } +} diff --git a/src/activities/share/WidgetOption.qml b/src/activities/share/WidgetOption.qml new file mode 100644 index 000000000..4e190d3cf --- /dev/null +++ b/src/activities/share/WidgetOption.qml @@ -0,0 +1,199 @@ +/* GCompris - WidgetOption.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 QtQuick.Window 2.2 +import GCompris 1.0 + +import "../../core" + +Rectangle { + id: widget + + width: items.cellSize * 1.5 + height: items.cellSize * 1.5 + color: "transparent" + + //initial position of the element + //(these vars are assigned to element after release of click mouse) + property int lastX + property int lastY + property string src + property int current: 0 + property int total: 0 + property string name + property bool canDrag: true + property alias element: element + + Image { + id: element + sourceSize.width: items.cellSize * 1.5 + sourceSize.height: items.cellSize * 1.5 + source: widget.src + + property alias elementText: elementText + + //number of available items + GCText { + id: elementText + anchors.left: parent.left + anchors.bottom: parent.bottom + text: (background.showCount && widget.name !== "basket" && background.easyMode) ? + widget.total - widget.current : "" + } + + property alias dragAreaElement: dragAreaElement + + MouseArea { + id: dragAreaElement + anchors.fill: parent + drag.target: (widget.canDrag) ? parent : null + onPressed: { + instruction.hide() + if (widget.name !== "candy") + background.resetCandy() + //set the initial position + widget.lastX = element.x + widget.lastY = element.y + } + + onReleased: { + var newCoordinate = widget.mapToItem(background, element.x, element.y) + var basketActive = false + + switch(widget.name) { + case "candy": + ////////////////////// START of EASY mode + if (background.easyMode) { + if (background.currentCandies < items.totalCandies) { + items.acceptCandy = true + + for (var i = 0; i < listModel.count; i++) { + var currentChild = repeater_drop_areas.itemAt(i) + var childCoordinate = drop_areas.mapToItem(background, currentChild.x, currentChild.y) + //coordinates of "boy/girl rectangle" in background coordinates + if ((listModel.get(i).countS + 1) > 8) { + print("in if: ", listModel.get(i).countS+1 + " -------------> CONINTUE ------->") + continue + } + + var currentElement = element.parent.mapToItem(background, element.x, element.y) + + if (currentElement.x > childCoordinate.x && currentElement.x < childCoordinate.x + currentChild.area.width && + currentElement.y > childCoordinate.y + currentChild.childImage.height && + currentElement.y < childCoordinate.y + currentChild.childImage.height + currentChild.area.height) { + listModel.setProperty(i, "countS", listModel.get(i).countS+1) + background.currentCandies ++ + } + + if (background.currentCandies == items.totalCandies) { + widget.canDrag = false + background.resetCandy() + candyWidget.element.opacity = 0.6 + } + + //find if the basket is already present on the board + if (currentChild.name === "basket" && background.rest != 0) { + basketActive = true + } + } + + //if there is rest and the basket is not yet present on the board, show the basket + if (background.rest != 0 && basketActive === false) + items.basketWidget.element.opacity = 1 + } + else { + widget.canDrag = false + background.resetCandy() + element.opacity = 0.6 + } + + ////////////////////// END of EASY mode + } else { + if (background.currentCandies < widget.total) { + items.acceptCandy = true + + for (i = 0; i < listModel.count; i++) { + currentChild = repeater_drop_areas.itemAt(i) + childCoordinate = drop_areas.mapToItem(background, currentChild.x, currentChild.y) + //coordinates of "boy/girl rectangle" in background coordinates + currentElement = element.parent.mapToItem(background, element.x, element.y) + + if (currentElement.x > childCoordinate.x && currentElement.x < childCoordinate.x + currentChild.area.width && + currentElement.y > childCoordinate.y + currentChild.childImage.height && + currentElement.y < childCoordinate.y + currentChild.childImage.height + currentChild.area.height) { + + if ((listModel.get(i).countS + 1) > 8) { + print("in if: ", listModel.get(i).countS+1 + " -------------> CONINTUE -------> i " + i) + background.wrongMove.fadeInOut.start() + continue + } + + listModel.setProperty(i, "countS", listModel.get(i).countS+1) + background.currentCandies ++ + } + } + // if all the "dropAreas" are full with 8 candies, then stop the "swing" effect of the candy in leftWidget + if (background.currentCandies + 1 == widget.total) + background.resetCandy() + } + } + /////////////////// END of HARD mode + break; + + case "basket": + if (background.contains(newCoordinate.x, newCoordinate.y, grid)) { + if (widget.canDrag) { + widget.canDrag = false + widget.element.opacity = 0 + listModel.append({countS: 0, nameS: "basket"}); + } + } + break; + + //default is for "boy" and "girl" + default: + if (background.contains(newCoordinate.x, newCoordinate.y, grid)) { + if (widget.current < widget.total) { + if (widget.canDrag) { + widget.current ++ + listModel.append({countS: 0, nameS: widget.name}); + + // set the candies already "preset" + if (widget.name == "boy") + listModel.setProperty(listModel.count-1, "countS", background.placedInBoys) + if (widget.name == "girl") + listModel.setProperty(listModel.count-1, "countS", background.placedInGirls) + + if (widget.current === widget.total) { + widget.canDrag = false + element.opacity = 0.6 + } + } + } + else + widget.canDrag = false + } + } + //set the widget to its initial coordinates + element.x = widget.lastX + element.y = widget.lastY + } + } + } +} diff --git a/src/activities/share/resource/README b/src/activities/share/resource/README new file mode 100644 index 000000000..569d746e3 --- /dev/null +++ b/src/activities/share/resource/README @@ -0,0 +1,7 @@ +Image source: + https://openclipart.org/ + +girl: https://openclipart.org/detail/233385/girl-and-boy +boy: https://openclipart.org/detail/233385/girl-and-boy +candy: https://openclipart.org/detail/189393/candy-cane +basket: https://openclipart.org/detail/215766/basket-02 diff --git a/src/activities/share/resource/board/board0.qml b/src/activities/share/resource/board/board0.qml new file mode 100644 index 000000000..8e8f136b7 --- /dev/null +++ b/src/activities/share/resource/board/board0.qml @@ -0,0 +1,69 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are given in the left widget which eases kid work. + No rest (basket). +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Paul wants to equally share 2 candies between his friends. They are 2. One girl and one boy. Can you help him? Place first the children in center, then drag the candies to each of them."), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 2, + "showCount": true, + "forceShowBakset": "false", + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Now he wants to give 4 candies to his friends."), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 4, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Can you now give 6 of Paul's candies to his friends?"), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 6, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + + }, + { + "instruction" : qsTr("Paul has only 10 candies left. He eats 2 candies and he gives the rest to his friends. Can you help him equally split the 8 remaining candies?"), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 8, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board1.qml b/src/activities/share/resource/board/board1.qml new file mode 100644 index 000000000..ae2aeb266 --- /dev/null +++ b/src/activities/share/resource/board/board1.qml @@ -0,0 +1,58 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are given in the left widget which eases kid work. + There is a rest (basket) +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("George wants to equally share 3 candies between his friends. They are 2. One girl and one boy. Can he equally split the candies to his friends? Place first the children in center, then drag the candies to each of them. Be careful, a rest will remain!"), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 3, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Maria wants to equally share 5 candies between her friends. They are 3. One girl and two boys. Can she equally split the candies to her friends? Place first the children in center, then drag the candies to each of them. Be careful, a rest will remain!"), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 5, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("John wants to equally share 10 candies between his friends. They are 3. One boy and two girls. Can he equally split the candies to his friends? Place first the children in center, then drag the candies to each of them."), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 10, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board2.qml b/src/activities/share/resource/board/board2.qml new file mode 100644 index 000000000..a5fdd62c7 --- /dev/null +++ b/src/activities/share/resource/board/board2.qml @@ -0,0 +1,68 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are not given anymore in the left widget which forces kids to understand this part. + No rest (basket). +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Alice wants to equally share 3 candies between her friends. They are 3: One girl and two boys. Can you help her? Place first the children in the center, then drag the candies to each of them."), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 3, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Now, Alice wants to give 6 candies to her friends"), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 6, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Can you help Alice give 9 candies to her friends: one girl and two boys?"), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 9, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Alice has 12 candies left. She wants to give them all to her friends. Can you help her split the candies equally?"), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 12, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board3.qml b/src/activities/share/resource/board/board3.qml new file mode 100644 index 000000000..3a484f569 --- /dev/null +++ b/src/activities/share/resource/board/board3.qml @@ -0,0 +1,68 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are not given anymore in the left widget. + There is a rest (basket). +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Michael wants to equally share 5 candies between his friends. They are 2. One girl and one boy. Can you help him? Place first the children in center, then drag the candies to each of them!"), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 5, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Helen has 3 friends: one boy and two girls. She wants to give them 7 candies. Help her split the candies between her friends!"), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 7, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Michelle has 9 candies and wants to split them with two brothers and two sisters. Help her share the candies!"), + "totalBoys" : 2, + "totalGirls" : 2, + "totalCandies" : 9, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Thomas wants to share his 11 candies with his friends: three boys and one girl. Can you help him?"), + "totalBoys" : 3, + "totalGirls" : 1, + "totalCandies" : 11, + "showCount": false, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board4.qml b/src/activities/share/resource/board/board4.qml new file mode 100644 index 000000000..c50c48788 --- /dev/null +++ b/src/activities/share/resource/board/board4.qml @@ -0,0 +1,58 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are not given anymore in the left widget. + There is always a basket even if the rest can be equal to 0 +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Charles wants to share his 8 candies to one boy and two girls. Can he split the candies equally?"), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 8, + "showCount": true, + "forceShowBakset": true, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("For her birthday, Elizabeth has 12 candies to share with her friends. They are two girls and two boys. How should she split the candies to her friends?"), + "totalBoys" : 2, + "totalGirls" : 2, + "totalCandies" : 12, + "showCount": true, + "forceShowBakset": true, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Jason's father gave him 14 candies to share with his friends: two boys and three girls. Help him give the candies to his friends!"), + "totalBoys" : 2, + "totalGirls" : 3, + "totalCandies" : 14, + "showCount": true, + "forceShowBakset": true, + "placedInGirls": 0, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board5.qml b/src/activities/share/resource/board/board5.qml new file mode 100644 index 000000000..7b1e72b7f --- /dev/null +++ b/src/activities/share/resource/board/board5.qml @@ -0,0 +1,59 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are not given anymore in the left widget. + No rest (basket). + Boy or Girl rectangles already contain a given number of candies. +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Bob wants to give 5 candies to his friends: two boys and one girl, his girlfriend already has one candy. Can you help him equally split the candies so each friend will have the same amount of candies?"), + "totalBoys" : 2, + "totalGirls" : 1, + "totalCandies" : 6, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 1, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Harry wants to equally share 8 candies between his friends: one boy and two girls. Place the children in center, then drag the candies to each of them so each of them has an equal number of candies."), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 9, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 1 + }, + { + "instruction" : qsTr("Can you now give 6 of Harry's candies to his friends?"), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 8, + "showCount": true, + "forceShowBakset": false, + "placedInGirls": 0, + "placedInBoys": 2 + } + ] +} diff --git a/src/activities/share/resource/board/board6.qml b/src/activities/share/resource/board/board6.qml new file mode 100644 index 000000000..392a068b8 --- /dev/null +++ b/src/activities/share/resource/board/board6.qml @@ -0,0 +1,59 @@ +/* GCompris + * + * 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.0 + +/* + Numbers of kids are not given anymore in the left widget. + No rest (basket). + Boy or Girl rectangles already contain a given number of candies. +*/ + +QtObject { + property variant levels : [ + { + "instruction" : qsTr("Help Jon split 9 candies to three boys and two girls. The rest will remain to Jon."), + "totalBoys" : 3, + "totalGirls" : 2, + "totalCandies" : 9, + "showCount": false, + "forceShowBakset": true, + "placedInGirls": 0, + "placedInBoys": 0 + }, + { + "instruction" : qsTr("Jon wants to share the rest of his candies with his brother and his sister. Can you split them equally, knowing that his brother already has two candies?"), + "totalBoys" : 1, + "totalGirls" : 1, + "totalCandies" : 6, + "showCount": false, + "forceShowBakset": true, + "placedInGirls": 0, + "placedInBoys": 2 + }, + { + "instruction" : qsTr("Help Tux split some candies to his friends: 9 candies to one boy and two girls."), + "totalBoys" : 1, + "totalGirls" : 2, + "totalCandies" : 13, + "showCount": false, + "forceShowBakset": true, + "placedInGirls": 2, + "placedInBoys": 0 + } + ] +} diff --git a/src/activities/share/resource/board/board7.qml b/src/activities/share/resource/board/board7.qml new file mode 100644 index 000000000..e22722f34 --- /dev/null +++ b/src/activities/share/resource/board/board7.qml @@ -0,0 +1,29 @@ +/* GCompris + * + * 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.0 + +QtObject { + property variant levels : [ + { + "maxBoys" : 2, + "maxGirls" : 2, + "maxCandies" : 16, + "alreadyPlaced": false + } + ] +} diff --git a/src/activities/share/resource/board/board8.qml b/src/activities/share/resource/board/board8.qml new file mode 100644 index 000000000..91d87e965 --- /dev/null +++ b/src/activities/share/resource/board/board8.qml @@ -0,0 +1,29 @@ +/* GCompris + * + * 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.0 + +QtObject { + property variant levels : [ + { + "maxBoys" : 3, + "maxGirls" : 3, + "maxCandies" : 24, + "alreadyPlaced": true + } + ] +} diff --git a/src/activities/share/resource/board/board9.qml b/src/activities/share/resource/board/board9.qml new file mode 100644 index 000000000..e4dadd691 --- /dev/null +++ b/src/activities/share/resource/board/board9.qml @@ -0,0 +1,29 @@ +/* GCompris + * + * 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.0 + +QtObject { + property variant levels : [ + { + "maxBoys" : 3, + "maxGirls" : 3, + "maxCandies" : 24, + "alreadyPlaced": true + } + ] +} diff --git a/src/activities/share/resource/images/basket.svg b/src/activities/share/resource/images/basket.svg new file mode 100644 index 000000000..cd00f82b2 --- /dev/null +++ b/src/activities/share/resource/images/basket.svg @@ -0,0 +1,92 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/activities/share/resource/images/boy.svg b/src/activities/share/resource/images/boy.svg new file mode 100644 index 000000000..f01842a72 --- /dev/null +++ b/src/activities/share/resource/images/boy.svg @@ -0,0 +1,183 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/activities/share/resource/images/candy.svg b/src/activities/share/resource/images/candy.svg new file mode 100644 index 000000000..79e4dc364 --- /dev/null +++ b/src/activities/share/resource/images/candy.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Openclipart + + + + + + + + + + + diff --git a/src/activities/share/resource/images/girl.svg b/src/activities/share/resource/images/girl.svg new file mode 100644 index 000000000..8274664fe --- /dev/null +++ b/src/activities/share/resource/images/girl.svg @@ -0,0 +1,170 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/activities/share/share.js b/src/activities/share/share.js new file mode 100644 index 000000000..d49615375 --- /dev/null +++ b/src/activities/share/share.js @@ -0,0 +1,237 @@ +/* GCompris - share.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 + +var currentLevel = 0 +var numberOfLevel = 10 +var items + +var savedTotalBoys +var savedTotalGirls +var savedTotalCandies +var savedPlacedInGrils +var savedPlacedInBoys +var savedCurrentCandies + +function start(items_) { + items = items_ + currentLevel = 0 + initLevel() +} + +function stop() { +} + +function initLevel() { + items.bar.level = currentLevel + 1 + var filename = "resource/board/"+ "board" + currentLevel + ".qml" + items.dataset.source = filename + + setUp() +} + +function setUp() { + var levelData = items.dataset.item + + // use board levels + if (currentLevel < 7) { + items.totalBoys = levelData.levels[items.currentSubLevel].totalBoys + items.totalGirls = levelData.levels[items.currentSubLevel].totalGirls + items.totalCandies = levelData.levels[items.currentSubLevel].totalCandies + + items.instruction.text = levelData.levels[items.currentSubLevel].instruction + items.nbSubLevel = levelData.levels.length + + + items.background.currentCandies = items.totalGirls * levelData.levels[items.currentSubLevel].placedInGirls + + items.totalBoys * levelData.levels[items.currentSubLevel].placedInBoys + + items.background.placedInGirls = levelData.levels[items.currentSubLevel].placedInGirls + items.background.placedInBoys = levelData.levels[items.currentSubLevel].placedInBoys + items.background.showCount = levelData.levels[items.currentSubLevel].showCount + + + items.background.rest = items.totalCandies - + Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) + items.basketWidget.element.opacity = (levelData.levels[items.currentSubLevel].forceShowBakset === true || + items.background.rest !== 0) ? 1 : 0 + + // create random (guided) levels + } else { + // get a random number between 1 and max for boys, girls and candies + var maxBoys = levelData.levels[0].maxBoys + var maxGirls = levelData.levels[0].maxGirls + var maxCandies = levelData.levels[0].maxCandies + + items.totalBoys = Math.floor(Math.random() * maxBoys) + 1 + items.totalGirls = Math.floor(Math.random() * maxGirls) + 1 + var sum = items.totalBoys + items.totalGirls + // use sum * 4 as top margin (max 4 candies per rectangle) + items.totalCandies = Math.floor(Math.random() * (4 * sum - sum + 1)) + sum + + // stay within the max margin + if (items.totalCandies > maxCandies) + items.totalCandies = maxCandies + + // grammer correction depending the number of children: 1 (singular) or more (plural) + var boys + var girls + + if (items.totalBoys > 1) + boys = "boys" + else boys = "boy" + + if (items.totalGirls > 1) + girls = "girls" + else girls = "girl" + + items.instruction.text = qsTr("Place " + items.totalBoys + " " + boys + " and " + + items.totalGirls + " " + girls + " in the center, then equally split " + + items.totalCandies + " candies between them.") + + items.background.showCount = false + items.nbSubLevel = 5 + + // depending on the levels configuration, add candies from start in a child rectangle + if (levelData.levels[0].alreadyPlaced == false) { + items.background.placedInGirls = 0 + items.background.placedInBoys = 0 + items.background.currentCandies = 0 + } else { + items.background.currentCandies = items.totalCandies * 2 + while (items.background.currentCandies > items.totalCandies / 3) { + items.background.placedInGirls = Math.floor(Math.random() * 3) + 0 + items.background.placedInBoys = Math.floor(Math.random() * 3) + 0 + items.background.currentCandies = items.totalGirls * items.background.placedInGirls + + items.totalBoys * items.background.placedInBoys + } + // update the total number of candies with the candies already added + items.totalCandies += items.background.currentCandies + } + + items.background.rest = items.totalCandies - + Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) + items.basketWidget.element.opacity = 1 + + saveVariables() + } + + items.background.currentGirls = 0 + items.background.currentBoys = 0 + items.background.resetCandy() + items.background.finished = false + + items.acceptCandy = false + items.instruction.opacity = 1 + items.listModel.clear() + + items.girlWidget.current = 0 + items.girlWidget.canDrag = true + items.girlWidget.element.opacity = 1 + + items.boyWidget.current = 0 + items.boyWidget.canDrag = true + items.boyWidget.element.opacity = 1 + + items.candyWidget.canDrag = true + items.candyWidget.element.opacity = 1 + if (items.totalCandies - items.background.currentCandies == 0) + items.candyWidget.element.opacity = 0.6 + + items.basketWidget.canDrag = true +} + +function saveVariables() { + savedTotalBoys = items.totalBoys + savedTotalGirls = items.totalGirls + savedTotalCandies = items.totalCandies + savedPlacedInGrils = items.background.placedInGirls + savedPlacedInBoys = items.background.placedInBoys + savedCurrentCandies = items.background.currentCandies +} + +function loadVariables() { + items.totalBoys = savedTotalBoys + items.totalGirls = savedTotalGirls + items.totalCandies = savedTotalCandies + items.background.placedInGirls = savedPlacedInGrils + items.background.placedInBoys = savedPlacedInBoys + items.background.currentCandies = savedCurrentCandies +} + +function reloadRandom() { + if (currentLevel < 7) { + initLevel() + } else { + loadVariables() + + items.background.currentGirls = 0 + items.background.currentBoys = 0 + items.background.rest = items.totalCandies - + Math.floor(items.totalCandies / items.totalChildren) * (items.totalBoys+items.totalGirls) + items.background.resetCandy() + items.background.showCount = false + items.acceptCandy = false + + items.instruction.opacity = 1 + items.listModel.clear() + + items.girlWidget.current = 0 + items.girlWidget.canDrag = true + items.girlWidget.element.opacity = 1 + + items.boyWidget.current = 0 + items.boyWidget.canDrag = true + items.boyWidget.element.opacity = 1 + + items.candyWidget.canDrag = true + items.candyWidget.element.opacity = 1 + if (items.totalCandies - items.background.currentCandies == 0) + items.candyWidget.element.opacity = 0.6 + + items.basketWidget.canDrag = true + items.basketWidget.element.opacity = 1 + } +} + +function nextSubLevel() { + items.currentSubLevel ++ + if (items.currentSubLevel === items.nbSubLevel) { + nextLevel() + } + else + setUp() +} + +function nextLevel() { + if(numberOfLevel <= ++currentLevel ) { + currentLevel = 0 + } + items.currentSubLevel = 0; + initLevel(); +} + +function previousLevel() { + if(--currentLevel < 0) { + currentLevel = numberOfLevel - 1 + } + items.currentSubLevel = 0; + initLevel(); +} diff --git a/src/activities/share/share.svg b/src/activities/share/share.svg new file mode 100644 index 000000000..f01842a72 --- /dev/null +++ b/src/activities/share/share.svg @@ -0,0 +1,183 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + +