// 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

const { ccclass, property } = cc._decorator;

@ccclass
export default class EndView extends cc.Component {

    @property(cc.Node)
    winRoot: cc.Node = null;

    @property(cc.Node)
    loseRoot: cc.Node = null;

    @property(cc.Node)
    redIcon: cc.Node = null;

    @property(cc.Node)
    blueIcon: cc.Node = null;

    @property(cc.Label)
    lb_red: cc.Label = null;

    @property(cc.Label)
    lb_blue: cc.Label = null;

    @property(cc.Node)
    replayNode: cc.Node = null;

    onLoad() {

        this.replayNode.on("click", this.replay, this)

    }

    showView(win: boolean, redScore, blueScore, redUrl, blueUrl) {

        this.winRoot.active = win;
        this.loseRoot.active = !win;
        this.lb_blue.string = blueScore;
        this.lb_red.string = redScore;

        cc.loader.load({ url: redUrl }, (err, img) => {
            this.redIcon.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(img)
        })
        cc.loader.load({ url: blueUrl }, (err, img) => {
            this.blueIcon.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(img)
        })
    }

    replay() {
        cc.game.restart();
    }

}
