PersonRoleInstallCategoryListCell.js 5.54 KB
//明星列表ListCell
var Common = require('Common');
var FocusInfo = require('FocusInfo');
var ListView = require('ListView');
var ListCell = require('ListCell');
var Network = require('Network');

cc.Class({
    extends: ListCell,

    properties: {

    },

    statics: {
        PFB_NAME: 'prefab/pfbPersonRoleInstallCategoryListCell',
        CELL_NAME: 'RoleInstallListCell',
    },

    init: function (iCellIndex, bIsFocusEnable, compSceneCanvas) {
        this._compSceneCanvas = compSceneCanvas;
        this._iCellIndex = iCellIndex;
        this.node.zIndex=20;    //TODO:提升权值,显示在背景框上层
        var self=this;
        // cc.loader.loadRes('texture/ui/personal_cell_focus', cc.SpriteFrame, function (err, spriteFrame) {
        //     cc.find('Bg', self.node).getComponent(cc.Sprite).spriteFrame = spriteFrame;
        // });
        let nodeExplainText = cc.find('Explain/Text', this.node);

        nodeExplainText.getComponent(cc.Label).string = "载入中...";

        //准备焦点坐标
        let fiCategoryBlock = this.node.addComponent(FocusInfo);
        fiCategoryBlock.init(
            '{"click":[{\
                "action":"ChangeScene",\
                "parameters":{\
                    "sceneName":"sceneStarList",\
                    "categoryId":"",\
                    "elderLevel":"1",\
                    "appId":""\
                }\
            }]}',
            false, null, null, 1.0
        );
        compSceneCanvas.addNodeToFocusTarget(0, this.node.name, this.node);
    },

    render(oData, iRecordIndex) {
        let nodePic = this.node.getChildByName('Pic');
        let nodeExplainText=cc.find('Explain/Text',this.node);
        let nodeInstallIcon=cc.find('InstallIcon',this.node);   //是否安装
        // oData.in_use==1?nodeInstallIcon.opacity=255:nodeInstallIcon.opacity=0;
        if(oData.in_use){
            nodeInstallIcon.opacity=255;
            nodeExplainText.getComponent(cc.Label).string="按【确定】卸载";
        }else{
            nodeInstallIcon.opacity=0;
            nodeExplainText.getComponent(cc.Label).string="按【确定】使用";
        }
        var fileURL = '';
        if (typeof (oData.images) != 'undefined' && oData.images.map.thumbnail != null) {
            var index = oData.images.map.thumbnail[0];
            fileURL = oData.images.list[index].fileUrl;
        }
        Network.loadImageInNativeRuntime(
            Common.TOPDRAW_IMAGE_SERVER + fileURL,
            function (texture) {
                nodePic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
            }, null, this
        );


        //准备焦点坐标   
        let fiCategoryBlock = this.node.getComponent(FocusInfo);
        fiCategoryBlock.setTVLink('{"click": [{"action": "ChangeScene",' +
            '"parameters": {' +
            '"sceneName":"sceneClassifyDetail",' +
            '"categoryId": "' + oData.id + '",' +
            '"elderLevel":"1",' +
            '"appId":"' + this._compSceneCanvas._strAppId + '"' +
            '}}]}');
    },

    enableFocusInfo: function () {
        this.node.getComponent(FocusInfo).setEnable(true);
    },

    disableFocusInfo: function () {
        this.node.getComponent(FocusInfo).setEnable(false);
    },

    setUIWithFocus: function () {

        //let nodeSongListCell=;
        let nodeCollection = this.node.getChildByName('Collection');
        nodeCollection.opacity = 255;
        //nodeCollection.getComponent(FocusInfo).setEnable(true);

        //转起来 这部分以后要尽量放到Cell里去
        let nodeTitleMask = this.node.getChildByName('ImageBlock').getChildByName('TitleMask');
        let nodeTitleContainer = nodeTitleMask.getChildByName('TitleContainer');
        let nodeTitleText1 = nodeTitleContainer.getChildByName("TitleText1");
        let nodeTitleText2 = nodeTitleContainer.getChildByName("TitleText2");

        let fOriginalX = nodeTitleContainer.x;
        let fOriginalY = nodeTitleContainer.y;

        if (nodeTitleText1.width > nodeTitleMask.width) {  //字超出长度才滚动

            let fEndPositionDelta = nodeTitleText1.width / 2 + 50 + nodeTitleText2.width / 2;

            //下方时长和字有关系,才能速度一样
            var ftaTitleMoveToTarget = cc.moveTo(10, fOriginalX - fEndPositionDelta, fOriginalY);
            var ftaTitleMoveToBack = cc.moveTo(0, fOriginalX, fOriginalY);

            var sequenceTitle = cc.sequence(ftaTitleMoveToTarget, ftaTitleMoveToBack);

            var repeatTitle = cc.repeat(sequenceTitle, 10);
            repeatTitle.setTag(Common.OVERLENGTH_MOVING);

            nodeTitleContainer.stopAction(nodeTitleContainer.getActionByTag(Common.OVERLENGTH_MOVING));
            nodeTitleContainer.runAction(repeatTitle);
        }

    },
    setUIWithoutFocus: function () {


        let nodeImageBlock = this.node.getChildByName('ImageBlock')
        let nodeTitleMask = nodeImageBlock.getChildByName('TitleMask');
        let nodeTitleContainer = nodeTitleMask.getChildByName('TitleContainer');

        let nodeCollection = this.node.getChildByName('Collection');

        //if (nodeTo!=nodeCollectionFrom){ //离开图片并且去的不是图片所在的Collection区
        //    nodeCollectionFrom.opacity=0;
        //    nodeCollectionFrom.getComponent(FocusInfo).setEnable(false);
        //}

        //let nodeTitleContainer=this.node.getChildByName('ImageBlock').getChildByName('TitleMask').getChildByName('TitleContainer');
        nodeTitleContainer.stopAction(nodeTitleContainer.getActionByTag(Common.OVERLENGTH_MOVING));
        nodeTitleContainer.x = 0;
    },

});