Squaby Demo
import QtQuick 2.0
Item {
id: upgradeWeapon
property string upgradeType: ""
property alias cost:costTag.cost
property bool affordable: player.gold>=cost
opacity: affordable && !fullyUpgraded ? 1 : 0.5
property bool fullyUpgraded: false
property int upgradeLevel: 0
property string selectedTowerId: "undefined"
property string selectedTowerType: "undefined"
property string source
signal clicked
width: upgradeWeaponSprite.width
height: upgradeWeaponSprite.height
function setUpgradeButtonFromEvent(event) {
var rangeUpgrade;
var shootDelayUpgrade;
var activeUpgrade;
for(var i=0;i<event.upgrades.length;i++) {
var upgrade = event.upgrades[i];
if(upgrade.type === "range")
rangeUpgrade = upgrade;
else if(upgrade.type === "shootDelay" || upgrade.type === "damagePerSecond")
shootDelayUpgrade = upgrade;
if(upgrade.type === upgradeType)
activeUpgrade = upgrade;
}
if(!activeUpgrade || !rangeUpgrade || !shootDelayUpgrade) {
console.log("WARNING: one of the necessary upgrades range or shootDelay not found, this should never happen!");
console.log("UpgradeWeapon: activeUpgrade: " + activeUpgrade + ", rangeUpgrade: " + rangeUpgrade + ", shootDelayUpgrade: " + shootDelayUpgrade + ", upgradeType of QML object: " + upgradeType);
return;
}
console.log("UpgradeWeapon: active upgrade is " + activeUpgrade.type);
cost = activeUpgrade.cost;
selectedTowerId = event.entityId;
selectedTowerType = event.entityType;
if(activeUpgrade.upgradeLevel === activeUpgrade.currentPlayerUpgradeLevel) {
console.debug("UpgradeWeapon: upgrade of type " + upgradeType + " is fully upgraded");
fullyUpgraded = true;
} else {
console.debug("UpgradeWeapon: upgrade of type " + upgradeType + " is not fully upgraded");
fullyUpgraded = false;
}
console.log("UpgradeWeapon: activeUpgrade.currentPlayerUpgradeLevel: " + activeUpgrade.currentPlayerUpgradeLevel + ", activeUpgrade.upgradeLevel: " + activeUpgrade.upgradeLevel + ", selectedTowerType: " + selectedTowerType);
if(activeUpgrade.type === "range") {
if(activeUpgrade.upgradeLevel === 1)
if(selectedTowerType === "nailgun")
source = "nailgunUpgradeRange.png";
else if(selectedTowerType === "flamethrower")
source = "flamethrowerUpgradeRange.png";
else if(selectedTowerType === "taser")
source = "taserUpgradeRange.png";
else if(selectedTowerType === "tesla")
source = "teslaUpgradeRange.png";
else if(selectedTowerType === "turbine")
source = "turbineUpgradeRange.png"
if(shootDelayUpgrade.currentPlayerUpgradeLevel === 1 && !fullyUpgraded)
if(selectedTowerType === "nailgun")
source = "nailgunUpgradeBoth.png";
else if(selectedTowerType === "flamethrower")
source = "flamethrowerUpgradeBoth.png";
else if(selectedTowerType === "taser")
source = "taserUpgradeBoth.png";
else if(selectedTowerType === "tesla")
source = "teslaUpgradeBoth.png";
else if(selectedTowerType === "turbine")
source = "turbineUpgradeBoth.png"
} else if(activeUpgrade.type === "shootDelay" || activeUpgrade.type === "damagePerSecond" ) {
if(upgrade.upgradeLevel === 1)
if(selectedTowerType === "nailgun")
source = "nailgunUpgradeFire.png";
else if(selectedTowerType === "flamethrower")
source = "flamethrowerUpgradeFire.png";
else if(selectedTowerType === "taser")
source = "taserUpgradeFire.png";
else if(selectedTowerType === "tesla")
source = "teslaUpgradeFire.png";
else if(selectedTowerType === "turbine")
source = "turbineUpgradeFire.png"
if(rangeUpgrade.currentPlayerUpgradeLevel === 1 && !fullyUpgraded)
if(selectedTowerType === "nailgun")
source = "nailgunUpgradeBoth.png";
else if(selectedTowerType === "flamethrower")
source = "flamethrowerUpgradeBoth.png";
else if(selectedTowerType === "taser")
source = "taserUpgradeBoth.png";
else if(selectedTowerType === "tesla")
source = "teslaUpgradeBoth.png";
else if(selectedTowerType === "turbine")
source = "turbineUpgradeBoth.png"
}
console.log("UpgradeWeapon: selected source: " + source);
}
SingleSquabySprite {
id: upgradeWeaponSprite
source: upgradeWeapon.source !== "" ? Qt.resolvedUrl("../../../assets/img/menu_labels/" + upgradeWeapon.source) : upgradeWeapon.source
}
PriceTag {
id: costTag
anchors.right: parent.right
anchors.bottom: parent.bottom
}
MouseArea {
anchors.fill: parent
onClicked: {
if(affordable && !fullyUpgraded) {
var selectedTower = entityManager.getEntityById(selectedTowerId);
if(!selectedTower) {
console.debug("UpgradeWeapon: WARNING: the tower with id '", selectedTowerId, "' was not found in the entity array! no upgrade possible!")
return;
}
if(!tutorials.nextAction("upgradeButton",upgradeType))
return
selectedTower.upgradeTower(upgradeType);
upgradeWeapon.clicked();
}