// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Cup from "./cup_PK_Game";
import Player from "./player_PK_Game";

const { ccclass, property } = cc._decorator;

@ccclass
export default class MyInfo extends cc.Component {

    @property(cc.Node)
    root: cc.Node = null;
    @property(cc.Node)
    barIn: cc.Node = null;
    @property(cc.Node)
    barOut: cc.Node = null;
    @property(cc.Node)
    head: cc.Node = null;
    @property(cc.Node)
    btn_rank: cc.Node = null;
    @property(cc.Node)
    btn_rise: cc.Node = null;
    @property(cc.Label)
    lb_rank: cc.Label = null;
    @property(cc.Label)
    lb_score: cc.Label = null;
    @property(cc.Label)
    lb_name: cc.Label = null;
    mainCom: any;

    onLoad() {

        this.barOut.active = false;
        this.barIn.active = true;
        this.btn_rise.on("click", this.onClickRisk, this)
        this.btn_rank.on("click", this.onClickRank, this)
    }
    openMask() {

        this.barOut.active = true;
        this.barIn.active = false;
    }
    hideMask() {
        this.barOut.active = false;
        this.barIn.active = true;
    }
    onClickRank() {

        this.mainCom.showRank();
    }
    onClickRisk() {
        this.mainCom.showRisk();
    }
    hide() {

        cc.tween(this.root).to(0.2, { y: -400 }, { easing: "sineOut" }).start();

    }
    show() {

        cc.tween(this.root).to(0.2, { y: 0 }, { easing: "sineIn" }).start();

    }

    init(data) {

        this.lb_score.string = data.score;
        this.lb_name.string = data.name;
        this.lb_rank.string = data.rank + 1;
        this.head.getComponent(Player).init(data.url);

        this.root.getChildByName("cup").getComponent(Cup).init(data.score);

    }

    // update (dt) {}
}
