// 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 NewClass extends cc.Component {

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

    @property
    text: string = 'hello';

    btnStatic: number = 0;

    propName: string = "";

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        // console.log(cc.fx.GameConfig.GM_INFO.level, "新模式");
        for (let i = 0; i < cc.fx.GameConfig.NEW_LEVEL.length; i++) {
            if ((cc.fx.GameConfig.GM_INFO.level + 1) == cc.fx.GameConfig.NEW_LEVEL[i].level) {
                this.propName = cc.fx.GameConfig.NEW_LEVEL[i].name;
                const path = 'Window_Prop/' + this.propName;
                if (i == 6 || (i < 11 && i > 7))
                    this.node.getChildByName("newmode").getChildByName("icon").y = 155
                else
                    this.node.getChildByName("newmode").getChildByName("icon").y = 100

                if (i > 10)
                    this.node.getChildByName("newmode").getChildByName("light").y = 140
                else
                    this.node.getChildByName("newmode").getChildByName("light").y = -72


                cc.resources.load(path, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
                    if (err) {
                        console.error('动态加载背景图失败:', err);
                        return;
                    }
                    this.node.getChildByName("newmode").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
                })
                break;
            }
        }
    }

    setMode(mode: number) {
        this.btnStatic = mode;
        let name = "GameScene";
        if (mode == 1) {
            name = "HomeScene";
        }
        cc.director.preloadScene(name, () => {

        })
    }

    clickBtn() {
        cc.fx.AudioManager._instance.playEffect("anniu_Big", null);
        if (this.btnStatic == 1) {
            cc.fx.GameTool.getUserAvatar(() => {
            })
            cc.director.loadScene("HomeScene");
        }
        else if (this.btnStatic == 2) {
            cc.director.loadScene("GameScene");
        }
    }

    // update (dt) {}
}
