pubgv3/assets/scripts/UI/task/mission_choose.js
guoqing.zhu bc54ca812a update
2022-06-04 20:21:14 +08:00

244 lines
5.8 KiB
JavaScript

const {
playerConfig,
itemConfig,
dropItemConfig,
} = require('../../game/gameConfig');
const NetManage = require('../../manages/NetManage');
const { type } = require('../../netBattle/net/proto/bytebuffer');
cc.Class({
extends: cc.Component,
properties: {
mission_detail: {
default: null,
type: cc.Node,
},
// allAddNode: {
// default: null,
// type: cc.Node,
// },
missionTitle:{
default:null,
type:cc.Label
},
missionDesc:{
default:null,
type:cc.Label
},
herolistNode:{
default:null,
type:cc.Node
},
gunlistNode:{
default:null,
type:cc.Node
},
// needNode: {
// default: null,
// type: cc.Node,
// },
},
initData(data) {
console.log("mission detail:"+JSON.stringify(data))
this.allChooseHero = new Array();
this.allChooseHero.length = 5;
this.allChooseGun = new Array();
this.allChooseHero.length = 10;
// this.currentBtn = 0;
// this.allChoose.length = 5;
// this.allShowNode = new Array();
// this.missionData = data;
// this.allNeed = new Array();
// if (data.param1) {
// this.initNeedIcon(data.param1, 0);
// this.allNeed.push(data.param1.toString());
// }
// if (data.param2) {
// this.initNeedIcon(data.param2, 1);
// this.allNeed.push(data.param2.toString());
// }
// if (data.param3) {
// this.initNeedIcon(data.param3, 2);
// this.allNeed.push(data.param3.toString());
// }
// if (data.param4) {
// this.initNeedIcon(data.param4, 3);
// this.allNeed.push(data.param4.toString());
// }
// if (data.param5) {
// this.initNeedIcon(data.param5, 4);
// this.allNeed.push(data.param5.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}`;
// this.allNeed.push(pp.toString());
// }
// }
// 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.needNode.children[index].name = `${paramp}`;
// // this.needNode.children[index].getComponent(
// // cc.Sprite
// // ).spriteFrame = res;
// // this.needNode.children[index].active = true;
// // this.allShowNode.push(this.needNode.children[index]);
// });
// }
// },
onLoad() {
// cc.Notifier.on('hasChoose', this, (data) => {
// this.allAddNode.children[this.currentBtn]
// .getComponent('mission_oneBox')
// .init(data);
// this.allChoose[this.currentBtn] = data;
// this.setIcon();
// });
// cc.Notifier.on('ClearOneBox', this, (data) => {
// this.allChoose[data] = null;
// this.setIcon();
// });
},
setIcon() {
// this.needNode.children.forEach((element) => {
// element.children[0].active = false;
// });
// this.allChoose.forEach((data) => {
// if (data) {
// if (data.hero_id) {
// var type = playerConfig[data.hero_id].herotype;
// this.needNode.children.forEach((nd) => {
// if (
// nd.name == `${data.hero_id}` ||
// nd.name == type.toString()
// ) {
// nd.children[0].active = true;
// }
// });
// }
// if (data.gun_id) {
// this.needNode.children.forEach((nd) => {
// if (nd.name == `${data.gun_id}`) {
// nd.children[0].active = true;
// }
// });
// }
// }
// });
},
close() {
this.node.destroy();
},
onClickAdd(event, param) {
this.currentBtn = param;
this.mission_detail.active = true;
// this.mission_detail
// .getComponent('mission_chooseDetail')
// .init(this.missionData);
},
check() {
return true
// let toReturn = true;
// this.allShowNode.forEach((element) => {
// if (element.children[0].active == false) {
// toReturn = false;
// }
// });
// return toReturn;
// this.hasChooseParam = new Array();
// this.allChoose.forEach((element) => {
// if (element) {
// if (element.gun_id) {
// this.hasChooseParam.push(element.gun_id);
// }
// if (element.hero_id) {
// var type = playerConfig[element.hero_id].herotype;
// this.hasChooseParam.push(element.hero_id);
// this.hasChooseParam.push(type.toString());
// }
// }
// });
// function includes(arr1, arr2) {
// console.log(arr1);
// console.log(arr2);
// return arr2.every((val) => arr1.includes(val));
// }
// return includes(this.hasChooseParam, this.allNeed);
},
// 0:1234|1:1234
onClickSend() {
if (this.check()) {
this.sendData = '';
this.allChooseHero.forEach((element) => {
if (element) {
if (element.hero_id) {
this.sendData += `${1}:${element.hero_uniid}|`;
}
if (element.gun_id) {
this.sendData += `${0}:${element.gun_uniid}|`;
}
}
});
NetManage.sendWantedMission(
this.missionData.id,
this.sendData,
(res) => {
if (res.errcode == 0) {
this.node.destroy();
cc.Notifier.emit('ReFreshMission');
} else {
cc.uiHelper.showTips('Failed');
}
}
);
} else {
cc.uiHelper.showTips('Not meeting the requirements');
}
},
});