pubgv3/assets/scripts/UI/task/mission_chooseDetail.js
guoqing.zhu 20d0a96752 add
2022-06-04 22:14:38 +08:00

145 lines
2.8 KiB
JavaScript

const {
all_ItemConfig,
playerConfig,
dropItemConfig,
} = require('../../game/gameConfig');
const NetManage = require('../../manages/NetManage');
cc.Class({
extends: cc.Component,
properties: {
nd_closeBtn: {
default: null,
type: cc.Node,
},
nd_gun: {
default: null,
type: cc.Node,
},
nd_hero: {
default: null,
type: cc.Node,
},
nd_gunContent: {
default: null,
type: cc.Node,
},
nd_heroContent: {
default: null,
type: cc.Node,
},
pb_hero: {
default: null,
type: cc.Prefab,
},
pb_gun: {
default: null,
type: cc.Prefab,
},
},
init(data) {
console.log(JSON.stringify(data))
this.allHasGot = new Array()
for(let i=0;i<data.length;i+=1){
if(data[i]) this.allHasGot.push(data[i].hero_uniid)
}
this.set()
},
close() {
this.nd_heroContent.children.forEach((element) => {
element.scale = 1;
});
this.nd_gunContent.children.forEach((element) => {
element.scale = 1;
});
this.node.active = false;
this.currentData = null;
},
set() {
this.nd_gunContent.destroyAllChildren();
this.nd_heroContent.destroyAllChildren();
NetManage.getHeroList((data) => {
var list = data.hero_list;
list.forEach((element) => {
const node = cc.instantiate(this.pb_hero);
var sc = node.getComponent('herochoseone');
sc.initdata(element);
node.on('click', () => {
this.nd_heroContent.children.forEach((element) => {
element.scale = 1;
});
this.nd_gunContent.children.forEach((element) => {
element.scale = 1;
});
node.scale = 1.1;
this.currentData = element;
});
//set cover
if (
this.allHasGot.includes(element.hero_uniid.toString())
) {
node.getComponent('wantedHero').showCover();
}
this.nd_heroContent.addChild(node);
});
});
NetManage.gunList((data) => {
var list = data.gun_list;
list.forEach((element) => {
const node = cc.instantiate(this.pb_gun);
var sc = node.getComponent('guns_single');
sc.init(element);
node.on('click', () => {
this.nd_heroContent.children.forEach((element) => {
element.scale = 1;
});
this.nd_gunContent.children.forEach((element) => {
element.scale = 1;
});
node.scale = 1.1;
this.currentData = element;
});
this.nd_gunContent.addChild(node);
});
});
},
onClickComfirm() {
if (this.currentData != null) {
// console.log("current send data:"+JSON.stringify(this.currentData))
cc.Notifier.emit('hasChoose', this.currentData);
this.close();
}
},
onClickHero() {
this.nd_hero.active = true;
this.nd_gun.active = false;
},
onClickGun() {
this.nd_hero.active = false;
this.nd_gun.active = true;
},
});