123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /** @format */
- import {UI} from '../../enums/UI'
- import {BaseUI} from '../BaseUI'
- import {node, observer} from '../../mobx/observer'
- import {Data, Mgr} from '../../GameControl'
- import {EVENT, GOODS, MOD} from '../../enums/Enum'
- import {ccUtils} from '../../utils/ccUtils'
- import {GoodsConfig} from '../../config/GoodsConfig'
- const {ccclass, property} = cc._decorator
- @ccclass
- @observer
- export class CurrencyUI extends BaseUI {
- @node('goods/item')
- item: cc.Node
- goodsIDs: number[]
- items: cc.Node[]
- onShow(args, fromUI: number) {
- let isShow = false
- Mgr.goods.goodsEndPosMap.clear()
- this.goodsIDs = args
- 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
- this.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
- case GOODS.roleSoulStone:
- case GOODS.equipRuneStones:
- case GOODS.normalDrawScroll:
- case GOODS.rarelDrawScroll:
- Mgr.global.tryJumpMod(MOD.dailyGift)
- break
- case GOODS.launchLotteryCoin:
- Mgr.event.trigger(EVENT.openLotteryTask)
- break
- default:
- Mgr.global.tryJumpMod(MOD.dailyGift)
- break
- }
- }
- }
|