diff --git a/src/activities/railroad/Railroad.qml b/src/activities/railroad/Railroad.qml index f2c055180..ea3eb4dc1 100644 --- a/src/activities/railroad/Railroad.qml +++ b/src/activities/railroad/Railroad.qml @@ -1,176 +1,205 @@ /* GCompris - railroad.qml * * Copyright (C) 2016 YOUR NAME * * Authors: * (GTK+ version) * YOUR NAME (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.1 import "../../core" import "railroad.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Image { id: background source: Activity.resourceURL + "railroad-bg.svg" height: activity.height / 2 width: activity.width anchors.fill: parent 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 sampleList: sampleList property alias listModel: listModel property alias displayList: displayList + property alias animateFlow: animateFlow } onStart: { Activity.start(items) } onStop: { Activity.stop() } // GCText { // anchors.centerIn: parent // text: "UTKARSH TIWARI" // fontSize: largeSize // } // Top Display Area Rectangle { Flow { id: displayFlow x: 2 y: background.height / 12 Repeater { id: displayList model: listModel delegate: Image { id: wagon source: Activity.resourceURL + "loco1.svg" height: background.height / 8.5 width: background.width / (Activity.railWidthArray[0] + 1) visible: true MouseArea { id: displayWagonMouseArea hoverEnabled: true enabled: true anchors.fill: parent onClicked: { - listModel.remove(index); + if (Activity.memoryMode == true) { + listModel.remove(index); + } else { + animateFlow.stop(); + displayFlow.x = 2; + listModel.clear(); + Activity.memoryMode = true; + } } } states: State { name: "waganHover" when: displayWagonMouseArea.containsMouse PropertyChanges { target: wagon scale: 1.1 } } } } + onXChanged: { + if (displayFlow.x >= background.width) { + animateFlow.stop(); + displayFlow.x = 2; + listModel.clear(); + Activity.memoryMode = true; + } + } + PropertyAnimation { + id: animateFlow + target: displayFlow + properties: "x" + from: 2 + to: background.width + duration: 11000 + easing.type: Easing.InExpo + loops: 1 + } } ListModel { id: listModel } } // Lower Sample Wagon Display Area Rectangle { id: railCollection Flow { id: railCarriages x: 2 y: background.height / 4.7 height: background.height - (background.height / 5) width: background.width anchors.margins: 1 anchors.bottomMargin: 10 spacing: 8 flow: Flow.LeftToRight Repeater { id: sampleList model: 22 Image { id: loco source: Activity.resourceURL + "loco" + (index + 1) + ".svg" height: background.height / 7.5 width: background.width / Activity.railWidthArray[index] visible: true MouseArea { id: mouseArea hoverEnabled: true enabled: true anchors.fill: parent onClicked: { Activity.addWagon(index); } } states: State { name: "carHover" when: mouseArea.containsMouse PropertyChanges { target: loco scale: 1.1 } } } } } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar - content: BarEnumContent { value: help | home | level } + content: BarEnumContent { value: help | home | level | reload} onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() + onReloadClicked: { + Activity.reset() + } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } } } diff --git a/src/activities/railroad/railroad.js b/src/activities/railroad/railroad.js index b3df6e710..3cbfe091c 100644 --- a/src/activities/railroad/railroad.js +++ b/src/activities/railroad/railroad.js @@ -1,67 +1,106 @@ /* GCompris - railroad.js * * Copyright (C) 2016 YOUR NAME * * Authors: * (GTK+ version) * "YOUR NAME" (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 QtQuick 2.0 as Quick var currentLevel = 0 var numberOfLevel = 4 var noOfCarriages = [4, 5, 4, 4, 5] var railWidthArray = [5, 4, 3.8, 3.8, 5, 6.5, 6.5, 3.8, 6.5, 4, 4, 4, 4.5, 4, 4, 4.5, 4, 5, 5.5, 6.5, 6.5, 3.8] -var items +var memoryMode = false +var backupArray = [] +var isReset = false var resourceURL = "qrc:/gcompris/src/activities/railroad/resource/" +var items function start(items_) { items = items_ currentLevel = 0 initLevel() } function stop() { } function initLevel() { - items.bar.level = currentLevel + 1 + var index = 0; + memoryMode = false; + items.listModel.clear(); + items.displayList.model = items.listModel; + if (isReset == false) { + // Initiates a new level + backupArray = []; + for (var i = 0; i < currentLevel + 2; i++) { + if (i == (currentLevel + 1)) { + // Selects the last carriage + index = Math.floor(Math.random() * 9) + 1; + + } else { + // Selects the follow up wagons + index = Math.floor(Math.random() * 12) + 10; + } + backupArray.push(index); + items.listModel.append({"name" : index}); + (items.displayList.itemAt(items.listModel.count - 1)).source = resourceURL + "loco" + (index) + ".svg"; + (items.displayList.itemAt(items.listModel.count - 1)).width = items.background.width / (railWidthArray[index - 1] + 1); + + } + } else { + // Re-setup the same level + for ( var i = 0; i < backupArray.length; i++) { + items.listModel.append({"name" : backupArray[i]}); + (items.displayList.itemAt(items.listModel.count - 1)).source = resourceURL + "loco" + (backupArray[i]) + ".svg"; + (items.displayList.itemAt(items.listModel.count - 1)).width = items.background.width / (railWidthArray[backupArray[i] - 1] + 1); + } + isReset = false; + } + items.animateFlow.start() + items.bar.level = currentLevel + 1; } function nextLevel() { if(numberOfLevel <= ++currentLevel ) { currentLevel = 0 } initLevel(); } function previousLevel() { if(--currentLevel < 0) { currentLevel = numberOfLevel - 1 } initLevel(); } +function reset() { + isReset = true; + items.animateFlow.stop(); + initLevel(); +} + function addWagon(index) { /* Appends wagons to the display area */ items.listModel.append({"name" : index}); (items.displayList.itemAt(items.listModel.count - 1)).source = resourceURL + "loco" + (index + 1) + ".svg"; (items.displayList.itemAt(items.listModel.count - 1)).width = items.background.width / (railWidthArray[index] + 1); - - }