Commit cf75c6e7 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

guessnumber, improved layout

Now use the helico in svg
Better position for messages and helico
Some code cleanup
parent 66fa5986
......@@ -25,8 +25,8 @@ import "guessnumber.js" as Activity
Rectangle {
id: answerBackground
width: 140 * ApplicationInfo.ratio
height: 70 * ApplicationInfo.ratio
width: 100 * ApplicationInfo.ratio
height: 60 * ApplicationInfo.ratio
color: activeFocus ? "#ff07fff2" : "#cccccccc"
radius: 10
border {
......@@ -34,12 +34,9 @@ Rectangle {
color: "black"
}
property string imgPath
// The backspace code comming from the vitual keyboard
property string backspaceCode
Component.onCompleted: Activity.registerAnswerItem(answerBackground)
// A top gradient
Rectangle {
anchors.fill: parent
......@@ -55,21 +52,8 @@ Rectangle {
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: Activity.registerAnswerItem(answerBackground)
}
onClicked: parent.forceActiveFocus()
Image {
id: img
anchors {
left: parent.left
leftMargin: 10
verticalCenter: parent.verticalCenter
}
height: parent.height * 0.75
width: height
source: imgPath
fillMode: Image.PreserveAspectFit
}
Keys.onPressed: {
......@@ -114,11 +98,9 @@ Rectangle {
Text {
id: userEntry
anchors {
left: img.right
verticalCenter: img.verticalCenter
leftMargin: 10
}
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "?"
color: "black"
font.pointSize: 28
......
......@@ -30,10 +30,12 @@ ActivityBase {
onStart: focus = true
onStop: {}
pageComponent: Rectangle {
pageComponent: Image {
id: background
fillMode : Image.PreserveAspectCrop
source: "resource/cave.svg"
anchors.fill: parent
color: "#ABCDEF"
signal start
signal stop
......@@ -50,7 +52,7 @@ ActivityBase {
property alias bar: bar
property alias bonus: bonus
property alias helico: helico
property alias textzone: textarea
property alias textArea: textArea
property alias infoText: userInfo
property alias answerArea: answer
}
......@@ -58,41 +60,39 @@ ActivityBase {
onStart: { Activity.start(items) }
onStop: { Activity.stop() }
Image {
id: back
anchors.fill: parent
fillMode : Image.PreserveAspectCrop
source: "resource/cave.svg"
}
Helico{
Helico {
id: helico
}
AnswerArea{
anchors.right: back.right
anchors.top: back.top
id: answer
}
Text{
id: textarea
anchors.top: back.top
Text {
id: textArea
anchors.top: parent.top
anchors.topMargin: 10
anchors.horizontalCenter: back.horizontalCenter
anchors.left: parent.left
horizontalAlignment: Text.AlignHCenter
width: parent.width - answer.width - 10
wrapMode: TextEdit.WordWrap
color: "white"
font.bold: true
font.pixelSize: 24
font.pointSize: 20
}
Text{
AnswerArea {
id: answer
anchors.right: parent.right
anchors.rightMargin: 10
anchors.top: parent.top
anchors.topMargin: 10
}
Text {
id: userInfo
anchors.top: back.top
anchors.topMargin: 40
anchors.horizontalCenter: back.horizontalCenter
color: "cyan"
anchors.top: textArea.bottom
anchors.topMargin: 15
anchors.horizontalCenter: parent.horizontalCenter
color: "white"
font.bold: true
font.pixelSize: 20
font.pointSize: 16
}
DialogHelp {
......
......@@ -19,18 +19,25 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import GCompris 1.0
Image {
id: helico
y: back.height/2
source: "resource/tuxhelico.png"
source: "resource/tuxhelico.svg"
sourceSize.height: 120 * ApplicationInfo.ratio
function init() {
x = 2
y = parent.height / 2 - height / 2
}
Behavior on x {
PropertyAnimation {
id: xAnim
easing.type: Easing.OutQuad
duration: 1000
onRunningChanged: if(!xAnim.running && helico.state=="advancing")
helico.state="horizontal"
onRunningChanged: if(!xAnim.running && helico.state == "advancing")
helico.state = "horizontal"
}
}
Behavior on y {
......@@ -39,8 +46,8 @@ Image {
transform: Rotation {
id: helicoRotation;
origin.x: helico.width/2;
origin.y: helico.height/2;
origin.x: helico.width / 2;
origin.y: helico.height / 2;
axis { x: 0; y: 0; z: 1 }
Behavior on angle {
animation: rotAnim
......
......@@ -39,10 +39,9 @@ function stop() {
function initLevel() {
items.bar.level = currentLevel + 1
items.helico.x = 0
items.helico.y = items.background.height/2
items.helico.init()
items.helico.state = "horizontal"
items.infoText.text=qsTr("")
items.infoText.text = ""
switch(currentLevel) {
case 0: currentMax = 20
numberToGuess = getRandomInt(1,currentMax)
......@@ -57,7 +56,8 @@ function initLevel() {
numberToGuess = getRandomInt(1,currentMax)
break;
}
items.textzone.text = qsTr("Guess a number between 1 and %1").arg(currentMax);
items.textArea.text = qsTr("Guess a number between 1 and %1").arg(currentMax);
items.answerArea.forceActiveFocus()
}
function nextLevel() {
......@@ -79,35 +79,28 @@ function getRandomInt(min, max) {
}
function setUserAnswer(value){
if(value==0)
if(value === 0)
return;
if(value>currentMax){
if(value > currentMax){
items.infoText.text = qsTr("Number too high")
return;
}
if(value>numberToGuess){
if(value > numberToGuess){
items.infoText.text = qsTr("Number too high")
}
if(value<numberToGuess){
if(value < numberToGuess){
items.infoText.text = qsTr("Number too low")
}
items.helico.state="advancing"
if(value==numberToGuess){
items.helico.state = "advancing"
if(value === numberToGuess) {
items.infoText.text = qsTr("Number found!")
items.bonus.good("tux")
items.helico.x = items.background.width
items.helico.y = items.background.height/2 - items.background.height/10
}
else {
items.helico.y = items.background.height / 2 - items.helico.height / 2
} else {
var diff = Math.abs(numberToGuess-value)/currentMax
items.helico.x = (items.background.width-items.helico.width)-diff*items.background.width
items.helico.y = items.background.height/2 + ((numberToGuess-value)/currentMax)*(items.background.height/2) - items.helico.height/2
items.helico.x = (items.background.width-items.helico.width) - diff * items.background.width
items.helico.y = items.background.height / 2 +
((numberToGuess-value) / currentMax) * (items.background.height/2) - items.helico.height / 2
}
}
var currentAnswerItem
function registerAnswerItem(item) {
currentAnswerItem = item
item.forceActiveFocus()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment