175 lines
3.6 KiB
JavaScript
175 lines
3.6 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,
|
|
},
|
|
|
|
// toggle_gun:{
|
|
// default: null,
|
|
// type: cc.Node,
|
|
// },
|
|
|
|
// toggle_hero:{
|
|
// default: null,
|
|
// type: cc.Node,
|
|
// },
|
|
},
|
|
|
|
init(datahero, datagun, type) {
|
|
// hero
|
|
|
|
if (type == 0) {
|
|
this.onClickHero();
|
|
} else {
|
|
this.onClickGun();
|
|
}
|
|
|
|
this.allHasGotHero = new Array();
|
|
this.allHasGotGun = new Array();
|
|
for (let i = 0; i < datahero.length; i += 1) {
|
|
if (datahero[i]) this.allHasGotHero.push(datahero[i].hero_uniid);
|
|
}
|
|
for (let i = 0; i < datagun.length; i += 1) {
|
|
if (datagun[i]) this.allHasGotGun.push(datagun[i].gun_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.allHasGotHero.includes(
|
|
element.hero_uniid.toString()
|
|
) ||
|
|
element.lock_type != 0
|
|
) {
|
|
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;
|
|
});
|
|
|
|
if (
|
|
this.allHasGotGun.includes(element.gun_uniid.toString()) ||
|
|
element.lock_type == 3
|
|
) {
|
|
node.getComponent('wantedHero').showCover();
|
|
}
|
|
|
|
this.nd_gunContent.addChild(node);
|
|
});
|
|
});
|
|
},
|
|
|
|
onClickComfirm() {
|
|
if (this.currentData != null) {
|
|
if (this.currentData.hero_uniid) {
|
|
cc.Notifier.emit('hasChooseHero', this.currentData);
|
|
} else {
|
|
cc.Notifier.emit('hasChooseGun', this.currentData);
|
|
}
|
|
|
|
// console.log("current send data:"+JSON.stringify(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;
|
|
},
|
|
});
|