Squaby Demo
import QtQuick 2.0
import Felgo 4.0
import "../common"
SquabySceneBase {
id: mainMenuScene
state: "exited"
signal playClicked
signal myLevelsClicked
signal creditsClicked
signal gameNetworkViewClicked
property string exitAction: ""
property bool exitDialogShown: false
property bool vplayLinkShown: false
MultiResolutionImage {
source: Qt.resolvedUrl("../../assets/img/bgSubmenu.png")
anchors.centerIn: parent
property int pixelFormat: 3
}
MultiResolutionImage {
id: squabyBg
source: Qt.resolvedUrl("../../assets/img/bgMainmenu.png")
anchors.centerIn: parent
}
Column {
id: menuColumn
anchors.left: parent.gameWindowAnchorItem.left
y:15
spacing: 4
MainMenuButton {
id: b1
offsetX: -80
text: qsTr("Play")
onClicked: {
mainMenuScene.state = "exited"
exitAction = "playClicked"
}
}
MainMenuButton {
id: b2
visible: false
offsetX: -60
delay: 500
text: qsTr("Levels")
onClicked: {
mainMenuScene.state = "exited"
exitAction = "myLevelsClicked"
}
}
MainMenuButton {
id: b3
offsetX: -40
delay: 1000
text: qsTr("Credits")
onClicked: {
mainMenuScene.state = "exited"
exitAction = "creditsClicked"
}
}
MainMenuButton {
id: settingsButton
slideInFromRight: false
offsetX: (system.isPlatform(System.IOS) || system.isPlatform(System.Android)) ? -410 : -310
delay: 1500
outslidedXBase: -115
Row {
id: moreSubRowMyLevels
spacing: 10
y: 1
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
MenuButton {
source: Qt.resolvedUrl("../../assets/img/menu-settings-music.png")
active: !settings.musicEnabled
onClicked: {
settings.musicEnabled ^= true
flurry.logEvent("Settings.Changed","Music",settings.musicEnabled)
}
}
MenuButton {
source: Qt.resolvedUrl("../../assets/img/menu-settings-sound.png")
active: !settings.soundEnabled
onClicked: {
settings.soundEnabled ^= true
flurry.logEvent("Settings.Changed","Sound",settings.musicEnabled)
}
}
Item {
width: adsButton.width
height: adsButton.height
visible: system.isPlatform(System.IOS) || system.isPlatform(System.Android)
MultiResolutionImage {
id: adsButton
source: Qt.resolvedUrl("../../assets/img/menu-ad-purchased.png")
visible: levelStore.noAdsGood.purchased
}
MultiResolutionImage {
source: Qt.resolvedUrl("../../assets/img/menu-ad.png")
visible: !levelStore.noAdsGood.purchased
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.scale = 1.0
if(!levelStore.noAdsGood.purchased) {
flurry.logEvent("Store","Advert")
levelStore.buyItem(levelStore.noAdsGood.itemId)
}
}
onPressed: {
parent.scale = 0.85
}
onReleased: {
parent.scale = 1.0
}
onCanceled: {
parent.scale = 1.0
}
}
}
Item {
width: fbSettingsButton.width
height: fbSettingsButton.height
visible: system.isPlatform(System.IOS) || system.isPlatform(System.Android)
MultiResolutionImage {
id: fbSettingsButton
source: Qt.resolvedUrl("../../assets/img/menu-settings-fb-on.png")
visible: gameNetwork.facebookConnectionSuccessful
}
MultiResolutionImage {
source: Qt.resolvedUrl("../../assets/img/menu-settings-fb-off.png")
visible: !gameNetwork.facebookConnectionSuccessful
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.scale = 1.0
flurry.logEvent("Store","Facebook")
gameNetworkViewClicked()
}
onPressed: {
parent.scale = 0.85
}
onReleased: {
parent.scale = 1.0
}
onCanceled: {
parent.scale = 1.0
}
}
}
MenuButton {
source: Qt.resolvedUrl("../../assets/img/menu-settings.png")
active: !settingsButton.slidedOut
onClicked: {
if(settingsButton.slidedOut) {
settingsButton.slideIn()
} else {
settingsButton.slideOut()
}
}
}
}
}
}
Image {
id: logo
anchors.left: mainMenuScene.gameWindowAnchorItem.left
anchors.leftMargin: 10
anchors.bottom: mainMenuScene.gameWindowAnchorItem.bottom
anchors.bottomMargin: 10
source: Qt.resolvedUrl("../../assets/img/felgo-logo.png")
fillMode: Image.PreserveAspectFit
height: 55
MouseArea {
anchors.fill: parent
onClicked: {
vplayLinkShown = true
flurry.logEvent("MainScene.ShowDialog.VPlayWeb")
NativeUtils.displayMessageBox(qsTr("Felgo"), qsTr("This game is built with Felgo. The source code is available in the free Felgo SDK - so you can build your own tower defense in minutes! Visit Felgo.net now?"), 2)
}
}
SequentialAnimation {
running: true
loops: -1
NumberAnimation { target: logo; property: "opacity"; to: 0.1; duration: 1200 }
NumberAnimation { target: logo; property: "opacity"; to: 1; duration: 1200 }
}
}
Connections {
target: activeScene === mainMenuScene ? NativeUtils : null
function onMessageBoxFinished(accepted) {
console.debug("the user confirmed the Ok/Cancel dialog with:", accepted)
if(accepted && exitDialogShown) {
Qt.quit()
} else if(accepted && vplayLinkShown) {
flurry.logEvent("MainScene.Show.VPlayWeb")
NativeUtils.openUrl("https://felgo.com/showcases/?utm_medium=game&utm_source=squaby&utm_campaign=squaby#squaby");
}
exitDialogShown = false
vplayLinkShown = false
}
}
onBackButtonPressed: {
exitDialogShown = true
NativeUtils.displayMessageBox(qsTr("Really quit the game?"), "", 2);
}
function enterScene() {
state = "entered"
}
states: [
State {
name: "entered"
PropertyChanges { target: squabyBg; opacity: 1 }
PropertyChanges { target: settingsButton; opacity: 1 }
StateChangeScript {
script: {
b1.slideIn();
b2.slideIn();
b3.slideIn();
}
}
},
State {
name: "exited"
PropertyChanges { target: squabyBg; opacity: 0 }
PropertyChanges { target: settingsButton; opacity: 0 }
StateChangeScript {
script: {
b1.slideOut();
b2.slideOut();
b3.slideOut();
settingsButton.slideOut();
sceneChangeTimer.start()
}
}
}
]
Timer {
id: sceneChangeTimer
interval: b3.slideDuration
onTriggered: {
if(exitAction === "playClicked") {
playClicked()
} else if(exitAction === "myLevelsClicked") {
myLevelsClicked()
} else if(exitAction === "creditsClicked") {
creditsClicked()
}
}
}
transitions: Transition {
NumberAnimation {
targets: [squabyBg,settingsButton]
duration: 900
property: "opacity"
easing.type: Easing.InOutQuad
}