import { all_ItemConfig } from '../../game/gameConfig'; import { arrtoarr } from '../../tools/utilsts'; const { ccclass, property } = cc._decorator; @ccclass export class UIGuns extends cc.Component { @property(cc.Node) gun_tableview: cc.Node = null; @property(cc.Prefab) single_prefab: cc.Node = null; @property(cc.Node) listContent: cc.Node = null; @property(cc.Node) btns: cc.Node = null; private _data = null; private btnMap = new Map(); onLoad() { cc.Notifier.on('gunList', this, this.initdata.bind(this)); for (let i = 0; i < this.btns.childrenCount; i += 1) { this.btnMap.set(`${i}`, this.btns.children[i]); } } onDestroy() { cc.Notifier.off('gunList', this); } initdata(data, type = 0) { this._data = data; const list = data.gun_list; let newlist = []; if (type != 0) { list.forEach((element) => { const config = all_ItemConfig[element.gun_id]; console.log(config); 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, }); } onChange(data) { this.btnMap.forEach((element, key) => { if (data.name.includes(element.name)) { this.initdata(this._data, key); } }); } onclose() { this.node.destroy(); } }