FocusInfo.js 4.5 KB
var Common = require('Common');
var FocusInfo = require('FocusInfo');

cc.Class({
    extends: cc.Component,
    properties: {
        // TODO: to be a real Component?
        //_fLeft:0,
        //_fTop:0,
        //_fWidth:0,
        //_fHeight:0,
        //_oFocusNode:null,//deprecated
        _strTVLink: '',
        _bEnable: false,
        _fScaleFactor: 1.06,
    },

    //ctor: function (fLeft,fTop,fWidth,fHeight,oFocusNode,strTVLink,bEnable,fnOnFocus,fnOnBlur) {
    ctor: function () {
        //this._fLeft=arguments[0];
        //this._fTop=arguments[1];
        //this._fWidth=arguments[2];
        //this._fHeight=arguments[3];
        //this._oFocusNode=arguments[4];
        this._strTVLink = arguments[0];
        this._bEnable = arguments[1];
        this._fnOnFocus = arguments[2];
        this._fnOnBlur = arguments[3];
        //this._fLeft=fLeft;
        //this._fTop=fTop;
        //this._fWidth=fWidth;
        //this._fHeight=fHeight;
        //this._oFocusNode=oFocusNode;
    },

    init: function (/*fLeft,fTop,fWidth,fHeight,oFocusNode,*/strTVLink, bEnable, fnOnFocus, fnOnBlur, fScaleFactor) {
        //this._fLeft=arguments[0];
        //this._fTop=arguments[1];
        //this._fWidth=arguments[2];
        //this._fHeight=arguments[3];
        //this._oFocusNode=arguments[4];
        this._strTVLink = strTVLink;
        this._bEnable = bEnable;
        this._fnOnFocus = fnOnFocus;
        this._fnOnBlur = fnOnBlur;
        this._fScaleFactor = fScaleFactor;
        //this._fLeft=fLeft;
        //this._fTop=fTop;
        //this._fWidth=fWidth;
        //this._fHeight=fHeight;
        //this._oFocusNode=oFocusNode;
    },

    // use this for initialization
    onLoad: function () {
        //气泡式向上传递 通常收不到
        //this.node.on('foucs', this._fnOnFocus || function(){},this);
        //this.node.on('blur', this._fnOnBlur || function(){},this);
    },

    getLeft: function () {
        //return this._fLeft;
        return Common.SCREEN_WIDTH / 2 + (this.getX() - this.node.width / 2);
    },

    //setLeft:function(fLeft){
    //    this._fLeft=fLeft;
    //},

    getTop: function () {
        //return this._fTop;
        return Common.SCREEN_HEIGHT / 2 - (this.getY() + this.node.height / 2);
    },

    getX: function () {
        return Common.getX(this.node);
    },
    getY: function () {
        return Common.getY(this.node);
    },
    //setTop:function(fTop){
    //   this._fTop=fTop;
    //},
    getWidth: function () {
        //return this._fWidth;
        return this.node.width;
    },
    setWidth: function (fWidth) {
        //    this._fWidth=fWidth;
        this.node.width = fWidth;
    },
    getHeight: function () {
        //return this._fHeight;
        return this.node.height;
    },
    //setHeight:function(fHeight){
    //    this._fHeight=fHeight;
    //},
    //getFocusNode:function(){
    //    return this._oFocusNode;
    //},
    //setFocusNode:function(oFocusNode){
    //    this._oFocusNode=oFocusNode;
    //},
    getTVLink: function () {
        return this._strTVLink;
    },
    setTVLink: function (strTVLink) {
        this._strTVLink = strTVLink;
    },
    getEnable: function () {
        return this._bEnable;
    },
    setEnable: function (bEnable) {
        this._bEnable = bEnable;
    },
    onFocus: function (fiFrom) {
        if (this._fnOnFocus) {
            this._fnOnFocus(fiFrom);
        }
    },
    onBlur: function (fiTo) {
        if (this._fnOnBlur) {
            this._fnOnBlur(fiTo);
        }
    },
    getScaleFactor: function () {
        return this._fScaleFactor;
    },
    setScaleFactor: function (fScaleFactor) {
        this._fScaleFactor = fScaleFactor;
    },

    onEnable: function () {    //修改节点的active属性为true时会执行挂载组件的onEnable方法
        //注意:子节点有ListView要慎用!会使所有未初始化数据的子节点也改变焦点状态
        // cc.log("执行FocusInfo中onEnable方法");
        if (0 != this.node.name.indexOf('RoleInstallListCell') && 0 != this.node.name.indexOf('AchievementListCell')) {
            this._bEnable = true;
        }
    },

    onDisable: function () {   //修改节点的active属性为false时会执行挂载组件的onDisable方法
        // cc.log("执行FocusInfo中onDisable方法" + this.node.name);
        this._bEnable = false;
    },

    onDestroy: function () {
        // cc.log("节点销毁-------->" + this.node.name);
        cc.director.emit('stop_render');   //分发事件

        // this.node.removeComponent(FocusInfo);
    },

});