main.js
86.5 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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
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 TVScrollParameter = require('TVScrollParameter');
// var ListView = require('ListView');
var ListView = require('ListView_SimulateData');
var BusinessParameter = require('BusinessParameter');
var ListCell = require('ListCell');
//热更新相关
var UpdatePanel = require('UpdatePanel');
var info = cc.Class({
name: 'info',
properties: {
target: cc.Node,
num: 0
}
});
cc.Class({
extends: TVCanvas,
properties: {
test_json: {
default: null,
type: cc.JsonAsset
},
PFB_COMMON_WIDGET: {
default: null,
type: cc.Prefab
},
PFB_COMMON: {
default: null,
type: cc.Prefab
},
PFB_MAIN_HIGH_SCORE: {
default: null,
type: cc.Prefab
},
PFB_VIEWPAGER_LABEL: {
default: null,
type: cc.Prefab
},
targetAry: {
default: [],
type: [info],
},
//热更新弹窗
panel: UpdatePanel,
manifestUrl: {
type: cc.Asset,
default: null
},
},
onLoad: function () {
this._super();
this._iSceneStatus = 0;
this._oInit = {};
this._bAbleHotUpdate = false;
this._bIsDataListMoving = false;
this._bIsScrollViewMoving = false;
this._bInitCategoryListSuccess = false;
this._bInitRecommendDataSuccess = false;
this._scrollview = this.node.getComponent(cc.ScrollView);
this._oSceneContext.focusPath = "scrollContent/TopNavi/topNavi1";
this._oSceneContext._iPageIndex = 1;
this._oSceneContext._iCurrentLeftIndex = 1;
this._oSceneContext._iViewPagerIndex = 0;
let oSceneParameter = this._cApplication.getTopSceneParameter();
let aSceneParameter = this._cApplication.getSceneParameter();
cc.find("update/update_panel/update_btn", this.node).getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 208, 100));
cc.find("update/update_panel/close_btn", this.node).getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 208, 100));
cc.log("main->aSceneParameter..." + aSceneParameter);
cc.log("main->oSceneParameter..." + oSceneParameter);
//首页无参数
// if (oSceneParameter) {
// this._oSceneContext._iCurrentLeftIndex = oSceneParameter && oSceneParameter._iCurrentLeftIndex || 1;
// cc.log("current top navi..." + this._oSceneContext._iCurrentLeftIndex);
// }
//有必要的话恢复上下文
// cc.log("恢复上下文:" + this._cApplication.getBackStatus());
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("恢复上下文后的光标:" + this._oSceneContext._iPageIndex);
this._oSceneContext._iCurrentLeftIndex = this._oSceneContext._iCurrentLeftIndex == 0 ? 1 : this._oSceneContext._iCurrentLeftIndex;
this.node.getChildByName("scrollContent").height = 2300; //这里暂且写死,scrollView有bug
this._scrollview.scrollToTop();
//搞轮播图
this.initViewPager();
//升级相关
this.getUpdateDesc();
this.getMainLayoutJsonRequest();
},
//轮播图相关
initViewPager: function () {
this._pageView = cc.find('scrollContent/ViewPagerArea', this.node).getComponent(cc.PageView);
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_viewpager.json", null, null,
function (strResponse) {
try {
// cc.log("请求viewPager数据:" + strResponse);
var oJSONResult = JSON.parse(strResponse);
for (let i = 0; i < oJSONResult.resultSet.length; i++) {
let nodeViewPager = cc.find("scrollContent/ViewPagerArea/view/Content/page_" + i, this.node);
let blockShadow = cc.find("scrollContent/BlockShadow", this.node);
//搞图片
Network.loadImageInNativeRuntime(Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].images.fileUrl, null,
function (texture, iRequestId) {
nodeViewPager.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
}, function () { }, this
);
let nodeNav = cc.instantiate(this.PFB_VIEWPAGER_LABEL);
nodeNav.getComponent(cc.Widget).top = i * (nodeNav.height + 2);
blockShadow.addChild(nodeNav, 10, "view_pager_label" + i);
nodeNav.getComponent('pfbViewPagerLabelCell').init(oJSONResult.resultSet[i], function () { //让细胞自己渲染
}, i);
let fiNav = nodeNav.addComponent(FocusInfo);
fiNav.init(oJSONResult.resultSet[i].tvlink, false, null, null, 1.1); //最后一个参数决定要不要放大显示
this._aFocusTargets[0]["view_pager_label" + i] = nodeNav;
}
} catch (error) {
cc.log("Business Exception:Get initViewPager..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get initViewPager..." + strResponse);
}, this, "uuid");
},
//升级框内容
getUpdateDesc: function () {
let updateTitle = cc.find("update/update_panel/update_title", this.node);
let updateInfo = cc.find("update/update_panel/update_info", this.node);
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "updateDesc.json", null, null,
function (strResponse) {
try {
// cc.log("获取升级内容。。。" + strResponse);
var oJSONResult = JSON.parse(strResponse);
updateTitle.getComponent(cc.Label).string = "发现新版本(" + oJSONResult.versionCode + ")";
updateInfo.getComponent(cc.Label).string = oJSONResult.desc;
} catch (error) {
cc.log("Business Exception:Get getUpdateDesc..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get getUpdateDesc..." + strResponse);
}, this, "uuid");
},
//请求main_layout.json
getMainLayoutJsonRequest: function () {
var self = this;
if (self._oInit.oMainLayoutJson && self._oInit.oMainLayoutJson.children.length > 0) {
return;
}
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_layout.json", null, null,
function (strResponse) {
try {
// cc.log("远程数据:"+strResponse);
var oJSONResult = JSON.parse(strResponse);
self._oInit.oMainLayoutJson = oJSONResult;
//走马灯数据=========
this._oInit.aMarquee = oJSONResult.marquee.split(";");
// cc.log("走马灯获取的数据:" + this._oInit.aMarquee[1]);
//=========
self.getTopNaviRequest("topNavi");
self.getTopNaviRequest("topCell");
self.getRecommendModelRequest();
//在这里选择是初始化首页瀑布流还是初始化其他导航的列表数据
if (this._oSceneContext._iCurrentLeftIndex == 1) {
cc.log("初始化瀑布流");
self.getRightRecommendRequestData();
cc.find("scrollContent/ViewPagerArea", this.node).active = true;
cc.find("scrollContent/BlockShadow", this.node).active = true;
} else {
this.getSimulateRequest();
cc.log("不显示轮播图。。。");
cc.find("scrollContent/ViewPagerArea", this.node).active = false;
cc.find("scrollContent/BlockShadow", this.node).active = false;
}
//搞通知框
this.initNotifyBox();
} catch (error) {
cc.log("Business Exception:Get getMainLayoutJsonRequest..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get getMainLayoutJsonRequest..." + strResponse);
}, this, "uuid");
},
//走马灯通知
initNotifyBox: function () {
let nodeLabel = cc.find("scrollContent/notify/Label", this.node);
nodeLabel.width = 656;
let compMarquee = nodeLabel.addComponent("Marquee");
compMarquee.active = true;
compMarquee.init(null, this._oInit.aMarquee);
compMarquee.setUIWithFocus();
},
//请求顶部个人中心和订购按钮
getTopNaviRequest: function (strCellName) {
// Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_layout.json", null, null,
// function (strResponse) {
try {
// cc.log("获取的远程数据:"+JSON.stringify(this._oInit.oMainLayoutJson));
// var oJSONResult = this.test_json.json;
// this._oInit.oMainLayoutJson = oJSONResult;
var oJSONResult = this._oInit.oMainLayoutJson;
let aTopNaviJson;
if (strCellName == "topNavi") {
aTopNaviJson = oJSONResult.children[0].data.resultSet;
} else if (strCellName == "topCell") {
aTopNaviJson = oJSONResult.children[1].data.resultSet;
}
let count = aTopNaviJson.length;
let topNaviLayout = this.targetAry[0].target;
if (strCellName == "topNavi") {
this._oInit.aTopNaviImg = [];
} else {
this._oInit.aTopCellImg = [];
}
for (let i = 0; i < count; i++) {
let nodeNav = cc.instantiate(this.PFB_COMMON_WIDGET);
if (i > 0 && strCellName == "topNavi" || strCellName == "topCell") { //刨掉第一个logo图片
// cc.log("头部图片:"+aTopNaviJson[i].imageURL);
if (strCellName == "topCell") {
this._oInit.aTopCellImg.push(Common.TOPDRAW_IMAGE_SERVER + aTopNaviJson[i].imageURL);
} else {
this._oInit.aTopNaviImg.push(Common.TOPDRAW_IMAGE_SERVER + aTopNaviJson[i].imageURL);
}
let fiNav = nodeNav.addComponent(FocusInfo);
fiNav.init(
aTopNaviJson[i].tvlink,
true, null, null, 1.1 //最后一个参数决定要不要放大显示
);
this._aFocusTargets[0][strCellName + i] = nodeNav;
}
nodeNav.width = aTopNaviJson[i].width;
nodeNav.height = aTopNaviJson[i].height;
nodeNav.getChildByName('Pic').width = aTopNaviJson[i].width;
nodeNav.getChildByName('Pic').height = aTopNaviJson[i].height;
Network.loadImageInNativeRuntime(Common.TOPDRAW_IMAGE_SERVER + aTopNaviJson[i].imageURL, null,
function (texture, iRequestId) {
if (strCellName == "topNavi") {
nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, aTopNaviJson[i].width, aTopNaviJson[i].height));
if (i == 1 && 1 == this._oSceneContext._iCurrentLeftIndex && this._oSceneContext.focusPath != "scrollContent/TopNavi/topNavi1") {//恢复光标记忆不需要选中状态,将i先改为1,其他导航暂时不做光标记忆,有点复杂,后续考虑做。。。
nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, aTopNaviJson[i].height * 2, aTopNaviJson[i].width, aTopNaviJson[i].height));
} else if (i == this._oSceneContext._iCurrentLeftIndex) {
nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, aTopNaviJson[i].height, aTopNaviJson[i].width, aTopNaviJson[i].height));
}
} else {
nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, aTopNaviJson[i].width, aTopNaviJson[i].height));
}
}, function () { }, this
);
if (strCellName == "topNavi" && i > 0) {
nodeNav.getComponent(cc.Widget).top = aTopNaviJson[i].top - aTopNaviJson[i].height / 2;
} else {
nodeNav.getComponent(cc.Widget).top = aTopNaviJson[i].top;
}
nodeNav.getComponent(cc.Widget).left = aTopNaviJson[i].left;
topNaviLayout.addChild(nodeNav, 10, strCellName + i);
}
this.checkDataReadyAndInitFocus();
} catch (error) {
cc.log("Business Exception:Get getTopNaviRequest..." + error);
}
// },
// function (strResponse) {
// cc.log("Business Error:Get getTopNaviRequest..." + strResponse);
// }, this, "uuid");
},
//请求休闲益智的推荐位
getCategoryListRecommendRequest: function () {
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_category_list_recommend.json", null, null,
function (strResponse) {
try {
let categoryListRecommendLayout = cc.find("scrollContent/CategoryListRecommendLayout", this.node);
// var arrModules = this.test_category_list_recommend_json.json;
var arrModules = JSON.parse(strResponse);
let count = arrModules.data.resultSet.length;
for (let i = 0; i < count; i++) {
let nodeNav = cc.instantiate(this.PFB_COMMON_WIDGET);
let data = arrModules.data.resultSet[i];
nodeNav.width = data.width;
nodeNav.height = data.height;
nodeNav.getChildByName("Pic").width = data.width;
nodeNav.getChildByName("Pic").height = data.height;
// cc.loader.loadRes(data.imageURL, cc.Texture2D, function (err, texture) {
// nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
// });
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + data.imageURL, null,
function (texture, iRequestId) {
nodeNav.getChildByName("Pic").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
}, function () { }, this
);
nodeNav.getComponent(cc.Widget).top = data.top;
nodeNav.getComponent(cc.Widget).left = data.left;
categoryListRecommendLayout.addChild(nodeNav, 10, "category_list_recommend" + i);
let fiNav = nodeNav.addComponent(FocusInfo);
fiNav.init(
data.tvlink,
false, null, null, 1.0 //最后一个参数决定要不要放大显示
);
this._aFocusTargets[0]["category_list_recommend" + i] = nodeNav;
}
} catch (error) {
cc.log("Business Exception:Get getCategoryListRecommendRequest..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get getCategoryListRecommendRequest..." + strResponse);
}, this, "uuid");
},
getRecommendModelRequest: function () {
// var arrModules = this.layout_json.json.children;
var arrModules = this._oInit.oMainLayoutJson.children;
var aRecommend = arrModules[2].data.resultSet;
let count = aRecommend.length;
let recommendLayout = this.targetAry[1].target;
recommendLayout.width = arrModules[2].width;
recommendLayout.height = arrModules[2].height;
this._iRightRecommendHeight = arrModules[2].width;
if (arrModules[2].position[0] && arrModules[2].position[1]) { //确定位置
recommendLayout.getComponent(cc.Widget).top = arrModules[2].position[1]; //加20是内边距
recommendLayout.getComponent(cc.Widget).left = arrModules[2].position[0];
}
},
getRightRecommendRequestData: function () {
if (this._oInit.main_recommend) {
this.getRightRecommendRequest();
return;
}
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_recommend.json", null, null,
function (strResponse) {
try {
this._oInit.main_recommend = strResponse;
this.getRightRecommendRequest();
} catch (error) {
cc.log("Business Exception:Get getRightRecommendRequest..." + error);
}
},
function (strResponse) {
cc.log("Business Error:Get getRightRecommendRequest..." + strResponse);
}, this, "uuid");
},
//渲染推荐框架
getRightRecommendRequest: function () {
var self = this;
var rightNodeLayout = this.targetAry[1].target;
// Network.ajax("GET", Common.TOPDRAW_API_SERVER + "main/main_recommend.json", null, null,
// function (strResponse) {
try {
// var arrModules = waterfall_model.waterfall; //拿到模拟数据
// var arrModules = this.test_json.json;
var arrModules = JSON.parse(this._oInit.main_recommend);
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.isAlignLeft = true;
widgetLayout.top = bgHeight;
widgetLayout.left = 0;
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 && oModule.name == "SpecialList") { //子布局需要左右滑动
let specialListAreaNode = cc.find("SpecialListArea", this.node);
let specialListRectNode = cc.find("SpecialListWrapper", specialListAreaNode);
let specialListNode = cc.find("SpecialList", specialListRectNode);
this._specialListRectNode = specialListRectNode;
this._specialListNode = specialListNode;
this._specialListNode.addComponent(TVScrollParameter);
specialListAreaNode.width = 1280 - oModule.position[0];
specialListRectNode.width = 1280 - oModule.position[0];
specialListAreaNode.height = oModule.height;
specialListRectNode.height = oModule.height;
specialListAreaNode.getComponent(cc.Widget).top = oModule.position[1];
specialListAreaNode.getComponent(cc.Widget).left = oModule.position[0];
for (let k = 0; k < oModule.data.resultSet.length; k++) { //渲染子细胞
let node = cc.instantiate(this.PFB_COMMON);
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];
}
// if (oModule.data.resultSet[k].imageURL) {
// cc.loader.loadRes(oModule.data.resultSet[k].imageURL, cc.Texture2D, function (err, texture) {
// node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
// });
// }
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oModule.data.resultSet[k].imageURL, null,
function (texture, iRequestId) {
node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
}, function () { }, this
);
node.x = node.width / 2 + k * (node.width + 24) - 20;
// node.getComponent(cc.Widget).top = 0;
// node.getComponent(cc.Widget).left = node.width / 2 + k * (node.width + 24);
specialListNode.addChild(node, 10, "SpecialList" + k);
//准备焦点坐标
let fiNodeBlock = node.addComponent(FocusInfo);
fiNodeBlock.init('', true, null, null, 1.1);
fiNodeBlock.init(
oModule.data.resultSet[k].tvlink, true, null, null, 1.0 //最后一个参数决定要不要放大显示
);
this._aFocusTargets[0]["SpecialList" + k] = node;
}
specialListAreaNode.removeFromParent();
nodeLayout.addChild(specialListAreaNode, 10, "hasChildFrame");
}
else if (oModule.hasChildFrame && oModule.name != "SpecialList") {
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];
}
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_MAIN_HIGH_SCORE);
if (oModule.childrenSize[0] && oModule.childrenSize[1]) {
node.height = oModule.childrenSize[1]; //拿子节点的高
node.width = oModule.childrenSize[0];
if (oModule.name != "highScore") {
node.getChildByName('Pic').height = oModule.childrenSize[1]; //拿子节点的高
node.getChildByName('Pic').width = oModule.childrenSize[0];
}
}
if (oModule.data.resultSet[k].imageURL) {
// cc.loader.loadRes(oModule.data.resultSet[k].imageURL, cc.Texture2D, function (err, texture) {
// node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
// });
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oModule.data.resultSet[k].imageURL, null,
function (texture, iRequestId) {
node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
}, function () { }, this
);
}
//自动布局的文字填充
if (oModule.data.resultSet[k].title_visible == 1) { //
node.getComponent('pfbMainHighScoreCell').render(oModule.data.resultSet[k], function () { //让细胞自己渲染文字
}, k);
}
autoNode.addChild(node, 10, oModule.data.resultSet[k].code);
//准备焦点坐标
let fiNodeBlock = node.addComponent(FocusInfo);
// fiNodeBlock.init('', true, null, null, 1.1);
fiNodeBlock.init(
oModule.data.resultSet[k].tvlink, true, null, null, 1.1 //最后一个参数决定要不要放大显示
);
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_COMMON_WIDGET);
node.width = oModule.width;
node.height = oModule.height;
if (oModule.imageURL) {
if (oModule.name == "backToTop") {
// cc.loader.loadRes(oModule.imageURL, cc.Texture2D, function (err, texture) {
// node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, oModule.width, oModule.height));
// });
this._oInit.backToTopImg = Common.TOPDRAW_IMAGE_SERVER + oModule.imageURL;
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oModule.imageURL, null,
function (texture, iRequestId) {
node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, oModule.width, oModule.height));
}, function () { }, this
);
} else {
// cc.loader.loadRes(oModule.imageURL, cc.Texture2D, function (err, texture) {
// node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
// });
Network.loadImageInNativeRuntime(
Common.TOPDRAW_IMAGE_SERVER + oModule.imageURL, null,
function (texture, iRequestId) {
node.getChildByName('Pic').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
}, function () { }, this
);
}
}
node.getChildByName('Pic').width = oModule.width;
node.getChildByName('Pic').height = oModule.height;
node.getChildByName('Pic').getComponent(cc.Sprite).sizeMode = cc.Sprite.SizeMode.CUSTOM;
node.getComponent(cc.Widget).top = oModule.top;
node.getComponent(cc.Widget).left = oModule.left;
nodeLayout.addChild(node, 10, oModule.name);
if (!oModule.disable) { //标题不给他焦点
//准备焦点坐标
let fiNodeBlock = node.addComponent(FocusInfo);
fiNodeBlock.init(
oModule.tvlink, true, null, null, 1.06 //最后一个参数决定要不要放大显示
);
this._aFocusTargets[0][oModule.code] = node;
}
if (0 == oModule.name.indexOf("blockShadow")) {
node.opacity = 0;
}
}
}
}
nodeLayout.parent = rightNodeLayout;
// cc.log("子节点:"+nodeLayout.childrenCount);
}
this._bInitRecommendDataSuccess = true;
this.checkDataReadyAndInitFocus();
// this.node.getChildByName("scrollContent").height = 2300; //这里暂且写死,scrollView有bug
// this._scrollview.scrollToTop();
} catch (error) {
cc.log("Business Exception:Get getRightRecommendRequest..." + error);
}
// },
// function (strResponse) {
// cc.log("Business Error:Get getRightRecommendRequest..." + strResponse);
// }, this, "uuid");
},
recoverFocusPath: function () {
// if (this._oSceneContext._iCurrentLeftIndex == 1) {//在调用处已经判断了,不需要重复判断
if (this._oSceneContext._iPageIndex == 1) {
this.scheduleOnce(() => {
let fiFocusTarget = cc.find(this._oSceneContext.focusPath, this.node).getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_DOWN, null, null);
return;
}, 0);
}
let height = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0; //-1,打补丁:解决回退回来页面对不上的bug
this.onScrollViewScrollStart();
this._scrollview.scrollToOffset(cc.v2(0, height), 0.5);
var showFocusCallback = function (dt) {
if (0 != this._fiCurrentFocus.node.name.indexOf("view_pager_label"))
this._cFocus.show();
this.onScrollViewScrollEnd();
}
this.scheduleOnce(function () {
// cc.log("执行恢复跳转。。。" + this._oSceneContext.focusPath);
let fiFocusTarget = cc.find(this._oSceneContext.focusPath, this.node).getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_DOWN, null, null);
this.scheduleOnce(showFocusCallback, 0.5);
}, 0.5);
let blockShadow = cc.find("scrollContent/BlockShadow", this.node);
for (let i = 0; i < blockShadow.childrenCount; i++) {
blockShadow.children[i].active = true;
}
// }
},
getSimulateRequest: function () {
var self = this;
if (this._oSceneContext._iCurrentLeftIndex <= 1) {
this.requestMediaList(1);
return;
}
var aJsonList = ["", "", "catetory_xxyz_list.json", "catetory_dztg_list.json", "catetory_3dyx_list.json", "catetory_jycl_list.json", "catetory_jsby_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 start...");
//把之前的东西删掉
let nodeCategoryList = this.node.getChildByName("scrollContent").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 || "SongList/DataContainerMask/DataContainer/ListCell0/SongTitleContainer";
this._strSongListCellComponentName = "pfbMainCategoryListCell";
this._iBeginPositionX = -440;
this._iBeginPositionY = 160;
this._iShowCellRows = 2;
this._iAlphaCellRows = 3; //补丁:这里放很多Alpha半透明,为了解决向下滑动时找不到下方其他categoryList列表元素的问题
this._iHiddenCellRows = 2;
this._iCellCountEachRow = 4;
this._fCellMarginTop = 0;
this._fCellMarginRight = 24;
this._fCellMarginBottom = 16;
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(9);
}
);
// 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("scrollContent").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
);
// lvCategoryList.loadData(
// function (strResponse) {
// cc.log("列表:" + this._oInit[this._oSceneContext._iCurrentLeftIndex]);
let strResponse = this._oInit[this._oSceneContext._iCurrentLeftIndex]; //这里采用列表
if (strResponse && strResponse != "undefined") { //防止焦点未初始化完成就去跳转,导致报错
this._bInitCategoryListSuccess = false;
}
lvCategoryList.renderInitData(strResponse, function () {
cc.log("InitCategoryList-------------------->");
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
// );
// cc.find("scrollContent/CategoryList", this.node).active = false;
},
checkDataReadyAndInitFocus: function () {
// cc.log("checkDataReadyAndInitFocus:"+(!this._bIsFocusInit && (this._bInitRecommendDataSuccess || this._bInitCategoryListSuccess)));
if (!this._bIsFocusInit && (this._bInitRecommendDataSuccess || this._bInitCategoryListSuccess)) {
this.scheduleOnce(() => { //指定0让回调函数在下一帧立即执行
this.initFocus();
}, 0);
this._bIsFocusInit = true;
}
},
//初始化焦点框
initFocus: function () {
this._aFocusTargets[1] = [];
let fiViewPagerArea = cc.find('scrollContent/ViewPagerArea', this.node).addComponent(FocusInfo); //轮播图
fiViewPagerArea.init('', false, null, null, 1.0);
this._aFocusTargets[0]['view_pager_area'] = cc.find('scrollContent/ViewPagerArea', this.node);
if (this._oSceneContext._iCurrentLeftIndex == 1) {
cc.find("scrollContent/ViewPagerArea", this.node).active = false; //打补丁,解决第一次不能跳转到轮播图上面的问题
cc.find("scrollContent/ViewPagerArea", this.node).active = true;
}
let fiHotUpdateBtn = cc.find('update/update_panel/update_btn', this.node).addComponent(FocusInfo); //热更新按钮
fiHotUpdateBtn.init('', false, null, null, 1.1);
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.1);
this._aFocusTargets[1]['hot_close_btn'] = cc.find('update/update_panel/close_btn', this.node);
// cc.log("返回路径:" + this._oSceneContext.focusPath);
var nodeInitFocus;
if (this._oSceneContext._iCurrentLeftIndex == 1) { //只对导航1瀑布流做光标记忆,其他暂不做,以后考虑会做
nodeInitFocus = cc.find(this._oSceneContext.focusPath, this.node);
} else {
nodeInitFocus = cc.find("scrollContent/TopNavi/topNavi" + this._oSceneContext._iCurrentLeftIndex, 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._cFocus.hide();
if (!Common._bIsHotUpdate) {
Common._bIsHotUpdate = true;
// this.checkUpdate(); //热更新(先测试放在loading中更新)
}
if (this._oSceneContext.focusPath != "scrollContent/TopNavi/topNavi1" && this._oSceneContext._iCurrentLeftIndex == 1) {
this.recoverFocusPath(); //有必要的话去恢复焦点记忆
return;
}
// if (this._oSceneContext._iCurrentLeftIndex > 1) { //不是第一个焦点框就跳过去,恢复记忆
// this.scheduleOnce(function () {
// this._cFocus.flyFocus(this._fiCurrentFocus, nodeInitFocus.getComponent(FocusInfo), Common.MOVE_DIRECTION_RIGHT, null, null);
// }, 0);
// }
},
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);
// cc.log("目标节点:" + fiFocusTarget.node.name);
if (!fiFocusTarget) { return; }
aCheckResult = this.checkFocusTarget(fiFocusTarget, null, Direct);
fiFocusTarget = aCheckResult[0];
oScrollParameter = aCheckResult[1];
if (0 == this._fiCurrentFocus.node.name.indexOf("CategoryListCell") && 0 == fiFocusTarget.node.name.indexOf("category_list_recommend")) {
if (Direct == Common.MOVE_DIRECTION_RIGHT) return; //补丁:这里向右如果滑到了上方会出现问题
this.onScrollViewScrollStart();
this._scrollview.scrollToOffset(cc.v2(0, 0), 0.1);
this._cFocus.hide();
var showFocusCallback = function (dt) {
this._cFocus.show();
this.onScrollViewScrollEnd();
}
var flayCallback = function (dt) {
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
this.scheduleOnce(showFocusCallback, 0.2);
}
this.scheduleOnce(flayCallback, 0.5);
return;
}
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
},
checkFocusTarget: function (fiFocusTarget, oScrollParameter, Direct) {
if (fiFocusTarget)
cc.log("目标节点名称:" + fiFocusTarget.node.name);
var leftNavLayout = this.targetAry[0].target;
// if (!this._bInitCategoryListSuccess) {
// return [null, oScrollParameter];
// }
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("topNavi") || 0 == fiFocusTarget.node.name.indexOf("topCell")) {
if (0 != this._fiCurrentFocus.node.name.indexOf("topNavi") && 0 != this._fiCurrentFocus.node.name.indexOf("topCell")) {//如果不是TypeList之间跳转,则哪里来回哪里去
fiFocusTarget = cc.find("topNavi" + this._oSceneContext._iCurrentLeftIndex, leftNavLayout).getComponent(FocusInfo);
}
}
var blockShadowNode = cc.find("scrollContent/BlockShadow", this.node);
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("view_pager_label")) { //viewPager旁边的问题记忆
if (0 != this._fiCurrentFocus.node.name.indexOf("view_pager_label") && 0 != this._fiCurrentFocus.node.name.indexOf("view_pager_label")) {
fiFocusTarget = cc.find("view_pager_label" + this._oSceneContext._iViewPagerIndex, blockShadowNode).getComponent(FocusInfo);
}
}
if (0 == this._fiCurrentFocus.node.name.indexOf("category_list_recommend") && 0 == fiFocusTarget.node.name.indexOf("CategoryListCell")) {
this.onScrollViewScrollStart();
this._scrollview.scrollToOffset(cc.v2(0, 150), 0.1);
this._cFocus.hide();
var showFocusCallback = function (dt) {
this._cFocus.show();
this.onScrollViewScrollEnd();
}
var flayCallback = function (dt) {
fiFocusTarget = cc.find("scrollContent/CategoryList/DataContainerMask/DataContainer/CategoryListCell0", this.node).getComponent(FocusInfo);
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, null, oScrollParameter);
this.scheduleOnce(showFocusCallback, 0.2);
}
this.scheduleOnce(flayCallback, 0.5);
return [null, oScrollParameter];
}
if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("SpecialList")) {
// cc.log(fiFocusTarget.node.x + " : " + fiFocusTarget.node.width / 2 + " : " + this._specialListNode.x + " : " + this._specialListRectNode.width);
if (fiFocusTarget.node.x + this._specialListNode.x >= this._specialListRectNode.width) {
if (0 != this._fiCurrentFocus.node.name.indexOf("SpecialList")) {
return [null, oScrollParameter];
}
oScrollParameter = this._specialListNode.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep((fiFocusTarget.node.x + fiFocusTarget.node.width / 2 + this._specialListNode.x) - this._specialListRectNode.width);
oScrollParameter.setTargetPosition(this._specialListNode.x - oScrollParameter.getStep());
// this._oSceneContext.nodeTypeListX = this._nodeNavList.x - oScrollParameter.getStep();
}
if (fiFocusTarget.node.x + this._specialListNode.x < 0) {
oScrollParameter = this._specialListNode.getComponent(TVScrollParameter);
oScrollParameter.setHasRelation(true);
oScrollParameter.setStep(-fiFocusTarget.node.x + fiFocusTarget.node.width / 2 - this._specialListNode.x);
oScrollParameter.setTargetPosition(this._specialListNode.x + oScrollParameter.getStep())
// this._oSceneContext.nodeTypeListX = this._nodeNavList.x + oScrollParameter.getStep();
}
}
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; }
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("scrollContent").getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowUp(index, this._oInit[this._oSceneContext._iCurrentLeftIndex])) {
return;
}
}
if (0 == fiFocusTarget.node.name.indexOf("CategoryListCell")) { //休闲益智不需要翻页滚楼
this.keyDownDirection(Common.MOVE_DIRECTION_UP);
return;
}
let iTargetTopUp = 0;
if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("block")) { //嵌套了两层的布局
iTargetTopUp = fiFocusTarget.node.getParent().getParent().getComponent(cc.Widget).top;
} else if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("SpecialList")) {
iTargetTop = fiFocusTarget.node.getParent().getParent().getParent().getParent().getComponent(cc.Widget).top;
} else if (fiFocusTarget.node.getParent().getComponent(cc.Widget)) {
iTargetTopUp = fiFocusTarget.node.getParent().getComponent(cc.Widget).top;
}
// cc.log("目标节点: "+fiCurrentFocus.node.name);
if (this._aBgHeight && this._aBgHeight.length > 0) {
let iCurrentFloorBottomUp = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0;//当前楼层底部高度
// cc.log(iCurrentFloorBottomUp + "目标节点的高度:" + iTargetTopUp);
if (this._bIsScrollViewMoving) {
return;
}
if (iTargetTopUp < iCurrentFloorBottomUp && fiCurrentFocus.node.name.indexOf("NaviCell") == -1) {
if (this._oSceneContext._iPageIndex > 1) {
//---------------隐藏焦点0.6秒,就看不到焦点框长时间的跳转------------------
this._cFocus.hide();
setTimeout(function () {
if (0 != fiFocusTarget.node.getName().indexOf('view_pager_label')) //补丁:跳到view_pager_label列表不允许显示焦点框
this._cFocus.show();
this.onScrollViewScrollEnd();
}.bind(this), 600);
//----------------------------------------------------------------------
this._oSceneContext._iPageIndex--;
let height = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0; //520,750,1177,1463,1737,2119,2239
this.onScrollViewScrollStart();
this._scrollview.scrollToOffset(cc.v2(0, height), 0.5);
// cc.log("滚动到:" + height);
this.scheduleOnce(function () {
this.keyDownDirection(Common.MOVE_DIRECTION_UP);
}, 0.3);
// 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);
// cc.log("准备滚行:。。。"+fiCurrentFocus.node);
if (!fiFocusTarget) { return; }
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("scrollContent").getChildByName('CategoryList').getComponent(ListView);
if (lvCategoryList.scrollARowDown(null, index, this._oInit[this._oSceneContext._iCurrentLeftIndex])) {
return;
}
}
if (0 == fiFocusTarget.node.name.indexOf("CategoryListCell") || 0 == fiFocusTarget.node.name.indexOf("view_pager_label")) {
this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
return;
}
let iTargetTop = 0;
if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("block")) { //嵌套了两层的布局
iTargetTop = fiFocusTarget.node.getParent().getParent().getComponent(cc.Widget).top;
} else if (0 == fiFocusTarget.node.getParent().getParent().name.indexOf("SpecialList")) {
iTargetTop = fiFocusTarget.node.getParent().getParent().getParent().getParent().getComponent(cc.Widget).top;
} else if (fiFocusTarget.node.getParent().getComponent(cc.Widget)) {
iTargetTop = fiFocusTarget.node.getParent().getComponent(cc.Widget).top;
}
if (this._aBgHeight && this._aBgHeight.length > 0) {
let iCurrentFloorBottom = this._aBgHeight[this._oSceneContext._iPageIndex - 1] || 0;//当前楼层底部高度
// cc.log(iCurrentFloorBottom + "目标节点的高度:" + iTargetTop + "::" + this._oSceneContext._iPageIndex);
if (this._bIsScrollViewMoving) {
return;
}
if (iTargetTop > iCurrentFloorBottom && fiCurrentFocus.node.name.indexOf("NaviCell") == -1 && fiCurrentFocus.node.name.indexOf("TopCell") == -1) {
if (this._oSceneContext._iPageIndex < this._aBgHeight.length - 1) {
//---------------隐藏焦点0.6秒,就看不到焦点框长时间的跳转------------------
this._cFocus.hide();
setTimeout(function () {
if (0 != fiFocusTarget.node.name.indexOf("backToTop"))
this._cFocus.show();
this.onScrollViewScrollEnd();
}.bind(this), 600);
//----------------------------------------------------------------------
let height = this._aBgHeight[this._oSceneContext._iPageIndex] || 0; //520,750,1177,1463,1737,2119,2239
this.onScrollViewScrollStart();
this._scrollview.scrollToOffset(cc.v2(0, height), 0.5);
// cc.log("滚动到:"+height);
this._oSceneContext._iPageIndex++;
this.scheduleOnce(function () {
this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
}, 0.3);
// 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 (this._bAbleHotUpdate && (0 == this._fiCurrentFocus.node.name.indexOf('close') || 0 == this._fiCurrentFocus.node.name.indexOf('close_btn'))) {
// cc.game.end();
// return;
// }
if (0 == this._fiCurrentFocus.node.name.indexOf('close') || 0 == this._fiCurrentFocus.node.name.indexOf('close_btn')) {
this._iSceneStatus = 0;
this._cFocus.hide();
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 if (0 == fiCurrentFocus.node.getName().indexOf('backToTop')) {
this.backToTop();
return;
} else if (0 == fiCurrentFocus.node.getName().indexOf('topCell')) {
this.commonSimpleTip("敬请期待!", 3);
return;
}
else {
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
}
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
this.backAScene();
break;
}
},
backToTop: function () {
this._scrollview.scrollToTop();
this._oSceneContext._iPageIndex = 1; //当前页恢复
let fiFocusTarget = cc.find("scrollContent/TopNavi/topNavi1", this.node).getComponent(FocusInfo);//这里写死地址,不然恢复光标记忆时会错乱
setTimeout(function () { //延迟0.8秒跳转
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_UP, 1.0, null);
}.bind(this), 300);
},
onBeforeFocusChange: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
if (0 == fiFrom.node.getName().indexOf('backToTop')) {
// cc.loader.loadRes("Main/icon_back", 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.backToTopImg, 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
);
}
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 - 1]) {
if (0 == fiTo.node.getName().indexOf('topNavi')) {
// cc.loader.loadRes(this._oInit.aTopNaviImg[iIndex - 1], 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 - 1], 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 - 1], 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 - 1], 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 == 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.aTopCellImg[iIndex]) {
// cc.loader.loadRes(this._oInit.aTopCellImg[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.aTopCellImg[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
);
}
}
if (0 == fiFrom.node.getName().indexOf('view_pager_label')) {
if (0 == fiTo.node.getName().indexOf('view_pager_label')) {
fiFrom.node.getChildByName("Title").active = true;
fiFrom.node.getChildByName("Select").active = false;
fiFrom.node.getChildByName("AfterSelect").active = false;
} else {
fiFrom.node.getChildByName("Title").active = false;
fiFrom.node.getChildByName("Select").active = false;
fiFrom.node.getChildByName("AfterSelect").active = true;
}
}
if (0 == fiFrom.node.getName().indexOf('CategoryListCell') || 0 == fiFrom.node.getName().indexOf('highScore')) {
fiFrom.node.getChildByName("Normal").active = true;
fiFrom.node.getChildByName("Name").active = false;
fiFrom.node.getComponent(ListCell).setUIWithoutFocus();
}
if (0 == fiFrom.node.getName().indexOf('update_btn')) {
cc.loader.loadRes("Hot_update/btn_update", 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));
});
}
if (0 == fiFrom.node.getName().indexOf('close_btn')) {
cc.loader.loadRes("Hot_update/btn_cancel", 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) {
let fiTo = event.detail.to;
let fiFrom = event.detail.from;
if (0 == fiTo.node.getName().indexOf('topCell')) {
let iIndex = fiTo.node.name.replace("topCell", '');
// cc.log(iIndex + "图片:" + this._oInit.aTopCellImg[iIndex]);
if (this._oInit.aTopCellImg[iIndex]) {
// cc.loader.loadRes(this._oInit.aTopCellImg[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.aTopCellImg[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._iRenderItemCount--;
}, this
);
}
}
if (0 == fiTo.node.getName().indexOf('backToTop')) {
// cc.loader.loadRes("Main/icon_back", 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.backToTopImg, 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
);
}
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 - 1]) {
// cc.loader.loadRes(this._oInit.aTopNaviImg[iIndex - 1], 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 - 1], 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._iRenderItemCount--;
}, this
);
}
if (0 == fiFrom.node.getName().indexOf('topNavi')) {//如果不是导航之间切换,不必要重新刷新数据
this._oSceneContext._iCurrentLeftIndex = iIndex;
this.scheduleOnce(function () {
this.getSimulateRequest();
}, 0);
var rightNodeLayout = this.targetAry[1].target;
let blockShadow = cc.find("scrollContent/BlockShadow", this.node);
if (iIndex == 1) {
cc.find("scrollContent/ViewPagerArea", this.node).active = true;
blockShadow.active = true;
} else {
cc.find("scrollContent/ViewPagerArea", this.node).active = false;
blockShadow.active = false;
}
if (rightNodeLayout.childrenCount == 0 && iIndex == 1) { //恢复光标的界面可能需要初始化瀑布流
this.getRightRecommendRequestData();
}
for (let i = 0; i < rightNodeLayout.childrenCount; i++) {
if (iIndex == 1) { //“休闲益智”采用单独的框架渲染 || iIndex == 3
rightNodeLayout.children[i].active = true;
} else {
rightNodeLayout.children[i].active = false;
}
}
}
}
// cc.log("选中变颜色。。。" + fiTo.node.getName());
if (0 == fiTo.node.getName().indexOf('view_pager_label')) {
let iIndex = fiTo.node.name.replace("view_pager_label", '');
fiTo.node.getChildByName("Title").active = false;
fiTo.node.getChildByName("Select").active = true;
fiTo.node.getChildByName("AfterSelect").active = false;
this._oSceneContext._iViewPagerIndex = iIndex;
this._pageView.scrollToPage(iIndex);
}
if (0 == fiTo.node.getName().indexOf('CategoryListCell') || 0 == fiTo.node.getName().indexOf('highScore')) {
fiTo.node.getChildByName("Normal").active = false;
fiTo.node.getChildByName("Name").active = true;
fiTo.node.getComponent(ListCell).setUIWithFocus();
}
//这里想统一处理焦点框显示隐藏问题
// cc.log("节点名称:" + fiTo.node.getName());
if (0 == fiTo.node.getName().indexOf('view_pager_label') || 0 == fiTo.node.getName().indexOf('topNavi')
|| 0 == fiTo.node.getName().indexOf('topCell') || 0 == fiTo.node.getName().indexOf('backToTop')
|| 0 == fiTo.node.getName().indexOf('update_btn') || 0 == fiTo.node.getName().indexOf('close_btn')) {
this._cFocus.hide();
} else {
if (!this._bIsScrollViewMoving)
this._cFocus.show();
}
if (0 == fiTo.node.getName().indexOf('update_btn')) {
cc.loader.loadRes("Hot_update/btn_update", 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('close_btn')) {
cc.loader.loadRes("Hot_update/btn_cancel", 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));
});
}
},
doCurrentFocusTVLinkAction: function (strAction) {
let strTVLink = this._fiCurrentFocus.getTVLink();
// cc.log("tvlink===============" + strTVLink);
// cc.log("tvlink===============" + this._oSceneContext._iPageIndex);
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":
default:
this.doTVLinkAction(aOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
onListScrollStart: function () {
this._bIsDataListMoving = true;
// cc.log("scroll start");
},
onListScrollEnd: function () {
this._bIsDataListMoving = false;
// cc.log("scroll completed");
},
//针对scrollView滑动做了限制
onScrollViewScrollStart: function () {
this._bIsScrollViewMoving = true;
// cc.log("scroll start");
},
onScrollViewScrollEnd: function () {
this._bIsScrollViewMoving = false;
// cc.log("scroll completed");
},
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._bAbleHotUpdate = true;
this._iSceneStatus = 1; //焦点框跳转层级
cc.find("update", this.node).active = true; //显示出来更新面板
// this._cFocus.hide();
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;
// if (this._bAbleHotUpdate) {
// this.hotUpdate(); //放在这里可以静默升级
// }
},
hotUpdate: function () {
cc.log("hotUpdate start...");
//隐藏更新说明,显示更新进度条
// cc.find("update/update_panel/NewLabel", this.node).active = false;//因为新的更新界面没有进度条,先不要显示更新进度
// cc.find("update/update_panel/versionLabel", 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();
}
},
});