72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import { _decorator, AudioClip, clamp01, Component, easing, game, Label, Node, Sprite, Vec3 } from 'cc';
|
|
import GachaBase from '../Base/GachaBase';
|
|
import SpineAnimationHandler from '../Base/SpineAnimationHandler';
|
|
import AudioManager from '../Manager/AudioManager';
|
|
import GachaManager, { RewardConfig } from '../Manager/GachaManager';
|
|
import Utils from '../Utilities';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('FreeReward')
|
|
export default class FreeReward extends GachaBase {
|
|
@property(SpineAnimationHandler)
|
|
private animationHandler: SpineAnimationHandler;
|
|
@property(Node)
|
|
private spineRoot: Node;
|
|
@property(Node)
|
|
private rewardRoot: Node;
|
|
@property(Sprite)
|
|
private rewardSprite: Sprite;
|
|
@property(Label)
|
|
private rewardLabel: Label;
|
|
@property(AudioClip)
|
|
private openSound: AudioClip;
|
|
|
|
private _opened: boolean = false;
|
|
private _reward: RewardConfig;
|
|
|
|
protected onLoad(): void {
|
|
this.animationHandler.setListener((_, e) => {
|
|
switch (e.data.name) {
|
|
case 'open':
|
|
this.rewardRoot.setActive(true);
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
protected onEnable(): void {
|
|
this.spineRoot.setActive(false);
|
|
this.rewardRoot.setActive(false);
|
|
this._opened = false;
|
|
}
|
|
|
|
public async show() {
|
|
this.spineRoot.setActive(true);
|
|
await this.animationHandler.setAnimationAsync('appear');
|
|
this.animationHandler.addAnimation('idle', { loop: true });
|
|
}
|
|
|
|
public async open() {
|
|
if (this._opened) return;
|
|
this._opened = true;
|
|
this._reward = await GachaManager.instance.getReward();
|
|
if (this._reward) {
|
|
AudioManager.playSfx(this.openSound);
|
|
this.rewardSprite.spriteFrame = this._reward.icon;
|
|
this.rewardLabel.string = 'x' + this._reward.quantity;
|
|
await this.animationHandler.setAnimationAsync('open');
|
|
this.rewardRoot.setActive(true);
|
|
GachaManager.instance.showFloatingText(
|
|
this._reward.quantity.toString(),
|
|
this.node.worldPosition,
|
|
this._reward.icon,
|
|
);
|
|
GachaManager.instance.gachaDone();
|
|
return;
|
|
}
|
|
|
|
GachaManager.instance.gachaDone();
|
|
}
|
|
}
|