// pg.event.on('layer_ending_touch_replay', () => {
//     alert('replay')
// })
// pg.event.on('layer_ending_touch_next', () => {
//     alert('next')
// })
// pg.event.emit('layer_ending_show')
import pg from "../../scene/pg_hy17_hds";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LayerEnding extends cc.Component {
    private layer_center: cc.Node;
    private replay_btn: cc.Node;
    private next_btn: cc.Node;
    onLoad() {
        this.layer_center = pg.view.find(this.node, "layer_center")
        pg.view.visible(this.layer_center, false);
        this.replay_btn = pg.view.find(this.layer_center, "replay_btn")
        this.next_btn = pg.view.find(this.layer_center, "next_btn")
        pg.view.touchOn(this.replay_btn, this.onTouchReplay, this)
        pg.view.touchOn(this.next_btn, this.onTouchNext, this)
        pg.event.on('layer_ending_show', (data) => {
            this.showLayer(data);
        })
    }
    showLayer(data) {
        pg.view.visible(this.layer_center, true)
        pg.view.setString(pg.view.find(this.layer_center, 'finish_box/coin_num'), 'X' + data.coin);

        let finish_cat = pg.view.find(this.layer_center, "finish_cat")
        pg.view.playDBAnimation(finish_cat, "finish", 1); 
        let bg_light = pg.view.find(this.layer_center, "bg_light")
        cc.tween(bg_light).by(2, { angle: 360 }).repeatForever().start();
        pg.view.visible(this.layer_center, true)
    }

    onTouchReplay() {
        pg.view.visible(this.layer_center, false)
        pg.event.emit('layer_ending_touch_replay');
    }

    onTouchNext() {
        pg.view.visible(this.layer_center, false)
        pg.event.emit('layer_ending_touch_next');
    }
}

