pubgv3/assets/scripts/UI/task/mission_chooseDetail.js
zhuguoqing 53febf2dc4 update
2022-05-28 10:31:45 +08:00

210 lines
4.7 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,
},
nd_upperNode: {
default: null,
type: cc.Node,
},
},
init(data) {
this.allParam = new Array();
if (data.param1) {
this.initNeedIcon(data.param1, 0);
this.allParam.push(data.param1.toString());
}
if (data.param2) {
this.initNeedIcon(data.param2, 1);
this.allParam.push(data.param2.toString());
}
if (data.param3) {
this.initNeedIcon(data.param3, 2);
this.allParam.push(data.param3.toString());
}
if (data.param4) {
this.initNeedIcon(data.param4, 3);
this.allParam.push(data.param4.toString());
}
if (data.param5) {
this.initNeedIcon(data.param5, 4);
this.allParam.push(data.param5.toString());
}
this.allParam.forEach((param) => {
if (param.toString()[0] == '2') {
var pp = dropItemConfig[param.toString()].link_sort;
this.allParam.push(pp.toString());
}
});
},
initNeedIcon(param, index) {
var count = param.toString().length;
var url = '';
if (count == 1) {
url = `textures/wanted/ocupation_${param}`;
} else {
if (param.toString()[0] == '3') {
url = `textures/wanted/role_${param}`;
} else if (param.toString()[0] == '7') {
url = `textures/wanted/weapon_${param}`;
} else if (param.toString()[0] == '2') {
var pp = dropItemConfig[param.toString()].link_sort;
url = `textures/wanted/weapon_${pp}`;
}
}
if (url != '') {
cc.loader.loadRes(url, cc.SpriteFrame, (err, res) => {
if (err) {
return false;
}
var paramp = param;
if (param.toString()[0] == '2') {
paramp =
dropItemConfig[param.toString()].link_sort.toString();
}
this.nd_upperNode.children[index].name = `${paramp}`;
this.nd_upperNode.children[index].getComponent(
cc.Sprite
).spriteFrame = res;
this.nd_upperNode.children[index].active = true;
});
}
},
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;
},
onLoad() {
this.nd_gunContent.destroyAllChildren();
this.nd_heroContent.destroyAllChildren();
NetManage.getHeroList((data) => {
var list = data.hero_list;
// console.log(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;
});
var type = playerConfig[element.hero_id].herotype;
//set cover
if (
this.allParam.includes(element.hero_id.toString()) ||
this.allParam.includes(type.toString())
) {
node.getComponent('wantedHero').hideCover();
}
//
this.nd_heroContent.addChild(node);
});
});
NetManage.gunList((data) => {
var list = data.gun_list;
// console.log(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.allParam.includes(element.gun_id.toString())) {
node.getComponent('wantedHero').hideCover();
}
this.nd_gunContent.addChild(node);
});
});
},
onClickComfirm() {
if (this.currentData != null) {
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;
},
});