gameCategory.js
32.1 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
var Common = require('Common');
var Network = require('Network');
var CCNetwork = require('CCNetwork');
var TVFocus = require('TVFocus');
var CCTVFocus = require('CCTVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
// var ListView = require('ListView');
var ListView = require('ListView_SimulateData');
var BusinessParameter = require('BusinessParameter');
var ListCell = require('ListCell');
cc.Class({
extends: TVCanvas,
properties: {
PFB_COMMON: {
default: null,
type: cc.Prefab
},
},
onLoad: function () {
this._super();
this._oInit = {};
this._lastFocus = null;
this._oSceneContext._iCurrentLeftIndex = 0;
// this._oSceneContext.focusPath = "TypeListArea/TypeListWrapper/TypeList/topNavi" + this._oSceneContext._iCurrentLeftIndex;
this._bIsDataListMoving = false;
this._bInitCategoryListSuccess = false;
let aSceneParameter = this._cApplication.getSceneParameter();
cc.log("gameDetail->aSceneParameter..." + JSON.stringify(aSceneParameter));
if (aSceneParameter.length) {
this._oSceneContext._iCurrentLeftIndex = aSceneParameter[aSceneParameter.length - 1].currentIndex || 0;
} else if (aSceneParameter) {
this._oSceneContext._iCurrentLeftIndex = aSceneParameter.currentIndex || 0;
}
if (this._cApplication.getBackStatus()) { //返回值放到下方,否则恢复的数据是首页带回来的数值
//恢复上下文 包括
//光标位置 focusPath
let oSceneContext = this._cApplication.popSceneContext();
if (oSceneContext) {
this._oSceneContext = oSceneContext;
cc.log(this._oSceneContext);
}
this._cApplication.setBackStatus(false);
}
cc.log("back status: " + this._oSceneContext._iCurrentLeftIndex);
this._nodeTypeListWrapper = cc.find("TypeListArea/TypeListWrapper", this.node);
this._nodeTypeList = cc.find("TypeList", this._nodeTypeListWrapper);
this._nodeTypeList.addComponent(TVScrollParameter);
//滚动条按钮
// let nodeScrollBtn = cc.find("CategoryList/ScrollBarContainer/ScrollBarShadow/ScrollBarBlock", this.node);
// var fiScrollBtn = nodeScrollBtn.addComponent(FocusInfo);
// this._aFocusTargets[0]['scroll_bar_block'] = nodeScrollBtn;
// fiScrollBtn.init(null, true);
this.getNavList(); //获取导航栏信息
},
getNavList: function () {
var self = this;
this._nodeTypeList.y = 0;
// var oNavParas = {
// 'view': 'json',
// "start": 0,
// "limit": 10,
// "dictionaryCode": "categoryNav",
// "sortField": "sequence",
// "sortDirection": 'asc',
// 'token': Common.TEST_API_TOKEN,
// };
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "category/category_navi.json", null, null,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
// var oJSONResult = this.navi_json.json;
// this._cLog.screenI("gameCategory getNavList start..." + JSON.stringify(oJSONResult));
if (oJSONResult.businessCode == 'success') {
this._oInit.aNavList = [];
this._oInit.aTopNaviImg = [];
for (let i = 0; i < oJSONResult.resultSet.length; i++) {
var oProgram = oJSONResult.resultSet[i];
// var oTvlink = JSON.parse(oProgram.description);
let node = cc.instantiate(this.PFB_COMMON);
if (oProgram.image[0] && oProgram.image[0].fileUrl) {
this._oInit.aTopNaviImg.push(Common.TOPDRAW_IMAGE_SERVER + oProgram.image[0].fileUrl);
node.width = oProgram.image[0].width;
node.height = oProgram.image[0].height;
node.getChildByName("Pic").width = oProgram.image[0].width;
node.getChildByName("Pic").height = oProgram.image[0].height;
// cc.loader.loadRes(oProgram.image[0].fileUrl, cc.Texture2D, function (err, texture) {
// node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, oProgram.image[0].width, oProgram.image[0].height));
// if (i == self._oSceneContext._iCurrentLeftIndex) {
// node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, oProgram.image[0].height, oProgram.image[0].width, oProgram.image[0].height));
// }
// });
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oProgram.image[0].fileUrl, null,
function (texture, iRequestId) {
node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, oProgram.image[0].width, oProgram.image[0].height));
if (i == self._oSceneContext._iCurrentLeftIndex) {
node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, oProgram.image[0].height * 2, oProgram.image[0].width, oProgram.image[0].height));
}
}, function () { }, this
);
// Network.loadImageInNativeRuntime(Common.TOPDRAW_IMAGE_SERVER + oProgram.image[0].fileUrl, i,
// function (texture, iRequestId) {
// node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, oProgram.image[1].width, oProgram.image[1].height));
// if (i == 1) {
// node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, oProgram.image[1].height, oProgram.image[1].width, oProgram.image[1].height));
// }
// },
// function (texture, iRequestId) {
// },
// );
}
// node.x = node.width / 2 + i * (node.width + 29);
node.y = -node.height / 2 - i * (node.height);
this._nodeTypeList.addChild(node, 10, "topNavi" + i);
//准备焦点坐标
let fiNodeBlock = node.addComponent(FocusInfo);
fiNodeBlock.init(
'', true, null, null, 1.1 //最后一个参数决定要不要放大显示
);
this._aFocusTargets[0]["topNavi" + i] = node;
}
// this._oSceneContext.focusPath = "TypeListArea/TypeListWrapper/TypeList/topNavi" + this._oSceneContext._iCurrentLeftIndex;
this.checkDataReadyAndInitFocus();
// this.requestMediaList(1);
this.getSimulateRequest();
} else {
cc.log("Business Error:getNavList..." + oJSONResult.description);
}
} catch (error) {
cc.log("Business Exception:getNavList..." + error);
}
},
function (strResponse) {
cc.log("Business Error:getNavList..." + strResponse);
}, this, "uuid");
},
getSimulateRequest: function () {
var self = this;
var aJsonList = ["catetory_jtdr_list.json", "catetory_all_list.json", "catetory_nlbz_list.json", "catetory_3dyx_list.json", "catetory_dfdj_list.json"];
if (this._oInit[this._oSceneContext._iCurrentLeftIndex]) { //已经加载过数据直接取
self.requestMediaList(1);
} else {
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/" + aJsonList[this._oSceneContext._iCurrentLeftIndex], null, null,
function (strResponse) {
try {
this._oInit[this._oSceneContext._iCurrentLeftIndex] = strResponse;
this.scheduleOnce(function () {
self.requestMediaList(1); //重新渲染CategoryList
}, 0);
} catch (error) {
cc.log("Business Exception:Get getSimulateRequest..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get getSimulateRequest..." + strResponse);
}, this, "uuid");
}
},
requestMediaList: function (cId) {
var self = this;
if (cId) {
// cc.log("//////////"+requestMediaList);
//把之前的东西删掉
let nodeCategoryList = this.node.getChildByName('CategoryList');
// nodeCategoryList.getChildByName('DataContainerMask').getChildByName('DataContainer').removeAllChildren();
nodeCategoryList.getChildByName('DataContainerMask').getChildByName('DataContainer').destroyAllChildren();
// let strAppId = this._oInit.aNavList[this._oSceneContext.iNaviIndex].appId;
// switch (strAppId) {
// case BusinessParameter.CARTOON_APPID:
this._oSceneContext.focusPath = this._oSceneContext.focusPath || "CategoryList/DataContainerMask/DataContainer/CategoryListCell0";
this._strSongListCellComponentName = "pfbCategoryListCell";
this._iBeginPositionX = -350;
this._iBeginPositionY = 196;
this._iShowCellRows = 3;
this._iAlphaCellRows = 0;
this._iHiddenCellRows = 3;
this._iCellCountEachRow = 4;
this._fCellMarginTop = 0;
this._fCellMarginRight = 24;
this._fCellMarginBottom = 24;
this._fCellMarginLeft = 0;
// break;
// default:
// // this._oSceneContext.focusPath = this._oSceneContext.focusPath || "SongList/DataContainerMask/DataContainer/ListCell0/ImageBlock";
// this._strSongListCellComponentName = "CategoryOtherListCell";
// this._iBeginPositionX = -271;
// this._iBeginPositionY = 166;
// this._iShowCellRows = 3;
// this._iAlphaCellRows = 0;
// this._iHiddenCellRows = 3;
// this._iCellCountEachRow = 3;
// this._fCellMarginTop = 3;
// break;
// }
//重新开始
let lvCategoryList = nodeCategoryList.getComponent(ListView);
if (!lvCategoryList) {
lvCategoryList = nodeCategoryList.addComponent(ListView);
}
lvCategoryList.init(this, this._iShowCellRows, this._iAlphaCellRows, this._iHiddenCellRows, this._iCellCountEachRow, this._strSongListCellComponentName,
this._iBeginPositionX, this._iBeginPositionY,//起始位置
this._fCellMarginTop, this._fCellMarginRight, this._fCellMarginBottom, this._fCellMarginLeft,
1, 1, //0-横向 1-纵向
function () {
this.renderCategoryList(cId);
}
);
// this._strAppId = this._oInit.aNavList[this._oSceneContext.iNaviIndex].appId;
// lvCategoryList.setDataDecorator(
// function (oData, onDecorate, oScope) {
// let aData = oData.refData;
// //造一个跳转tvlink
// for (let i = 0; i < aData.length; i++) {
// //造一个跳转界面
// let tvlink = '{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneProgram",\
// "appId":"' + self._strAppId + '","id":"' + aData[i].id + '"}}]}';
// aData[i].tvlink = tvlink;
// }
// if (onDecorate) {
// if (null != oScope) {
// onDecorate.call(oScope, aData);
// } else {
// onDecorate(aData);
// }
// }
// }
// );
// lvCategoryList.setDataPositionRender(function (iPosition, iCount) {
// //这里是ListView的this 执行时作用域
// let nodeDataPosition = self.node.getChildByName('DataPosition');
// if (null == iCount) {
// iCount = parseInt(nodeDataPosition.getComponent(cc.Label).string.split('/')[1]);
// // cc.log(iCount);
// }
// nodeDataPosition.getComponent(cc.Label).string = Math.ceil(Math.min((iPosition + self._iShowCellRows * self._iCellCountEachRow - 1), iCount) / self._iShowCellRows / self._iCellCountEachRow) + " / " + Math.ceil(iCount / self._iShowCellRows / self._iCellCountEachRow);
// nodeDataPosition.x = Common.SCREEN_WIDTH / 2 - 70 - nodeDataPosition.width / 2;
// // this._compSceneCanvas.checkCountAndDisplayTopBtns(iCount);
// });
}
},
renderCategoryList: function (cId) {
// let strAppId = this._oInit.aNavList[this._oSceneContext.iNaviIndex].appId;
let strAppId = "";
let nodeCategoryList = this.node.getChildByName('CategoryList');
//请求列表
let oMediaParas = {};
oMediaParas.categoryId = cId;//
oMediaParas.appId = strAppId;
let iStart1 = 0;
if (null != this._oSceneContext.categoryRecordIndexOfFirstCell) {
iStart1 = this._oSceneContext.categoryRecordIndexOfFirstCell;
}
let lvCategoryList = nodeCategoryList.getComponent(ListView);
//函数默认取一页数据,但是第一次显示需要加上Alpha的部分
lvCategoryList.setDataSource(
"GET",
Common.TOPDRAW_API_SERVER + "Media/List",
oMediaParas,
iStart1, (lvCategoryList.getShowCellRows() + lvCategoryList.getAlphaCellRows()) * lvCategoryList.getCellCountEachRow(),
null, null
);
let strResponse = this._oInit[this._oSceneContext._iCurrentLeftIndex];
lvCategoryList.loadData(
function (strResponse) {
lvCategoryList.renderInitData(strResponse, function () {
var oJSONResult = JSON.parse(strResponse);
// if (oJSONResult.resultSet.length <= 0) { //没有数据就显示占位图
// cc.find('BlankIcon', this.node).opacity = 255;
// } else {
// cc.find('BlankIcon', this.node).opacity = 0;
// }
this._bInitCategoryListSuccess = true;
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
this.checkDataReadyAndInitFocus();
});
}, null, this, strResponse
);
},
checkDataReadyAndInitFocus: function () {
if (!this._bIsFocusInit && this._bInitCategoryListSuccess) {
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, 10, 6, 1.1, true);
this._lastFocus = nodeInitFocus.getComponent(FocusInfo);
if (0 == nodeInitFocus.name.indexOf("topNavi")) {
this._cFocus.hide();
}
if (0 == nodeInitFocus.getName().indexOf('CategoryListCell')) {
nodeInitFocus.getChildByName("Normal").active = false;
nodeInitFocus.getChildByName("Name").active = true;
nodeInitFocus.getComponent(ListCell).setUIWithFocus();
}
//处理焦点位于下方问题
if (this._oSceneContext.typeListY) {
this._nodeTypeList.y = this._oSceneContext.typeListY;
}
},
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, null, Direct);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
},
checkFocusTarget: function (fiFocusTarget, oScrollParameter, Direct) {
this._cFocus.show();
// cc.log("目标节点:" + fiFocusTarget.node.x);
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("topNavi")) {
this._cFocus.hide();
if (0 != this._fiCurrentFocus.node.name.indexOf("topNavi")) {//如果不是TypeList之间跳转,则哪里来回哪里去
fiFocusTarget = cc.find("topNavi" + this._oSceneContext._iCurrentLeftIndex, this._nodeTypeList).getComponent(FocusInfo);
}
}
//打补丁,焦点在TypeList向下滑动,会找到category的焦点,禁掉这种
if (0 == this._fiCurrentFocus.node.name.indexOf("topNavi") && 0 != fiFocusTarget.node.name.indexOf("topNavi")
&& Direct == Common.MOVE_DIRECTION_DOWN) {
this._cFocus.hide();
fiFocusTarget = null;
}
//打补丁:Direct != Common.MOVE_DIRECTION_LEFT,右侧categoryCell跳到左侧总会出错
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("topNavi") && Direct != Common.MOVE_DIRECTION_LEFT) {
if (-fiFocusTarget.node.y + fiFocusTarget.node.height / 2 - this._nodeTypeList.y >= this._nodeTypeListWrapper.height) {
oScrollParameter = this._nodeTypeList.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep(-(-fiFocusTarget.node.y + fiFocusTarget.node.height / 2 - this._nodeTypeList.y) + this._nodeTypeListWrapper.height);
oScrollParameter.setTargetPosition(this._nodeTypeList.y - oScrollParameter.getStep());
this._oSceneContext.nodeTypeListY = this._nodeTypeList.y - oScrollParameter.getStep();
}
if (-fiFocusTarget.node.y - this._nodeTypeList.y - 30 < 0) { //打补丁:30
oScrollParameter = this._nodeTypeList.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep(-fiFocusTarget.node.y - fiFocusTarget.node.height / 2 - this._nodeTypeList.y);
oScrollParameter.setTargetPosition(this._nodeTypeList.y + oScrollParameter.getStep())
this._oSceneContext.nodeTypeListY = this._nodeTypeList.y + oScrollParameter.getStep();
}
}
return [fiFocusTarget, oScrollParameter];
},
onKeyUp: function (event) {
// cc.log(this._lastFocus.node.name + " down->抬起。。。" + this._fiCurrentFocus.node.name);
cc.log("抬起:" + event.keyCode);
if (this._lastFocus != null && 0 == this._lastFocus.node.getName().indexOf('topNavi')
&& 0 == this._fiCurrentFocus.node.getName().indexOf('topNavi')
&& event.keyCode != (Common.ANDROID_KEY.left || cc.macro.KEY.left)) {
this.scheduleOnce(function () {
this.getSimulateRequest();
}, 0);
}
},
onKeyDown: function (event) {
this._super(event);
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
this._lastFocus = this._fiCurrentFocus; //存储上一个节点
switch (event.keyCode) {
case cc.macro.KEY.up:
case Common.ANDROID_KEY.up:
// cc.log("变量值:"+this._bIsDataListMoving);
if (this._bIsDataListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('CategoryListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('CategoryListCell', ''));
// cc.log("当前时多少条目:" + index);
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowUp(index, this._oInit[this._oSceneContext._iCurrentLeftIndex])) {
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
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:
if (this._bIsDataListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('CategoryListCell')) {
var index = parseInt(this._fiCurrentFocus.node.getName().replace('CategoryListCell', ''));
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowDown(null, index, this._oInit[this._oSceneContext._iCurrentLeftIndex])) {
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
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 {
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();
let cellData = JSON.stringify(this._fiCurrentFocus.node.getComponent(ListCell)._cellData);
// cc.log("tvlink===============" + JSON.stringify(this._fiCurrentFocus.node.getComponent(ListCell)._cellData));
try {
let oTVLink = JSON.parse(strTVLink);
let aOperationList = oTVLink.click;
this._oSceneContext._iPageIndex = 1;
for (let i = 0; i < aOperationList.length; i++) {
switch (aOperationList[i].action) {
case "changeLayout":
default:
aOperationList[i]['parameters']["cellData"] = cellData;
this.doTVLinkAction(aOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
onBeforeFocusChange: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
if (0 == this._fiCurrentFocus.node.getName().indexOf('topNavi')) {
// 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("topNavi", '');
if (this._oInit.aTopNaviImg[iIndex]) {
if (0 == fiTo.node.getName().indexOf('topNavi')) {
// cc.loader.loadRes(this._oInit.aTopNaviImg[iIndex], cc.Texture2D, function (err, texture) {
// fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
// });
Network.loadImageInNativeRuntime(
this._oInit.aTopNaviImg[iIndex], null,
function (texture, iRequestId) {
fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
}, function () { }, this
);
} else {
// cc.loader.loadRes(this._oInit.aTopNaviImg[iIndex], cc.Texture2D, function (err, texture) {
// fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiFrom.node.height * 2, fiFrom.node.width, fiFrom.node.height));
// });
Network.loadImageInNativeRuntime(
this._oInit.aTopNaviImg[iIndex], null,
function (texture, iRequestId) {
fiFrom.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiFrom.node.height * 2, fiFrom.node.width, fiFrom.node.height));
}, function () { }, this
);
}
// 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 == fiFrom.node.getName().indexOf('CategoryListCell')) {
fiFrom.node.getChildByName("Normal").active = true;
fiFrom.node.getChildByName("Name").active = false;
fiFrom.node.getComponent(ListCell).setUIWithoutFocus();
}
// 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) {
let fiTo = event.detail.to;
let fiFrom = event.detail.from;
if (0 == fiTo.node.getName().indexOf('topNavi')) {
let iIndex = fiTo.node.name.replace("topNavi", '');
// fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
// cc.log(iIndex + " ... " + this._oInit.aTopNaviImg[iIndex]);
if (this._oInit.aTopNaviImg[iIndex]) {
// cc.loader.loadRes(this._oInit.aTopNaviImg[iIndex], cc.Texture2D, function (err, 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));
// });
Network.loadImageInNativeRuntime(
this._oInit.aTopNaviImg[iIndex], null,
function (texture, iRequestId) {
fiTo.node.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
}, function () { }, this
);
// Network.loadImageInNativeRuntime(
// this._oInit.aTopNaviImg[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
// );
}
if (0 == fiFrom.node.getName().indexOf('topNavi')) {
this._oSceneContext._iCurrentLeftIndex = iIndex;
this._oSceneContext.categoryRecordIndexOfFirstCell = 0; //将列表记录置空
// this.scheduleOnce(function () { //这个放到onKeyUp中去,解决长按导致的焦点丢失
// cc.log("onAfter..." + iIndex);
// // this.requestMediaList(1); //重新渲染CategoryList
// this.getSimulateRequest();
// }, 0);
}
}
if (0 == fiTo.node.getName().indexOf('CategoryListCell')) {
fiTo.node.getChildByName("Normal").active = false;
fiTo.node.getChildByName("Name").active = true;
fiTo.node.getComponent(ListCell).setUIWithFocus();
}
// 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
// );
// }
// }
},
onListScrollStart: function () {
this._bIsDataListMoving = true;
// cc.log("scroll start");
},
onListScrollEnd: function () {
this._bIsDataListMoving = false;
// cc.log("scroll completed");
},
});