Search.js
31.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
//搜索界面
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
var ListView = require('ListView');
var ListCell = require('ListCell');
cc.Class({
extends: TVCanvas,
properties: {
spriteKeywordDelete: cc.Sprite,
_bBackStatus: false,
PFB_RECORD: {
default: null,
type: cc.Prefab,
},
PFB_CHAR: {
default: null,
type: cc.Prefab,
},
PFB_TYPE: {
default: null,
type: cc.Prefab,
},
},
onLoad: function () {
this._super();
this.spriteKeywordDelete.spriteFrame.setRect(cc.rect(0, 0, this.spriteKeywordDelete.node.width, this.spriteKeywordDelete.node.height));
this._oInit = {
keyword: '',
aChar: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
};
//-----------上下文及参数相关处理------------
let oSceneParameter = this._cApplication.getTopSceneParameter();
if (oSceneParameter) {
this._strAppId = oSceneParameter.appId;//应用id
}
//恢复上下文
if (this._cApplication.getBackStatus()) {
this._oSceneContext = this._cApplication.popSceneContext();
this._cApplication.setBackStatus(false);
this._bBackStatus = true;
} else {
this._oSceneContext = {};
this._oSceneContext._iCurrentTypeIndex = 0;
this._oSceneContext.categoryRecordIndexOfFirstCell = 0;
this._oSceneContext.nodeTypeListX = 0;
this._oSceneContext.focusPath = "KeywordsDelete";
this._oSceneContext.elderTypeId = (oSceneParameter != null ? oSceneParameter.elderTypeId : 0) || 37; //从上级拿过来的二级父Id
}
this._strAppId = this._strAppId || "tda7e47f868313d9f5"; //测试
//---------上下文及参数相关处理结束-----------
//Type分类框框
this._nodeTypeListWrapper = cc.find("TypeListArea/TypeListWrapper", this.node);
this._nodeTypeList = cc.find("TypeList", this._nodeTypeListWrapper);
this._nodeTypeList.addComponent(TVScrollParameter);
//Record分类框框
this._nodeRecordListWrapper = cc.find("RecordListArea/RecordListWrapper", this.node);
this._nodeRecordList = cc.find("RecordList", this._nodeRecordListWrapper);
this._nodeRecordList.addComponent(TVScrollParameter);
//Category分类框框
this._nodeCategoryList = cc.find("CategoryList", this.node);
let lvCategoryList = this._nodeCategoryList.addComponent(ListView);
lvCategoryList.init(this, 2, 1, 2, 3, 'SearchCategoryListCell',
-215, 114, //起始位置
0, 20, 16, 0, //margin
1, 1,
function () {
// this.navRequest(); //暂时不需要Nav
this.getCategoryList();
}
);
// lvCategoryList.setScrollBarBlockHeight(94);//这里有些问题,先注释掉
//滚动条按钮
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.getPageBg(this, "background");
this.initCharList();
// this.getRecordListRequest(); //暂时不需要请求搜索记录
cc.find("RecordListArea", this.node).active = false; //隐藏搜索记录面板,显示按键栏
cc.find("CharList", this.node).active = true;
this.checkDataReadyAndInitFocus();
},
initCharList: function () {
let y = 0;
for (let i = 0; i < 36; i++) {
if (i % 6 == 0) y -= 68;
let nodeCharListCell = cc.instantiate(this.PFB_CHAR);
cc.find("Text", nodeCharListCell).getComponent(cc.Label).string = this._oInit.aChar[i];
nodeCharListCell.x = nodeCharListCell.width / 2 + (i % 6) * (nodeCharListCell.width + 4);
nodeCharListCell.y = y + 34; //整体上移半行
cc.find("CharList", this.node).addChild(nodeCharListCell, 10, "CharListCell" + i);
let fiCharBlock = nodeCharListCell.addComponent(FocusInfo);
fiCharBlock.init('', false, null, null, 1.0);
this._aFocusTargets[0]['char_list_cell_' + i] = nodeCharListCell;
}
},
getRecordListRequest: function () {
var oGetRecordListParas = {
'view': 'json',
token: Common.TEST_API_TOKEN,
}
Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Search/GetPersonalMediaSearchHistory", null, oGetRecordListParas,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
if (oJSONResult.resultSet.length > 0) {
this._oInit.aRecordMediaList = [];
var aHistory = oJSONResult.resultSet[0].history;
for (var i = 0; i < aHistory.length; i++) {
var aMedia = aHistory[i].split(',');
var aCell = {};
aCell.id = aMedia[0];
aCell.name = aMedia[1];
aCell.appId = aMedia[2];
this._oInit.aRecordMediaList.push(aCell);
let nodeRecordListCell = cc.instantiate(this.PFB_RECORD);
nodeRecordListCell.y = -nodeRecordListCell.height / 2 - i * (nodeRecordListCell.height + 5) - 10;
this._nodeRecordList.addChild(nodeRecordListCell, 10, "RecordListCell" + i);
//准备焦点坐标
let fiTypeBlock = nodeRecordListCell.addComponent(FocusInfo);
fiTypeBlock.init('', true, null, null, 1.0);
this._aFocusTargets[0]['record_list_cell_' + i] = nodeRecordListCell;
cc.find('Name/NormalName/MidName', nodeRecordListCell).getComponent(cc.Label).string = aCell.name;
cc.find('Name/ActiveName/NameContainer/NameText/NameText1', nodeRecordListCell).getComponent(cc.Label).string = aCell.name;
cc.find('Name/ActiveName/NameContainer/NameText/NameText2', nodeRecordListCell).getComponent(cc.Label).string = aCell.name;
}
this._bInitHistorySuccess = true;
} else {
if (!this._bBackStatus)
this._oSceneContext.focusPath = "KeywordsDelete";
this._bInitHistorySuccess = true;
cc.find("RecordListArea", this.node).active = false; //隐藏搜索记录面板,显示按键栏
cc.find("CharList", this.node).active = true;
}
this.checkDataReadyAndInitFocus();
cc.log("Success GET RecordList...");
} else {
cc.log("Error GET RecordList..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When RecordList..." + error);
}
},
function (strResponse) {
cc.log("Error When RecordList..." + strResponse);
}, this, "uuid");
},
navRequest: function () {
var oNavParas = {
'view': 'json',
"name": "indexSearch",
"start": "0",
"limit": "15",
token: Common.TEST_API_TOKEN,
"sortField": "left",
"sortDirection": "desc"
}
Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Promotion/ListItemByName", null, oNavParas,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
if (oJSONResult.resultSet.length > 0) {
this._oInit.aNavList = [];
this._oInit.aTypeListImg = [];
for (var i = 0; i < oJSONResult.resultSet.length; i++) {
//恢复上下文带过来的位置
if (this._oSceneContext.requestedTypeId && this._oSceneContext.requestedTypeId == oJSONResult.resultSet[i].id) {
this._oSceneContext._iCurrentTypeIndex = i;
}
let oTvlink = JSON.parse(oJSONResult.resultSet[i].tvlink);
let oListCell = {};
oListCell.appId = oTvlink.appId;
oListCell.dirURL = oTvlink.dirURL;
oListCell.destRUL = oTvlink.destRUL;
this._oInit.aNavList.push(oListCell);
let nodeTypeListCell = cc.instantiate(this.PFB_TYPE);
nodeTypeListCell.x = i * (2 * nodeTypeListCell.width / 5) + 50;
this._nodeTypeList.addChild(nodeTypeListCell, 10, "TypeListCell" + i);
//准备焦点坐标
let fiTypeBlock = nodeTypeListCell.addComponent(FocusInfo);
fiTypeBlock.init('', true, null, null, 1.0);
this._aFocusTargets[0]['type_list_cell_' + i] = nodeTypeListCell;
if (oJSONResult.resultSet[i].image[0]) {
this._oInit.aTypeListImg.push(Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl);
let width = oJSONResult.resultSet[i].width;
let height = oJSONResult.resultSet[i].height;
nodeTypeListCell.width = width;
nodeTypeListCell.height = height;
if (this._oSceneContext._iCurrentTypeIndex == i) {
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl,
function (texture) {
cc.find('Bg', nodeTypeListCell).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, height, width, height));
}, null, this
);
} else {
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl,
function (texture) {
cc.find('Bg', nodeTypeListCell).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, width, height));
}, null, this
);
}
}
}
// this.getCategoryList(); //暂时不在这里请求
} else {
// this._oSceneContext.focusPath = "app";
}
cc.log("Success GET TYPE LIST...");
} else {
cc.log("Error GET TYPE LIST..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When IndexStar..." + error);
}
},
function (strResponse) {
cc.log("Error When IndexStar..." + strResponse);
}, this, "uuid");
},
//搜索有条件的数据
addSearchRecordRequest: function () {
},
getCategoryList: function () {
let lvCategoryList = this._nodeCategoryList.getComponent(ListView);
let oCategoryRequestParameters = {
"view": "json",
keyword: this._oInit.keyword,
// "appId": this._oInit.aNavList[this._oSceneContext._iCurrentTypeIndex].appId || "",
"appId": "",
sortField: "play_times",
sortDirection: "desc",
token: Common.TEST_API_TOKEN_EDU,
};
let iStart1 = 0;
if (null != this._oSceneContext.categoryRecordIndexOfFirstCell && this._oSceneContext.categoryRecordIndexOfFirstCell != 0) {
iStart1 = this._oSceneContext.categoryRecordIndexOfFirstCell;
}
lvCategoryList.setDataSource(
"GET",
Common.TOPDRAW_API_SERVER_EDU + "Media/List",
oCategoryRequestParameters,
iStart1, (lvCategoryList.getShowCellRows() + lvCategoryList.getAlphaCellRows()) * lvCategoryList.getCellCountEachRow(),
"", ""
);
lvCategoryList.loadData(
function (strResponse) {
lvCategoryList.renderInitData(strResponse, function () {
this._bIsCategoryListDataInit = true;
// this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
this.checkDataReadyAndInitFocus();
});
},
null,
this
);
var self = this;
this._iShowCellRows = 2;
this._iCellCountEachRow = 3;
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 - 100 - nodeDataPosition.width / 2;
// this._compSceneCanvas.checkCountAndDisplayTopBtns(iCount);
});
// self._strAppId = this._oInit.aNavList[this._oSceneContext._iCurrentTypeIndex].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);
}
}
}
);
},
checkDataReadyAndInitFocus: function () {
if (!this._bIsFocusInit) {
this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行
this.initFocus();
}, 0);
this._bIsFocusInit = true;
}
},
initFocus: function () {
var fiKeywordDelete = this.spriteKeywordDelete.addComponent(FocusInfo);
this._aFocusTargets[0]['to_keyword_delete'] = fiKeywordDelete;
fiKeywordDelete.init(
null, true
);
var nodeInitFocus = cc.find(this._oSceneContext.focusPath, this.node);
var nodeFocus = new cc.Node('nodeFocus');
this.node.addChild(nodeFocus, 10);
this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
this._cFocus.init('focusContainer', this,
nodeInitFocus.getComponent(FocusInfo),
Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 2, 6, 1.0);
if (0 == nodeInitFocus.name.indexOf('RecordListCell')) {
this._cFocus.hide();
nodeInitFocus.getChildByName("Bg").active = true;
} else if (0 == nodeInitFocus.name.indexOf('KeywordsDelete')) {
// nodeInitFocus.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, nodeInitFocus.height, nodeInitFocus.width, nodeInitFocus.height));
cc.loader.loadRes('button/char_delete', cc.Texture2D, function (err, texture) {
nodeInitFocus.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, nodeInitFocus.height, nodeInitFocus.width, nodeInitFocus.height));
});
}
//处理焦点位于下方问题
if (this._oSceneContext.nodeTypeListX) {
this._nodeTypeList.x = this._oSceneContext.nodeTypeListX;
}
},
onKeyDown: function (event) {
this._super(event);
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
let aCheckResult;
//TODO:给ListView传值,使其可以让滑块跟随滚动
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList) {
lvCategoryList.setCurrentFocus(this._fiCurrentFocus);
}
if (event.keyCode == cc.macro.KEY.up || event.keyCode == Common.ANDROID_KEY.up) {
if (this._bIsCategoryItemMoving || this._bIsSongListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('ScrollBarBlock')) { //如果滚动条
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollAPageUp()) {
}
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)) {
return;
}
}
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, 0, Common.MOVE_DIRECTION_UP);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, null, oScrollParameter);
}
if (event.keyCode == cc.macro.KEY.right || event.keyCode == Common.ANDROID_KEY.right) {
fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, 0, Common.MOVE_DIRECTION_RIGHT);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_RIGHT, null, oScrollParameter);
}
if (event.keyCode == cc.macro.KEY.down || event.keyCode == Common.ANDROID_KEY.down) {
if (this._bIsCategoryItemMoving || this._bIsSongListMoving) {
return;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('ScrollBarBlock')) { //如果是滚动条
let lvCategoryList = this.node.getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollAPageDown()) {
}
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)) {
return;
}
}
fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, 0, Common.MOVE_DIRECTION_DOWN);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_DOWN, null, oScrollParameter);
}
if (event.keyCode == cc.macro.KEY.left || event.keyCode == Common.ANDROID_KEY.left) {
fiFocusTarget = this._cFocus.findTarget(this._fiCurrentFocus, this._aFocusTargets, 0, Common.MOVE_DIRECTION_LEFT);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_LEFT, null, oScrollParameter);
}
if (event.keyCode == cc.macro.KEY.enter || event.keyCode == Common.ANDROID_KEY.enter) {
if (0 == fiCurrentFocus.node.name.indexOf('CharListCell')) {
if (this._oInit.keyword.length < 30) {
let char = fiCurrentFocus.node.getChildByName('Text').getComponent(cc.Label).string;
this._oInit.keyword += char;
}
cc.find("KeywordsContainer/Text", this.node).getComponent(cc.Label).string = this._oInit.keyword;
this.getCategoryList();
} else if (0 == fiCurrentFocus.node.name.indexOf('KeywordsDelete')) {
if (this._oInit.keyword.length > 0) {
this._oInit.keyword = this._oInit.keyword.substr(0, this._oInit.keyword.length - 1); //删除一个字符
}
cc.find("KeywordsContainer/Text", this.node).getComponent(cc.Label).string = this._oInit.keyword;
if (this._oInit.keyword.length <= 0) {
cc.find("KeywordsContainer/Text", this.node).getComponent(cc.Label).string = "如搜索奥姆,输入AM即可";
}
this.getCategoryList();
}
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
}
if (event.keyCode == cc.macro.KEY.space) {
// this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
}
if (event.keyCode == cc.macro.KEY.backspace || event.keyCode == 6) {
this.backAScene();
}
//记录CategoryList滚动位置
if (lvCategoryList) {
this._oSceneContext.categoryRecordIndexOfFirstCell = lvCategoryList.getRecordIndexOfFirstCellInPage();
}
},
checkFocusTarget: function (fiFocusTarget, oScrollParameter) {
//如果在typeList中跳转,要检测categoryList列表是否初始化完成
if (0 == this._fiCurrentFocus.node.name.indexOf("TypeListCell") && 0 != fiFocusTarget.node.name.indexOf("TypeListCell")) {
if (!this._bIsCategoryListDataInit) {
return [null, oScrollParameter];
}
}
if (0 == this._fiCurrentFocus.node.name.indexOf("RecordListCell") && 0 != fiFocusTarget.node.name.indexOf("RecordListCell")) {
this._cFocus.show();
cc.find("RecordListArea", this.node).active = false;
cc.find("CharList", this.node).active = true;
}
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("TypeListCell")) {
if (0 != this._fiCurrentFocus.node.name.indexOf("TypeListCell")) {//如果不是TypeList之间跳转,则哪里来回哪里去
fiFocusTarget = cc.find("TypeListCell" + this._oSceneContext._iCurrentTypeIndex, this._nodeTypeList).getComponent(FocusInfo);
} else {
if (fiFocusTarget.node.x - fiFocusTarget.node.width / 2 + this._nodeTypeList.x >= this._nodeTypeListWrapper.width) {
oScrollParameter = this._nodeTypeList.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep((fiFocusTarget.node.x + fiFocusTarget.node.width / 2 + this._nodeTypeList.x) - this._nodeTypeListWrapper.width);
oScrollParameter.setTargetPosition(this._nodeTypeList.x - oScrollParameter.getStep());
this._oSceneContext.nodeTypeListX = this._nodeTypeList.x - oScrollParameter.getStep();
}
if (fiFocusTarget.node.x + this._nodeTypeList.x < 0) {
oScrollParameter = this._nodeTypeList.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep(-fiFocusTarget.node.x + fiFocusTarget.node.width / 2 - this._nodeTypeList.x);
oScrollParameter.setTargetPosition(this._nodeTypeList.x + oScrollParameter.getStep())
this._oSceneContext.nodeTypeListX = this._nodeTypeList.x + oScrollParameter.getStep();
}
}
}
return [fiFocusTarget, oScrollParameter];
},
onBeforeFocusChange: function (event) {
this._super(event);
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
var index = parseInt(this._fiCurrentFocus.node.getName().replace('CategoryListCell', ''));
// cc.log("上一个列表的索引值:"+fiFrom.node.getName());
if (0 == fiFrom.node.getName().indexOf('CategoryListCell')) {
fiFrom.node.getComponent(ListCell).setUIWithoutFocus();
}
if (0 == fiFrom.node.getName().indexOf('RecordListCell')) {
fiFrom.node.getChildByName('Bg').active = false;
}
if (0 == fiFrom.node.getName().indexOf('CharListCell')) {
fiFrom.node.getChildByName('ActiveBg').active = false;
fiFrom.node.getChildByName('Bg').active = true;
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('TypeListCell') && 0 == fiTo.node.getName().indexOf('TypeListCell')) {
// fiFrom.node.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
if (this._oInit.aTypeListImg[this._oSceneContext._iCurrentTypeIndex]) {
Network.loadImageInNativeRuntime(
this._oInit.aTypeListImg[this._oSceneContext._iCurrentTypeIndex],
function (texture) {
fiFrom.node.getChildByName("Bg").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('KeywordsDelete')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/char_delete', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
});
}
},
onAfterFocusChange: function (event) {
this._super(event);
var self = this;
let fiTo = event.detail.to;
let fiFrom = event.detail.from;
// cc.log("当前列表的索引值:"+fiTo.node.getName());
if (0 == fiTo.node.getName().indexOf('CategoryListCell')) {
fiTo.node.getComponent(ListCell).setUIWithFocus();
}
if (0 == fiTo.node.getName().indexOf('CharListCell')) {
fiTo.node.getChildByName('Bg').active = false;
fiTo.node.getChildByName('ActiveBg').active = true;
}
if (0 == fiTo.node.getName().indexOf('RecordListCell')) {
fiTo.node.getChildByName('Bg').active = true;
}
if (0 == fiTo.node.getName().indexOf('KeywordsDelete')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/char_delete', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
});
}
if (0 == fiTo.node.getName().indexOf('TypeListCell') && 0 == fiFrom.node.getName().indexOf('TypeListCell')) {
let iIndex = fiTo.node.name.replace("TypeListCell", '');
// fiTo.node.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
if (this._oInit.aTypeListImg[iIndex]) {
Network.loadImageInNativeRuntime(
this._oInit.aTypeListImg[iIndex],
function (texture) {
fiTo.node.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
}, null, this
);
}
this._bIsCategoryListDataInit = false; //初始它
this._iChangeingTypeIndex = iIndex;
this.scheduleOnce(this.changeCategoryListByType, 1);
}
},
changeCategoryListByType: function () {
this._oSceneContext._iCurrentTypeIndex = this._iChangeingTypeIndex;
this.getCategoryList();
},
doCurrentFocusTVLinkAction: function (strAction) {
let strTVLink = this._fiCurrentFocus.getTVLink();
var joTVLink = null;
try {
joTVLink = JSON.parse(strTVLink);
let jaOperationList = joTVLink.click;
for (let i = 0; i < jaOperationList.length; i++) {
switch (jaOperationList[i].action) {
default:
this.doTVLinkAction(jaOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
onListScrollStart: function () {
this._bIsSongListMoving = true;
cc.log("scroll start");
},
onListScrollEnd: function () {
this._bIsSongListMoving = false;
cc.log("scroll completed");
},
onDestroy: function () {
cc.director.emit('stop_render'); //分发事件
},
});