152 lines
4.1 KiB
JavaScript
152 lines
4.1 KiB
JavaScript
|
|
import BridgeComp from "bridge.component";
|
||
|
|
import TowerMod from "startower.mod";
|
||
|
|
import ItemLay from "cmp.common.itemlayout";
|
||
|
|
import StartowerEvent from "startower.define"
|
||
|
|
cc.Class({
|
||
|
|
extends: BridgeComp,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
awardBar:{
|
||
|
|
default:null,
|
||
|
|
type:cc.ProgressBar
|
||
|
|
},
|
||
|
|
togLay:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
togNd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
showNd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
list:{
|
||
|
|
default:null,
|
||
|
|
type:ItemLay
|
||
|
|
},
|
||
|
|
boxs:{
|
||
|
|
default:[],
|
||
|
|
type:[cc.Node]
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// LIFE-CYCLE CALLBACKS:
|
||
|
|
|
||
|
|
onLoad () {
|
||
|
|
this._super();
|
||
|
|
this.awards = game.configs.star_tower_data.data_get_floor_award;
|
||
|
|
this.pro_list = [0.2,0.5,1];
|
||
|
|
this.box_data = {};
|
||
|
|
|
||
|
|
this.bindGEvent( StartowerEvent.Update_Reward_Event, this.updateBoxAwards.bind( this ) );
|
||
|
|
},
|
||
|
|
|
||
|
|
start () {
|
||
|
|
|
||
|
|
},
|
||
|
|
onDestroy(){
|
||
|
|
this.awards = null;
|
||
|
|
this.pro_list = null;
|
||
|
|
},
|
||
|
|
|
||
|
|
onDisable(){
|
||
|
|
this.list.rebuild([]);
|
||
|
|
this.unbindGEvents();
|
||
|
|
},
|
||
|
|
|
||
|
|
onEnable(){
|
||
|
|
this.updateBoxAwards();
|
||
|
|
},
|
||
|
|
|
||
|
|
updateBoxAwards(){
|
||
|
|
let max_tower = TowerMod.getInstance().getNowTowerId() || 0;
|
||
|
|
let arr = this.sortAwards();
|
||
|
|
//每三十層換一輪
|
||
|
|
let floor_awards = [];
|
||
|
|
for(let i in arr){
|
||
|
|
let seq = arr[i];
|
||
|
|
if(max_tower >= seq[0].tower && max_tower <= seq[2].tower){
|
||
|
|
floor_awards = seq;
|
||
|
|
break;
|
||
|
|
}else if(max_tower < seq[0].tower){
|
||
|
|
floor_awards = seq;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
// else if(max_tower > seq[2].tower){
|
||
|
|
// floor_awards = seq;
|
||
|
|
// break;
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
|
||
|
|
//刷新進度條
|
||
|
|
this.awardBar.progress = 0;
|
||
|
|
for(let floor = 0;floor < floor_awards.length;floor++){
|
||
|
|
this.createBox(floor,floor_awards[floor],max_tower);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
createBox(order,cfg,max_tower){
|
||
|
|
let box = this.boxs[order];
|
||
|
|
this.box_data[order] = cfg;
|
||
|
|
let award_status = TowerMod.getInstance().getRewardDataById(cfg.id);
|
||
|
|
let tog = nx.gui.find(box,"tog");
|
||
|
|
nx.gui.setSpriteFrame(tog,"bg",cc.js.formatStr("prefab/pve/startower/ui/%s",order+1));
|
||
|
|
nx.gui.setSpriteFrame(tog,"check",cc.js.formatStr("prefab/pve/startower/ui/%s",(order+1)*10+(order+1)));
|
||
|
|
nx.gui.setString(tog,"bg/txt",cc.js.formatStr(nx.text.getKey("RankArriInfo"),cfg.tower));
|
||
|
|
nx.gui.setString(tog,"check/txt",cc.js.formatStr(nx.text.getKey("RankArriInfo"),cfg.tower));
|
||
|
|
if(max_tower >= cfg.tower){
|
||
|
|
this.awardBar.progress = this.pro_list[order];
|
||
|
|
if(!award_status || award_status.status <= 1){
|
||
|
|
nx.gui.setActive(tog,"check",false);
|
||
|
|
nx.gui.setActive(tog,"bg",true);
|
||
|
|
}else{
|
||
|
|
nx.gui.setActive(tog,"check",true);
|
||
|
|
nx.gui.setActive(tog,"bg",false);
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
nx.gui.setActive(tog,"check",false);
|
||
|
|
nx.gui.setActive(tog,"bg",true);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
sortAwards(){
|
||
|
|
let new_list = [];
|
||
|
|
let index = 0;
|
||
|
|
let arr = [];
|
||
|
|
for(let i in this.awards){
|
||
|
|
if(index < 3){
|
||
|
|
arr.push(this.awards[i]);
|
||
|
|
index++;
|
||
|
|
if(index >= 3){
|
||
|
|
index = 0;
|
||
|
|
new_list.push(arr);
|
||
|
|
arr = [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return new_list;
|
||
|
|
},
|
||
|
|
|
||
|
|
onClickShowAward(_index){
|
||
|
|
let data = this.box_data[_index];
|
||
|
|
if(data){
|
||
|
|
this.list.rebuild(data.award || []);
|
||
|
|
this.showNd.active = true;
|
||
|
|
this.showNd.x = this.boxs[_index].x + 150;
|
||
|
|
this.showNd.y = this.boxs[_index].y + 50;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
onHideAward(){
|
||
|
|
this.showNd.active = false;
|
||
|
|
},
|
||
|
|
|
||
|
|
onClickAllGift(){
|
||
|
|
TowerMod.getInstance().sender11328(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
// update (dt) {},
|
||
|
|
});
|