// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.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

cc.Class({
    extends: require("BaseItemConstroller"),

    properties: {

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {

        this._super();
        this.init();
        this.game = cc.find("Canvas/Game");
        this.GameMode._gamestart = false;
    },
    start() {
        //this.interface_Against = cc.find("Canvas/Interface_Against");
        this.interface_info = cc.find("Canvas/Interface_Info").getComponent('Interface_Info');
    },
    btn_touch(event) {
        cc.audioEngine.playEffect(this.UiController.audioArr[0]);
        this.UiController.back_btn.active = false;
        this.node.parent.removeAllChildren();
        if (event.target.name == "Btn_Back") {
            console.log("回到主界面");

            this.UiController.Panel_Botton.active = true;
            this.Interface_Node.removeAllChildren();
            // this.interface_Against.active = true;
            if (this.GameState.gameresult) {
                console.log("获取箱子");
                this.interface_info.creatorgird();
                this.GameState.gameresult = false;
            }
            this.UiController.change_interface(this.UiController.interfacaArr, 0);



        }
        if (event.target.name == "Btn_LoadGame") {
            console.log("重启游戏");
            this.Interface_Node.removeAllChildren();
            this.game.removeAllChildren();
            this.UiController.actions();
            //var self = this;
            if (this.GameState.gameresult) {
                this.interface_info.creatorgird();
                this.GameState.gameresult = false;
                this.GameState._currPass--;
            }
            this.game.addChild(cc.instantiate(this.UiController.passArr[this.GameState._currPass]));
            // cc.resources.loadDir("prefab/Pass", (err, prefabs) => {
            //     var interfacegame = cc.instantiate(prefabs[self.GameState._currPass]);
            //     self.game.addChild(interfacegame);
            // });


        }
        if (event.target.name == "Btn_Box") {
            // 加载 Prefab
            cc.loader.loadRes("prefab/Result/interface_Box", (err, prefab) => {
                cc.find("Canvas/PanelResult").addChild(cc.instantiate(prefab));
            });

        }
    },

    // update (dt) {},
    init() {
        this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
        this.Interface_Node = cc.find("Canvas/Interface_Node");
        this.GameState = cc.find("GameStates").getComponent("GameStates");
        this.GameMode = cc.find("GameMode").getComponent("GameMode");
    },
});