const { all_ItemConfig } = require("../../game/gameConfig"); const { showLoading, closeloading } = require("../../gif/Loading"); const NetManage = require("../../manages/NetManage"); const { arrtoarr } = require("../../tools/utilsts"); cc.Class({ extends: cc.Component, properties: { gun_tableview: { default: null, type: cc.Node, }, singlePrefab: { default: null, type: cc.Prefab, }, listContent: { default: null, type: cc.Node, }, btns: { default: null, type: cc.Node, }, }, onLoad() { this.hasget = false; this.btnMap = new Map(); for (let i = 0; i < this.btns.childrenCount; i += 1) { this.btnMap.set(`${i}`, this.btns.children[i]); } showLoading(); NetManage.gunList((data) => { this.hasget = true; closeloading(); this.init(data); }); }, update() { if (this.hasget) { closeloading(); } }, startFrom(weaponBlockIndex) { this.weaponIndex = weaponBlockIndex; }, init(data, type = 0) { this._data = data; const list = data.gun_list; list.forEach((element) => { if ( window.firstgun && element.gun_uniid == window.firstgun.weapon_uniid ) { var index = list.indexOf(element); list.splice(index, 1); } if ( window.secondgun && element.gun_uniid == window.secondgun.weapon_uniid ) { var index = list.indexOf(element); list.splice(index, 1); } }); let newlist = []; if (type != 0) { list.forEach((element) => { const config = all_ItemConfig[element.gun_id]; if (config.sub_type == type) { newlist.push(element); } }); } else { newlist = data.gun_list; } newlist = arrtoarr(newlist, 3); this.gun_tableview.getComponent("tableView").initTableView(newlist.length, { array: newlist, target: this, }); closeloading(); this.listContent.children.forEach((element) => { element.children.forEach((cellGun) => { cellGun.children.forEach((gun) => { // gun.getComponent(cc.Button). gun.getComponent("guns_single").removeClickEvent(); gun.off("click", this.chooseEvent, this); gun.on("click", this.chooseEvent, this); }); }); }); }, chooseEvent(event) { var guninfo = JSON.parse(event.node.name); window.currentWeaponName = guninfo.name; cc.find("Canvas").getComponentInChildren("chooseGun").node.destroy(); for (var key in guninfo) { if (key == "name") { delete guninfo[key]; break; } } if (this.weaponIndex == 0) { window.firstgun = guninfo; } else if (this.weaponIndex == 1) { window.secondgun = guninfo; } cc.Notifier.emit( "haschooseWeapon", this.weaponIndex, `${window.currentWeaponName}` ); }, onChange(data) { this.btnMap.forEach((element, key) => { if (data.name.includes(element.name)) { this.init(this._data, key); } }); }, onclose() { this.node.destroy(); }, });