rp_11001/assets/Game/scripts/game/TotalWin.ts
TJH f466306084
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m19s
代码整理
2025-12-22 16:17:40 +08:00

102 lines
3.9 KiB
TypeScript

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);
this.scheduleOnce(() => {
AudioManager.instance.playSFX('Total_Settle_Sound_End');
}, 0.5)
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()
}
}