Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
import "../../common"
Item {
id: levelSelectionItem
property bool isDownloaded: levelEditor.isLevelDownloaded(modelData.levelId)
property bool isAuthorCreated: modelData.storageLocation == "authorGenerated"
property bool isPublished: modelData.publishedLevelId !== undefined
property bool isRated: modelData.rating !== undefined
property bool isUserLevel: modelData.storageLocation === levelEditor.userGeneratedLevelsLocation
property bool isLoggedInPlayer: (modelData && modelData.user && modelData.user.id === gameNetwork.user.userId) ? true : false
property bool ratingAndDownloadedVisible: levelScene.state == "communityLevels"
property bool playButtonVisible: levelScene.state != "demoLevels" && levelScene.state != "communityLevels"
property bool demoPlayButtonVisible: levelScene.state == "demoLevels"
property bool editButtonVisible: levelScene.state == "myLevels" && levelScene.subState == "createdLevels" && !isPublished
property bool removeButtonVisible: levelScene.state == "myLevels" && levelScene.subState == "createdLevels" && !isPublished
property bool unpublishButtonVisible: isAuthorCreated && isPublished
property bool leaderboardButtonVisible: levelScene.state == "myLevels" && levelScene.subState == "downloadedLevels" || isAuthorCreated && isPublished
property bool downloadButtonVisible: levelScene.state == "communityLevels" && !levelEditor.isLevelDownloaded(modelData.levelId) && !(isUserLevel && isLoggedInPlayer)
property bool rateButtonVisible: levelScene.state == "communityLevels" && isDownloaded
width: 110
height: modelData.user ? 70 : 65
Rectangle {
width: parent.width
height: parent.height
border.width: 1
border.color: "black"
radius: 3
gradient: {
if(isDownloaded && !isAuthorCreated || isUserLevel && isLoggedInPlayer)
return downloadedGradient
else if(isAuthorCreated && isPublished)
return publishedGradient
else
return defaultGradient
}
Gradient {
id: defaultGradient
GradientStop { position: 0.0; color: "#cccccc" }
GradientStop { position: 0.5; color: "#e0e0e0" }
GradientStop { position: 1.0; color: "#cccccc" }
}
Gradient {
id: downloadedGradient
GradientStop { position: 0.0; color: "#67e667" }
GradientStop { position: 0.5; color: "#8cff8c" }
GradientStop { position: 1.0; color: "#67e667" }
}
Gradient {
id: publishedGradient
GradientStop { position: 0.0; color: "#e6e667" }
GradientStop { position: 0.5; color: "#ffff8c" }
GradientStop { position: 1.0; color: "#e6e667" }
}
}
Text {
id: levelName
text: modelData.levelName
height: 16
anchors.top: parent.top
anchors.right: removeButton.left
anchors.left: parent.left
anchors.margins: 5
anchors.bottomMargin: 0
fontSizeMode: Text.Fit
font.pixelSize: 13
minimumPixelSize: 8
}
Text {
id: userName
text: modelData.user ? modelData.user.name : ""
height: 5
anchors.top: levelName.bottom
anchors.right: removeButton.left
anchors.left: parent.left
anchors.margins: 5
anchors.topMargin: 0
font.pixelSize: 8
}
MultiResolutionImage {
id: ratingIcon
visible: ratingAndDownloadedVisible
width: 15
height: 15
anchors.left: parent.left
anchors.bottom: downloadedIcon.top
anchors.leftMargin: 5
source: "../../../assets/ui/star.png"
}
Text {
id: ratingText
visible: ratingAndDownloadedVisible
height: ratingIcon.height
anchors.left: ratingIcon.right
anchors.verticalCenter: ratingIcon.verticalCenter
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
font.pixelSize: 10
text: {
if(modelData["average_quality"]) {
var rating = modelData["average_quality"]
var roundedRating = Math.round(rating * 10) / 10
return ""+roundedRating
}
else
return "0"
}
}
MultiResolutionImage {
id: downloadedIcon
visible: ratingAndDownloadedVisible
width: 15
height: 15
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: 5
source: "../../../assets/ui/download.png"
}
Text {
id: downloadedText
visible: ratingAndDownloadedVisible
height: downloadedIcon.height
anchors.left: downloadedIcon.right
anchors.verticalCenter: downloadedIcon.verticalCenter
anchors.leftMargin: 2
verticalAlignment: Text.AlignVCenter
font.pixelSize: 10
text: modelData["times_downloaded"] ? modelData["times_downloaded"] : "0"
}
PlatformerImageButton {
id: playButton
visible: playButtonVisible
width: 50
height: 30
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: 2
image.source: "../../../assets/ui/play.png"
onClicked: {
levelScene.playLevelPressed(modelData)
audioManager.playSound("start")
}
}
PlatformerImageButton {
id: demoPlayButton
visible: demoPlayButtonVisible
height: 30
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/play.png"
onClicked: {
levelScene.playLevelPressed(modelData)
audioManager.playSound("start")
}
}
PlatformerImageButton {
id: editButton
visible: editButtonVisible
width: 50
height: 30
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/edit.png"
onClicked: levelScene.editLevelPressed(modelData)
}
PlatformerImageButton {
id: removeButton
visible: removeButtonVisible
width: 30
height: 20
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/remove.png"
color: "#ff9999"
onClicked: {
removeLevelDialog.levelData = modelData
removeLevelDialog.opacity = 1
}
}
PlatformerImageButton {
id: unpublishButton
visible: unpublishButtonVisible
width: 30
height: 20
anchors.top: parent.top
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/remove.png"
color: "#ff9999"
onClicked: {
unpublishDialog.levelData = modelData
unpublishDialog.opacity = 1
}
}
PlatformerImageButton {
id: leaderboardButton
visible: leaderboardButtonVisible
width: 50
height: 30
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/leaderboard.png"
onClicked: {
var leaderboard = modelData.id
if(!leaderboard)
leaderboard = modelData.publishedLevelId
if(leaderboard) {
gameNetwork.showLeaderboard(leaderboard)
}
}
}
PlatformerImageButton {
id: downloadButton
visible: downloadButtonVisible
width: 40
height: 35
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: 2
image.source: "../../../assets/ui/download.png"
onClicked: levelEditor.downloadLevel(modelData)
}
PlatformerImageButton {
id: rateButton
visible: rateButtonVisible
enabled: !isRated
width: 40
height: 35
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.margins: 2
image.source: {
if(!isRated) {
"../../../assets/ui/rate.png"
}
else {
switch(modelData.rating.quality) {
case 5: return "../../../assets/ui/rate_5stars.png"
case 4: return "../../../assets/ui/rate_4stars.png"
case 3: return "../../../assets/ui/rate_3stars.png"
case 2: return "../../../assets/ui/rate_2stars.png"
default: return "../../../assets/ui/rate_1star.png"
}
}
}
onClicked: {
ratingDialog.levelData = modelData
ratingDialog.opacity = 1