diff --git a/src/activities/money/MoneyArea.qml b/src/activities/money/MoneyArea.qml new file mode 100644 index 000000000..59aa906db --- /dev/null +++ b/src/activities/money/MoneyArea.qml @@ -0,0 +1,89 @@ +/* GCompris - MoneyArea.qml + * + * Copyright (C) 2018 Smit S. Patil + * + * Authors: + * Smit S. Patil + * + * 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 "../../core" +import "money.js" as Activity + +Rectangle { + id: moneyAreaBody + height: (column.itemHeight + 10) * column.nbLines + width: column.width + color: "#55333333" + border.color: "black" + border.width: 2 + radius: 5 + + property alias pocketModel: pocketModel + property alias answer: pocket + signal transaction(int index) + + Flow { + anchors.topMargin: 4 + anchors.bottomMargin: 4 + anchors.leftMargin: 10 + anchors.rightMargin: 10 + anchors.fill: parent + spacing: 10 + + add: Transition { + NumberAnimation { + properties: "x" + from: parent.width * 0.05 + easing.type: Easing.InOutQuad + } + } + + move: Transition { + NumberAnimation { + properties: "x,y" + easing.type: Easing.InOutQuad + } + } + + Repeater { + id: pocket + model: ListModel { id: pocketModel } + Image { + source: Activity.url + img + sourceSize.height: column.itemHeight + height: column.itemHeight + + property bool selected: false + + MultiPointTouchArea { + anchors.fill: parent + onReleased: moneyAreaBody.transaction(index) + } + + Rectangle{ + width: parent.width * 1.1 + height: parent.height * 1.1 + color: "#88111111" + anchors.centerIn : parent + radius: 5 + visible: selected + z: -1 + } + } + } + } +} diff --git a/src/activities/money/MoneyCore.qml b/src/activities/money/MoneyCore.qml index 6130bac24..ec859c262 100644 --- a/src/activities/money/MoneyCore.qml +++ b/src/activities/money/MoneyCore.qml @@ -1,382 +1,269 @@ /* GCompris - MoneyCore.qml * * Copyright (C) 2014 Bruno Coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (Qt Quick port) * * 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 "../../core" import "money.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} property var dataset pageComponent: Image { id: background anchors.fill: parent source: Activity.url + "/background.svg" sourceSize.width: parent.width 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 GCSfx audioEffects: activity.audioEffects - property alias answerModel: answerModel - property alias pocketModel: pocketModel + property alias answerModel: answerArea.pocketModel + property alias pocketModel: pocketArea.pocketModel property alias store: store property alias instructions: instructions property alias tux: tux property alias tuxMoney: tuxMoney property alias bar: bar property alias bonus: bonus property int itemIndex - property bool pocketFocus - property var area - property alias pocket: pocket + property var selectedArea + property alias pocket: pocketArea.answer + property alias answer: answerArea.answer } onStart: { Activity.start(items, dataset) } onStop: { Activity.stop() } Column { id: column spacing: 10 x: parent.width * 0.05 y: parent.height * 0.05 width: parent.width * 0.9 property int nbColumns: 5 property int nbLines: 2 property int itemWidth: Math.min(width / nbColumns - 10 - 10 / nbColumns, parent.height * 0.4 / nbLines - 10 - 10 / nbLines) property int itemHeight: itemWidth * 0.59 // === The Answer Area === - Rectangle { + MoneyArea { id: answerArea - height: (column.itemHeight + 10) * column.nbLines - width: column.width - color: "#55333333" - border.color: "black" - border.width: 2 - radius: 5 - - Flow { - anchors.topMargin: 4 - anchors.bottomMargin: 4 - anchors.leftMargin: 10 - anchors.rightMargin: 10 - anchors.fill: parent - spacing: 10 - - add: Transition { - NumberAnimation { - properties: "x" - from: parent.width * 0.05 - easing.type: Easing.InOutQuad - } - } - - move: Transition { - NumberAnimation { - properties: "x,y" - easing.type: Easing.InOutQuad - } - } - - Repeater { - id: answer - model: ListModel { id: answerModel } - Image { - source: Activity.url + img - sourceSize.height: column.itemHeight - height: column.itemHeight - - property bool selected: false - - MultiPointTouchArea { - anchors.fill: parent - onReleased: Activity.unpay(index) - } - - Rectangle{ - width: parent.width * 1.1 - height: parent.height * 1.1 - color: "#88111111" - anchors.centerIn : parent - radius: 5 - visible: selected - z: -1 - } - } - } - } + onTransaction: Activity.unpay(index) } // === The Store Area === property int nbStoreColumns: activity.dataset === "BACK_WITHOUT_CENTS" || activity.dataset === "BACK_WITH_CENTS" ? store.model.length + 1 : store.model.length //tempSpace is a workaround to replace instructionsArea.realHeight that is freezing with Qt-5.9.1 property int tempSpace: bar.level === 1 ? 140 + column.spacing : 0 property int itemStoreWidth: Math.min((column.width - storeAreaFlow.spacing * nbStoreColumns) / nbStoreColumns, (parent.height - answerArea.height - pocketArea.height - bar.height) * 0.8) - tempSpace property int itemStoreHeight: itemStoreWidth Rectangle { id: storeArea height: (column.itemStoreHeight + 10) width: column.width color: "#55333333" border.color: "black" border.width: 2 radius: 5 Flow { id: storeAreaFlow anchors.topMargin: 4 anchors.bottomMargin: 4 anchors.leftMargin: 20 anchors.rightMargin: 20 anchors.fill: parent spacing: 40 add: Transition { NumberAnimation { properties: "x" from: parent.width * 0.05 duration: 300 } } Image { id: tux visible: activity.dataset === "BACK_WITHOUT_CENTS" || activity.dataset === "BACK_WITH_CENTS" source: Activity.url + "/tux.svg" sourceSize.height: column.itemStoreHeight sourceSize.width: column.itemStoreHeight Repeater { id: tuxMoney Image { source: Activity.url + modelData.img sourceSize.height: column.itemStoreHeight * 0.4 x: tux.x + index * 20 y: tux.y + tux.height / 2 + index * 20 } } } Repeater { id: store Image { source: Activity.url + modelData.img sourceSize.height: column.itemStoreHeight sourceSize.width: column.itemStoreHeight GCText { text: modelData.price fontSize: 16 font.weight: Font.DemiBold style: Text.Outline styleColor: "black" color: "white" anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: index % 2 == 0 ? 0 : parent.height - height } } } } } // == The instructions Area == Rectangle { id: instructionsArea height: instructions.height width: column.width color: "#55333333" border.color: "black" border.width: 2 radius: 5 anchors.topMargin: 4 anchors.bottomMargin: 4 anchors.leftMargin: 10 anchors.rightMargin: 10 visible: bar.level === 1 property int realHeight: bar.level === 1 ? height + column.spacing : 0 GCText { id: instructions horizontalAlignment: Text.AlignHCenter width: column.width height: column.height / 6 wrapMode: Text.WordWrap fontSizeMode: Text.Fit } } // === The Pocket Area === - Rectangle { + MoneyArea { id: pocketArea - height: (column.itemHeight + 10) * column.nbLines - width: column.width - color: "#661111AA" - border.color: "black" - border.width: 2 - radius: 5 - - Flow { - anchors.topMargin: 4 - anchors.bottomMargin: 4 - anchors.leftMargin: 10 - anchors.rightMargin: 10 - anchors.fill: parent - spacing: 10 - - add: Transition { - NumberAnimation { - properties: "x" - from: parent.width * 0.05 - easing.type: Easing.InOutQuad - } - } - - move: Transition { - NumberAnimation { - properties: "x,y" - easing.type: Easing.InOutQuad - } - } - - Repeater { - id: pocket - model: ListModel { id: pocketModel } - Image { - source: Activity.url + img - sourceSize.height: column.itemHeight - height: column.itemHeight - - property bool selected: false - - MultiPointTouchArea { - anchors.fill: parent - onReleased: Activity.pay(index) - } - Rectangle { - width: parent.width * 1.1 - height: parent.height * 1.1 - color: "#88111111" - anchors.centerIn: parent - radius: 5 - visible: selected - z: -1 - } - } - } - } + onTransaction: Activity.pay(index) } } Keys.onPressed: { if(event.key === Qt.Key_Tab) { - if(items.area.count !== 0 && items.itemIndex !== -1) - items.area.itemAt(items.itemIndex).selected = false + if(items.selectedArea.count !== 0 && items.itemIndex !== -1) + items.selectedArea.itemAt(items.itemIndex).selected = false - if(items.pocketFocus) { - items.pocketFocus = false - items.area = answer + if(items.selectedArea == items.pocket) { + items.selectedArea = items.answer } else { - items.pocketFocus = true - items.area = pocket + items.selectedArea = items.pocket } items.itemIndex = 0 } - if(items.area.count !== 0) { + if(items.selectedArea.count !== 0) { if(items.itemIndex >= 0) - items.area.itemAt(items.itemIndex).selected = false + items.selectedArea.itemAt(items.itemIndex).selected = false if(event.key === Qt.Key_Right) { - if(items.itemIndex != (items.area.count-1)) + if(items.itemIndex != (items.selectedArea.count-1)) items.itemIndex++ else items.itemIndex = 0 } if(event.key === Qt.Key_Left) { if(items.itemIndex > 0) items.itemIndex-- else - items.itemIndex = items.area.count-1 + items.itemIndex = items.selectedArea.count-1 } - if([Qt.Key_Space, Qt.Key_Return].indexOf(event.key) != -1 && items.itemIndex !== -1 ) { - if(items.pocketFocus) + if([Qt.Key_Space, Qt.Key_Enter, Qt.Key_Return].indexOf(event.key) != -1 && items.itemIndex !== -1 ) { + if(items.selectedArea == items.pocket) Activity.pay(items.itemIndex) else Activity.unpay(items.itemIndex) if(items.itemIndex > 0) items.itemIndex-- } } - if(items.area.count !== 0 && items.itemIndex !== -1) - items.area.itemAt(items.itemIndex).selected = true + if(items.selectedArea.count !== 0 && items.itemIndex !== -1) + items.selectedArea.itemAt(items.itemIndex).selected = true } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar content: BarEnumContent { value: help | home | level } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/money/money.js b/src/activities/money/money.js index 5277d8e10..dd44ac123 100644 --- a/src/activities/money/money.js +++ b/src/activities/money/money.js @@ -1,785 +1,784 @@ /* GCompris - money.js * * Copyright (C) 2014 Bruno Coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (Qt Quick port) * * 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 "qrc:/gcompris/src/core/core.js" as Core .import GCompris 1.0 as GCompris var url = "qrc:/gcompris/src/activities/money/resource/" // We create 3 prices categories to make the game more realistic. // List of images to use in the game (cheap objects) var cheapObjects = [ "apple.svg", "orange.svg", "banane.svg", "pamplemousse.svg", "carot.svg", "cerise.svg", "cake.svg" ] var normalObjects = [ "umbrella.svg", "pencil.svg", "bottle.svg", "light.svg", "eggpot.svg" ] var expensiveObjects = [ "lamp.svg", "football.svg", "bicycle.svg" ] var moneyItems = { MONEY_EURO_COIN_1C: { img: "c1c.svg", val: 0.01 }, MONEY_EURO_COIN_2C: { img: "c2c.svg", val: 0.02 }, MONEY_EURO_COIN_5C: { img: "c5c.svg", val: 0.05 }, MONEY_EURO_COIN_10C: { img: "c10c.svg", val: 0.1 }, MONEY_EURO_COIN_20C: { img: "c20c.svg", val: 0.20 }, MONEY_EURO_COIN_50C: { img: "c50c.svg", val: 0.5 }, MONEY_EURO_COIN_1E: { img: "c1e.svg", val: 1.0 }, MONEY_EURO_COIN_2E: { img: "c2e.svg", val: 2.0 }, MONEY_EURO_PAPER_5E: { img: "n5e.svg", val: 5.0 }, MONEY_EURO_PAPER_10E: { img: "n10e.svg", val: 10.0 }, MONEY_EURO_PAPER_20E: { img: "n20e.svg", val: 20.0 }, MONEY_EURO_PAPER_50E: { img: "n50e.svg", val: 50.0 }, } var fullDataset = { WITHOUT_CENTS: [ { numberOfItem: 1, minPrice: 3, maxPrice: 10, pocket: [ moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 1, minPrice: 10, maxPrice: 20, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 2, minPrice: 20, maxPrice: 30, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 2, minPrice: 30, maxPrice: 40, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 3, minPrice: 40, maxPrice: 50, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 3, minPrice: 50, maxPrice: 60, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 60, maxPrice: 70, pocket: [ moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 70, maxPrice: 80, pocket: [ moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 50, maxPrice: 100, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E ] } ], WITH_CENTS: [ { numberOfItem: 1, minPrice: 1, maxPrice: 3, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C, ] }, { numberOfItem: 1, minPrice: 1, maxPrice: 3, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 2, minPrice: 1, maxPrice: 3, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C, ] }, { numberOfItem: 3, minPrice: 1, maxPrice: 3, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 4, minPrice: 0, maxPrice: 4, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C, ] } ], BACK_WITHOUT_CENTS: [ { numberOfItem: 1, minPrice: 3, maxPrice: 9, paid: 10, pocket: [ moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, ] }, { numberOfItem: 1, minPrice: 1, maxPrice: 19, paid: 20, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 2, minPrice: 2, maxPrice: 29, paid: 30, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 2, minPrice: 2, maxPrice: 39, paid: 40, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 3, minPrice: 3, maxPrice: 49, paid: 50, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 3, minPrice: 3, maxPrice: 60, paid: 100, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 4, maxPrice: 70, paid: 100, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 4, maxPrice: 80, paid: 100, pocket: [ moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E ] }, { numberOfItem: 4, minPrice: 4, maxPrice: 99, paid: 100, pocket: [ moneyItems.MONEY_EURO_PAPER_10E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_5E, moneyItems.MONEY_EURO_PAPER_5E ] } ], BACK_WITH_CENTS: [ { numberOfItem: 1, minPrice: 1, maxPrice: 3, paid: 5, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 1, minPrice: 1, maxPrice: 3, paid: 5, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 2, minPrice: 1, maxPrice: 3, paid: 5, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 3, minPrice: 1, maxPrice: 3, paid: 5, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] }, { numberOfItem: 4, minPrice: 0, maxPrice: 4, paid: 5, pocket: [ moneyItems.MONEY_EURO_COIN_2E, moneyItems.MONEY_EURO_COIN_1E, moneyItems.MONEY_EURO_COIN_5C, moneyItems.MONEY_EURO_COIN_2C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_50C, moneyItems.MONEY_EURO_COIN_20C, moneyItems.MONEY_EURO_COIN_10C, moneyItems.MONEY_EURO_COIN_1C, moneyItems.MONEY_EURO_COIN_1C ] } ] } var currentLevel var numberOfLevel var dataset var items var centsMode var backMode var priceTotal function start(items_, datasetName) { items = items_ switch(datasetName) { case "WITHOUT_CENTS": dataset = fullDataset.WITHOUT_CENTS centsMode = false backMode = false break case "WITH_CENTS": dataset = fullDataset.WITH_CENTS centsMode = true backMode = false break case "BACK_WITHOUT_CENTS": dataset = fullDataset.BACK_WITHOUT_CENTS centsMode = false backMode = true break case "BACK_WITH_CENTS": dataset = fullDataset.BACK_WITH_CENTS centsMode = true backMode = true break } currentLevel = 0 numberOfLevel = dataset.length initLevel() } function stop() { } function initLevel() { items.bar.level = currentLevel + 1 items.answerModel.clear() items.pocketModel.clear() var data = dataset[currentLevel] var pocket = Core.shuffle(data.pocket) for (var i in pocket) items.pocketModel.append(pocket[i]) // fill up the store in a random way var storeModel = new Array() priceTotal = Math.floor(data.minPrice + Math.random() * (data.maxPrice - data.minPrice)) var priceCounter = 0 for(var i = 0; i < data.numberOfItem; i++) { var price if(i < data.numberOfItem - 1) // Calc a random price for each item based on the previous prices price = Math.floor((centsMode ? 0 : 1) + Math.random() * ((priceTotal - priceCounter) / data.numberOfItem)) else // Put the remaining missing price on the last item price = priceTotal - priceCounter var cents = 0 if(centsMode) { if(currentLevel === 0) cents += 0.10 + Math.floor(Math.random() * 9) / 10 else cents += 0.01 + Math.floor(Math.random() * 9) / 100 priceTotal += cents price += cents } var locale = GCompris.ApplicationSettings.locale if(locale == "system") { locale = Qt.locale().name == "C" ? "en_US" : Qt.locale().name } var priceText = Number(price).toLocaleCurrencyString(Qt.locale(locale)) if(!centsMode) { // Strip floating part priceText = priceText.replace((/.00/), "") } storeModel.push({img: getRandomObject(price), price: priceText}) priceCounter += price } items.store.model = storeModel if(!backMode) { items.instructions.text = qsTr("Click on the coins or paper money at the bottom of the screen to pay." + " If you want to remove a coin or note, click on it on the upper screen area.") } else { var tuxMoney switch(data.paid) { case 5: tuxMoney = [moneyItems.MONEY_EURO_PAPER_5E] break case 10: tuxMoney = [moneyItems.MONEY_EURO_PAPER_10E] break case 20: tuxMoney = [moneyItems.MONEY_EURO_PAPER_20E] break case 30: tuxMoney = [moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_10E] break case 40: tuxMoney = [moneyItems.MONEY_EURO_PAPER_20E, moneyItems.MONEY_EURO_PAPER_20E] break case 50: tuxMoney = [moneyItems.MONEY_EURO_PAPER_50E] break case 100: tuxMoney = [moneyItems.MONEY_EURO_PAPER_50E, moneyItems.MONEY_EURO_PAPER_50E] break } items.tuxMoney.model = tuxMoney var tuxTotal = 0 for(var i=0; i < tuxMoney.length; i++) tuxTotal += tuxMoney[i].val var locale = GCompris.ApplicationSettings.locale if(locale == "system") { locale = Qt.locale().name == "C" ? "en_US" : Qt.locale().name } var priceText = Number(tuxTotal).toLocaleCurrencyString(Qt.locale(locale)) if(!centsMode) { // Strip floating part priceText = priceText.replace((/.00/), "") } /* The money sign is inserted based on the current locale */ items.instructions.text = qsTr("Tux just bought some items in your shop.\n" + "He gives you %1, please give back his change.") .arg(priceText) } //Keyboard reset items.itemIndex = -1 - items.pocketFocus = true - items.area = items.pocket + items.selectedArea = items.pocket } // Given a price return a random object function getRandomObject(price) { var list if(price < 5) list = cheapObjects else if(price < 10) list = normalObjects else list = expensiveObjects return list[Math.floor(Math.random() * list.length)] } function checkAnswer() { var paid = 0 for (var i = 0; i < items.answerModel.count; ++i) paid += items.answerModel.get(i).val paid = paid.toFixed(2) if(!backMode) { if(paid === priceTotal.toFixed(2)) items.bonus.good("flower") } else { if(paid === (dataset[currentLevel].paid - priceTotal).toFixed(2)) items.bonus.good("flower") } } function pay(index) { items.audioEffects.play(url + "money1.wav") // Add it to the anwser items.answerModel.append(items.pocketModel.get(index)) // Remove it from the pocket items.pocketModel.remove(index, 1) checkAnswer() } function unpay(index) { items.audioEffects.play(url + "money2.wav") // Add it to the pocket items.pocketModel.append(items.answerModel.get(index)) // Remove it from the Answer items.answerModel.remove(index, 1) checkAnswer() } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); }