Recommend.js
31 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
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');
/**
* 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],
},
},
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.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
// 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 () {
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.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, 0, 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:
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);
}
},
});