import { _decorator, Component, Label, Node, tween, Vec3 } from 'cc';
import { Clips } from './Enums';
import { AudioMgr } from './AudioMgr';
import { Global } from './Global';
const { ccclass, property } = _decorator;

@ccclass('TipsAction')
export class TipsAction extends Component {
    @property({ type: Label })
    level_label: Label = null;
    msg: string[] = [];
    running = false;
    start() {
        this.set_default();
    }

    set_default() {
        this.node.setPosition(0, -1000)
    }

    update(deltaTime: number) {

    }

    public show(str: string) {
        this.msg.push(str);
        // console.log("TipsAction>>>",str,this.level_label);
        if (!this.running) {
            this.play();
        }
    }

    /**
     * 
     * @returns 
     */
    private play() {
        let self = this;
        if (self.msg.length == 0) {
            self.running = false;
            return;
        }
        self.running = true;
        self.level_label.string = self.msg.shift();
        self.set_default();
        tween(self.node)
            .to(0.35, { position: new Vec3(0, 0, 0) }, Global.our_easing)
            .delay(1)
            .to(0.1, { position: new Vec3(0, 1000, 0) }, Global.our_easing)
            .call(() => {
                AudioMgr.ins.playSound(Clips.reng);
                // this.set_default();
                self.play();
            })
            .start();
    }
}

