Squaby Demo
import QtQuick 2.0
import Felgo 4.0
BuildEntityButton {
id: buyTowerButton
width: buttonSprite.width
height: buttonSprite.height
property alias source: buttonSprite.source
property alias cost:priceTag.cost
property bool __affordable: player.gold>=cost
opacity: __affordable ? 1 : 0.5
enabled: __affordable
Connections {
id: buyTowerButtonConnection
function onCostChanged() {
var theNewCost = 0
if(createdEntity.entityType === "nailgun") {
theNewCost = level.balancingSettings.nailgun.cost
} else if(createdEntity.entityType === "flamethrower") {
theNewCost = level.balancingSettings.flamethrower.cost
} else if(createdEntity.entityType === "taser") {
theNewCost = level.balancingSettings.taser.cost
} else if(createdEntity.entityType === "tesla") {
theNewCost = level.balancingSettings.tesla.cost
} else if(createdEntity.entityType === "turbine") {
theNewCost = level.balancingSettings.turbine.cost
}
buyTowerButton.cost = theNewCost
}
}
onCreatedEntityChanged: {
console.debug("BuyTowerButton: createdEntityChanged to", createdEntity)
if(createdEntity) {
if(createdEntity.entityType === "nailgun") {
buyTowerButtonConnection.target = level.balancingSettings.nailgun
cost = level.balancingSettings.nailgun.cost
} else if(createdEntity.entityType === "flamethrower") {
buyTowerButtonConnection.target = level.balancingSettings.flamethrower
cost = level.balancingSettings.flamethrower.cost
} else if(createdEntity.entityType === "taser") {
buyTowerButtonConnection.target = level.balancingSettings.taser
cost = level.balancingSettings.taser.cost
} else if(createdEntity.entityType === "tesla") {
buyTowerButtonConnection.target = level.balancingSettings.tesla
cost = level.balancingSettings.tesla.cost
} else if(createdEntity.entityType === "turbine") {
buyTowerButtonConnection.target = level.balancingSettings.turbine
cost = level.balancingSettings.turbine.cost
}
console.debug("BuyTowerButton: setting cost of button to", cost)
}
}
onEntityPressed: {
selectedTowerRange.isAllowedToBuild = createdEntity.allowedToBuild;
selectedTowerRange.colliderRadius = createdEntity.colliderRadius;
selectedTowerRange.visible = true;
tutorials.nextAction(createdEntity.entityType, "pressed")
}
onEntityReleased: {
selectedTowerRange.visible = false;
}
onEntityWasBuilt: {
towerConstructEffect.play();
if(createdEntity.entityType === "nailgun")
player.nailgunsBuilt++;
else if(createdEntity.entityType === "flamethrower")
player.flamethrowersBuilt++;
else if(createdEntity.entityType === "taser")
player.tasersBuilt++;
else if(createdEntity.entityType === "tesla")
player.teslasBuilt++;
else if(createdEntity.entityType === "turbine")
player.turbinesBuilt++;
flurry.logEvent("Tower.Built", {"towerType": createdEntity.entityType, "playerGold": player.gold, "wave": player.wave});
player.gold -= cost;
tutorials.nextAction(createdEntity.entityType, "entityBuilt",Qt.point(createdEntity.x,createdEntity.y))
}
SingleSquabySprite {
id: buttonSprite
}
PriceTag {
id: priceTag
anchors.right: parent.right
anchors.bottom: parent.bottom
}
GameSoundEffect {
id: towerConstructEffect
source: Qt.resolvedUrl("../../../assets/snd/towerConstruct.wav")
}
Connections {
target: createdEntity ? createdEntity : null
function onXChanged() {
selectedTowerRange.x = createdEntity.x;
}
function onYChanged() {
selectedTowerRange.y = createdEntity.y;
}
function onAllowedToBuildChanged() {
selectedTowerRange.isAllowedToBuild = createdEntity.allowedToBuild;
}