diff --git a/src/activities/number_sequence/ActivityConfig.qml b/src/activities/number_sequence/ActivityConfig.qml new file mode 100644 --- /dev/null +++ b/src/activities/number_sequence/ActivityConfig.qml @@ -0,0 +1,66 @@ +/* GCompris - ActivityConfig.qml + * + * Copyright (C) 2020 Shubham Mishra + * + * Authors: + * Shubham Mishra + * + * 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 "number_sequence.js" as Activity +import "../../core" + +Item { + id: activityConfiguration + property Item background + property alias modeBox: modeBox + width: if(background) background.width + property var availableModes: [ + { "text": qsTr("Automatic"), "value": 1 }, + { "text": qsTr("Manual"), "value": 2 } + ] + Flow { + id: flow + spacing: 5 + width: dialogActivityConfig.width + GCComboBox { + id: modeBox + model: availableModes + background: dialogActivityConfig + label: qsTr("Go to next level") + } + } + + property var dataToSave + + function setDefaultValues() { + if(dataToSave["mode"] === undefined) { + dataToSave["mode"] = 1; + modeBox.currentIndex = 0 + } + for(var i = 0 ; i < availableModes.length ; i ++) { + if(availableModes[i].value == dataToSave["mode"]) { + modeBox.currentIndex = i; + break; + } + } + } + + function saveValues() { + var newMode = availableModes[modeBox.currentIndex].value; + dataToSave = {"mode": newMode}; + Activity.initLevel(); + } +} diff --git a/src/activities/number_sequence/NumberSequence.qml b/src/activities/number_sequence/NumberSequence.qml --- a/src/activities/number_sequence/NumberSequence.qml +++ b/src/activities/number_sequence/NumberSequence.qml @@ -46,7 +46,7 @@ signal stop Component.onCompleted: { - dialogActivityConfig.getInitialConfiguration() + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -65,7 +65,7 @@ property alias imageBack: imageBack property alias imageBack2: imageBack2 property int pointIndexToClick - property int mode: 1 + property int mode } onStart: { Activity.start(items,mode,dataset,url) } @@ -246,82 +246,36 @@ onClose: home() } - DialogActivityConfig { + DialogChooseLevel { id: dialogActivityConfig - currentActivity: activity - content: Component { - Item { - property alias modeBox: modeBox - - property var availableModes: [ - { "text": qsTr("Automatic"), "value": 1 }, - { "text": qsTr("Manual"), "value": 2 } - ] - - Flow { - id: flow - spacing: 5 - width: dialogActivityConfig.width - GCComboBox { - id: modeBox - model: availableModes - background: dialogActivityConfig - label: qsTr("Go to next level") - } - } - } - } + currentActivity: activity.activityInfo onClose: home() onLoadData: { - if(dataToSave && dataToSave["mode"]) { - items.mode = dataToSave["mode"]; - } - } - onSaveData: { - var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modeBox.currentIndex].value; - if (newMode !== items.mode) { - items.mode = newMode; - dataToSave = {"mode": items.mode}; - } - if (items.mode == 1) { - bonus.win.connect(Activity.nextLevel) - } else { - bonus.win.disconnect(Activity.nextLevel) - } - Activity.initLevel(); - } - function setDefaultValues() { - for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length ; i++) { - if(dialogActivityConfig.configItem.availableModes[i].value === items.mode) { - dialogActivityConfig.configItem.modeBox.currentIndex = i; - break; - } + if(activityData && activityData["mode"]) { + items.mode = activityData["mode"]; } } } Bar { id: bar - content: BarEnumContent { value: help | home | level | config } + content: BarEnumContent { value: help | home | level | activityConfig } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() - onConfigClicked: { - dialogActivityConfig.active = true - // Set default values - dialogActivityConfig.setDefaultValues(); + onActivityConfigClicked: { displayDialog(dialogActivityConfig) } } Bonus { id: bonus - Component.onCompleted: items.mode == 1 ? win.connect(Activity.nextLevel) : win.disconnect(Activity.nextLevel) + onWin: items.mode == 1 ? Activity.nextLevel() : 1; } } } diff --git a/src/activities/number_sequence/number_sequence.js b/src/activities/number_sequence/number_sequence.js --- a/src/activities/number_sequence/number_sequence.js +++ b/src/activities/number_sequence/number_sequence.js @@ -51,6 +51,7 @@ items.bar.level = currentLevel + 1 items.pointIndexToClick = 0 loadCoordinates() + eraseSegments() loadBackgroundImage() if(mode == "drawletters" || mode == "drawnumbers") { //function to play letter sound at start @@ -80,6 +81,11 @@ items.audioVoices.append(sound) } +function eraseSegments(){ + for(var i = 0; i < items.segmentsRepeater.count; i++) + items.segmentsRepeater.itemAt(i).opacity = 0 +} + function drawSegment(pointIndex) { if (pointIndex == items.pointIndexToClick) {