/** @format */ import {node, observer} from '../mobx/observer' import {EVENT, GOODS, MOD} from '../enums/Enum' import {Mgr} from '../GameControl' import {ccUtils} from '../utils/ccUtils' import {GoodsConfig} from '../config/GoodsConfig' import {BaseUI} from '../ui/BaseUI' const {ccclass, property} = cc._decorator @ccclass @observer export class TopCell extends cc.Component { @node('goods/item') item: cc.Node goodsIDs: number[] items: cc.Node[] init(goodsIDs: GOODS[], baseUI: BaseUI) { let isShow = false Mgr.goods.goodsEndPosMap.clear() this.goodsIDs = goodsIDs let nodes, node nodes = this.items = ccUtils.instantChildren(this.item, this.goodsIDs?.length) this.item.parent.getComponent(cc.Layout).updateLayout() for (let i = 0; i < nodes.length; i++) { node = nodes[i] let goodID = this.goodsIDs[i] this.items[i]['id'] = goodID let cfg = GoodsConfig[goodID] this[`_${cfg.icon}`] = Mgr.goods.getGoodsNum(goodID) ccUtils.setLabel(Math.toKMBNum(Mgr.goods.getGoodsNum(goodID)), node, 'lb') Mgr.goods.goodsEndPosMap.set(goodID, ccUtils.convertToWorldSpaceCanvasAR(cc.find('lb', node))) //移除正在飞行的道具回调,避免重复增加 let cbArr = Mgr.goods.flyGoodsCBMap.get(goodID) if (cbArr) cbArr.length = 0 baseUI.loadTexImg(`Public/goods/${cfg.icon}`, node, 'icon') } Mgr.event.add(EVENT.goodsChangeSync, this, this.showCurrency) } onHide(): any { Mgr.goods.goodsEndPosMap.clear() Mgr.event.removeAll(this) } //网络事件======================================= //触发事件======================================= showCurrency(goodID: number, changeNum: number) { let item = this.items[this.goodsIDs.indexOf(goodID)] if (!item) return let key: string = GoodsConfig[goodID]?.icon if (!key) { console.error('CurrencyUI 道具表没有该道具') } this[`_${key}`] += changeNum ccUtils.setLabel(Math.toKMBNum(this[`_${key}`]), item, 'lb') } // 点击事件======================================= onAddClick(event) { let type = event.target.parent['id'] switch (type) { case GOODS.fatigue: Mgr.global.tryJumpMod(MOD.fatigueBuy) break case GOODS.coin: Mgr.global.tryJumpMod(MOD.moneyBuy) break case GOODS.diamond: Mgr.global.tryJumpMod(MOD.resourceStore) break } } }