Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smallnumbers, add different number representations on dices #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions src/activities/gletters/FallingImage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -70,7 +70,7 @@ Item {
if (wonState)
return

var chars = text.split("");
var chars = imageText.split("");
if (chars[unmatchedIndex] == c) {
unmatchedIndex++;
return true;
Expand All @@ -88,14 +88,58 @@ 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 {
id: image
// 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
Expand Down Expand Up @@ -123,7 +167,7 @@ Item {

onStopped: {
Activity.audioCrashPlay();
Activity.appendRandomWord(word.text)
Activity.appendRandomWord(word.imageText)
Activity.deleteWord(word);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/activities/gletters/Gletters.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/activities/gletters/gletters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 62 additions & 1 deletion src/activities/smallnumbers/Smallnumbers.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}