Platformer with Level Editor
import QtQuick 2.0
import Felgo 3.0
import "../common"
import "dialogs"
import "sceneElements"
SceneBase {
id: levelScene
property int timeLimit: 0
property string order: "created_at"
property alias removeLevelDialog: removeLevelDialog
property var activeLevelGrid
property bool demoLevelsVisible: state == "demoLevels"
property bool myLevelsVisible: state == "myLevels"
property bool myCreatedLevelsVisible: myLevelsVisible && subState == "createdLevels"
property bool myDownloadedLevelsVisible: myLevelsVisible && subState == "downloadedLevels"
property bool communityLevelsVisible: state == "communityLevels"
signal newLevelPressed
signal playLevelPressed(var levelData)
signal editLevelPressed(var levelData)
signal removeLevelPressed(var levelData)
signal backPressed
state: "myLevels"
property string subState: "createdLevels"
onStateChanged: reloadLevels()
onSubStateChanged: reloadLevels()
onTimeLimitChanged: reloadLevels()
onOrderChanged: reloadLevels()
onActiveLevelGridChanged: {
if(activeLevelGrid === communityLevelGrid) {
activeLevelGrid.startLoading()
}
else {
activeLevelGrid.finishLoading()
}
}
Rectangle {
id: background
anchors.fill: parent.gameWindowAnchorItem
gradient: Gradient {
GradientStop { position: 0.0; color: "#4595e6" }
GradientStop { position: 0.9; color: "#80bfff" }
GradientStop { position: 0.95; color: "#009900" }
GradientStop { position: 1.0; color: "#804c00" }
}
}
Rectangle {
id: mainBar
width: parent.gameWindowAnchorItem.width
height: 40
anchors.top: parent.gameWindowAnchorItem.top
anchors.left: parent.gameWindowAnchorItem.left
gradient: Gradient {
GradientStop { position: 0.0; color: "transparent" }
GradientStop { position: 0.5; color: "#80ffffff" }
GradientStop { position: 1.0; color: "transparent" }
}
Row {
height: 30
anchors.centerIn: parent
spacing: 5
PlatformerSelectableTextButton {
id: demoLevels
screenText: "Demos"
width: 80
isSelected: levelScene.state == "demoLevels"
onClicked: levelScene.state = "demoLevels"
}
PlatformerSelectableTextButton {
id: myLevels
screenText: "My Levels"
width: 80
isSelected: levelScene.state == "myLevels"
onClicked: levelScene.state = "myLevels"
}
PlatformerSelectableTextButton {
id: communityLevels
screenText: "Community"
width: 80
isSelected: levelScene.state == "communityLevels"
onClicked: levelScene.state = "communityLevels"
}
}
PlatformerImageButton {
id: menuButton
image.source: "../../assets/ui/home.png"
width: 40
height: 30
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: 5
onClicked: backPressed()
}
}
Rectangle {
id: subBar
width: parent.gameWindowAnchorItem.width
height: 40
anchors.top: mainBar.bottom
anchors.left: parent.gameWindowAnchorItem.left
anchors.topMargin: -1
gradient: Gradient {
GradientStop { position: 0.0; color: "transparent" }
GradientStop { position: 0.5; color: "#80ffffff" }
GradientStop { position: 1.0; color: "transparent" }
}
visible: myLevelsVisible || communityLevelsVisible
Row {
height: 30
anchors.centerIn: parent
spacing: 5
visible: myLevelsVisible
PlatformerImageButton {
id: newLevelButton
width: 50
height: 30
image.source: "../../assets/ui/add.png"
color: "#00d900"
onClicked: newLevelPressed()
}
PlatformerSelectableTextButton {
id: createdLevelsButton
screenText: "Created"
width: 80
isSelected: subState == "createdLevels"
onClicked: subState = "createdLevels"
}
PlatformerSelectableTextButton {
id: downloadedLevelsButton
screenText: "Downloaded"
width: 80
isSelected: subState == "downloadedLevels"
onClicked: subState = "downloadedLevels"
}
}
Row {
height: 30
anchors.centerIn: parent
spacing: 5
visible: communityLevelsVisible
PlatformerTextButton {
id: orderButton
screenText: order == "created_at" ? "Newest" : order == "average_quality" ? "Highest Rated" : order == "times_downloaded" ? "Most Downloaded" : ""
onClicked: levelOrderDialog.opacity = 1
}
PlatformerTextButton {
id: timeLimitButton
screenText: timeLimit == 0 ? "All Time" : timeLimit == 24 * 7 ? "This Week" : timeLimit == 24 ? "Today" : ""
width: orderButton.width
onClicked: levelTimeLimitDialog.opacity = 1
}
}
}
LevelGrid {
id: demoLevelGrid
visible: demoLevelsVisible
levelMetaDataArray: gameWindow.levelEditor.applicationJSONLevels
}
LevelGrid {
id: createdLevelGrid
visible: myCreatedLevelsVisible
levelMetaDataArray: gameWindow.levelEditor.authorGeneratedLevels
}
LevelGrid {
id: downloadedLevelGrid
visible: myDownloadedLevelsVisible
levelMetaDataArray: gameWindow.levelEditor.downloadedLevels
}
LevelGrid {
id: communityLevelGrid
visible: communityLevelsVisible
levelMetaDataArray: gameWindow.levelEditor.communityLevels
}
LevelOrderDialog {
id: levelOrderDialog
}
LevelTimeLimitDialog {
id: levelTimeLimitDialog
}
RemoveLevelDialog {
id: removeLevelDialog
}
UnpublishDialog {
id: unpublishDialog
}
RatingDialog {
id: ratingDialog
onLevelRated: reloadLevels()
}
function reloadLevels() {
var params = {}
if(timeLimit > 0) {
params.timeLimit = timeLimit
}
params.order = order
if(state == "demoLevels") {
levelEditor.loadAllLevelsFromStorageLocation(levelEditor.applicationJSONLevelsLocation)
activeLevelGrid = demoLevelGrid
}
else if(state == "myLevels") {
if(subState == "createdLevels") {
levelEditor.loadAllLevelsFromStorageLocation(levelEditor.authorGeneratedLevelsLocation)
activeLevelGrid = createdLevelGrid
}
else if(subState == "downloadedLevels") {
levelEditor.loadAllLevelsFromStorageLocation(levelEditor.downloadedLevelsLocation)
activeLevelGrid = downloadedLevelGrid
}
else {
console.debug("invalid subState", subState)
}
}
else if (state == "communityLevels") {
levelEditor.loadCommunityLevels(params)
activeLevelGrid = communityLevelGrid
}
else {
console.debug("invalid state", state)