Recommend.js 43.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var CCTVFocus = require('CCTVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TestLayout = require('TestLayout');
var waterfall_recommend = require('waterfall_recommend');
var waterfall_course = require('waterfall_course');
var waterfall_parent = require('waterfall_parent');
var waterfall_primarySchool = require('waterfall_primarySchool');
var waterfall_three2six = require('waterfall_three2six');

//热更新相关
var UpdatePanel = require('UpdatePanel');

/**
 * ScrollView有问题,
 *  多个scrollView切换时,高度短的ScrollView无法向上/向下滚动,且初始化后的scrollView位置会错乱
 *  目前暂且将所有scrollView设置为固定高度
 */

var info = cc.Class({
    name: 'info',
    properties: {
        target: cc.Node,
        num: 0
    }
});

cc.Class({
    extends: TVCanvas,

    properties: {
        _iRightRecommendHeight: 0,       //右侧瀑布流宽度
        _aBgHeight: [],  //右侧瀑布流楼层高度

        PFB_LEFT_RECOMMEND: {   //左侧导航栏
            default: null,
            type: cc.Prefab
        },
        PFB_RECOMMEND_RIGHT: {
            default: null,
            type: cc.Prefab
        },
        targetAry: {
            default: [],
            type: [info],
        },

        //热更新弹窗
        panel: UpdatePanel,
        manifestUrl: {
            type: cc.Asset,
            default: null
        },
    },

    onLoad: function () {
        this._super();
        this._scrollview = this.node.getComponent(cc.ScrollView);
        this._oSceneContext.focusPath = "LeftNaviLayout/NaviCell0";
        this._oSceneContext._iPageIndex = 1;
        this._oSceneContext._iCurrentLeftIndex = 0;
        this._oInit = {};
        this._iSceneStatus=0;

        // this.checkUpdate(); //热更新检查是否有新版本        //放到初始化焦点框后

        this.getLeftBgRequest();    //渲染左侧导航
        this.getTopBgRequest();     //渲染顶部导航
        this.getRightBgRequest();   //渲染右侧导航
        this.getRightRecommendRequest(waterfall_recommend);   //渲染右侧推荐框架
    },

    //请求左侧导航
    getLeftBgRequest: function () {
        var arrModules = TestLayout.layout4Page.children;     //拿到模拟数据
        let aLeftRecommend = arrModules[0].data.resultSet;    //左侧导航栏数据
        let count = aLeftRecommend.length;
        var leftNavLayout = this.targetAry[0].target;
        this._oInit.aLeftImg = [];

        for (let i = 0; i < aLeftRecommend.length; i++) {
            let nodeLeftRecommend = cc.instantiate(this.PFB_LEFT_RECOMMEND);
            this._oInit.aLeftImg.push(Common.TOPDRAW_IMAGE_SERVER_EDU + aLeftRecommend[i].imageURL);
            nodeLeftRecommend.getComponent('pfbRecommendCell').init(aLeftRecommend[i], function () {   //让细胞自己渲染
                count--;
                if (!count) {     //初始化完成了
                    leftNavLayout.getComponent(cc.Layout).updateLayout();
                }
            });
            leftNavLayout.addChild(nodeLeftRecommend, 10, "NaviCell" + i);

            //准备焦点坐标
            let fiNodeBlock = nodeLeftRecommend.addComponent(FocusInfo);
            fiNodeBlock.init(
                aLeftRecommend[i].tvlink, true, null, null, 1.0           //最后一个参数决定要不要放大显示
            );
            this._aFocusTargets[0]["NaviCell" + i] = nodeLeftRecommend;
        }

        if (arrModules[0].childrenSize[0] && arrModules[0].childrenSize[1]) {               //子元素大小
            leftNavLayout.getComponent(cc.Layout).cellSize = new cc.size(arrModules[0].childrenSize[0], arrModules[0].childrenSize[1]);
            leftNavLayout.Width = arrModules[0].childrenSize[0];            //计算Layout宽高
            leftNavLayout.height = arrModules[0].childrenSize[1] * 5 + arrModules[0].childrenMargin[2] * 4;
        }
        leftNavLayout.getComponent(cc.Layout).spacingY = arrModules[0].childrenMargin[2];   //子元素间距
        if (arrModules[0].position[0] && arrModules[0].position[1]) {               //确定位置
            leftNavLayout.getComponent(cc.Widget).top = arrModules[0].position[1];
            leftNavLayout.getComponent(cc.Widget).left = arrModules[0].position[0];
        }
        this.checkDataReadyAndInitFocus();
    },

    //请求顶部导航
    getTopBgRequest: function () {
        var arrModules = TestLayout.layout4Page.children;     //拿到模拟数据
        let aLeftRecommend = arrModules[1].data.resultSet;    //顶部导航栏数据
        let count = aLeftRecommend.length;
        var topNavLayout = this.targetAry[1].target;
        topNavLayout.getComponent(cc.Widget).top = 0;
        topNavLayout.getComponent(cc.Widget).left = 0;

        this._oInit.aTopImg = [];
        for (let i = 0; i < aLeftRecommend.length; i++) {
            let nodeLeftRecommend = cc.instantiate(this.PFB_LEFT_RECOMMEND);
            nodeLeftRecommend.width = aLeftRecommend[i].width;
            nodeLeftRecommend.height = aLeftRecommend[i].height;
            this._oInit.aTopImg.push(Common.TOPDRAW_IMAGE_SERVER_EDU + aLeftRecommend[i].imageURL);
            nodeLeftRecommend.getComponent('pfbRecommendCell').init(aLeftRecommend[i], function () {   //让细胞自己渲染
                count--;
                if (!count) {     //初始化完成了

                }
            });
            // cc.log("------------------->"+aLeftRecommend[i].left);
            nodeLeftRecommend.getComponent(cc.Widget).top = aLeftRecommend[i].top;
            nodeLeftRecommend.getComponent(cc.Widget).left = aLeftRecommend[i].left;
            topNavLayout.addChild(nodeLeftRecommend, 10, "TopCell" + i);

            //准备焦点坐标
            let fiNodeBlock = nodeLeftRecommend.addComponent(FocusInfo);
            fiNodeBlock.init(
                aLeftRecommend[i].tvlink, true, null, null, 1.0           //最后一个参数决定要不要放大显示
            );
            this._aFocusTargets[0]["TopCell" + i] = nodeLeftRecommend;
        }
    },

    //请求右侧导航
    getRightBgRequest: function () {
        var arrModules = TestLayout.layout4Page.children;     //拿到模拟数据
        let aLeftRecommend = arrModules[2].data.resultSet;    //顶部导航栏数据
        let count = aLeftRecommend.length;
        var rightNavLayout = this.targetAry[2].target;
        rightNavLayout.width = arrModules[2].width;
        rightNavLayout.height = arrModules[2].height;
        this._iRightRecommendHeight = arrModules[2].width;

        if (arrModules[2].position[0] && arrModules[2].position[1]) {               //确定位置
            rightNavLayout.getComponent(cc.Widget).top = arrModules[2].position[1] + 20;      //加20是内边距
            rightNavLayout.getComponent(cc.Widget).left = arrModules[2].position[0] + 20;
        }
    },

    //渲染推荐框架
    getRightRecommendRequest: function (waterfall_model) {
        var rightNodeLayout = this.targetAry[2].target;
        var arrModules = waterfall_model.waterfall;     //拿到模拟数据
        var bgHeight = 0;
        this._aBgHeight = [];
        this._aBgHeight.push(0);
        for (let i = 0; i < arrModules.resultSet.length; i++) {
            let nodeLayout = new cc.Node(arrModules.resultSet[i].name);   //创建瀑布流的每一层layout
            nodeLayout.width = this._iRightRecommendHeight;
            nodeLayout.height = arrModules.resultSet[i].height;
            var widgetLayout = nodeLayout.addComponent(cc.Widget);
            widgetLayout.isAlignTop = true;
            widgetLayout.top = bgHeight;
            bgHeight += arrModules.resultSet[i].height;   //逐层增加高度
            // cc.log("高度"+bgHeight);                    
            if (i == arrModules.resultSet.length - 1) {     //最后一个条目不够高,手动加高
                bgHeight += 300;
            }
            this._aBgHeight.push(bgHeight);
            if (arrModules.resultSet[i].hasChildFrame) {      //还有子列表
                for (let j = 0; j < arrModules.resultSet[i].data.resultSet.length; j++) {
                    let oModule = arrModules.resultSet[i].data.resultSet[j];
                    if (oModule.hasChildFrame) {
                        let autoNode = new cc.Node();       //创建特殊层的第二层自动填充的布局
                        let autoNodeLayout = autoNode.addComponent(cc.Layout);
                        autoNodeLayout.type = cc.Layout.Type.GRID;                        //网格
                        autoNodeLayout.resizeMode = cc.Layout.ResizeMode.CHILDREN;        //对子节点大小进行缩放
                        autoNodeLayout.startAxis = cc.Layout.AxisDirection.HORIZONTAL;      //排版起始轴
                        autoNodeLayout.horizontalDirection = cc.Layout.HorizontalDirection.LEFT_TO_RIGHT; //布局方向
                        let widgetAutoNode = autoNode.addComponent(cc.Widget);
                        widgetAutoNode.isAlignLeft = true;
                        widgetAutoNode.isAlignTop = true;
                        autoNode.width = oModule.width;         //获取自动布局宽高
                        if (oModule.childrenSize[0] && oModule.childrenSize[1]) {
                            autoNode.height = oModule.childrenSize[1];          //拿子节点的高
                            autoNodeLayout.cellSize = new cc.size(oModule.childrenSize[0], oModule.childrenSize[1]);
                        }
                        if (oModule.childrenMargin[1]) {                              //细胞间隔小些
                            autoNodeLayout.spacingX = oModule.childrenMargin[1] / 2;
                        }
                        if (oModule.position[0] != "undefined" && oModule.position[1] != "undefined") {               //确定位置
                            widgetAutoNode.top = oModule.position[1];
                            widgetAutoNode.left = oModule.position[0];
                        }
                        for (let k = 0; k < oModule.data.resultSet.length; k++) {          //渲染子细胞
                            let node = cc.instantiate(this.PFB_RECOMMEND_RIGHT);
                            if (oModule.childrenSize[0] && oModule.childrenSize[1]) {
                                node.height = oModule.childrenSize[1];          //拿子节点的高
                                node.width = oModule.childrenSize[0];
                                node.getChildByName('Pic').height = oModule.childrenSize[1];          //拿子节点的高
                                node.getChildByName('Pic').width = oModule.childrenSize[0];
                            }
                            autoNode.addChild(node, 10, oModule.data.resultSet[k].code);

                            //准备焦点坐标
                            let fiNodeBlock = node.addComponent(FocusInfo);
                            // fiNodeBlock.init(
                            //     oParameter.promotion_items[i].tvlink, true, null, null, 1.0           //最后一个参数决定要不要放大显示
                            // );
                            this._aFocusTargets[0][oModule.data.resultSet[k].code] = node;
                        }
                        // autoNode.parent=nodeLayout;
                        // cc.log("添加循环子节点"+autoNode.childrenCount);
                        nodeLayout.addChild(autoNode, 10, "hasChildFrame");
                    } else {
                        let node = cc.instantiate(this.PFB_RECOMMEND_RIGHT);
                        node.width = oModule.width;
                        node.height = oModule.height;
                        node.getChildByName('Pic').width = oModule.width;
                        node.getChildByName('Pic').height = oModule.height;
                        node.getComponent(cc.Widget).top = oModule.top;
                        node.getComponent(cc.Widget).left = oModule.left;
                        nodeLayout.addChild(node, 10, oModule.code);

                        if (!oModule.disable) {  //标题不给他焦点
                            //准备焦点坐标
                            let fiNodeBlock = node.addComponent(FocusInfo);
                            // fiNodeBlock.init(
                            //     oParameter.promotion_items[i].tvlink, true, null, null, 1.0           //最后一个参数决定要不要放大显示
                            // );
                            this._aFocusTargets[0][oModule.code] = node;
                        }
                    }
                }
            }
            nodeLayout.parent = rightNodeLayout;
            // cc.log("子节点:"+nodeLayout.childrenCount);
        }
        this.node.getChildByName("ScrollContent").height = 2539;        //这里暂且写死,scrollView有bug
        cc.log("ScrollView高度: " + bgHeight); 2239
        this._scrollview.scrollToTop();
        // cc.log("ScrollView相对的偏移量 "+this._scrollview.getMaxScrollOffset());

        // cc.log("子节点个数: "+rightNodeLayout.childrenCount);

        this.getNaviPromotion("page_d14e8acf-db3d-4f74-b535-c98458596eb8");
    },

    //请求各导航推荐位图片
    getNaviPromotion: function (pageCode) {
        var self = this;
        var oGetPromotionPara = {
            "view": "json",
            "pageCode": pageCode,
            token: Common.TEST_API_TOKEN_EDU,
        };
        Network.ajax('GET', Common.TOPDRAW_API_SERVER_EDU + "Promotion/ListItemByPage", null, oGetPromotionPara,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    var rightNodeLayout = this.targetAry[2].target;
                    let bolockCount = rightNodeLayout.childrenCount; //组个数
                    for (let i = 0; i < oJSONResult.resultSet.length; i++) {    //先循环对比最外层
                        for (let j = 0; j < bolockCount; j++) {
                            if (oJSONResult.resultSet[i].name == rightNodeLayout.children[j].name) {
                                for (let m = 0; m < oJSONResult.resultSet[i].promotions[0].promotion_items.length; m++) {   //对比内层
                                    for (let n = 0; n < rightNodeLayout.children[j].childrenCount; n++) {
                                        let currentRemote = oJSONResult.resultSet[i].promotions[0].promotion_items[m];//匹配的远程条目
                                        let currentNode = rightNodeLayout.children[j].children[n];   //匹配的已经渲染过的节点
                                        if (currentRemote.code == currentNode.name) {
                                            Network.loadImageInNativeRuntime(
                                                Common.TOPDRAW_IMAGE_SERVER_EDU_RIGHT + currentRemote.image[0].fileUrl,
                                                function (texture) {
                                                    currentNode.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                                }, null, this
                                            );
                                            if (currentNode.getComponent(FocusInfo)) {
                                                let fiBlock = currentNode.getComponent(FocusInfo);        //弄tvlink
                                                if(currentNode.name=="promotionItem_9fd6d854-2a72-42d5-a2c0-1ce824cf406c"){    //针对课程表搞出来一个tvlink
                                                    fiBlock.setTVLink('{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneClass"}}]}');
                                                }else{
                                                    // fiBlock.setTVLink(currentRemote.tvlink);
                                                    fiBlock.setTVLink('{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneCategory"}}]}');
                                                }
                                            }
                                        } else if (currentNode.name == "hasChildFrame" && currentNode.childrenCount > 0) { //渲染自动布局的节点
                                            for (let k = 0; k < currentNode.childrenCount; k++) {
                                                let sonCurrentNode = currentNode.children[k];
                                                if (currentRemote.code == sonCurrentNode.name) {
                                                    Network.loadImageInNativeRuntime(
                                                        Common.TOPDRAW_IMAGE_SERVER_EDU_RIGHT + currentRemote.image[0].fileUrl,
                                                        function (texture) {
                                                            sonCurrentNode.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                                        }, null, this
                                                    );
                                                    if (sonCurrentNode.getComponent(FocusInfo)) {
                                                        let fiBlock = sonCurrentNode.getComponent(FocusInfo);        //弄tvlink
                                                        // fiBlock.setTVLink(currentRemote.tvlink);
                                                        fiBlock.setTVLink('{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneCategory"}}]}');
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (error) {
                    cc.log("Exception When FloorPromotion..." + error);
                }
            },
            function (strResponse) {
                cc.log("Error When FloorPromotion..." + strResponse);
            }, this, "uuid");
    },

    checkDataReadyAndInitFocus: function () {
        if (!this._bIsFocusInit) {
            this.scheduleOnce(() => {           //指定0让回调函数在下一帧立即执行
                this.initFocus();
            }, 0);
            this._bIsFocusInit = true;
        }
    },

    //初始化焦点框
    initFocus: function () {
        this._aFocusTargets[1]=[];

        let fiHotUpdateClose=cc.find('update/update_panel/close',this.node).addComponent(FocusInfo); //热更新关闭按钮
        fiHotUpdateClose.init('',false,null,null,1.0);
        this._aFocusTargets[1]['hot_update_close']=cc.find('update/update_panel/close',this.node);

        let fiHotUpdateBtn=cc.find('update/update_panel/update_btn',this.node).addComponent(FocusInfo); //热更新按钮
        fiHotUpdateBtn.init('',false,null,null,1.0);
        this._aFocusTargets[1]['hot_update_btn']=cc.find('update/update_panel/update_btn',this.node);

        let fiCloseBtn=cc.find('update/update_panel/close_btn',this.node).addComponent(FocusInfo); //热更新按钮
        fiCloseBtn.init('',false,null,null,1.0);
        this._aFocusTargets[1]['hot_close_btn']=cc.find('update/update_panel/close_btn',this.node);

        var nodeInitFocus = cc.find(this._oSceneContext.focusPath, this.node);
        // cc.log("初始化 "+nodeInitFocus.name);
        var nodeFocus = new cc.Node('nodeFocus');
        this.node.addChild(nodeFocus, 10);
        this._cFocus = this.node.getChildByName('nodeFocus').addComponent(CCTVFocus);
        this._cFocus.init('focusContainer', this,
            nodeInitFocus.getComponent(FocusInfo),
            Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 2, 6, 1.0, true);

        this.checkUpdate();     //热更新

        this.scheduleOnce(() => {           //指定0让回调函数在下一帧立即执行
            if (0 == nodeInitFocus.name.indexOf('NaviCell')) {
                // nodeInitFocus.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, nodeInitFocus.height, nodeInitFocus.width, nodeInitFocus.height));
                Network.loadImageInNativeRuntime(
                    this._oInit.aLeftImg[0],
                    function (texture) {
                        nodeInitFocus.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, nodeInitFocus.height, nodeInitFocus.width, nodeInitFocus.height));
                    }, null, this
                );
            }
        }, 0);
    },

    onBeforeFocusChange: function (event) {
        this._super(event);
        let fiFrom = event.detail.from;
        let fiTo = event.detail.to;

        if (0 == this._fiCurrentFocus.node.getName().indexOf('NaviCell') && 0 == fiTo.node.getName().indexOf('NaviCell')) {
            // fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            let iIndex = fiFrom.node.name.replace("NaviCell", '');
            if (this._oInit.aLeftImg[iIndex]) {
                Network.loadImageInNativeRuntime(
                    this._oInit.aLeftImg[iIndex],
                    function (texture) {
                        fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
                    }, null, this
                );
            }
        }

        if (0 == this._fiCurrentFocus.node.getName().indexOf('TopCell')) {
            // fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            let iIndex = fiFrom.node.name.replace("TopCell", '');
            if (this._oInit.aTopImg[iIndex]) {
                Network.loadImageInNativeRuntime(
                    this._oInit.aTopImg[iIndex],
                    function (texture) {
                        fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
                    }, null, this
                );
            }
        }
    },

    onAfterFocusChange: function (event) {
        this._super(event);
        let fiTo = event.detail.to;
        let fiFrom = event.detail.from;

        if (0 == fiTo.node.getName().indexOf('NaviCell')) {
            let iIndex = fiTo.node.name.replace("NaviCell", '');
            // fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            if (this._oInit.aLeftImg[iIndex]) {
                Network.loadImageInNativeRuntime(
                    this._oInit.aLeftImg[iIndex],
                    function (texture) {
                        fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
                    }, null, this
                );
            }

            this._oSceneContext._iCurrentLeftIndex = iIndex;
        }

        if (0 == fiTo.node.getName().indexOf('TopCell')) {
            let iIndex = fiTo.node.name.replace("TopCell", '');
            // fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            if (this._oInit.aTopImg[iIndex]) {
                Network.loadImageInNativeRuntime(
                    this._oInit.aTopImg[iIndex],
                    function (texture) {
                        fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
                    }, null, this
                );
            }
        }
    },

    keyDownDirection: function (Direct) {
        var fiFocusTarget = null;
        var fiCurrentFocus = this._fiCurrentFocus;
        var oScrollParameter = null;
        let aCheckResult;
        fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Direct);
        if (!fiFocusTarget) { return; }
        aCheckResult = this.checkFocusTarget(fiFocusTarget);
        fiFocusTarget = aCheckResult[0];
        oScrollParameter = aCheckResult[1];
        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
    },

    checkFocusTarget: function (fiFocusTarget, oScrollParameter) {
        var leftNavLayout = this.targetAry[0].target;
        if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("NaviCell")) {
            if (0 != this._fiCurrentFocus.node.name.indexOf("NaviCell")) {//如果不是TypeList之间跳转,则哪里来回哪里去
                fiFocusTarget = cc.find("NaviCell" + this._oSceneContext._iCurrentLeftIndex, leftNavLayout).getComponent(FocusInfo);
            }
        }

        return [fiFocusTarget, oScrollParameter];
    },

    onKeyDown: function (event) {
        this._super(event);
        var fiFocusTarget = null;
        var fiCurrentFocus = this._fiCurrentFocus;
        switch (event.keyCode) {
            case cc.macro.KEY.up:
            case Common.ANDROID_KEY.up:
                fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_UP);
                if (!fiFocusTarget) { return; }
                let iTargetTopUp = 0;
                if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("block")) {    //嵌套了两层的布局
                    iTargetTopUp = fiFocusTarget.node.getParent().getParent().getComponent(cc.Widget).top;
                } else {
                    iTargetTopUp = fiFocusTarget.node.getParent().getComponent(cc.Widget).top;
                }
                // cc.log("目标节点: "+fiCurrentFocus.node.name);
                let iCurrentFloorBottomUp = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0;//当前楼层底部高度
                // cc.log(iCurrentFloorBottomUp + "目标节点的高度:" + iTargetTopUp);
                if (iTargetTopUp < iCurrentFloorBottomUp && fiCurrentFocus.node.name.indexOf("NaviCell") == -1) {
                    if (this._oSceneContext._iPageIndex > 1) {
                        //---------------隐藏焦点0.6秒,就看不到焦点框长时间的跳转------------------
                        this._cFocus.hide();
                        setTimeout(function () {
                            this._cFocus.show();
                        }.bind(this), 600);
                        //----------------------------------------------------------------------
                        this._oSceneContext._iPageIndex--;
                        let height = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0;   //520,750,1177,1463,1737,2119,2239
                        this._scrollview.scrollToOffset(cc.v2(0, height), 0.5);
                        // cc.log("滚动到:" + height);
                        setTimeout(function () {
                            this.keyDownDirection(Common.MOVE_DIRECTION_UP);
                        }.bind(this), 300);
                        return;
                    }
                }
                this.keyDownDirection(Common.MOVE_DIRECTION_UP);
                break;
            case cc.macro.KEY.right:
            case Common.ANDROID_KEY.right:
                this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
                break;
            case cc.macro.KEY.down:
            case Common.ANDROID_KEY.down:
                fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Common.MOVE_DIRECTION_DOWN);
                if (!fiFocusTarget) { return; }
                let iTargetTop = 0;
                if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("block")) {    //嵌套了两层的布局
                    iTargetTop = fiFocusTarget.node.getParent().getParent().getComponent(cc.Widget).top;
                } else {
                    iTargetTop = fiFocusTarget.node.getParent().getComponent(cc.Widget).top;
                }
                let iCurrentFloorBottom = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0;//当前楼层底部高度
                // cc.log(iCurrentFloorBottom+"目标节点的高度:"+iTargetTop);
                if (iTargetTop > iCurrentFloorBottom && fiCurrentFocus.node.name.indexOf("NaviCell") == -1) {
                    if (this._oSceneContext._iPageIndex < this._aBgHeight.length - 1) {
                        //---------------隐藏焦点0.6秒,就看不到焦点框长时间的跳转------------------
                        this._cFocus.hide();
                        setTimeout(function () {
                            this._cFocus.show();
                        }.bind(this), 600);
                        //----------------------------------------------------------------------
                        let height = this._aBgHeight[this._oSceneContext._iPageIndex] || 0;   //520,750,1177,1463,1737,2119,2239
                        this._scrollview.scrollToOffset(cc.v2(0, height), 0.5);
                        // cc.log("滚动到:"+height);
                        this._oSceneContext._iPageIndex++;
                        setTimeout(function () {
                            this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
                        }.bind(this), 300);
                        return;
                    }
                }
                this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
                break;
            case cc.macro.KEY.left:
            case Common.ANDROID_KEY.left:
                this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
                break;
            case cc.macro.KEY.enter:
            case cc.macro.KEY.space:
            case Common.ANDROID_KEY.enter:
                if (0 == this._fiCurrentFocus.node.name.indexOf('close') || 0 == this._fiCurrentFocus.node.name.indexOf('close_btn')) {
                    this._iSceneStatus=0;
                    cc.find("update", this.node).active = false;    //关闭更新面板
                    let fiAfterNode=cc.find(this._oSceneContext.focusPath,this.node).getComponent(FocusInfo); //热更新按钮 
                    this._cFocus.flyFocus(this._fiCurrentFocus, fiAfterNode, Common.MOVE_DIRECTION_RIGHT, null, null);
                }
                else if(0 == this._fiCurrentFocus.node.name.indexOf('update_btn')){
                    this.hotUpdate();
                }
                else{
                    this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
                }
                break;
            case cc.macro.KEY.backspace:
            case Common.ANDROID_KEY.back:
                this.backAScene();
                break;
        }
    },

    doCurrentFocusTVLinkAction: function (strAction) {
        let strTVLink = this._fiCurrentFocus.getTVLink();
        // cc.log("tvlink===============" + strTVLink);
        try {
            let oTVLink = JSON.parse(strTVLink);
            let aOperationList = oTVLink.click;
            var rightNavLayout = this.targetAry[2].target;
            rightNavLayout.destroyAllChildren();        //销毁完以前所有的子模块
            this._oSceneContext._iPageIndex = 1;
            for (let i = 0; i < aOperationList.length; i++) {
                switch (aOperationList[i].action) {
                    case "changeLayout":
                        let model = aOperationList[i].parameters.layoutPath;  //获取要加载的框架
                        if (-1 != model.indexOf("waterfall_recommend")) {
                            this.getRightRecommendRequest(waterfall_recommend);   //渲染右侧推荐框架
                        } else if (-1 != model.indexOf("waterfall_parent")) {
                            this.getRightRecommendRequest(waterfall_parent);
                        } else if (-1 != model.indexOf("waterfall_course")) {
                            this.getRightRecommendRequest(waterfall_course);
                        } else if (-1 != model.indexOf("waterfall_primarySchool")) {
                            this.getRightRecommendRequest(waterfall_primarySchool);
                        } else if (-1 != model.indexOf("waterfall_three2six")) {
                            this.getRightRecommendRequest(waterfall_three2six);
                        }
                        break;
                    // case "changeUI":         //放在TVCanvas中全局管理
                    //     let parameter = aOperationList[i].parameters.uiName;  //更换界面的名称
                    //     if (parameter=="collection") {              //收藏
                    //         this.getRightRecommendRequest(waterfall_recommend);   
                    //     } else if (parameter=="history") {          //历史
                    //         this.getRightRecommendRequest(waterfall_parent);   
                    //     } else if (parameter=="search") {           //搜索
                    //         this.getRightRecommendRequest(waterfall_course);  
                    //     }
                    //     break;
                    default:
                        this.doTVLinkAction(aOperationList[i]); 
                        break;
                }
            }
        } catch (error) {
            cc.log("runTVLinkAction Exception..." + error);
        }
    },

    checkUpdate: function () {
        if (!cc.sys.isNative) {     //不是原生的就不进行检查了
            return;
        }

        //--------------onLoad--------------------
        this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'blackjack-remote-asset');
        cc.log('Storage path for remote asset : ' + this._storagePath);

        // Setup your own version compare handler, versionA and B is versions in string
        // if the return value greater than 0, versionA is greater than B,
        // if the return value equals 0, versionA equals to B,
        // if the return value smaller than 0, versionA is smaller than B.
        this.versionCompareHandle = function (versionA, versionB) {
            cc.log("JS Custom Version Compare: version A is " + versionA + ', version B is ' + versionB);
            var vA = versionA.split('.');
            var vB = versionB.split('.');
            for (var i = 0; i < vA.length; ++i) {
                var a = parseInt(vA[i]);
                var b = parseInt(vB[i] || 0);
                if (a === b) {
                    continue;
                }
                else {
                    return a - b;
                }
            }
            if (vB.length > vA.length) {
                return -1;
            }
            else {
                return 0;
            }
        };

        // Init with empty manifest url for testing custom manifest
        this._am = new jsb.AssetsManager('', this._storagePath, this.versionCompareHandle);

        var panel = this.panel;
        // Setup the verification callback, but we don't have md5 check function yet, so only print some message
        // Return true if the verification passed, otherwise return false
        this._am.setVerifyCallback(function (path, asset) {
            // When asset is compressed, we don't need to check its md5, because zip file have been deleted.
            var compressed = asset.compressed;
            // Retrieve the correct md5 value.
            var expectedMD5 = asset.md5;
            // asset.path is relative path and path is absolute.
            var relativePath = asset.path;
            // The size of asset file, but this value could be absent.
            var size = asset.size;
            if (compressed) {
                panel.info.string = "Verification passed : " + relativePath;
                return true;
            }
            else {
                panel.info.string = "Verification passed : " + relativePath + ' (' + expectedMD5 + ')';
                return true;
            }
        });

        this.panel.info.string = 'Hot update is ready, please check or directly update.';

        if (cc.sys.os === cc.sys.OS_ANDROID) {
            // Some Android device may slow down the download process when concurrent tasks is too much.
            // The value may not be accurate, please do more test and find what's most suitable for your game.
            this._am.setMaxConcurrentTask(2);
            this.panel.info.string = "Max concurrent tasks count have been limited to 2";
        }

        this.panel.fileProgress.progress = 0;
        //----------------------------------------

        if (this._updating) {
            this.panel.info.string = 'Checking or updating ...';
            return;
        }
        if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
            // Resolve md5 url
            var url = this.manifestUrl.nativeUrl;
            // cc.log("///////////"+this.manifestUrl);
            if (cc.loader.md5Pipe) {
                url = cc.loader.md5Pipe.transformURL(url);
            }
            this._am.loadLocalManifest(url);
        }
        if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
            this.panel.info.string = 'Failed to load local manifest ...';
            return;
        }
        this._am.setEventCallback(this.checkCb.bind(this));

        this._am.checkUpdate();
        this._updating = true;
    },

    checkCb: function (event) {
        cc.log('Code: ' + event.getEventCode());
        switch (event.getEventCode()) {
            case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                this.panel.info.string = "No local manifest file found, hot update skipped.";
                break;
            case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
            case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                this.panel.info.string = "Fail to download manifest file, hot update skipped.";
                break;
            case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                this.panel.info.string = "Already up to date with the latest remote version.";
                break;
            case jsb.EventAssetsManager.NEW_VERSION_FOUND:          //可以更新了
                cc.log("可以更新了");   //处理焦点框跳转
                this.panel.info.string = 'New version found, please try to update.';
                this.panel.fileProgress.progress = 0;
                // this.panel.byteProgress.progress = 0;

                this._iSceneStatus=1;       //焦点框跳转层级
                cc.find("update", this.node).active = true;       //显示出来更新面板
                let fiHotUpdateBtn=cc.find('update/update_panel/update_btn',this.node).getComponent(FocusInfo); //热更新按钮 
                this._cFocus.flyFocus(this._fiCurrentFocus, fiHotUpdateBtn, Common.MOVE_DIRECTION_RIGHT, null, null);

                break;
            default:
                return;
        }

        this._am.setEventCallback(null);
        this._checkListener = null;
        this._updating = false;
    },

    hotUpdate: function () {
        //隐藏更新说明,显示更新进度条
        cc.find("update/update_panel/infoLabel", this.node).active = false;
        cc.find("update/update_panel/update_info", this.node).active = false;
        cc.find("update/update_panel/ProgressLabel", this.node).active = true;
        cc.find("update/update_panel/fileProgress", this.node).active = true;
        cc.find("update/update_panel/filep", this.node).active = true;

        if (this._am && !this._updating) {
            this._am.setEventCallback(this.updateCb.bind(this));

            if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
                // Resolve md5 url
                var url = this.manifestUrl.nativeUrl;
                if (cc.loader.md5Pipe) {
                    url = cc.loader.md5Pipe.transformURL(url);
                }
                this._am.loadLocalManifest(url);
            }

            this._failCount = 0;
            this._am.update();
            // this.panel.updateBtn.active = false;
            this._updating = true;
        }
    },

    updateCb: function (event) {
        var needRestart = false;
        var failed = false;
        switch (event.getEventCode())
        {
            case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                this.panel.info.string = 'No local manifest file found, hot update skipped.';
                failed = true;
                break;
            case jsb.EventAssetsManager.UPDATE_PROGRESSION:
                // this.panel.byteProgress.progress = event.getPercent();
                this.panel.fileProgress.progress = event.getPercentByFile();

                this.panel.fileLabel.string = event.getDownloadedFiles() + ' / ' + event.getTotalFiles();
                // this.panel.byteLabel.string = event.getDownloadedBytes() + ' / ' + event.getTotalBytes();

                var msg = event.getMessage();
                if (msg) {
                    this.panel.info.string = 'Updated file: ' + msg;
                    // cc.log(event.getPercent()/100 + '% : ' + msg);
                }
                break;
            case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
            case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                this.panel.info.string = 'Fail to download manifest file, hot update skipped.';
                failed = true;
                break;
            case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                this.panel.info.string = 'Already up to date with the latest remote version.';
                failed = true;
                break;
            case jsb.EventAssetsManager.UPDATE_FINISHED:
                this.panel.info.string = 'Update finished. ' + event.getMessage();
                needRestart = true;
                break;
            case jsb.EventAssetsManager.UPDATE_FAILED:
                this.panel.info.string = 'Update failed. ' + event.getMessage();
                this.panel.retryBtn.active = true;
                this._updating = false;
                this._canRetry = true;
                break;
            case jsb.EventAssetsManager.ERROR_UPDATING:
                this.panel.info.string = 'Asset update error: ' + event.getAssetId() + ', ' + event.getMessage();
                break;
            case jsb.EventAssetsManager.ERROR_DECOMPRESS:
                this.panel.info.string = event.getMessage();
                break;
            default:
                break;
        }

        if (failed) {
            this._am.setEventCallback(null);
            this._updateListener = null;
            this._updating = false;
        }

        if (needRestart) {
            this._am.setEventCallback(null);
            this._updateListener = null;
            // Prepend the manifest's search path
            var searchPaths = jsb.fileUtils.getSearchPaths();
            var newPaths = this._am.getLocalManifest().getSearchPaths();
            console.log(JSON.stringify(newPaths));
            Array.prototype.unshift.apply(searchPaths, newPaths);
            // This value will be retrieved and appended to the default search path during game startup,
            // please refer to samples/js-tests/main.js for detailed usage.
            // !!! Re-add the search paths in main.js is very important, otherwise, new scripts won't take effect.
            cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(searchPaths));
            jsb.fileUtils.setSearchPaths(searchPaths);

            cc.audioEngine.stopAll();
            cc.game.restart();
        }
    },

});