HistoryOtherListCell.js 5.99 KB
//观看历史-其他
var Common = require('Common');
var FocusInfo = require('FocusInfo');
var ListCell = require('ListCell');
var Network = require('Network');

cc.Class({
    extends: ListCell,

    properties: {
        id: 0,
        pic: cc.Sprite,
        activeName1: cc.Label,
        activeName2: cc.Label,
        normalName: cc.Label,
        textPlayTimes: cc.Label,    //观看次数
        collectBg: cc.Sprite,    //收藏外框
        collectPic: cc.Sprite,   //收藏内框
    },

    statics: {
        PFB_NAME: 'prefab/pfbHistoryOtherListCell',
        CELL_NAME: 'OtherListCell',
    },

    init: function (iCellIndex, bIsFocusEnable, compSceneCanvas) {
        // cc.find("CollectionBg", this.node).opacity = 0;
        // let nodeCollectionBg = this.node.getChildByName("CollectionBg");
        // nodeCollectionBg.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 53, 171));
        // let nodeCollectionPic = nodeCollectionBg.getChildByName('CollectionPic');
        // nodeCollectionPic.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 30, 28));

        // let fiCollection = this.node.getChildByName('CollectionBg').addComponent(FocusInfo);
        // fiCollection.init(
        //     null, true, null, null, 1.0);
        // compSceneCanvas.addNodeToFocusTarget(0, this.node.getChildByName('CollectionBg').name + iCellIndex, this.node);
        // 准备焦点坐标
        // let fiCategoryBlock=this.node.getChildByName('Pic').addComponent(FocusInfo);
        let fiCategoryBlock = this.node.addComponent(FocusInfo);
        fiCategoryBlock.init(
            null, false, null, null, 1.0
        );
        compSceneCanvas.addNodeToFocusTarget(0, this.node.name, this.node);
    },

    render(oData, iRecordIndex) {
        var self = this;
        this.id = oData.id;
        this.activeName1.string = oData.name;
        this.activeName2.string = oData.name;
        this.normalName.string = oData.name;
        this.activeName1._updateRenderData(true);
        this.activeName2._updateRenderData(true);
        this.normalName._updateRenderData(true);
        // if (oData.play_times) {
        //     let value = parseInt(oData.play_times);
        //     if (value > 10000) {
        //         this.textPlayTimes.string = parseInt(value / 10000) + "万+";
        //     } else {
        //         this.textPlayTimes.string = value;
        //     }
        // }
        if (oData.images.list[0]) {
            Network.loadImageInNativeRuntime(
                Common.TOPDRAW_IMAGE_SERVER_EDU_RIGHT + oData.images.list[0].fileUrl,
                function (texture) {
                    self.pic.spriteFrame = new cc.SpriteFrame(texture);
                }, null, this
            );
        }
        // self.collectBg.spriteFrame.setRect(cc.rect(0, 0, 53, 171));
        // self.collectPic.spriteFrame.setRect(cc.rect(0, 0, 30, 28));
        // if (oData.isCollect) {
        //     cc.loader.loadRes("texture/ui/collect_heart", cc.Texture2D, function (err, texture) {
        //         var spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 28, 30, 28));
        //         self.collectPic.spriteFrame = spriteFrame;
        //     });
        // } else {
        //     cc.loader.loadRes("texture/ui/collect_heart", cc.Texture2D, function (err, texture) {
        //         var spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 30, 28));
        //         self.collectPic.spriteFrame = spriteFrame;
        //     });
        // }

        this.node.getComponent(FocusInfo).setTVLink(oData.tvlink);
    },

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

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

    setUIWithFocus: function () {
        let nodeCellName = this.node.getChildByName('Name');
        cc.find("NormalName", nodeCellName).opacity = 255;
        //超出滚动
        let nodeScreenTitleText = cc.find('ActiveName/NameContainer/NameText', nodeCellName);

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

        let nodeScreenTitleText1 = nodeScreenTitleText.getChildByName('NameText1');
        let nodeScreenTitleText2 = nodeScreenTitleText.getChildByName('NameText2');
        nodeScreenTitleText2.x = nodeScreenTitleText1.x + nodeScreenTitleText1.width + 10;//TODO:补丁,解决滚动重叠
        if (nodeScreenTitleText1.width > nodeScreenTitleText.width) {
            cc.find("ActiveName/NameContainer", nodeCellName).opacity = 255;
            cc.find("NormalName", nodeCellName).opacity = 0;
            let fEndPositionDelta = (nodeScreenTitleText1.width + 30);
            //下方时长和字有关系,才能速度一样
            var ftaScreenTitleMoveToTarget = cc.moveTo(10 * (nodeScreenTitleText1.width / nodeScreenTitleText.width), fOriginalX - fEndPositionDelta, fOriginalY);
            var ftaScreenTitleMoveToBack = cc.moveTo(0, fOriginalX, fOriginalY);
            var sequenceMediaTitle = cc.sequence(ftaScreenTitleMoveToTarget, ftaScreenTitleMoveToBack);
            var repeatScreenTitle = cc.repeat(sequenceMediaTitle, 10);
            repeatScreenTitle.setTag(Common.OVERLENGTH_MOVING);
            nodeScreenTitleText.runAction(repeatScreenTitle);
            nodeScreenTitleText2.active = true;
        }
    },
    setUIWithoutFocus: function () {
        let nodeCellName = this.node.getChildByName('Name');
        cc.find("NormalName", nodeCellName).opacity = 255;
        // cc.find("ActiveName/ActiveNameBg", nodeCellName).opacity = 0;
        //如有滚动停止滚动
        let nodeScreenTitleText = cc.find('ActiveName/NameContainer/NameText', nodeCellName);
        if (null != nodeScreenTitleText.getActionByTag(Common.OVERLENGTH_MOVING)) {
            nodeScreenTitleText.stopActionByTag(Common.OVERLENGTH_MOVING);
            nodeScreenTitleText.getChildByName('NameText2').active = false;
            cc.find("ActiveName/NameContainer", nodeCellName).opacity = 0;
        }
        nodeScreenTitleText.x = 0;
    },

});