Stack With Friends Demo
import QtQuick 2.0
import Felgo 3.0
import "../common"
Item {
anchors.fill: gameScene.gameWindowAnchorItem
property string dialogState
function publishLevel() {
if(levelEditor.currentLevelNameString === qsTr("Unnamed")) {
dialogState = "enterLevelNameInPublishing"
nativeUtils.displayTextInput("Enter levelName", "Enter a level name before you can publish this level. Choose a name that expresses what makes your level special.", "", levelEditor.currentLevelNameString)
return
}
if(!gameNetwork.isUserNameSet(gameNetwork.userName)) {
dialogState = "enterUserName"
nativeUtils.displayTextInput("Enter your name", "Before you can publish this level, enter your userName that will be shown to all other players.", "", gameNetwork.userName)
return
}
levelEditor.saveCurrentLevel()
levelEditor.publishLevel()
if(cameFromScene === "menu") {
mainItem.state = "menu"
} else {
mainItem.state = "selectLevel"
}
}
Connections {
id: nativeUtilsConnection
target: nativeUtils
onTextInputFinished: {
if(accepted) {
if(dialogState === "enterLevelName" || dialogState === "enterLevelNameInPublishing") {
if(enteredText.indexOf(' ') !== -1) {
nativeUtils.displayMessageBox("Invalid level name", "No whitespaces allowed!")
return
}
if(enteredText.length > 20) {
nativeUtils.displayMessageBox("Invalid level name", "A maximum of 20 characters is allowed!")
return
}
if(gameNetwork.isValidUserInput(enteredText) && enteredText !== qsTr("Unnamed")) {
levelEditor.saveCurrentLevel( {levelMetaData: {levelName: enteredText}} )
if(dialogState ==="enterLevelNameInPublishing") {
publishLevel()
}
} else {
nativeUtils.displayMessageBox("Invalid level name", "You entered an invalid level name. Please do not use any swear words for your level name.")
}
} else if(dialogState === "enterUserName") {
var validName = gameNetwork.updateUserName(enteredText)
if(!validName) {
nativeUtils.displayMessageBox(qsTr(""), qsTr("You entered an invalid username, please try a different one. The username must not start with a number or contain any swearwords."))
} else {
publishLevel()
}
}
}
dialogState = ""
}
}
MultiResolutionImage {
id: header
source: "../../assets/img/levelstore-top.png"
anchors.horizontalCenter: parent.horizontalCenter
z: 1
opacity: gameScene.state != "levelEditing" ? 0.5 : 1
visible: gameScene.state === "levelEditing" || gameScene.state === "testing"
Item {
width: 39
height: 39
y: -1
x: 5
MultiResolutionImage {
source: "../../assets/img/back-button.png"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
if(gameScene.state === "levelEditing" || gameScene.state === "testing") {
gameScene.entitySelected(null)
levelEditor.saveCurrentLevel({levelMetaData: {levelName: levelEditor.currentLevelNameString}})
}
gameScene.stopGame()
if(cameFromScene === "menu") {
mainItem.state = "menu"
} else {
mainItem.state = "selectLevel"
}
}
}
}
Row {
id: headerRow
z: 1
spacing: 20
x: 64
MenuButton {
text: "Balance"
onClicked: itemEditor.visible = !itemEditor.visible
active: itemEditor.visible
clickable: levelEditor.isCurrentLevelOfLocation(levelEditor.authorGeneratedLevelsLocation)
}
MenuButton {
text: gameScene.state === "testing" ? "Edit" : "Test"
onClicked: {
if(text === "Edit")
gameScene.state = "levelEditing"
else {
gameScene.entitySelected(null)
gameScene.state = "testing"
}
}
clickable: levelEditor.isCurrentLevelOfLocation(levelEditor.authorGeneratedLevelsLocation)
}
MenuButton {
id: changeLevelNameButton
text: "Level Name"
onClicked: {
dialogState = "enterLevelName"
nativeUtils.displayTextInput("Enter levelName", "Enter a level name before you can publish this level. Choose a name that expresses what makes your level special.", "", levelEditor.currentLevelNameString)
}
clickable: gameScene.state === "levelEditing"
}
MenuButton {
text: "Publish"
onClicked: {
publishLevel()
}
clickable: gameScene.state === "levelEditing" && levelEditor.isCurrentLevelOfLocation(levelEditor.authorGeneratedLevelsLocation)
}
MenuButton {
text: "Delete"
onClicked: {
levelEditor.removeCurrentLevel()
mainItem.state = "selectLevel"
}
clickable: gameScene.state === "levelEditing"
}
}
}
MultiResolutionImage {
id: buildButtons
source: "../../assets/img/obstacle-buttons.png"
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
z: 1
property bool hide: false
visible: gameScene.state === "levelEditing" && !hide
Row {
spacing: 10
anchors.horizontalCenter: parent.horizontalCenter
y: 5
BuildEntityButton {
toCreateEntityTypeUrl: Qt.resolvedUrl("../entities/ObstacleBlock.qml")
width: 32
height: 32
Item {
width: parent.width
height: parent.height
Image {
source: "../../assets/img/block.png"
width: 16
height: 16
}
Image {
source: "../../assets/img/block.png"
width: 16
height: 16
x: 16
}
Image {
source: "../../assets/img/block.png"
width: 16
height: 16
y: 16
}
Image {
source: "../../assets/img/block.png"
width: 16
height: 16
x: 16
y: 16
}
}
onEntityWasBuilt: {
var entity = entityManager.getEntityById(builtEntityId)
gameScene.entitySelected(entity)
entity.entityState = "entitySelected"
}
}
BuildEntityButton {
toCreateEntityTypeUrl: Qt.resolvedUrl("../entities/ObstacleTriangle.qml")
width: 32
height: 32
Image {
width: parent.width
height: parent.height
source: "../../assets/img/block2.png"
}
onEntityWasBuilt: {
var entity = entityManager.getEntityById(builtEntityId)
gameScene.entitySelected(entity)
entity.entityState = "entitySelected"
}
}
}
}
Image {
visible: gameScene.state === "levelEditing"
width: 16
height: 16
source: "../../assets/img/hide-obstacle-buttons.png"
anchors.left: buildButtons.right
anchors.bottom: buildButtons.bottom
Text {
text: buildButtons.hide ? "+" : "-"
anchors.centerIn: parent
color: "red"
font.pixelSize: 16
}
MouseArea {
anchors.fill: parent
onClicked: buildButtons.hide = !buildButtons.hide
}
}
MultiResolutionImage {
source: "../../assets/img/gamescene-top.png"
anchors.horizontalCenter: parent.horizontalCenter
z: 1
opacity: 0.5
visible: gameScene.state == "playing"
Item {
width: 39
height: 39
x: 12
y: -1
MultiResolutionImage {
source: "../../assets/img/back-button.png"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
gameScene.stopGame()
if(cameFromScene === "menu") {
mainItem.state = "menu"
} else {
mainItem.state = "selectLevel"
}
}
}
}