From 8e8712154870cc8f638d1da463e4f9f53615e3ea Mon Sep 17 00:00:00 2001 From: Akshay Kumar Date: Thu, 8 Nov 2018 12:07:56 +0530 Subject: [PATCH] smallnumbers, add different number representations on dices --- src/activities/gletters/FallingImage.qml | 54 +++++++++++++++-- src/activities/gletters/Gletters.qml | 13 +++- src/activities/gletters/gletters.js | 10 +++- src/activities/smallnumbers/Smallnumbers.qml | 63 +++++++++++++++++++- 4 files changed, 129 insertions(+), 11 deletions(-) diff --git a/src/activities/gletters/FallingImage.qml b/src/activities/gletters/FallingImage.qml index aa9fba1f9e..e9349b7b3e 100644 --- a/src/activities/gletters/FallingImage.qml +++ b/src/activities/gletters/FallingImage.qml @@ -35,10 +35,10 @@ Item { /// index into text.split("") where next typed match should occur property int unmatchedIndex: 0; - property string text + property string imageText property alias image: image.source; property bool wonState: false - + property int mode: 1; signal won onWon: { @@ -70,7 +70,7 @@ Item { if (wonState) return - var chars = text.split(""); + var chars = imageText.split(""); if (chars[unmatchedIndex] == c) { unmatchedIndex++; return true; @@ -88,7 +88,39 @@ Item { function isCompleted() { - return (unmatchedIndex === text.length); + return (unmatchedIndex === imageText.length); + } + + function getImageText(imageText) { + if (mode == 1) { + return imageText; + } else if (mode == 2) { + if (imageText == "1") + return "I"; + else if (imageText == "2") + return "II"; + + else if (imageText == "3") + return "III"; + + else if (imageText == "4") + return "IV"; + + else if (imageText == "5") + return "V"; + + else if (imageText == "6") + return "VI"; + + else if (imageText == "7") + return "VII"; + + else if (imageText == "8") + return "VIII"; + + else if (imageText == "9") + return "IX"; + } } Image { @@ -96,6 +128,18 @@ Item { // FIXME, the size should be passed from the caller sourceSize.height: 106 * ApplicationInfo.ratio + GCText { + id: numberText + visible: ((mode == 1 || mode == 2) ? true : false) + y: 0 + fontSize: 30 + + anchors.horizontalCenter: parent.horizontalCenter + color: "white" + anchors.margins: ApplicationInfo.ratio * 5 + text: getImageText(imageText) + } + ParticleSystemStarLoader { id: particle clip: false @@ -123,7 +167,7 @@ Item { onStopped: { Activity.audioCrashPlay(); - Activity.appendRandomWord(word.text) + Activity.appendRandomWord(word.imageText) Activity.deleteWord(word); } } diff --git a/src/activities/gletters/Gletters.qml b/src/activities/gletters/Gletters.qml index a08e209feb..0d2ef02f02 100644 --- a/src/activities/gletters/Gletters.qml +++ b/src/activities/gletters/Gletters.qml @@ -34,6 +34,7 @@ ActivityBase { property string dataSetUrl: "qrc:/gcompris/src/activities/gletters/resource/" /* no need to display the configuration button for smallnumbers */ property bool configurationButtonVisible: true + property bool configurationDialogSelect: true property bool uppercaseOnly: false @@ -218,9 +219,15 @@ ActivityBase { onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onConfigClicked: { - dialogActivityConfig.active = true - dialogActivityConfig.setDefaultValues() - displayDialog(dialogActivityConfig) + if(configurationDialogSelect) { + dialogActivityConfig.active = true + dialogActivityConfig.setDefaultValues() + displayDialog(dialogActivityConfig) + } else { + diceDialogActivityConfig.active = true + diceDialogActivityConfig.setDefaultValues() + displayDialog(diceDialogActivityConfig) + } } } diff --git a/src/activities/gletters/gletters.js b/src/activities/gletters/gletters.js index 544d40e85a..32c53dd847 100644 --- a/src/activities/gletters/gletters.js +++ b/src/activities/gletters/gletters.js @@ -291,10 +291,16 @@ function createWord() var word if(items.ourActivity.getImage(text)) { + var mode = items.ourActivity.getMode(); + var images = "qrc:/gcompris/src/activities/smallnumbers/resource/dice0.svg"; + if(mode == 3) + images = items.ourActivity.getImage(text); + word = wordComponent.createObject( items.background, { - "text": text, - "image": items.ourActivity.getImage(text), + "imageText": text, + "image": images, + "mode": items.ourActivity.getMode(), // assume x=width-25px for now, Word auto-adjusts onCompleted(): "x": Math.random() * (items.main.width - 25), "y": -25, diff --git a/src/activities/smallnumbers/Smallnumbers.qml b/src/activities/smallnumbers/Smallnumbers.qml index 6cc3bcde9b..dc468160ae 100644 --- a/src/activities/smallnumbers/Smallnumbers.qml +++ b/src/activities/smallnumbers/Smallnumbers.qml @@ -30,9 +30,70 @@ Gletters { mode: "letter" dataSetUrl: "qrc:/gcompris/src/activities/smallnumbers/resource/" - configurationButtonVisible: false + configurationButtonVisible: true + configurationDialogSelect: false + QtObject { + id: items + property int mode: 1 + } + + DialogActivityConfig { + id: diceDialogActivityConfig + currentActivity: activity + content: Component { + Item { + property alias modeBox: modeBox + + property var availableModes: [ + { "text": qsTr("Numbers"), "value": 1 }, + { "text": qsTr("Romans"), "value": 2 }, + { "text": qsTr("Dots"), "value": 3 } + ] + + Flow { + id: flow + spacing: 5 + width: diceDialogActivityConfig.width + GCComboBox { + id: modeBox + model: availableModes + background: diceDialogActivityConfig + label: qsTr("Select Dice Type") + } + } + } + } + + onClose: home() + + onLoadData: { + if(dataToSave && dataToSave["mode"]) { + items.mode = dataToSave["mode"]; + } + } + onSaveData: { + var newMode = diceDialogActivityConfig.configItem.availableModes[diceDialogActivityConfig.configItem.modeBox.currentIndex].value; + if (newMode !== items.mode) { + items.mode = newMode; + dataToSave = {"mode": items.mode}; + } + activity.initLevel(); + } + function setDefaultValues() { + for(var i = 0 ; i < diceDialogActivityConfig.configItem.availableModes.length ; i++) { + if(diceDialogActivityConfig.configItem.availableModes[i].value === items.mode) { + diceDialogActivityConfig.configItem.modeBox.currentIndex = i; + break; + } + } + } + } function getImage(key) { return dataSetUrl + "dice" + key + ".svg" } + + function getMode() { + return items.mode; + } }