invite_page/assets/scripts/progressBar.js

106 lines
3.5 KiB
JavaScript

cc.Class({
extends: cc.Component,
properties: {
barPointerPrefab: {
default: null,
type: cc.Prefab
},
barCubePrefab: {
default: null,
type: cc.Prefab
},
barPopPrefab: {
default: null,
type: cc.Prefab
},
bar: {
default: null,
type: cc.Node
},
countLabel: {
default: null,
type: cc.Label
},
barCover: {
default: null,
type: cc.Node
},
popTitles: [],
currentVal: 1024,
margin: 170,
pointArr: [],
cubeArr: []
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.countLabel.string = '当前预约人数: ' + this.currentVal;
this.barCover.width = this.parseWidth();
this.popTitle = ['预约\n即送', '1w', '3w', '5w'];
let xNum = [-245, -75, 95, 265];
let cubeTypes = ['', 'wood', 'silver', 'gold'];
let openVals = [0, 10000, 30000, 50000];
for(let i = 0; i < 4; i++) {
var pop = cc.instantiate(this.barPopPrefab);
pop.getComponent('barCountPop').title = this.popTitle[i];
if (i === 0) {
pop.getComponent('barCountPop').titleLabel.fontSize = 25;
} else {
pop.getComponent('barCountPop').titleLabel.fontSize = 30;
}
this.node.addChild(pop);
pop.setPosition(cc.v2(xNum[i], 95));
var point = cc.instantiate(this.barPointerPrefab);
point.getComponent('barLine').updateShow((this.currentVal >= openVals[i]) ? 'w' : 'b');
this.bar.addChild(point);
this.pointArr.push(point);
point.setPosition(cc.v2(xNum[i], 21));
if (i > 0) {
var cube = cc.instantiate(this.barCubePrefab);
cube.getComponent('barCube').type = cubeTypes[i];
cube.getComponent('barCube').updateShow((this.currentVal >= openVals[i]) ? 'o' : 'c');
this.node.addChild(cube);
cube.setPosition(cc.v2(xNum[i], -125));
this.cubeArr.push(cube);
}
}
},
parseWidth() {
let width = 75;
if (this.currentVal <= 10000) {
width += this.margin * this.currentVal / 10000;
} else if (this.currentVal > 10000 && this.currentVal <= 30000) {
width += (this.margin + this.margin * (this.currentVal - 10000) / 20000);
} else if (this.currentVal > 30000 && this.currentVal <= 50000) {
width += (this.margin * 2 + this.margin * (this.currentVal - 30000) / 20000);
} else if (this.currentVal > 50000 && this.currentVal <= 55000) {
width += (this.margin * 3 + 68 * (this.currentVal - 50000) / 5000);
} else {
width = this.bar.width;
}
return width;
},
start () {
},
// update (dt) {},
updateShow(val) {
console.log('update show');
this.currentVal = val;
this.countLabel.string = '当前预约人数: ' + this.currentVal;
this.barCover.width = this.parseWidth();
let openVals = [0, 10000, 30000, 50000];
for(let i = 0; i < 4; i++) {
this.pointArr[i].getComponent('barLine').updateShow((this.currentVal >= openVals[i]) ? 'w' : 'b');
}
for(let i = 0; i < 3; i++) {
this.cubeArr[i].getComponent('barCube').updateShow((this.currentVal >= openVals[i+1]) ? 'o' : 'c');
}
}
});