import { _decorator, clamp01, Component, easing, game, Label, Node, Sprite, Vec3 } from 'cc'; import GachaBase from '../Base/GachaBase'; import SpineAnimationHandler from '../Base/SpineAnimationHandler'; 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; 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) { this.rewardSprite.spriteFrame = this._reward.icon; this.rewardLabel.string = 'x' + this._reward.quantity; await this.animationHandler.setAnimationAsync('open'); this.rewardRoot.setActive(true); GachaManager.instance.gachaDone(); return; } GachaManager.instance.gachaDone(); } }