//排行榜界面脚本

cc.Class({
    extends: cc.Component,

    properties: {
        spRank: cc.Sprite,
        _state: false,  //true渲染子域内容， false停止渲染子域内容
        _tex: null, //显示排行榜的精灵图片
        _sharedCanvas: null,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
    },

    onEnable: function(){
        if (window.sharedCanvas) {
            window.sharedCanvas.width = cc.game.canvas.width*2;
            window.sharedCanvas.height = cc.game.canvas.height*2;
        }
        //动态设置对齐
        let widget = this.spRank.node.getComponent(cc.Widget);
        widget.isAlignOnce =false;
        widget.isAlignLeft =true;
        widget.isAlignRight =true;
        widget.left =0;
        widget.right =0;
        widget.updateAlignment();
        //隐藏投诉按钮
        cc.HQ.GameMgr.feedbackButtonHide();
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            this._state =true; 
            if(!this._tex){
                console.log("需要newTexture2D");
                this._tex = new cc.Texture2D();
            }
            var openDataContext = wx.getOpenDataContext();
            this._sharedCanvas = openDataContext.canvas;
            //和设计分辨率大小一样
            // this._sharedCanvas.width = 750;
            // this._sharedCanvas.height = 1334;  
        } 
    },

    //关闭按钮
    onClose: function(){
        this._state =false;  //停止渲染子域内容
        this.node.active =false;
        //显示投诉按钮
        cc.HQ.GameMgr.feedbackButtonShow();
    },

    //渲染子域的内容
    renderSsubContent: function(){
        if(this._tex){
            var openDataContext = wx.getOpenDataContext();
            this._sharedCanvas = openDataContext.canvas;
            // //和设计分辨率大小一样
            // sharedCanvas.width = 750;
            // sharedCanvas.height = 1334;
            this._tex.initWithElement(this._sharedCanvas);
            this._tex.handleLoadedTexture();
            this.spRank.spriteFrame = new cc.SpriteFrame(this._tex);
        } 
    },

    update (dt) {
        if(this._state){        
            this.renderSsubContent();
        }
    }
});
