Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Stack With Friends Demo

 import QtQuick 2.0
 import Felgo 3.0
 import "../common"

 Item {
   id: levelItem
   // can either be "", or "shareLevel"
   property string inputState

   // for debugging the entry data
   Component.onCompleted: console.debug("modelData at completion:", JSON.stringify(modelData))

   width: 90
   height: 90

   property bool isAuthorLevel: modelData["storageLocation"] === levelEditor.authorGeneratedLevelsLocation
   property bool isUserLevel: modelData["storageLocation"] === levelEditor.userGeneratedLevelsLocation
   property bool isDownloaded: levelEditor.isLevelDownloaded(modelData.levelId)
   property bool isPublished: modelData["publishedLevelId"] !== undefined
   property bool isLoggedInPlayer: (modelData && modelData.user && modelData.user.id === gameNetwork.user.userId) ? true : false
   property bool greenTile: (isAuthorLevel && isPublished) || (isUserLevel && isLoggedInPlayer)
   property bool brownTile: (isUserLevel && isDownloaded) || levelScene.state === "myDownloadedLevels"
   property bool greyTile: ((isUserLevel && !isDownloaded) || (isAuthorLevel && !isPublished)) && !isLoggedInPlayer
   property bool displayUser: modelData["user"] !== undefined
   property bool displayScore: gameNetwork.userPositionForLeaderboard(getPublishedLevelId()) !== -1
   property bool displayRating: levelScene.state !== "myDownloadedLevels" && modelData["average_quality"] !== undefined
   property bool displayLeaderboard: ((isUserLevel || levelScene.state === "myDownloadedLevels") && (isDownloaded || isLoggedInPlayer)) || (isAuthorLevel && isPublished)
   property bool displayPurchase: (isUserLevel || levelScene.state === "myDownloadedLevels") && !isDownloaded && !isLoggedInPlayer
   property bool displayRate: levelScene.state !== "myDownloadedLevels" && (isUserLevel || levelScene.state === "myDownloadedLevels") && isDownloaded && !isLoggedInPlayer
   property bool displayInfo: (isUserLevel || levelScene.state === "myDownloadedLevels") && !isDownloaded && !isPublished

   function getPublishedLevelId() {
     // if the level has publishedLevelId, it is a local level, but the highscore should be shown for the published one!
     if(isPublished) {
       return modelData["publishedLevelId"].toString()
     } else {
       return modelData["levelId"].toString()
     }
   }

   MultiResolutionImage {
     source: "../../assets/img/levellist-item.png"
     visible: greenTile
   }

   MultiResolutionImage {
     source: "../../assets/img/levellist-item-community.png"
     visible: brownTile
   }

   MultiResolutionImage {
     source: "../../assets/img/levellist-item-notpurchased.png"
     visible: greyTile
   }

   MouseArea {
     anchors.fill: parent
     onClicked: {
       levelScene.levelSelected(modelData, isAuthorLevel, isUserLevel, isDownloaded, isPublished, isLoggedInPlayer)
     }
   }

   ResponsiveText {
     y: 7
     text: modelData["user"] ? gameNetwork.getDisplayNameFromUserName(modelData.user.name, modelData.user) : ""
     //text: modelData["user"] ? modelData.user.name : ""
     visible: displayUser
     anchors.horizontalCenter: parent.horizontalCenter
     color: "white"
     font.pixelSize: 8
     font.family: fontHUD.name
   }

   ResponsiveText {
     text: modelData.levelName
     anchors.horizontalCenter: parent.horizontalCenter
     color: "white"
     y: 17
     font.pixelSize: 12
     font.family: fontHUD.name
   }

   Text {
     y: 33
     z:10
     // the "of <totalPlayers>" takes too much space, especially at big leaderboards, so do not display it
     text: "Score: " + gameNetwork.userHighscoreForLeaderboard(getPublishedLevelId(), true) + " (#" + gameNetwork.userPositionForLeaderboard(getPublishedLevelId(), true) /*+ " of " + gameNetwork.userTotalPlayersForLeaderboard(getPublishedLevelId())*/ + ")"
     visible: displayScore
     anchors.horizontalCenter: parent.horizontalCenter
     color: "white"
     font.pixelSize: 8
     font.family: fontHUD.name
   }

   Text {
     text: "Id: " + modelData["publishedLevelId"]
     anchors.horizontalCenter: parent.horizontalCenter
     y: 45
     visible: isPublished
     font.pixelSize: 9
     color: "white"
     font.family: fontHUD.name
   }

   Item {
     y: 45
     width: 64
     anchors.horizontalCenter: parent.horizontalCenter
     visible: displayRating
     MultiResolutionImage {
       source: "../../assets/img/star-no.png"
       visible: modelData["average_quality"] < 5
     }
     Row {
       spacing: 1
       MultiResolutionImage {
         source: "../../assets/img/star.png"
         visible: modelData["average_quality"] >= 1
       }
       MultiResolutionImage {
         source: "../../assets/img/star.png"
         visible: modelData["average_quality"] >= 2
       }
       MultiResolutionImage {
         source: "../../assets/img/star.png"
         visible: modelData["average_quality"] >= 3
       }
       MultiResolutionImage {
         source: "../../assets/img/star.png"
         visible: modelData["average_quality"] >= 4
       }
       MultiResolutionImage {
         source: "../../assets/img/star.png"
         visible: modelData["average_quality"] >= 5
       }
     }
   }

   Row {
     id: buttons
     x: 6
     y: 60
     spacing: 3

     MultiResolutionImage {
       source: "../../assets/img/levellist-button.png"
       visible: displayLeaderboard
       Image {
         source: "../../assets/img/leaderboard.png"
         x: 9
         y: 4
         width: 17
         height: 12
       }

       MouseArea {
         anchors.fill: parent
         onClicked: {
           // this signal is handled in MainItem and then switched to the GameNetworkView
           levelScene.showHighscoreForLevel(getPublishedLevelId())
         }
       }
     }

     MultiResolutionImage {
       source: "../../assets/img/levellist-button.png"
       visible: displayPurchase

       Image {
         source: "../../assets/img/purchase.png"
         x: 10
         y: 4
         width: 17
         height: 12
       }

       MouseArea {
         anchors.fill: parent
         onClicked: {
           flurry.logEvent("Level.Download")
           levelScene.downloadLevelClicked(modelData)
         }
       }
     }

     MultiResolutionImage {
       source: "../../assets/img/levellist-button.png"
       visible: displayRate
       Text {
         text: "Rate"
         x: 8
         y: 4
         font.pixelSize: 9
         opacity: (modelData && modelData["rating"]) ? 0.5 : 1
         font.family: fontHUD.name
       }
       MouseArea {
         anchors.fill: parent
         onClicked: {
           flurry.logEvent("Level.Rate",modelData.levelName,modelData.average_quality)
           levelScene.rateLevelClicked(modelData)
         }
       }
     }

     MultiResolutionImage {
       source: "../../assets/img/levellist-button.png"
       visible: displayInfo
       Text {
         text: "Info"
         x: 8
         y: 4
         font.pixelSize: 9
         font.family: fontHUD.name
       }
       MouseArea {
         anchors.fill: parent
         onClicked: {
           flurry.logEvent("Level.ShowInfo","levelName",modelData.levelName)
           levelScene.showInfoClicked(modelData)
         }
       }
     }

     MultiResolutionImage {
       source: "../../assets/img/levellist-button.png"
       visible: isPublished
       Image {
         source: "../../assets/img/unpublish.png"
         x: 9
         y: 4
         width: 17
         height: 12
       }
       MouseArea {
         anchors.fill: parent
         onClicked: {
           flurry.logEvent("Level.Unpublish","levelName",modelData.levelName)
           levelScene.unpublishLevelClicked(modelData)
         }
       }
     }
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded