diff --git a/src/activities/algebra_by/Algebra.qml b/src/activities/algebra_by/Algebra.qml index 922fc8fcf..515d2e476 100644 --- a/src/activities/algebra_by/Algebra.qml +++ b/src/activities/algebra_by/Algebra.qml @@ -1,179 +1,239 @@ /* GCompris - Algebra.qml * * Copyright (C) 2014 Aruna Sankaranarayanan * * 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 "algebra.js" as Activity ActivityBase { id: activity + property int speedSetting: 5 property alias operand: operand onStart: { focus = true; } pageComponent: Image { id: background source: "qrc:/gcompris/src/activities/algebra_by/resource/background.svg" fillMode: Image.PreserveAspectCrop sourceSize.width: Math.max(parent.width, parent.height) signal start signal stop Component.onCompleted: { + dialogActivityConfig.getInitialConfiguration() activity.start.connect(start) activity.stop.connect(stop) } Item { id: coreItems property alias background: background property alias bar: bar property alias bonus: bonus property alias score: score property alias balloon: balloon property alias timer: timer property GCSfx audioEffects: activity.audioEffects } - onStart: Activity.start(coreItems, otherItems, operand) + onStart: Activity.start(coreItems, otherItems, operand, speedSetting) onStop: Activity.stop() + DialogActivityConfig { + id: dialogActivityConfig + currentActivity: activity + content: Component { + Item { + property alias speedSlider: speedSlider + height: column.height + + Column { + id: column + spacing: 10 + width: parent.width + + Flow { + width: dialogActivityConfig.width + spacing: 5 + GCSlider { + id: speedSlider + width: 250 * ApplicationInfo.ratio + value: activity.speedSetting + maximumValue: 5 + minimumValue: 1 + scrollEnabled: false + } + GCText { + id: speedSliderText + text: qsTr("Speed") + fontSize: mediumSize + wrapMode: Text.WordWrap + } + } + } + } + } + + onClose: home() + onLoadData: { + if(dataToSave) { + if(dataToSave["speedSetting"]) { + activity.speedSetting = dataToSave["speedSetting"]; + } + } + } + onSaveData: { + var oldSpeed = activity.speedSetting + activity.speedSetting = dialogActivityConfig.configItem.speedSlider.value + if(oldSpeed != activity.speedSetting) { + dataToSave = {"speedSetting": activity.speedSetting}; + background.stop(); + background.start(); + } + } + } + DialogHelp { id: dialogHelpLeftRight onClose: home() } Timer { id: timer interval: 1000 onTriggered: Activity.run() } Item { width: background.width - 60 * ApplicationInfo.ratio height: background.height Bar { id: bar - content: BarEnumContent { value: help | home | level } + content: BarEnumContent { value: (help | home | level | config) } onHelpClicked: { displayDialog(dialogHelpLeftRight) } onPreviousLevelClicked: { Activity.previousLevel() } onNextLevelClicked: { Activity.nextLevel() } + onConfigClicked: { + dialogActivityConfig.active = true + displayDialog(dialogActivityConfig) + } onHomeClicked: home() } } Balloon { id: balloon onTimeout: bonus.bad("smiley") } Bonus { id: bonus Component.onCompleted: { loose.connect(Activity.run) win.connect(Activity.nextLevel) } } Score { id: score x: parent.width * 0.25 y: parent.height * 0.65 anchors.right: undefined anchors.bottom: undefined currentSubLevel: 0 numberOfSubLevels: 10 } } Item { id: otherItems property alias iAmReady: iAmReady property alias firstOp: firstOp property alias secondOp: secondOp property alias numpad: numpad property int result } NumPad { id: numpad onAnswerChanged: Activity.questionsLeft() maxDigit: ('' + otherItems.result).length + 1 } ReadyButton { id: iAmReady onClicked: Activity.run() } Flow { id: textFlow x: parent.width / 2 - width / 2 y: 80 width: parent.width / 2 height: 100 anchors.margins: 4 spacing: 10 AlgebraText { id: firstOp visible: !iAmReady.visible } AlgebraText { id: operand visible: firstOp.visible } AlgebraText { id: secondOp visible: !iAmReady.visible } AlgebraText { id: equals visible: firstOp.visible text: "=" } AlgebraText { id: result visible: !iAmReady.visible text: numpad.answer } } Keys.onPressed: { numpad.updateAnswer(event.key, true); } Keys.onReleased: { numpad.updateAnswer(event.key, false); } } diff --git a/src/activities/algebra_by/algebra.js b/src/activities/algebra_by/algebra.js index 18c6e56d5..c27ba7199 100644 --- a/src/activities/algebra_by/algebra.js +++ b/src/activities/algebra_by/algebra.js @@ -1,171 +1,171 @@ /* GCompris - algebra.js * * Copyright (C) 2014 Aruna Sankaranarayanan and Bruno Coudoin * * 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 .import "qrc:/gcompris/src/core/core.js" as Core var currentLevel var coreItems var otherItems var operand var secondOperandVal var firstOperandVal var operations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +var speedSetting var OperandsEnum = { TIMES_SIGN : "\u00D7", PLUS_SIGN : "\u002B", MINUS_SIGN : "\u2212", DIVIDE_SIGN : "\u2215" } var nbLevel = operations.length -function start(coreItems_, otherItems_, operand_) { +function start(coreItems_, otherItems_, operand_, speedSetting_) { operand = operand_ coreItems = coreItems_ otherItems = otherItems_ + speedSetting = speedSetting_ currentLevel = 0 coreItems.score.numberOfSubLevels = 10 // for multiplication and addition, the first levels will display // currentLevel * N (N behind random) // where the last levels will do: // N * currentLevel if(operand.text === OperandsEnum.TIMES_SIGN || operand.text === OperandsEnum.PLUS_SIGN) nbLevel = 2 * operations.length else nbLevel = operations.length initLevel() } function stop() { coreItems.balloon.stopMoving() } function initLevel() { coreItems.bar.level = currentLevel + 1 coreItems.score.visible = false coreItems.score.currentSubLevel = 1 operations = Core.shuffle(operations) calculateOperands() otherItems.iAmReady.visible = true otherItems.firstOp.visible = false otherItems.secondOp.visible = false coreItems.balloon.stopMoving() } function nextLevel() { if(++currentLevel >= nbLevel) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = nbLevel - 1 } initLevel(); } function calculateOperands() { switch(operand.text) { case OperandsEnum.TIMES_SIGN: firstOperandVal = coreItems.bar.level secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; case OperandsEnum.PLUS_SIGN: firstOperandVal = coreItems.bar.level secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; case OperandsEnum.MINUS_SIGN: firstOperandVal = coreItems.bar.level + 9 secondOperandVal = operations[coreItems.score.currentSubLevel - 1] break; case OperandsEnum.DIVIDE_SIGN: firstOperandVal = coreItems.bar.level * operations[coreItems.score.currentSubLevel - 1] secondOperandVal = coreItems.bar.level break; } if(currentLevel < operations.length) { otherItems.firstOp.text = firstOperandVal otherItems.secondOp.text = secondOperandVal } else { otherItems.firstOp.text = secondOperandVal // Don't forget to remove the first operations.length levels firstOperandVal -= operations.length otherItems.secondOp.text = firstOperandVal } } // Return the expected answer function getAnswer() { switch(operand.text) { case OperandsEnum.TIMES_SIGN: return (firstOperandVal * secondOperandVal) case OperandsEnum.PLUS_SIGN: return (firstOperandVal + secondOperandVal) case OperandsEnum.MINUS_SIGN: return (firstOperandVal - secondOperandVal) case OperandsEnum.DIVIDE_SIGN: return (firstOperandVal / secondOperandVal) } } function validateAnswer(screenAnswer) { return (getAnswer() === screenAnswer) } function run() { calculateOperands() otherItems.numpad.resetText() coreItems.score.visible = true otherItems.iAmReady.visible = false otherItems.firstOp.visible = true otherItems.secondOp.visible = true otherItems.numpad.answerFlag = false otherItems.result = getAnswer() - - // TODO adjusting or disabling the difficulty - coreItems.balloon.startMoving(20000) + coreItems.balloon.startMoving(100000 / speedSetting) } function questionsLeft() { if(validateAnswer(parseInt(otherItems.numpad.answer))) { otherItems.numpad.answerFlag = true if(coreItems.score.currentSubLevel < coreItems.score.numberOfSubLevels) { coreItems.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/win.wav") coreItems.score.currentSubLevel++ coreItems.timer.start() } else { coreItems.score.currentSubLevel = 1 coreItems.balloon.stopMoving() coreItems.bonus.good("smiley"); } } }