TVCanvas.js
30 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
var Common = require('Common');
var Network = require('Network');
var FocusInfo = require('FocusInfo');
var Application = require('Application');
var Log = require('Log');
cc.Topdraw = cc.Topdraw || {};
cc.Topdraw.TVCanvas =
cc.Class({
extends: cc.Component,
properties: {
//如果成功了要添加
//Log 版块
_cLog: null,
_cApplication: null,
_cFocus: null,
_aFocusTargets: [], //可被聚焦的块集合 分成状态区
_fiCurrentFocus: null,
_iSceneStatus: 0, //场景状态 和焦点寻找有关系
_fFocusScaleFactor: 1.06, //焦点缩放因数
//数据初始化状态
_bIsFocusInit: false,
_oSceneContext: null, //当前场景的上下文,用于后续恢复
//_oCurrentSceneParameter:null, //去下一个场景的参数
_oNextSceneParameter: null, //去下一个场景的参数
_compPlayer: null,
_aTouchContext: [],
_defaultBackScene: null,//每个场景Canvas都有的 默认返回场景 每个场景自己构造函数内设置值
_oFocusScaleFactorInfo: null,
holdClick: false, //检测是否长按
_bShowExitBox: false,
},
// use this for initialization
onLoad: function () {
//关掉调试信息
cc.debug.setDisplayStats(true);
//设置背景为透明
//TODO:2.0警告建议cc.Camera.main.backgroundColor = cc.Color.TRANSPARENT;
// cc.director.setClearColor(cc.Color.TRANSPARENT);
cc.Camera.main.backgroundColor = cc.Color.TRANSPARENT;
this._oSceneContext = {};
this._oNextSceneParameter = {};
//获得应用级别的上下文状态
if (cc.find('application')) {
this._cApplication = cc.find('application').getComponent(Application);
} else {
let nodeApplication = new cc.Node('application');
cc.game.addPersistRootNode(nodeApplication);
this._cApplication = nodeApplication.addComponent(Application);
}
//创建Log节点
let nodeLog = new cc.Node('Log');
this._cLog = nodeLog.addComponent(Log);
this._cLog.init(this);
nodeLog.parent = this.node;
nodeLog.opacity = 0;
//注册键盘事件
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
//注册摸来摸去事件
this.node.on('touchstart', this.onTouchStart, this);
this.node.on('touchmove', this.onTouchMove, this);
this.node.on('touchend', this.onTouchEnd, this);
this.node.on('before_focus_change', this.onBeforeFocusChange, this);
this.node.on('after_focus_change', this.onAfterFocusChange, this);
this.node.on('focus', this.onFocus, this);
this.node.on('blur', this.onBlur, this);
//以后再考虑是否用这种做法
//this.node.on('focus_leave', this.onFocusLeave,this);
//this.node.on('focus_hover', this.onFocusHover,this);
//初始化焦点临接表
if (null == this._aFocusTargets[0]) {
this._aFocusTargets[0] = [];
}
//添加探针
this.sceneBIProbe();
},
onKeyUp: function (event) {
cc.log('OnKeyUp In TVCanvas');
//-----------------------禁止长按-------------------------------
this.holdClick = false;
//------------------------------------------------------
},
onKeyDown: function (event) {
//-------------------------禁止长按------------------------------
if (!this.holdClick) {
this.holdClick = true;
} else {
event.keyCode = 0; //更改keyCode值使该键值失效,
// return;
}
//-------------------------------------------------------
let nodeLog = null;
switch (event.keyCode) {
case cc.macro.KEY.t:
nodeLog = this.node.getChildByName('Log');
nodeLog.opacity = ((nodeLog.opacity == 0) ? 255 : 0);
this._cLog.screenD('....日志测试Test-' + nodeLog.opacity + '-a');
this._cLog.screenI('....日志测试Test-' + nodeLog.opacity + '-b');
this._cLog.screenW('....日志测试Test-' + nodeLog.opacity + '-c');
this._cLog.screenE('....日志测试Test-' + nodeLog.opacity + '-d');
break;
case cc.macro.KEY.enter:
case cc.macro.KEY.space:
case Common.ANDROID_KEY.enter:
if (0 == this._fiCurrentFocus.node.getName().indexOf('AppIcon')) {
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
}
if (0 == this._fiCurrentFocus.node.getName().indexOf('BtnBackTop')) {
this.backAScene();
}
break;
}
},
onTouchStart: function (event) {
cc.log('OnTouchStart In TVCanvas');
},
onTouchMove: function (event) {
cc.log('OnTouchMove In TVCanvas');
},
onTouchEnd: function (event) {
cc.log('OnTouchEnd In TVCanvas');
},
setCurrentFocus: function (fiCurrentFocus) {
this._fiCurrentFocus = fiCurrentFocus;
},
/**
* 返回上一个场景
*/
backAScene: function () {
//上下文
let compApplication = cc.find('application').getComponent(Application);
let aSceneContext = compApplication.getSceneContext();
let aSceneParameter = compApplication.getSceneParameter();
cc.log(aSceneContext);
if (aSceneParameter.length) {
this._bShowExitBox = false;
let oSceneParameter = aSceneParameter.pop();
cc.director.loadScene(oSceneParameter.backSceneName);
compApplication.setBackStatus(true);
} else {
if (!this._bShowExitBox) { //弹出挽留界面
this.showExitBox();
} else {
cc.log("退出应用!");
cc.game.end();
}
}
},
doTVLinkAction: function (oOperation) {
let nodeApplication = cc.find('application').getComponent(Application);
let aSceneContext = nodeApplication.getSceneContext();
let aSceneParameter = nodeApplication.getSceneParameter();
//---------------
nodeApplication.setTotalFrames(cc.director.getTotalFrames());
//---------------
let strForwardSceneName = "";
this._oNextSceneParameter.backSceneName = cc.director.getScene().name;
if (this._bShowExitBox && this._focusPath) { //挽留页跳转采用原先的值
this._oSceneContext.focusPath = this._focusPath;
} else {
this._oSceneContext.focusPath = Common.getNodePath(this._fiCurrentFocus.node);
}
switch (oOperation.action) {
case "ChangeScene":
strForwardSceneName = oOperation.parameters.sceneName;
for (let key in oOperation.parameters) {
if (null != oOperation.parameters[key] && '' != oOperation.parameters[key])
this._oNextSceneParameter[key] = oOperation.parameters[key];
}
break;
case "promotionBIProbe":
this.promotionBIProbe(oOperation.parameters.id);
break;
case "changeUI": //切换场景
let parameter = oOperation.parameters.uiName; //更换界面的名称
if (parameter == "collection") { //收藏
} else if (parameter == "history") { //历史
} else if (parameter == "search") { //搜索
}
break;
default:
/*
oSceneContext.categoryId="10";
oSceneContext.songListPageIndex="10";
oSceneContext.focusPath=""; //光标对象 如何保存 从场景中往下寻找Node
aSceneContext.push(oSceneContext);
cc.director.loadScene('sceneSearch');
*/
}
if (null != strForwardSceneName && 0 < strForwardSceneName.length) {
aSceneParameter.push(this._oNextSceneParameter);
aSceneContext.push(this._oSceneContext);
cc.director.loadScene(strForwardSceneName, function () {
cc.sys.garbageCollect();
});
}
},
addNodeToFocusTarget: function (iStatus, strKey, nodeFocusable) {
this._aFocusTargets[iStatus][strKey] = nodeFocusable;
},
getFocus: function () {
return this._cFocus;
},
getCurrentFocusInfo: function () {
return this._fiCurrentFocus;
},
getFocusTargets: function () {
return this._aFocusTargets;
},
onFocus: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
fiTo.onFocus(fiFrom);
},
onBlur: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
fiFrom.onBlur(fiTo);
},
/**
* 仅供测试使用
* @param strPlayURL 回调后得到的播放地址
*
*/
onGetPlayURL: function (strPlayURL) {
cc.log('TVCanvas onGetPlayURL..:' + strPlayURL);
if (this._compPlayer) {
this._compPlayer.remoteURL = strPlayURL;
this._compPlayer.play();
}
},
getPageBg: function (context, kind, spriteBg) {
let oRankingRequestParameters = {
"view": "json",
"token": Common.TEST_API_TOKEN,
};
Network.ajax('GET', Common.TOPDRAW_API_SERVER2 + 'ArrangeHut/GetWallPaperFrame', null, oRankingRequestParameters,
function (strResponse) {
// cc.log("Success When Get Ranking..."+strResponse);
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
if (oJSONResult.resultSet.length > 0) {
let nodeLeftRecommendPic = cc.find('Bg', context.node);
let normal = oJSONResult.resultSet[0].images.map.normal[0];
let background = oJSONResult.resultSet[0].images.map.background[0];
var strUrl = "";
if (kind == 'background') {
strUrl = Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[0].images.list[background].fileUrl;
} else if (kind == 'normal') {
strUrl = Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[0].images.list[normal].fileUrl;
}
if (spriteBg) { //新增骚操作
cc.loader.load(strUrl, function (err, texture) {
spriteBg.spriteFrame = new cc.SpriteFrame(texture);
});
return;
}
if (strUrl) {
cc.loader.load(strUrl, function (err, texture) {
nodeLeftRecommendPic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
});
}
} else {
cc.log("Nothing...");
}
} else {
cc.log("Error When Get WallPaper..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get WallPaper..." + error);
}
},
function (strResponse) {
cc.log("Error When Get WallPaper..." + strResponse);
}, this, "uuid");
},
//添加场景BI探针
sceneBIProbe: function () {
try {
//场景参数
let oSceneParameter = this._cApplication.getTopSceneParameter() || {};
let strCurSceneName = cc.director.getScene().name;
let strCurURL = strCurSceneName + "?";
for (let key in oSceneParameter) {
if (key != "sceneName") {
strCurURL += (key + "=" + oSceneParameter[key] + "&");
}
}
strCurURL = strCurURL.substring(0, strCurURL.length - 1);
//附加参数
oSceneParameter.platformAccount = Common.USER_ID;
oSceneParameter.url = encodeURIComponent(strCurURL);
oSceneParameter.referURL = oSceneParameter.backSceneName || "";
Network.ajax('GET', Common.BI_BASE_PATH, null, oSceneParameter,
function (strResponse) {
try {
// var oJSONResult = JSON.parse(strResponse);
// if (oJSONResult.businessCode == "success") {
// cc.log("Business Success : Page BI Probe Request Success");
// } else {
// cc.log("Business Error : Page BI Probe Request failed..." + oJSONResult.description);
// }
} catch (ex) {
cc.log("Business Exception : Page BI Probe Request Error.." + ex);
}
},
function (strResponse) {
cc.log("Communication Error : Page BI Probe Request Error..." + strResponse + "\r\n");
}, this, "uuid"
);
} catch (err) {
cc.log("Page BI Probe Request Error in promotionBIProbe..." + err);
}
},
/*推荐位BI探针*/
createPromotionBIProbeAction: function (strTVLink, strId) {
let joTVLink = JSON.parse(strTVLink);
joTVLink.click.push({ "action": "promotionBIProbe", "parameters": { "id": strId } });
return JSON.stringify(joTVLink);
},
promotionBIProbe: function (strPromotionId) {
try {
//为了BI方便统计,做些变形
let strBIURL = './NoPage/TopdrawPromotion?id=' + strPromotionId;//todo:这个地址其实还不确定
let oParams = {
"platformAccount": Common.USER_ID,
"url": strBIURL,
};
Network.ajax('GET', Common.BI_BASE_PATH, null, oParams,
function (strResponse) {
try {
let oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == "success") {
cc.log("Business Success : Promotion BI Probe Request Success");
} else {
cc.log("Business Error : Promotion BI Probe Request failed..." + oJSONResult.description);
}
} catch (ex) {
cc.log("Business Exception : Promotion BI Probe Request Error.." + ex);
}
},
function (strResponse) {
cc.log("Communication Error : Promotion BI Probe Request Error..." + strResponse + "\r\n");
}, this, "uuid"
);
} catch (err) {
cc.log("Promotion BI Probe Request Error in promotionBIProbe..." + err);
}
},
/**
*黄色提示框
* @param strTip String
* @param iTime Number
*/
commonTip: function (strTip, iTime) {
if (!this.commonTipFnCallback) {
this.commonTipFnCallback = function () {
nodeTip.opacity = 0;
}
}
this.unschedule(this.commonTipFnCallback);
if (!strTip) return;
iTime = iTime || 5;
let labelText = null;
let nodeTip = cc.find("CommonTip", this.node);
let nodeText = nodeTip && nodeTip.getChildByName("TipText");
if (!nodeText) {
nodeTip = new cc.Node("CommonTip");
let layout = nodeTip.addComponent(cc.Layout);
layout.type = 1;
layout.resizeMode = 1;
layout.paddingLeft = 20;
layout.paddingRight = 20;
layout.horizontalDirection = 0;
let spriteTipBg = nodeTip.addComponent(cc.Sprite);
// spriteTipBg.spriteFrame = new cc.SpriteFrame(cc.textureCache.addImage(cc.url.raw('resources/Texture/common_tip_bg.png')));
cc.loader.loadRes("Texture/cabin/common_tip_bg", cc.SpriteFrame, function (err, spriteFrame) {
spriteTipBg.spriteFrame = spriteFrame;
});
nodeTip.parent = this.node;
// nodeTip.setLocalZOrder(1000);
nodeTip.zIndex = 1000;
nodeText = new cc.Node("TipText");
labelText = nodeText.addComponent(cc.Label);
nodeText.color = cc.Color.RED;
nodeTip.addChild(nodeText);
} else {
labelText = nodeText.getComponent(cc.Label);
}
labelText.string = strTip;
nodeTip.opacity = 255;
this.scheduleOnce(this.commonTipFnCallback, iTime); //修改tip时间
},
/**
* 统一添加订购、推荐等按钮
*/
addHomeIcon: function (context) {
// var nodeOrder = new cc.Node('OrderIcon'); //订购
// nodeOrder.addComponent(cc.Sprite);
// var widgetOrder = nodeOrder.addComponent(cc.Widget);
// widgetOrder.isAlignLeft = true;
// widgetOrder.isAlignTop = true;
// widgetOrder.top = 44;
// widgetOrder.left = 1150;
// cc.loader.loadRes("Texture/common/order_icon", cc.SpriteFrame, function (err, spriteFrame) {
// spriteFrame.setTexture(null, cc.rect(0, 0, 54, 68));
// nodeOrder.getComponent(cc.Sprite).spriteFrame = spriteFrame;
// spriteFrame._calculateUV();
// });
// var fiOrderIcon = nodeOrder.addComponent(FocusInfo);
// context._aFocusTargets[0]['to_order_icon'] = nodeOrder;
// fiOrderIcon.init(
// null, true
// );
// context.node.addChild(nodeOrder, 10);
// var nodeApp = new cc.Node('AppIcon'); //首页
// nodeApp.addComponent(cc.Sprite);
// var widgetApp = nodeApp.addComponent(cc.Widget);
// widgetApp.isAlignLeft = true;
// widgetApp.isAlignTop = true;
// widgetApp.top = 44;
// widgetApp.left = 1213;
// cc.loader.loadRes("Texture/common/level_icon", cc.SpriteFrame, function (err, spriteFrame) {
// spriteFrame.setTexture(null, cc.rect(0, 0, 54, 68));
// nodeApp.getComponent(cc.Sprite).spriteFrame = spriteFrame;
// spriteFrame._calculateUV();
// });
// var fiAppIcon = nodeApp.addComponent(FocusInfo);
// context._aFocusTargets[0]['to_app_icon'] = nodeApp;
// fiAppIcon.init(
// '{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneRecommend"}}]}', true
// );
// context.node.addChild(nodeApp, 10);
},
//弹出挽留界面
showExitBox: function () {
this._bShowExitBox = true;
if (this._nodeExitBox) {
this._focusPath = Common.getNodePath(this._fiCurrentFocus.node); //记录原来值
//焦点框跳到第二次后不会干扰第一层级
this._cFocus.flyFocus(this._fiCurrentFocus, this._aFocusTargets[1]['back_right_btn'].getComponent(FocusInfo),
Common.MOVE_DIRECTION_UP, this._fFocusScaleFactor, null);
var oIndexBackPromotionPara = {
'view': 'json',
'limit': 2,
'start': 0,
'name': 'BabyDontGo',
"sortField": "left",
"sortDirection": "asc",
token: Common.TEST_API_TOKEN,
};
Network.ajax('GET', Common.TOPDRAW_API_SERVER + "Promotion/ListItemByName", null, oIndexBackPromotionPara,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
for (let i = 0; i < oJSONResult.resultSet.length; i++) {
let nodeBackPromotion = new cc.Node("backPromotion" + i);
nodeBackPromotion.width = oJSONResult.resultSet[i].width;
nodeBackPromotion.height = oJSONResult.resultSet[i].height;
let spritePromotion = nodeBackPromotion.addComponent(cc.Sprite);
spritePromotion.type = cc.Sprite.Type.SIMPLE;
spritePromotion.sizeMode = cc.Sprite.SizeMode.CUSTOM;
var widgetPromotion = nodeBackPromotion.addComponent(cc.Widget);
widgetPromotion.isAlignTop = true;
widgetPromotion.isAlignLeft = true;
if (oJSONResult.resultSet[i].image[0].fileUrl) {
nodeBackPromotion.zIndex = 101; //让导航栏背景处于最底层
cc.loader.load(Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[i].image[0].fileUrl, function (err, texture) {
spritePromotion.spriteFrame = new cc.SpriteFrame(texture);
});
}
widgetPromotion.top = oJSONResult.resultSet[i].top;
widgetPromotion.left = oJSONResult.resultSet[i].left;
nodeBackPromotion.parent = this._nodeExitBox;
}
//绑定立即观看按钮的tvlink
cc.find("BtnBackLeft", this._nodeExitBox).getComponent(FocusInfo).init(
oJSONResult.resultSet[0].tvlink, true
);
cc.find("BtnBackRight", this._nodeExitBox).getComponent(FocusInfo).init(
oJSONResult.resultSet[1].tvlink, true
);
} catch (error) {
cc.log("Exception When IndexBackPromotion..." + error);
}
},
function (strResponse) {
cc.log("Error When IndexBackPromotion..." + strResponse);
}, this, "uuid");
} else {
Common.loadRes("prefab/home/pfbExitBox", //挽留弹窗预制
function (loadedResource) {
this._nodeExitBox = cc.instantiate(loadedResource);
this._nodeExitBox.parent = this.node;
this._nodeExitBox.zIndex = 400; //假设400为最高zIndex
cc.find("BtnBackLeft", this._nodeExitBox).getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 294, 102));
cc.find("BtnBackRight", this._nodeExitBox).getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 294, 102));
cc.find("BtnBackTop", this._nodeExitBox).getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, 140, 50));
cc.find("BtnBackLeft", this._nodeExitBox).addComponent(FocusInfo);
cc.find("BtnBackRight", this._nodeExitBox).addComponent(FocusInfo);
cc.find("BtnBackTop", this._nodeExitBox).addComponent(FocusInfo);
if (null == this._aFocusTargets[1]) { //focus放到第二层级,避免冲突
this._aFocusTargets[1] = [];
}
this._aFocusTargets[1]['back_left_btn'] = cc.find("BtnBackLeft", this._nodeExitBox);
this._aFocusTargets[1]['back_right_btn'] = cc.find("BtnBackRight", this._nodeExitBox);
this._aFocusTargets[1]['back_top_btn'] = cc.find("BtnBackTop", this._nodeExitBox);
this.showExitBox();
},
function (error) {
cc.log("Error When Loading Prefab pfbExitBox ...");
}, this)
}
},
onBeforeFocusChange: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
if (0 == fiFrom.node.getName().indexOf('AppIcon')) {
var appIconSprite = cc.find("AppIcon", this.node).getComponent(cc.Sprite); //
cc.loader.loadRes("Texture/common/level_icon", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 0, 54, 68));
appIconSprite.spriteFrame = spriteFrame;
});
}
if (0 == fiFrom.node.getName().indexOf('OrderIcon')) {
var orderIconSprite = cc.find("OrderIcon", this.node).getComponent(cc.Sprite); //
cc.loader.loadRes("Texture/common/order_icon", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 0, 54, 68));
// spriteFrame.setTexture(null, cc.rect(0, 50, 130, 50));
orderIconSprite.spriteFrame = spriteFrame;
});
}
if (0 == fiFrom.node.getName().indexOf('BtnBackTop')) { //TODO:
// fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
cc.loader.loadRes("texture/button/back_btn", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
fiFrom.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
}
if (0 == fiFrom.node.getName().indexOf('BtnBackLeft') || 0 == fiFrom.node.getName().indexOf('BtnBackRight')) {
cc.loader.loadRes("texture/button/back_promotion_btn", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
fiFrom.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
}
},
onAfterFocusChange: function (event) {
let fiFrom = event.detail.from;
let fiTo = event.detail.to;
if (0 == fiTo.node.getName().indexOf('AppIcon')) {
var appIconSprite = cc.find("AppIcon", this.node).getComponent(cc.Sprite); //
cc.loader.loadRes("Texture/common/level_icon", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 68, 54, 68));
appIconSprite.spriteFrame = spriteFrame;
});
}
if (0 == fiTo.node.getName().indexOf('OrderIcon')) {
var orderIconSprite = cc.find("OrderIcon", this.node).getComponent(cc.Sprite); //
cc.loader.loadRes("Texture/common/order_icon", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, 68, 54, 68));
orderIconSprite.spriteFrame = spriteFrame;
});
}
if (0 == fiTo.node.getName().indexOf('BtnBackTop')) { //TODO:
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes("texture/button/back_btn", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
fiTo.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
}
if (0 == fiTo.node.getName().indexOf('BtnBackLeft') || 0 == fiTo.node.getName().indexOf('BtnBackRight')) {
cc.loader.loadRes("texture/button/back_promotion_btn", cc.Texture2D, function (err, Texture) {
var spriteFrame = new cc.SpriteFrame(Texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
fiTo.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
}
},
});