/**************************************************************************** ** ** Copyright (C) 2011 Nokia Institute of Technology. ** All rights reserved. ** Contact: Manager (renato.chencarek@openbossa.org) ** ** This file is part of the Incredible Circus project. ** ** GNU Lesser General Public License Usage ** ** This file may be used under the terms of the GNU Lesser General Public ** License version 2.1 as published by the Free Software Foundation and ** appearing in the file LICENSE.LGPL included in the packaging of this ** file. Please review the following information to ensure the GNU Lesser ** General Public License version 2.1 requirements will be met: ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ****************************************************************************/ import QtQuick 1.1 import Circus 1.0 import "widgets" Item { id: root property int worldIndex: manager.currentWorld ? manager.currentWorld.index : -1 signal backClicked() signal selected(variant model) signal extraLevelsUnlocked() function tryToUnlockExtraLevels() { if (!manager.hasExtraLevels(worldIndex)) return; if (manager.canUnlockExtraLevels(worldIndex)) { manager.unlockExtraLevels(worldIndex) levelBottomBar.blinkButton(); } if (!manager.isExtraLevelsUnlocked(worldIndex) && manager.nfcSupport) manager.startNfc(); else manager.stopNfc(); } Connections { target: manager onNfcLevelsUnlocked: { manager.unlockExtraLevels(root.worldIndex) levelBottomBar.blinkButton(); manager.stopNfc(); } } Image { anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: 26 * scaleFactor source: "image://cache/screens/level/bg_stars.png" Image { source: "image://cache/screens/level/star.png" anchors.horizontalCenter: parent.left anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: -1 anchors.horizontalCenterOffset: 1 } Label { anchors.centerIn: parent anchors.verticalCenterOffset: 3 anchors.horizontalCenterOffset: 3 anchors.verticalCenter: parent.verticalCenter fontSize: 20 * scaleFactor color: "#a56d26" text: { var world = manager.currentWorld if (!world) return "" else return world.score + "/" + world.maximumScore } } } Item { id: levelGrid anchors.fill: parent anchors.topMargin: 28 * scaleFactor scale: 0.85 Repeater { id: icons model: manager.currentWorld ? manager.currentWorld.levels : 0 LevelIcon { id: icon property int shift: (index > 14) ? index + 1 : index x: (shift % 3) * width y: Math.floor(shift / 3) * height width: Math.floor(root.width / 3) height: Math.floor(root.height / 6) visible: { if (manager.currentWorld == null) return true; if (manager.hasExtraLevels(worldIndex) && !manager.isExtraLevelsUnlocked(worldIndex) && manager.isExtraLevel(worldIndex, index)) return false; else return true; } Connections { target: root onExtraLevelsUnlocked: { if (manager.isExtraLevel(worldIndex, index)) { icon.burnIn() visible = true; } } } locked: modelData.locked scoreType: modelData.scoreType onClicked: { if (!locked) { icon.burn(); root.selected(modelData); } } } } BottomBar { id: levelBottomBar anchors.bottom: levelGrid.bottom anchors.bottomMargin: -16 * scaleFactor Button { text: qsTr("Back") onClicked: { if (manager.nfcSupport) manager.stopNfc(); root.backClicked() } } ImageButton { id: nfcButton property int index: 0 visible: { if (manager.currentWorld != null) { return (manager.hasExtraLevels(worldIndex) && !manager.isExtraLevelsUnlocked(worldIndex)) } else return false; } source: "image://cache/screens/level/bt_nfc-unlock_levels.png" onIndexChanged: { source = "image://cache/screens/level/bt_unlocked_" + (index % 2) +".png" if (index == 8) fade.start(); } Label { id: levelsUnlocked visible: !manager.nfcSupport anchors { left: parent.left leftMargin: 27 * scaleFactor right: parent.horizontalCenter top: parent.top bottom: parent.bottom } text: qsTr("Unlock levels") fontSize: 16 * scaleFactor color: "#fde260" } Item { id: nfcLevelsUnlocked visible: manager.nfcSupport anchors.fill: parent Label { id: nfcBig anchors { left: parent.left leftMargin: 27 * scaleFactor right: parent.horizontalCenter top: parent.top topMargin: 21 * scaleFactor } horizontalAlignment: SimpleText.AlignHCenter text: "NFC" fontSize: 32 * scaleFactor color: "#fde260" } Label { anchors { left: nfcBig.left right: nfcBig.right top: nfcBig.bottom topMargin: -2 } text: qsTr("Unlock") fontSize: 14 * scaleFactor color: "#fde260" } } opacity: 0.999 onClicked: { if (!manager.nfcSupport) { remainingStars.updateValue(); remainingStars.state = "opened"; return; } nfcUnlockLoader.sourceComponent = nfcUnlock; } SequentialAnimation { id: fade PauseAnimation { duration: 500; } NumberAnimation { target: nfcButton; property: "opacity"; from: 1.0; to: 0; duration: 400; } PropertyAction { target: nfcButton; property: "visible"; value: false; } } SequentialAnimation { id: blinkUnlock NumberAnimation { target: nfcButton; property: "index"; from: 1; to: 15; duration: 1800; } ScriptAction { script: root.extraLevelsUnlocked() } } } function blinkButton() { levelsUnlocked.width = 174 * scaleFactor; levelsUnlocked.text = qsTr("Levels unlocked"); nfcLevelsUnlocked.visible = false; levelsUnlocked.visible = true; blinkUnlock.start(); } } } Component { id: nfcUnlock NfcUnlock { Connections { target: manager onNfcLevelsUnlocked: { timer.stop(); state = ""; } } Timer { id: timer interval: 4000 onTriggered: { state = ""; } } onFadeOutFinished: { nfcUnlockLoader.sourceComponent = undefined; } Component.onCompleted: { state = "opened"; manager.startNfc(); timer.start(); } } } Loader { id: nfcUnlockLoader anchors.fill: parent } RemainingStars { id: remainingStars anchors.fill: parent onOkClicked: { remainingStars.state = ""; } } }