import { _decorator, Button, Component, Label, Node, Prefab, sp, Sprite, Tween, tween, UIOpacity, v3, Vec3 } from 'cc'; import { NodePoolManager } from '../../../Loading/scripts/manager/NodePoolManager'; import { gold2cash } from '../../../Loading/scripts/comm'; import { AudioManager } from '../../../Loading/scripts/manager/AudioManager'; const { ccclass, property } = _decorator; @ccclass('TotalWin') export class TotalWin extends Component { @property(Prefab) totalWinUiPre: Prefab = null; totalWinUINode: Node = null; freeSpinTimes: Label = null; totalWinNodeOpacity: UIOpacity | null = null; totalWinSpine: sp.Skeleton | null = null; totalWinSprite: Sprite | null = null; NumNodeOpacityCom: UIOpacity | null = null; scoreLabel: Label | null = null; // 分数节点 winScore: number = 0; // 最终赢分 btn: Button | null = null; closeCallBack: (() => void) | null = null; show(winScore: number, totalFreeTimes: number, closeCallBack: (() => void) | null = null) { this.totalWinUINode = NodePoolManager.instance.getNodeFromPoolStatic('totalWinUI', this.totalWinUiPre); this.totalWinSpine = this.totalWinUINode.getChildByName('spine').getComponent(sp.Skeleton); let titleNode = this.totalWinSpine.node.getChildByName('TitleNode'); this.totalWinNodeOpacity = titleNode.getComponent(UIOpacity); this.totalWinNodeOpacity.opacity = 255; this.totalWinSprite = titleNode.getChildByName('TOTALWIN').getComponent(Sprite); this.freeSpinTimes = titleNode.getChildByPath('freeSpin/spinTime').getComponent(Label); this.freeSpinTimes.string = totalFreeTimes.toString() let numNode = this.totalWinSpine.node.getChildByName('NumNode'); this.NumNodeOpacityCom = numNode.getComponent(UIOpacity); this.NumNodeOpacityCom.opacity = 255; this.scoreLabel = numNode.getChildByName('Label').getComponent(Label); Tween.stopAllByTarget(this.NumNodeOpacityCom.node); let btnNode = this.totalWinSpine.node.getChildByName('BtnNode'); this.btn = btnNode.getChildByName('btnCollect').getComponent(Button); this.btn.node.on(Button.EventType.CLICK, this.onClose, this); this.winScore = winScore; this.scoreLabel.string = gold2cash(winScore); this.btn.node.active = false; this.node.addChild(this.totalWinUINode); this.playAnimation(); AudioManager.instance.playSFX('Total_Settle_Sound'); this.closeCallBack = closeCallBack; } playAnimation() { this.totalWinSpine.clearTracks(); this.totalWinSpine.setAnimation(0, 'animation', true); this.totalWinSpine.node.setScale(0, 0, 0) this.totalWinSpine.node.getComponent(UIOpacity).opacity = 0 tween(this.totalWinSpine.node) .to(0.5, { scale: new Vec3(1, 1, 1) }) .call(() => { this.btn.node.active = true; this.scheduleOnce(() => { this.onClose(); }, 5) }) .start() tween(this.totalWinSpine.node.getComponent(UIOpacity)) .to(0.5, { opacity: 255 }) .start() } // 加入回调 onClose() { this.btn.node.off(Button.EventType.CLICK, this.onClose, this); // AudioManager.instance.playSFX('Total_Settle_Collect_Click'); this.scheduleOnce(() => { AudioManager.instance.playSFX('Total_Settle_Sound_End'); }, 0.5) // this.fadeOutScoreLabel(1.7, 0.6); this.btn.node.active = false; this.unscheduleAllCallbacks(); tween(this.totalWinSpine.node) .to(0.5, { scale: new Vec3(0, 0, 0) }) .call(() => { this.totalWinUINode.removeFromParent(); NodePoolManager.instance.putNodeToPool('totalWinUI', this.totalWinUINode); this.closeCallBack && this.closeCallBack(); }) .start() tween(this.totalWinSpine.node.getComponent(UIOpacity)) .to(0.5, { opacity: 0 }) .start() } // fadeOutScoreLabel(delay: number, duration: number) { // // 先停止可能正在进行的动画 // Tween.stopAllByTarget(this.NumNodeOpacityCom.node); // // 确保标签是可见的 // this.NumNodeOpacityCom.opacity = 255; // // 创建并执行渐隐动画 // tween(this.NumNodeOpacityCom) // .delay(delay) // .to(duration, { opacity: 0 }) // .start(); // // 先停止可能正在进行的动画 // Tween.stopAllByTarget(this.totalWinNodeOpacity.node); // // 确保标签是可见的 // this.totalWinNodeOpacity.opacity = 255; // // 创建并执行渐隐动画 // tween(this.totalWinNodeOpacity) // .delay(delay) // .to(duration, { opacity: 0 }) // .start(); // } }