All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m25s
96 lines
3.3 KiB
TypeScript
96 lines
3.3 KiB
TypeScript
import { _decorator, Button, Component, Label, Node, Prefab, sp, Sprite, Tween, tween, UIOpacity, v3 } 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;
|
|
btnNode: Node = null;
|
|
totalWinSpine: sp.Skeleton | null = null;
|
|
NumNodeOpacityCom: UIOpacity | null = null;
|
|
scoreLabel: Label | null = null; // 分数节点
|
|
winScore: number = 0; // 最终赢分
|
|
btn: Button | null = null;
|
|
|
|
closeCallBack: (() => void) | null = null;
|
|
|
|
|
|
show(winScore: number, closeCallBack: (() => void) | null = null) {
|
|
this.totalWinUINode = NodePoolManager.instance.getNodeFromPoolStatic('totalWinUI', this.totalWinUiPre);
|
|
this.totalWinSpine = this.totalWinUINode.getChildByName('spine').getComponent(sp.Skeleton);
|
|
|
|
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);
|
|
|
|
this.btnNode = this.totalWinSpine.node.getChildByName('BtnNode');
|
|
this.btn = this.btnNode.getChildByName('btnCollect').getComponent(Button);
|
|
|
|
this.btn.node.on(Button.EventType.CLICK, this.onClose, this);
|
|
|
|
this.winScore = winScore;
|
|
this.scoreLabel.string = gold2cash(winScore);
|
|
this.btnNode.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, 'in', false);
|
|
this.totalWinSpine.setCompleteListener(() => {
|
|
this.totalWinSpine.setAnimation(0, 'loop', true);
|
|
this.btnNode.active = true;
|
|
this.scheduleOnce(() => {
|
|
this.onClose();
|
|
}, 5)
|
|
})
|
|
}
|
|
|
|
// 加入回调
|
|
onClose() {
|
|
this.btn.node.off(Button.EventType.CLICK, this.onClose, this);
|
|
|
|
this.fadeOutScoreLabel(1.7, 0.6);
|
|
this.btnNode.active = false;
|
|
this.unscheduleAllCallbacks();
|
|
this.totalWinSpine.clearTracks();
|
|
this.totalWinSpine.setAnimation(0, 'out', true);
|
|
this.totalWinSpine.setCompleteListener(() => {
|
|
this.totalWinUINode.removeFromParent();
|
|
NodePoolManager.instance.putNodeToPool('totalWinUI', this.totalWinUINode);
|
|
this.closeCallBack && this.closeCallBack();
|
|
})
|
|
}
|
|
|
|
|
|
|
|
fadeOutScoreLabel(delay: number, duration: number) {
|
|
// 先停止可能正在进行的动画
|
|
Tween.stopAllByTarget(this.NumNodeOpacityCom.node);
|
|
|
|
// 确保标签是可见的
|
|
this.NumNodeOpacityCom.opacity = 255;
|
|
|
|
// 创建并执行渐隐动画
|
|
tween(this.NumNodeOpacityCom)
|
|
.delay(delay)
|
|
.to(duration, { opacity: 0 })
|
|
.start();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|