import { _decorator, Component, instantiate, Label, Node, Sprite, SpriteFrame, tween, Vec3 } from 'cc'; import { GEvent } from '../../mx/module/event/GEvent'; import { ItemNumType } from '../game/GameData'; import { SpriteLoad } from '../../mx/components/SpriteLoad'; import { GBundle, GPath } from '../game/ConfigRes'; import MTools from '../../mx/tools/MTools'; import { CurrencyManager } from '../../mx/components/tween/CurrencyManager'; const { ccclass, property } = _decorator; @ccclass('ItemCount') export class ItemCount extends Component { @property(Sprite) Icon: Sprite; @property(Sprite) tiliIcon: Sprite; @property(Sprite) zuanshiIcon: Sprite; @property private ItemID: number = ItemNumType.money; protected onLoad(): void { } protected onEnable(): void { GEvent.Ins.on(GEvent.FlyMoney, this.onFly, this); } protected onDisable(): void { GEvent.Ins.off(GEvent.FlyMoney, this.onFly, this); } private _animPool: Node[] = []; onFly(flyType, startPos, num: number = 0, parent = null, count = 0) { if (flyType == ItemNumType.money) { this.onFlyMoney(startPos, num, parent, count); } else if (flyType == ItemNumType.vigour) { this.onFlyTili(startPos, num, parent, count); } else if (flyType == ItemNumType.diamond) { this.onFlyZhuanshi(startPos, num, parent, count); } } onFlyMoney(startPos: Vec3, num: number = 0, parent = null, count = 0) { if (this.ItemID == ItemNumType.money) { let endPos = this.Icon.node.worldPosition; this.node.getComponent(CurrencyManager).setFlyNode(this.Icon.node) this.node.getComponent(CurrencyManager)?.playFlyAnimation(startPos, endPos, parent, count); let lb = this.node.getChildByName("addNum")?.getComponent(Label); if (num > 0 && lb) { let tempLbNode = null; if (this._animPool.length > 0) { tempLbNode = this._animPool.pop(); } else tempLbNode = instantiate(lb.node); tempLbNode.parent = this.node; tempLbNode.setPosition(lb.node.position); tempLbNode.y += 30; let tempLb = tempLbNode.getComponent(Label); tempLb.string = "+" + MTools.formatChineseUnit({ num: num }); tween(tempLbNode).delay(1.5).call(() => { tempLbNode.active = true; }).by(0.5, { position: new Vec3(0, 50, 0) }).call(() => { tempLbNode.active = false; this._animPool.push(tempLbNode); }).start(); } } } onFlyTili(startPos: Vec3, num: number = 0, parent = null, count = 0) { if (this.ItemID == ItemNumType.money) { let endPos = this.tiliIcon.node.worldPosition; this.node.getComponent(CurrencyManager).setFlyNode(this.tiliIcon.node) this.node.getComponent(CurrencyManager)?.playFlyAnimation(startPos, endPos, parent, count); let lb = this.node.getChildByName("addNum")?.getComponent(Label); if (num > 0 && lb) { let tempLbNode = null; if (this._animPool.length > 0) { tempLbNode = this._animPool.pop(); } else tempLbNode = instantiate(lb.node); tempLbNode.parent = this.node; tempLbNode.setPosition(lb.node.position); tempLbNode.y += 30; let tempLb = tempLbNode.getComponent(Label); tempLb.string = "+" + MTools.formatChineseUnit({ num: num }); tween(tempLbNode).delay(1.5).call(() => { tempLbNode.active = true; }).by(0.5, { position: new Vec3(0, 50, 0) }).call(() => { tempLbNode.active = false; this._animPool.push(tempLbNode); }).start(); } } } onFlyZhuanshi(startPos: Vec3, num: number = 0, parent = null, count = 0) { if (this.ItemID == ItemNumType.money) { let endPos = this.zuanshiIcon.node.worldPosition; this.node.getComponent(CurrencyManager).setFlyNode(this.zuanshiIcon.node) this.node.getComponent(CurrencyManager)?.playFlyAnimation(startPos, endPos, parent, count); let lb = this.node.getChildByName("addNum")?.getComponent(Label); if (num > 0 && lb) { let tempLbNode = null; if (this._animPool.length > 0) { tempLbNode = this._animPool.pop(); } else tempLbNode = instantiate(lb.node); tempLbNode.parent = this.node; tempLbNode.setPosition(lb.node.position); tempLbNode.y += 30; let tempLb = tempLbNode.getComponent(Label); tempLb.string = "+" + MTools.formatChineseUnit({ num: num }); tween(tempLbNode).delay(1.5).call(() => { tempLbNode.active = true; }).by(0.5, { position: new Vec3(0, 50, 0) }).call(() => { tempLbNode.active = false; this._animPool.push(tempLbNode); }).start(); } } } }