CurrencyPackPage.qml Example File

demos/ChickenOutbreak2/qml/CurrencyPackPage.qml
 import QtQuick 2.0
 import Felgo 3.0

 Item {
   id: currencyPackPage
   width: scene.gameWindowAnchorItem.width
   height: scene.gameWindowAnchorItem.height
   x: scene.gameWindowAnchorItem.x
   y: scene.gameWindowAnchorItem.y

   signal boughtPack
   signal closed

   visible: opacity > 0
   enabled: visible

   onBoughtPack: {
     opacity = 0
   }
   onClosed: {
     audioManager.play(audioManager.idMENUCLICK)
     opacity = 0
   }

   property bool isMoney: true

   Rectangle {
     anchors.fill: parent
     color: "black"
     opacity: 0.9
   }

   // if the player presses the overlay, hide it
   /*MouseArea {
     anchors.fill: parent
     onClicked: {
       closed()
     }
   }*/

   Text {
     text: isMoney ? qsTr("Buy coins to get ingame items!") : qsTr("Buy Angels to save your chicken from death!")
     anchors.horizontalCenter: parent.horizontalCenter
     anchors.bottom: currencyIcon.top
     anchors.bottomMargin: 10
     color: "white"
   }

   CoinDisplay {
     id: currencyIcon
     customCoins: isMoney ? 0 : store.saveit.balance
     displayCustomCoins: !isMoney
     displayBonusCoins: false

     anchors.horizontalCenter: parent.horizontalCenter
     anchors.bottom: contentColumn.top
     anchors.bottomMargin: 10
     color: "white"
   }

   Column {
     id: contentColumn
     anchors.centerIn: parent
     width: parent.width*0.8
     spacing: 10
     CurrencyPackageElement {
       source: currencyPackPage.isMoney ? "../assets/buy_currency_1.png" : "../assets/buy_saveit_1.png"
       isMoney: currencyPackPage.isMoney
       description: isMoney ? qsTr("Buy 100 Coins") : qsTr("Buy 1 Angel")
       message: isMoney ? qsTr("Buy power ups with coins") : qsTr("Buy angel to save one chicken")
       packID: isMoney ? store.money1Pack.itemId : store.saveit1Pack.itemId
       onBought: {
         connectingScreen.visible = true
       }
     }
     CurrencyPackageElement {
       source: isMoney ? "../assets/buy_currency_2.png" : "../assets/buy_saveit_2.png"
       isMoney: currencyPackPage.isMoney
       description: isMoney ? qsTr("Buy 300 Coins") : qsTr("Buy 3 Angels")
       message: isMoney ? qsTr("Save 33 percent") : qsTr("Save 33 percent")
       packID: isMoney ? store.money2Pack.itemId : store.saveit2Pack.itemId
       onBought:  {
         connectingScreen.visible = true
       }
     }
     CurrencyPackageElement {
       source: isMoney ? "../assets/buy_currency_3.png" : "../assets/buy_saveit_3.png"
       isMoney: currencyPackPage.isMoney
       description: isMoney ? qsTr("Buy 800 Coins") : qsTr("Buy 10 Angels")
       message: isMoney ? qsTr("Save 50 percent") : qsTr("Save 60 percent")
       packID: isMoney ? store.money3Pack.itemId : store.saveit3Pack.itemId
       onBought:  {
         connectingScreen.visible = true
       }
     }
     CurrencyPackageElement {
       source: isMoney ? "../assets/buy_currency_4.png" : "../assets/buy_saveit_4.png"
       isMoney: currencyPackPage.isMoney
       description: isMoney ? qsTr("Buy 1400 Coins") : qsTr("Buy 20 Angels")
       message: isMoney ? qsTr("Save 57 percent") : qsTr("Save 70 percent")
       packID: isMoney ? store.money4Pack.itemId : store.saveit4Pack.itemId
       onBought:  {
         connectingScreen.visible = true
       }
     }
   }

   // display a dummy close sign, just to give the player a hint that he can close the achievement by pressing
   /*Text {
     text: "X"
     color: "#444444"
     font.pixelSize: 30
     anchors.right: parent.right
     font.family: fontHUD.name
     anchors.rightMargin: 8
   }*/

   MenuButton {
     anchors.horizontalCenter: parent.horizontalCenter
     anchors.bottom: parent.bottom
     anchors.bottomMargin: 20

     text: qsTr("Back")

     onClicked: closed()
   }
   // make opacity changes smooth
   Behavior on opacity {
     NumberAnimation { duration: 150}
   }

   Connections {
     target: currencyPackPage.opacity > 0 ? store : null

     onInsufficientFundsError: {
       connectingScreen.visible = false
     }
     onItemNotFoundError:  {
       connectingScreen.visible = false
     }
     onItemPurchased: {
       connectingScreen.visible = false
     }

     onStorePurchaseCancelled: {
       connectingScreen.visible = false
     }

     onStorePurchased: {
       connectingScreen.visible = false
       boughtPack()
     }
   }

   //hide this because signals from store are not emitted correctly
   Rectangle {
     id: connectingScreen
     visible: false
     anchors.fill: parent
     color: "black"
     Text {
       anchors.centerIn: parent
       text: "Connecting..."
       color: "#444444"
       font.pixelSize: 30
       font.family: fontHUD.name
     }
   }
 }

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support