142 lines
5.0 KiB
TypeScript
142 lines
5.0 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('FreeSpinEnter')
|
|
export class FreeSpinEnter extends Component {
|
|
@property(Prefab)
|
|
freeSpinEnterPre: Prefab = null;
|
|
|
|
freeSpinEnterUI: Node = null;
|
|
btnNode: Node | null = null;
|
|
|
|
freeSpinEnterSpine: sp.Skeleton | null = null;
|
|
Node_1: Node | null = null;
|
|
numNode: Node | null = null;
|
|
contentNode: Node | null = null;
|
|
|
|
freeSpinEnterTitleSp: Sprite | null = null;
|
|
freeSpinEnterContentSp: Sprite | null = null;
|
|
NumNodeOpacityCom: UIOpacity | null = null;
|
|
freeCountLabel: Label | null = null;
|
|
freeCount: number = 0;
|
|
btn: Button | null = null;
|
|
|
|
closeCallBack: (() => void) | null = null;
|
|
|
|
show(freeCount: number, closeCallBack: (() => void) | null = null) {
|
|
AudioManager.instance.playSFX('Free_Load_Sound');
|
|
this.freeSpinEnterUI = NodePoolManager.instance.getNodeFromPoolStatic('freeSpinEnter', this.freeSpinEnterPre);
|
|
this.freeSpinEnterSpine = this.freeSpinEnterUI.getChildByName('spine').getComponent(sp.Skeleton);
|
|
this.Node_1 = this.freeSpinEnterSpine.node.getChildByName('Node');
|
|
this.numNode = this.Node_1.getChildByName('NumNode');
|
|
this.NumNodeOpacityCom = this.numNode.getComponent(UIOpacity);
|
|
this.NumNodeOpacityCom.opacity = 255;
|
|
Tween.stopAllByTarget(this.NumNodeOpacityCom.node);
|
|
this.freeCountLabel = this.numNode.getChildByName('Label').getComponent(Label);
|
|
|
|
this.contentNode = this.Node_1.getChildByName('ContentNode');
|
|
this.contentNode.getComponent(UIOpacity).opacity = 255
|
|
|
|
this.btnNode = this.Node_1.getChildByName('BtnNode');
|
|
this.btn = this.btnNode.getChildByName('BtnStart').getComponent(Button);
|
|
|
|
this.btn.node.on(Button.EventType.CLICK, this.onClose, this);
|
|
|
|
this.freeCount = freeCount;
|
|
this.freeCountLabel.string = `${freeCount}`;
|
|
this.btnNode.active = false;
|
|
this.node.addChild(this.freeSpinEnterUI);
|
|
this.playAnimation();
|
|
this.closeCallBack = closeCallBack;
|
|
}
|
|
|
|
playAnimation() {
|
|
this.freeSpinEnterSpine.clearTracks();
|
|
this.freeSpinEnterSpine.setAnimation(0, 'in', false);
|
|
this.contentNode.getComponent(UIOpacity).opacity = 0;
|
|
this.NumNodeOpacityCom.opacity = 0;
|
|
this.scheduleOnce(() => {
|
|
|
|
tween(this.NumNodeOpacityCom)
|
|
.to(0.2, { opacity: 255 })
|
|
.start();
|
|
|
|
tween(this.numNode)
|
|
.set({ scale: v3(0.5, 0.5, 0.5) })
|
|
.to(0.2, { scale: v3(1, 1, 1) })
|
|
.call(() => {
|
|
this.btnNode.active = true;
|
|
})
|
|
.start();
|
|
|
|
tween(this.contentNode.getComponent(UIOpacity))
|
|
.to(0.2, { opacity: 255 })
|
|
.start();
|
|
|
|
tween(this.contentNode)
|
|
.set({ scale: v3(0.5, 0.5, 0.5) })
|
|
.to(0.2, { scale: v3(1, 1, 1) })
|
|
.start();
|
|
|
|
}, 0.2)
|
|
|
|
|
|
this.freeSpinEnterSpine.setCompleteListener(() => {
|
|
this.freeSpinEnterSpine.setAnimation(0, 'loop', true);
|
|
this.scheduleOnce(() => {
|
|
this.onClose(false);
|
|
}, 5)
|
|
})
|
|
}
|
|
|
|
// 加入回调
|
|
onClose(isClick: boolean = true) {
|
|
if (isClick) {
|
|
AudioManager.instance.playSFX('Total_Settle_Collect_Click');
|
|
}
|
|
this.btn.node.off(Button.EventType.CLICK, this.onClose, this);
|
|
this.btnNode.active = false;
|
|
this.unscheduleAllCallbacks();
|
|
this.fadeOutScoreLabel(0.5, 0.5);
|
|
this.freeSpinEnterSpine.clearTracks();
|
|
this.freeSpinEnterSpine.setAnimation(0, 'out', true);
|
|
this.freeSpinEnterSpine.setCompleteListener(() => {
|
|
this.freeSpinEnterUI.removeFromParent();
|
|
NodePoolManager.instance.putNodeToPool('freeSpinEnter', this.freeSpinEnterUI);
|
|
this.closeCallBack && this.closeCallBack();
|
|
})
|
|
}
|
|
|
|
fadeOutScoreLabel(delay: number, duration: number) {
|
|
// 先停止可能正在进行的动画
|
|
Tween.stopAllByTarget(this.numNode);
|
|
|
|
// 确保标签是可见的
|
|
this.NumNodeOpacityCom.opacity = 255;
|
|
|
|
// 创建并执行渐隐动画
|
|
tween(this.NumNodeOpacityCom)
|
|
.delay(delay)
|
|
.to(duration, { opacity: 0 })
|
|
.start();
|
|
|
|
// 先停止可能正在进行的动画
|
|
Tween.stopAllByTarget(this.contentNode);
|
|
|
|
// 确保标签是可见的
|
|
this.contentNode.getComponent(UIOpacity).opacity = 255;
|
|
|
|
// 创建并执行渐隐动画
|
|
tween(this.contentNode.getComponent(UIOpacity))
|
|
.delay(delay)
|
|
.to(duration, { opacity: 0 })
|
|
.start();
|
|
|
|
}
|
|
}
|
|
|
|
|