diff --git a/src/activities/bargame/ActivityConfig.qml b/src/activities/bargame/ActivityConfig.qml new file mode 100644 --- /dev/null +++ b/src/activities/bargame/ActivityConfig.qml @@ -0,0 +1,68 @@ +/* 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 "../../core" + +Item { + id: activityConfiguration + property Item background + property alias modeBox: modeBox + width: if(background) background.width + property var availableModes: [ + { "text": qsTr("Easy"), "value": 1 }, + { "text": qsTr("Medium"), "value": 2 }, + { "text": qsTr("Difficult"), "value": 3 } + ] + Flow { + id: flow + spacing: 5 + width: parent.width + GCComboBox { + id: modeBox + model: availableModes + background: activityConfiguration.background + label: qsTr("Select your difficulty") + } + } + + 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; + if (newMode != dataToSave["mode"]) { + dataToSave["mode"] = newMode; + dataToSave = {"mode": dataToSave["mode"]}; + } + } +} diff --git a/src/activities/bargame/Bargame.qml b/src/activities/bargame/Bargame.qml --- a/src/activities/bargame/Bargame.qml +++ b/src/activities/bargame/Bargame.qml @@ -42,7 +42,7 @@ property bool horizontalLayout: background.width >= background.height Component.onCompleted: { - dialogActivityConfig.getInitialConfiguration() + dialogActivityConfig.initialize() activity.start.connect(start) activity.stop.connect(stop) } @@ -369,72 +369,34 @@ onClose: home() } - DialogActivityConfig { + DialogChooseLevel { id: dialogActivityConfig - currentActivity: activity - content: Component { - Item { - property alias modeBox: modeBox - - property var availableModes: [ - { "text": qsTr("Easy"), "value": 1 }, - { "text": qsTr("Medium"), "value": 2 }, - { "text": qsTr("Difficult"), "value": 3 } - ] - - Flow { - id: flow - spacing: 5 - width: dialogActivityConfig.width - GCComboBox { - id: modeBox - model: availableModes - background: dialogActivityConfig - label: qsTr("Select your difficulty") - } - } - } - } + currentActivity: activity.activityInfo onClose: home() onLoadData: { - if(dataToSave && dataToSave["mode"]) { - items.mode = dataToSave["mode"]; + if(activityData && activityData["mode"]) { + items.mode = activityData["mode"]; } } - onSaveData: { - var newMode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modeBox.currentIndex].value; - if (newMode !== items.mode) { - items.mode = newMode; - dataToSave = {"mode": items.mode}; - } - 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; - } - } + onStartActivity: { + rootWindow.stop() + rootWindow.start() } } Bar { id: bar level: 1 - content: BarEnumContent { value: help | home | level | reload | config } + content: BarEnumContent { value: help | home | level | reload | 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) } onReloadClicked: Activity.restartLevel() diff --git a/src/activities/bargame_2players/ActivityConfig.qml b/src/activities/bargame_2players/ActivityConfig.qml new file mode 100644 --- /dev/null +++ b/src/activities/bargame_2players/ActivityConfig.qml @@ -0,0 +1,68 @@ +/* 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 "../../core" + +Item { + id: activityConfiguration + property Item background + property alias modeBox: modeBox + width: if(background) background.width + property var availableModes: [ + { "text": qsTr("Easy"), "value": 1 }, + { "text": qsTr("Medium"), "value": 2 }, + { "text": qsTr("Difficult"), "value": 3 } + ] + Flow { + id: flow + spacing: 5 + width: parent.width + GCComboBox { + id: modeBox + model: availableModes + background: activityConfiguration.background + label: qsTr("Select your difficulty") + } + } + + 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; + if (newMode != dataToSave["mode"]) { + dataToSave["mode"] = newMode; + dataToSave = {"mode": dataToSave["mode"]}; + } + } +}