drgame-cc 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/drgame.js DELETED
@@ -1,3010 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
- return c > 3 && r && Object.defineProperty(target, key, r), r;
21
- };
22
- var __metadata = (this && this.__metadata) || function (k, v) {
23
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
36
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- define("BtnExtra", ["require", "exports"], function (require, exports) {
62
- "use strict";
63
- Object.defineProperty(exports, "__esModule", { value: true });
64
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
65
- var BtnExtra = (function (_super) {
66
- __extends(BtnExtra, _super);
67
- function BtnExtra() {
68
- var _this = _super !== null && _super.apply(this, arguments) || this;
69
- _this.hoverSprite = null;
70
- _this.normalSprite = null;
71
- return _this;
72
- }
73
- __decorate([
74
- property(cc.SpriteFrame),
75
- __metadata("design:type", cc.SpriteFrame)
76
- ], BtnExtra.prototype, "hoverSprite", void 0);
77
- __decorate([
78
- property(cc.SpriteFrame),
79
- __metadata("design:type", cc.SpriteFrame)
80
- ], BtnExtra.prototype, "normalSprite", void 0);
81
- BtnExtra = __decorate([
82
- ccclass
83
- ], BtnExtra);
84
- return BtnExtra;
85
- }(cc.Component));
86
- exports.default = BtnExtra;
87
- });
88
- define("Define", ["require", "exports"], function (require, exports) {
89
- "use strict";
90
- Object.defineProperty(exports, "__esModule", { value: true });
91
- exports.EVideoScene = void 0;
92
- var EVideoScene;
93
- (function (EVideoScene) {
94
- EVideoScene["UseProp"] = "use_prop";
95
- EVideoScene["StartGame"] = "start_game";
96
- EVideoScene["RevivePop"] = "revive_pop";
97
- EVideoScene["BuySkin"] = "buy_skin";
98
- EVideoScene["BuyProp"] = "buy_prop";
99
- EVideoScene["GameOver"] = "game_over";
100
- EVideoScene["LevelComplete"] = "level_complete";
101
- EVideoScene["Shop"] = "shop";
102
- EVideoScene["DailyReward"] = "daily_reward";
103
- EVideoScene["Boost"] = "boost";
104
- })(EVideoScene || (exports.EVideoScene = EVideoScene = {}));
105
- });
106
- define("config/TvUiConfig", ["require", "exports"], function (require, exports) {
107
- "use strict";
108
- Object.defineProperty(exports, "__esModule", { value: true });
109
- exports.createDefaultTvUiConfig = createDefaultTvUiConfig;
110
- function createDefaultTvUiConfig() {
111
- return {
112
- designWidth: 1920,
113
- designHeight: 1080,
114
- cpId: "ppl",
115
- version: "1.0.0",
116
- configPath: "tvui/config/default",
117
- defaultScopeId: "page",
118
- enableRemoteInput: true,
119
- enableLifecycle: true,
120
- focus: {
121
- enabled: true,
122
- frameEnabled: false,
123
- framePadding: 10,
124
- frameColor: "#ffd451",
125
- frameOpacity: 230,
126
- lineWidth: 5,
127
- animationTime: 0.1,
128
- defaultIconKey: "default",
129
- iconPlacement: "bottomRight",
130
- iconOffsetX: -20,
131
- iconOffsetY: 20,
132
- zIndex: 800
133
- },
134
- icons: {
135
- "default": {
136
- path: "tvui/icons/pointer-yellow-60",
137
- width: 60,
138
- height: 60,
139
- offsetX: -20,
140
- offsetY: 20
141
- },
142
- "yellow": {
143
- path: "tvui/icons/pointer-yellow-60",
144
- width: 60,
145
- height: 60,
146
- offsetX: -20,
147
- offsetY: 20
148
- },
149
- "blue": {
150
- path: "tvui/icons/pointer-blue-60",
151
- width: 60,
152
- height: 60,
153
- offsetX: -20,
154
- offsetY: 20
155
- },
156
- "pink": {
157
- path: "tvui/icons/pointer-pink-60",
158
- width: 60,
159
- height: 60,
160
- offsetX: -20,
161
- offsetY: 20
162
- }
163
- },
164
- adSdk: {
165
- platform: "xiaomi"
166
- },
167
- ads: {
168
- "reward": {
169
- enabled: true,
170
- mode: "reward",
171
- channels: [
172
- { type: "aggregate", priority: 1, reward_type: "reward" },
173
- { type: "mock", priority: 100 }
174
- ]
175
- },
176
- "popup": {
177
- enabled: true,
178
- mode: "popup",
179
- channels: [
180
- { type: "aggregate", priority: 1 },
181
- { type: "mock", priority: 100 }
182
- ]
183
- },
184
- "game": {
185
- enabled: true,
186
- mode: "popup",
187
- channels: [
188
- { type: "aggregate", priority: 1 },
189
- { type: "mock", priority: 100 }
190
- ]
191
- }
192
- }
193
- };
194
- }
195
- });
196
- define("config/TvUiConfigManager", ["require", "exports", "config/TvUiConfig"], function (require, exports, TvUiConfig_1) {
197
- "use strict";
198
- Object.defineProperty(exports, "__esModule", { value: true });
199
- var TvUiConfigManager = (function () {
200
- function TvUiConfigManager() {
201
- }
202
- TvUiConfigManager.init = function (config, callback) {
203
- var _this = this;
204
- this.projectConfig = config || {};
205
- this.rebuildConfig();
206
- this.loadResourceConfig(function (loaded) {
207
- if (loaded) {
208
- _this.rebuildConfig();
209
- _this.emitChanged();
210
- }
211
- if (callback)
212
- callback(_this.config);
213
- });
214
- };
215
- TvUiConfigManager.getConfig = function () {
216
- return this.config;
217
- };
218
- TvUiConfigManager.updateConfig = function (config, saveLocal) {
219
- if (saveLocal === void 0) { saveLocal = false; }
220
- if (saveLocal) {
221
- this.saveLocalConfig(config);
222
- }
223
- else {
224
- this.projectConfig = this.merge(this.projectConfig || {}, config || {});
225
- }
226
- this.rebuildConfig();
227
- this.emitChanged();
228
- };
229
- TvUiConfigManager.onChanged = function (listener) {
230
- if (!listener)
231
- return;
232
- if (this.listeners.indexOf(listener) < 0)
233
- this.listeners.push(listener);
234
- };
235
- TvUiConfigManager.offChanged = function (listener) {
236
- var index = this.listeners.indexOf(listener);
237
- if (index >= 0)
238
- this.listeners.splice(index, 1);
239
- };
240
- TvUiConfigManager.rebuildConfig = function () {
241
- var next = this.merge((0, TvUiConfig_1.createDefaultTvUiConfig)(), this.resourceConfig || {});
242
- next = this.merge(next, this.projectConfig || {});
243
- next = this.merge(next, this.loadLocalConfig());
244
- this.config = next;
245
- };
246
- TvUiConfigManager.loadResourceConfig = function (callback) {
247
- var _this = this;
248
- var path = (this.projectConfig && this.projectConfig.configPath) || this.config.configPath;
249
- if (!path || !cc || !cc.loader || !cc.loader.loadRes) {
250
- callback(false);
251
- return;
252
- }
253
- cc.loader.loadRes(path, function (error, asset) {
254
- if (error || !asset) {
255
- callback(false);
256
- return;
257
- }
258
- var json = asset.json || asset;
259
- _this.resourceConfig = json || null;
260
- callback(!!_this.resourceConfig);
261
- });
262
- };
263
- TvUiConfigManager.loadLocalConfig = function () {
264
- try {
265
- var raw = cc.sys.localStorage.getItem(this.LOCAL_KEY);
266
- if (!raw)
267
- return {};
268
- return JSON.parse(raw) || {};
269
- }
270
- catch (e) {
271
- return {};
272
- }
273
- };
274
- TvUiConfigManager.saveLocalConfig = function (config) {
275
- var local = this.merge(this.loadLocalConfig(), config || {});
276
- try {
277
- cc.sys.localStorage.setItem(this.LOCAL_KEY, JSON.stringify(local));
278
- }
279
- catch (e) {
280
- console.warn("[TvUiConfigManager] save local config failed", e);
281
- }
282
- };
283
- TvUiConfigManager.emitChanged = function () {
284
- for (var i = 0; i < this.listeners.length; i++) {
285
- this.listeners[i](this.config);
286
- }
287
- };
288
- TvUiConfigManager.merge = function (base, extra) {
289
- var result = {};
290
- var key;
291
- base = base || {};
292
- extra = extra || {};
293
- for (key in base) {
294
- if (!base.hasOwnProperty(key))
295
- continue;
296
- result[key] = this.clone(base[key]);
297
- }
298
- for (key in extra) {
299
- if (!extra.hasOwnProperty(key))
300
- continue;
301
- if (this.isPlainObject(result[key]) && this.isPlainObject(extra[key])) {
302
- result[key] = this.merge(result[key], extra[key]);
303
- }
304
- else {
305
- result[key] = this.clone(extra[key]);
306
- }
307
- }
308
- return result;
309
- };
310
- TvUiConfigManager.clone = function (value) {
311
- if (value instanceof Array) {
312
- var list = [];
313
- for (var i = 0; i < value.length; i++)
314
- list.push(this.clone(value[i]));
315
- return list;
316
- }
317
- if (this.isPlainObject(value)) {
318
- return this.merge({}, value);
319
- }
320
- return value;
321
- };
322
- TvUiConfigManager.isPlainObject = function (value) {
323
- return value && typeof value == "object" && !(value instanceof Array);
324
- };
325
- TvUiConfigManager.LOCAL_KEY = "tvui_local_config";
326
- TvUiConfigManager.config = (0, TvUiConfig_1.createDefaultTvUiConfig)();
327
- TvUiConfigManager.projectConfig = null;
328
- TvUiConfigManager.resourceConfig = null;
329
- TvUiConfigManager.listeners = [];
330
- return TvUiConfigManager;
331
- }());
332
- exports.default = TvUiConfigManager;
333
- });
334
- define("input/KeyCodeAdapter", ["require", "exports"], function (require, exports) {
335
- "use strict";
336
- Object.defineProperty(exports, "__esModule", { value: true });
337
- exports.TvRemoteKey = void 0;
338
- var TvRemoteKey;
339
- (function (TvRemoteKey) {
340
- TvRemoteKey["Back"] = "back";
341
- TvRemoteKey["Ok"] = "ok";
342
- TvRemoteKey["Left"] = "left";
343
- TvRemoteKey["Right"] = "right";
344
- TvRemoteKey["Up"] = "up";
345
- TvRemoteKey["Down"] = "down";
346
- TvRemoteKey["Pause"] = "pause";
347
- TvRemoteKey["Unknown"] = "unknown";
348
- })(TvRemoteKey || (exports.TvRemoteKey = TvRemoteKey = {}));
349
- var KeyCodeAdapter = (function () {
350
- function KeyCodeAdapter() {
351
- }
352
- KeyCodeAdapter.toRemoteKey = function (keyCode) {
353
- if ([0, 4, 8, 27, 10009].indexOf(keyCode) >= 0)
354
- return TvRemoteKey.Back;
355
- if ([13, 23, 66].indexOf(keyCode) >= 0)
356
- return TvRemoteKey.Ok;
357
- if ([80].indexOf(keyCode) >= 0)
358
- return TvRemoteKey.Pause;
359
- if ([21, 37].indexOf(keyCode) >= 0)
360
- return TvRemoteKey.Left;
361
- if ([19, 38].indexOf(keyCode) >= 0)
362
- return TvRemoteKey.Up;
363
- if ([22, 39].indexOf(keyCode) >= 0)
364
- return TvRemoteKey.Right;
365
- if ([20, 40].indexOf(keyCode) >= 0)
366
- return TvRemoteKey.Down;
367
- return TvRemoteKey.Unknown;
368
- };
369
- return KeyCodeAdapter;
370
- }());
371
- exports.default = KeyCodeAdapter;
372
- });
373
- define("focus/FocusScope", ["require", "exports"], function (require, exports) {
374
- "use strict";
375
- Object.defineProperty(exports, "__esModule", { value: true });
376
- var FocusScope = (function () {
377
- function FocusScope(scopeId, root) {
378
- this.lastFocusId = "";
379
- this.scopeId = scopeId || "page";
380
- this.root = root || null;
381
- }
382
- return FocusScope;
383
- }());
384
- exports.default = FocusScope;
385
- });
386
- define("focus/FocusManager", ["require", "exports", "input/KeyCodeAdapter", "focus/FocusScope"], function (require, exports, KeyCodeAdapter_1, FocusScope_1) {
387
- "use strict";
388
- Object.defineProperty(exports, "__esModule", { value: true });
389
- var FocusManager = (function () {
390
- function FocusManager() {
391
- }
392
- FocusManager.setCursor = function (options) {
393
- this.cursorOptions = options;
394
- };
395
- FocusManager.getCursor = function () {
396
- return this.cursorOptions;
397
- };
398
- FocusManager.register = function (target, options) {
399
- if (options === void 0) { options = {}; }
400
- var node = this.resolveNode(target);
401
- if (!node)
402
- return;
403
- var component = this.resolveComponent(target, node);
404
- var previousItem = this.findItemByNode(node);
405
- var previousBaseScale = previousItem ? { x: previousItem.baseScaleX, y: previousItem.baseScaleY } : null;
406
- this.unregister(node);
407
- var focusId = options.focusId || (component && component.focusId) || node.uuid || this.createFocusId(node);
408
- this.unregisterById(focusId);
409
- var baseScale = this.getNodeBaseScale(node, previousBaseScale);
410
- var item = {
411
- node: node,
412
- root: options.root,
413
- scopeId: options.scopeId || (component && component.scopeId) || this.activeScopeId || "page",
414
- focusId: focusId,
415
- iconKey: options.iconKey || (component && component.iconKey) || "",
416
- up: options.up || (component && component.up) || "",
417
- down: options.down || (component && component.down) || "",
418
- left: options.left || (component && component.left) || "",
419
- right: options.right || (component && component.right) || "",
420
- onClick: options.onClick,
421
- onFocus: options.onFocus || (component && component.onFocus),
422
- onBlur: options.onBlur || (component && component.onBlur),
423
- component: component,
424
- baseScaleX: baseScale.x,
425
- baseScaleY: baseScale.y,
426
- focusScale: options.focusScale || (component && component.focusScale) || 1.08,
427
- showCursor: options.showCursor !== false
428
- };
429
- this.items.push(item);
430
- this.itemMap[item.focusId] = item;
431
- this.ensureFocus();
432
- };
433
- FocusManager.unregister = function (target) {
434
- var node = this.resolveNode(target);
435
- if (!node)
436
- return;
437
- for (var i = this.items.length - 1; i >= 0; i--) {
438
- if (this.items[i].node == node) {
439
- this.removeItemAt(i);
440
- }
441
- }
442
- this.ensureFocus();
443
- };
444
- FocusManager.unregisterByRoot = function (root) {
445
- if (!root)
446
- return;
447
- for (var i = this.items.length - 1; i >= 0; i--) {
448
- var item = this.items[i];
449
- if (item.root == root || this.isChildOf(item.node, root)) {
450
- this.removeItemAt(i);
451
- }
452
- }
453
- this.ensureFocus();
454
- };
455
- FocusManager.unregisterById = function (focusId) {
456
- if (!focusId)
457
- return;
458
- for (var i = this.items.length - 1; i >= 0; i--) {
459
- if (this.items[i].focusId == focusId)
460
- this.removeItemAt(i);
461
- }
462
- };
463
- FocusManager.registerButtons = function (root, options) {
464
- var _this = this;
465
- if (options === void 0) { options = {}; }
466
- if (!root)
467
- return;
468
- this.unregisterByRoot(root);
469
- this.walk(root, function (node) {
470
- if (node instanceof cc.Scene)
471
- return;
472
- var button = node.getComponent(cc.Button);
473
- if (!button)
474
- return;
475
- _this.register(node, {
476
- root: root,
477
- scopeId: options.scopeId || _this.activeScopeId,
478
- iconKey: options.iconKey,
479
- focusScale: options.focusScale || 1.08,
480
- onClick: function () { return _this.invokeButton(button); }
481
- });
482
- });
483
- this.ensureFocus();
484
- };
485
- FocusManager.pushScope = function (scopeId, root, firstFocus) {
486
- scopeId = scopeId || "modal";
487
- var currentScope = this.getActiveScope();
488
- if (currentScope)
489
- currentScope.lastFocusId = this.currentFocusId;
490
- for (var i = 0; i < this.scopes.length; i++) {
491
- if (this.scopes[i].scopeId == scopeId) {
492
- this.scopes.splice(i, 1);
493
- break;
494
- }
495
- }
496
- this.scopes.push(new FocusScope_1.default(scopeId, root));
497
- this.activeScopeId = scopeId;
498
- this.setFocusById("", true);
499
- if (firstFocus)
500
- this.focus(firstFocus);
501
- this.ensureFocus();
502
- };
503
- FocusManager.popScope = function (scopeId) {
504
- if (this.scopes.length <= 1)
505
- return;
506
- var target = scopeId || this.activeScopeId;
507
- for (var i = this.scopes.length - 1; i >= 1; i--) {
508
- if (this.scopes[i].scopeId == target) {
509
- this.scopes.splice(i, 1);
510
- break;
511
- }
512
- }
513
- var active = this.scopes[this.scopes.length - 1];
514
- this.activeScopeId = active ? active.scopeId : "page";
515
- var restored = active && active.lastFocusId ? this.focus(active.lastFocusId) : false;
516
- if (!restored) {
517
- this.setFocusById("", true);
518
- this.ensureFocus();
519
- }
520
- };
521
- FocusManager.reset = function () {
522
- var old = this.getCurrentFocusItem();
523
- if (old)
524
- this.setFocusVisual(old, false, true);
525
- this.items = [];
526
- this.itemMap = {};
527
- this.currentFocusId = "";
528
- this.scopes = [new FocusScope_1.default("page")];
529
- this.activeScopeId = "page";
530
- this.emitFocusChanged(null, old);
531
- };
532
- FocusManager.focus = function (target) {
533
- this.cleanup();
534
- if (!target)
535
- return false;
536
- var item = null;
537
- if (typeof target == "string") {
538
- item = this.itemMap[target];
539
- }
540
- else {
541
- for (var i = 0; i < this.items.length; i++) {
542
- if (this.items[i].node == target) {
543
- item = this.items[i];
544
- break;
545
- }
546
- }
547
- }
548
- if (!item || !this.isItemActive(item) || !this.isInActiveScope(item))
549
- return false;
550
- this.setFocusById(item.focusId);
551
- return true;
552
- };
553
- FocusManager.focusNode = function (node) {
554
- return this.focus(node);
555
- };
556
- FocusManager.move = function (direction) {
557
- this.cleanup();
558
- var current = this.getCurrentFocusItem();
559
- if (!current) {
560
- this.ensureFocus();
561
- return !!this.getCurrentFocusItem();
562
- }
563
- var explicitId = current[direction];
564
- if (explicitId && this.focus(explicitId))
565
- return true;
566
- var vector = this.getDirectionVector(direction);
567
- var currentCenter = this.getWorldCenter(current.node);
568
- var best = null;
569
- var bestScore = Number.MAX_VALUE;
570
- for (var i = 0; i < this.items.length; i++) {
571
- var item = this.items[i];
572
- if (item == current || !this.isItemActive(item) || !this.isInActiveScope(item))
573
- continue;
574
- var center = this.getWorldCenter(item.node);
575
- var dx = center.x - currentCenter.x;
576
- var dy = center.y - currentCenter.y;
577
- if (vector.x != 0 && dx * vector.x <= 8)
578
- continue;
579
- if (vector.y != 0 && dy * vector.y <= 8)
580
- continue;
581
- var primary = vector.x != 0 ? Math.abs(dx) : Math.abs(dy);
582
- var secondary = vector.x != 0 ? Math.abs(dy) : Math.abs(dx);
583
- var score = primary + secondary * 2;
584
- if (score < bestScore) {
585
- bestScore = score;
586
- best = item;
587
- }
588
- }
589
- if (best) {
590
- this.setFocusById(best.focusId);
591
- return true;
592
- }
593
- return this.moveByOrder(direction == "left" || direction == "down" ? -1 : 1);
594
- };
595
- FocusManager.confirm = function () {
596
- this.ensureFocus();
597
- var item = this.getCurrentFocusItem();
598
- if (!item)
599
- return false;
600
- if (item.onClick) {
601
- item.onClick();
602
- return true;
603
- }
604
- if (item.component && item.component.onConfirm) {
605
- item.component.onConfirm();
606
- return true;
607
- }
608
- this.invokeButton(item.node.getComponent(cc.Button));
609
- return true;
610
- };
611
- FocusManager.back = function () {
612
- return false;
613
- };
614
- FocusManager.handleKey = function (keyCode) {
615
- var key = KeyCodeAdapter_1.default.toRemoteKey(keyCode);
616
- if (key == KeyCodeAdapter_1.TvRemoteKey.Ok)
617
- return this.confirm();
618
- if (key == KeyCodeAdapter_1.TvRemoteKey.Left)
619
- return this.move("left");
620
- if (key == KeyCodeAdapter_1.TvRemoteKey.Right)
621
- return this.move("right");
622
- if (key == KeyCodeAdapter_1.TvRemoteKey.Up)
623
- return this.move("up");
624
- if (key == KeyCodeAdapter_1.TvRemoteKey.Down)
625
- return this.move("down");
626
- if (key == KeyCodeAdapter_1.TvRemoteKey.Back)
627
- return this.back();
628
- return false;
629
- };
630
- FocusManager.clickCurrent = function () {
631
- return this.confirm();
632
- };
633
- FocusManager.getCurrentFocusItem = function () {
634
- var item = this.itemMap[this.currentFocusId];
635
- return this.isItemActive(item) ? item : null;
636
- };
637
- FocusManager.getActiveScopeId = function () {
638
- return this.activeScopeId;
639
- };
640
- FocusManager.onFocusChanged = function (listener) {
641
- if (!listener)
642
- return;
643
- if (this.listeners.indexOf(listener) < 0)
644
- this.listeners.push(listener);
645
- };
646
- FocusManager.offFocusChanged = function (listener) {
647
- var index = this.listeners.indexOf(listener);
648
- if (index >= 0)
649
- this.listeners.splice(index, 1);
650
- };
651
- FocusManager.setFocusById = function (focusId, silent) {
652
- if (silent === void 0) { silent = false; }
653
- if (focusId == this.currentFocusId && focusId) {
654
- var current_1 = this.getCurrentFocusItem();
655
- if (current_1 && !silent) {
656
- this.setFocusVisual(current_1, true);
657
- this.emitFocusChanged(current_1, current_1);
658
- }
659
- return;
660
- }
661
- var previous = this.getCurrentFocusItem();
662
- if (previous)
663
- this.setFocusVisual(previous, false);
664
- this.currentFocusId = focusId || "";
665
- var current = this.getCurrentFocusItem();
666
- if (current) {
667
- var scope = this.getActiveScope();
668
- if (scope)
669
- scope.lastFocusId = current.focusId;
670
- this.setFocusVisual(current, true);
671
- }
672
- if (!silent)
673
- this.emitFocusChanged(current, previous);
674
- if (silent && previous)
675
- this.emitFocusChanged(null, previous);
676
- };
677
- FocusManager.setFocusVisual = function (item, focused, immediate) {
678
- if (immediate === void 0) { immediate = false; }
679
- if (!item || !item.node || !item.node.isValid)
680
- return;
681
- this.setButtonSpriteVisual(item, focused);
682
- item.node.stopActionByTag(this.FOCUS_SCALE_ACTION_TAG);
683
- var targetScaleX = focused ? item.baseScaleX * item.focusScale : item.baseScaleX;
684
- var targetScaleY = focused ? item.baseScaleY * item.focusScale : item.baseScaleY;
685
- if (immediate) {
686
- item.node.setScale(targetScaleX, targetScaleY);
687
- }
688
- else {
689
- var action = cc.scaleTo(0.08, targetScaleX, targetScaleY);
690
- action.setTag(this.FOCUS_SCALE_ACTION_TAG);
691
- item.node.runAction(action);
692
- }
693
- if (focused && item.onFocus)
694
- item.onFocus.call(item.component || item.node);
695
- if (!focused && item.onBlur)
696
- item.onBlur.call(item.component || item.node);
697
- };
698
- FocusManager.setButtonSpriteVisual = function (item, focused) {
699
- var button = item.node.getComponent(cc.Button);
700
- if (!button || button.transition != cc.Button.Transition.SPRITE)
701
- return;
702
- var target = button.target || button.node;
703
- if (!target || !target.isValid)
704
- return;
705
- var sprite = target.getComponent(cc.Sprite);
706
- if (!sprite)
707
- return;
708
- var spriteFrame = focused ? (button.hoverSprite || button.pressedSprite) : button.normalSprite;
709
- if (spriteFrame)
710
- sprite.spriteFrame = spriteFrame;
711
- };
712
- FocusManager.ensureFocus = function () {
713
- this.cleanup();
714
- if (this.getCurrentFocusItem())
715
- return;
716
- var activeScope = this.getActiveScope();
717
- if (activeScope && activeScope.lastFocusId && this.focus(activeScope.lastFocusId))
718
- return;
719
- for (var i = 0; i < this.items.length; i++) {
720
- var item = this.items[i];
721
- if (this.isItemActive(item) && this.isInActiveScope(item)) {
722
- this.setFocusById(item.focusId);
723
- return;
724
- }
725
- }
726
- };
727
- FocusManager.moveByOrder = function (step) {
728
- var activeItems = [];
729
- for (var i = 0; i < this.items.length; i++) {
730
- if (this.isItemActive(this.items[i]) && this.isInActiveScope(this.items[i]))
731
- activeItems.push(this.items[i]);
732
- }
733
- if (activeItems.length <= 0)
734
- return false;
735
- var index = 0;
736
- for (var i = 0; i < activeItems.length; i++) {
737
- if (activeItems[i].focusId == this.currentFocusId) {
738
- index = i;
739
- break;
740
- }
741
- }
742
- var next = (index + step + activeItems.length) % activeItems.length;
743
- this.setFocusById(activeItems[next].focusId);
744
- return true;
745
- };
746
- FocusManager.removeItemAt = function (index) {
747
- var item = this.items[index];
748
- if (!item)
749
- return;
750
- this.setFocusVisual(item, false, true);
751
- delete this.itemMap[item.focusId];
752
- this.items.splice(index, 1);
753
- if (this.currentFocusId == item.focusId) {
754
- this.currentFocusId = "";
755
- this.emitFocusChanged(null, item);
756
- }
757
- };
758
- FocusManager.cleanup = function () {
759
- for (var i = this.items.length - 1; i >= 0; i--) {
760
- var item = this.items[i];
761
- if (!item.node || !item.node.isValid)
762
- this.removeItemAt(i);
763
- }
764
- };
765
- FocusManager.isItemActive = function (item) {
766
- if (!item || !item.node || !item.node.isValid || !item.node.activeInHierarchy)
767
- return false;
768
- var button = item.node.getComponent(cc.Button);
769
- return !button || button.interactable;
770
- };
771
- FocusManager.isInActiveScope = function (item) {
772
- return !!item && item.scopeId == this.activeScopeId;
773
- };
774
- FocusManager.getActiveScope = function () {
775
- for (var i = this.scopes.length - 1; i >= 0; i--) {
776
- if (this.scopes[i].scopeId == this.activeScopeId)
777
- return this.scopes[i];
778
- }
779
- return null;
780
- };
781
- FocusManager.getWorldCenter = function (node) {
782
- var box = node.getBoundingBoxToWorld();
783
- return cc.v2(box.x + box.width / 2, box.y + box.height / 2);
784
- };
785
- FocusManager.getDirectionVector = function (direction) {
786
- if (direction == "left")
787
- return cc.v2(-1, 0);
788
- if (direction == "right")
789
- return cc.v2(1, 0);
790
- if (direction == "up")
791
- return cc.v2(0, 1);
792
- return cc.v2(0, -1);
793
- };
794
- FocusManager.invokeButton = function (button) {
795
- if (!button || !button.node || !button.node.activeInHierarchy || !button.interactable)
796
- return;
797
- if (button.clickEvents && button.clickEvents.length > 0) {
798
- cc.Component.EventHandler.emitEvents(button.clickEvents, null);
799
- var event = new cc.Event.EventCustom(cc.Node.EventType.TOUCH_END, true);
800
- button.node.emit(cc.Node.EventType.TOUCH_END, event);
801
- }
802
- else {
803
- var event = new cc.Event.EventCustom(cc.Node.EventType.TOUCH_END, true);
804
- button.node.emit(cc.Node.EventType.TOUCH_END, event);
805
- }
806
- };
807
- FocusManager.emitFocusChanged = function (item, previous) {
808
- for (var i = 0; i < this.listeners.length; i++) {
809
- this.listeners[i](item, previous);
810
- }
811
- };
812
- FocusManager.resolveNode = function (target) {
813
- if (!target)
814
- return null;
815
- if (target instanceof cc.Node)
816
- return target;
817
- return target.node || null;
818
- };
819
- FocusManager.resolveComponent = function (target, node) {
820
- if (!target || target instanceof cc.Node)
821
- return node.getComponent("FocusItem");
822
- return target;
823
- };
824
- FocusManager.findItemByNode = function (node) {
825
- if (!node)
826
- return null;
827
- for (var i = 0; i < this.items.length; i++) {
828
- if (this.items[i].node == node)
829
- return this.items[i];
830
- }
831
- return null;
832
- };
833
- FocusManager.getNodeBaseScale = function (node, preferred) {
834
- var nodeAny = node;
835
- var storedX = nodeAny[this.BASE_SCALE_X_KEY];
836
- var storedY = nodeAny[this.BASE_SCALE_Y_KEY];
837
- if (this.isValidScale(storedX) && this.isValidScale(storedY)) {
838
- return { x: storedX, y: storedY };
839
- }
840
- var baseScale = preferred || {
841
- x: this.readScale(node, "scaleX"),
842
- y: this.readScale(node, "scaleY")
843
- };
844
- nodeAny[this.BASE_SCALE_X_KEY] = baseScale.x;
845
- nodeAny[this.BASE_SCALE_Y_KEY] = baseScale.y;
846
- return baseScale;
847
- };
848
- FocusManager.readScale = function (node, key) {
849
- var nodeAny = node;
850
- var value = nodeAny[key];
851
- if (this.isValidScale(value))
852
- return value;
853
- value = nodeAny.scale;
854
- return this.isValidScale(value) ? value : 1;
855
- };
856
- FocusManager.isValidScale = function (value) {
857
- return typeof value == "number" && isFinite(value);
858
- };
859
- FocusManager.createFocusId = function (node) {
860
- return "focus_" + (node.name || "node") + "_" + this.items.length;
861
- };
862
- FocusManager.walk = function (node, visitor) {
863
- visitor(node);
864
- for (var i = 0; i < node.childrenCount; i++) {
865
- this.walk(node.children[i], visitor);
866
- }
867
- };
868
- FocusManager.isChildOf = function (node, root) {
869
- var cur = node;
870
- while (cur) {
871
- if (cur == root)
872
- return true;
873
- cur = cur.parent;
874
- }
875
- return false;
876
- };
877
- FocusManager.FOCUS_SCALE_ACTION_TAG = 9911;
878
- FocusManager.BASE_SCALE_X_KEY = "__tvFocusBaseScaleX";
879
- FocusManager.BASE_SCALE_Y_KEY = "__tvFocusBaseScaleY";
880
- FocusManager.items = [];
881
- FocusManager.itemMap = {};
882
- FocusManager.currentFocusId = "";
883
- FocusManager.scopes = [new FocusScope_1.default("page")];
884
- FocusManager.activeScopeId = "page";
885
- FocusManager.listeners = [];
886
- FocusManager.cursorOptions = null;
887
- return FocusManager;
888
- }());
889
- exports.default = FocusManager;
890
- });
891
- define("icon/IconManager", ["require", "exports", "config/TvUiConfigManager"], function (require, exports, TvUiConfigManager_1) {
892
- "use strict";
893
- Object.defineProperty(exports, "__esModule", { value: true });
894
- var IconManager = (function () {
895
- function IconManager() {
896
- }
897
- IconManager.init = function () {
898
- var _this = this;
899
- if (this.inited)
900
- return;
901
- this.inited = true;
902
- TvUiConfigManager_1.default.onChanged(function () {
903
- _this.cache = {};
904
- });
905
- };
906
- IconManager.getIconConfig = function (iconKey) {
907
- var config = TvUiConfigManager_1.default.getConfig();
908
- var key = iconKey || (config.focus && config.focus.defaultIconKey) || "default";
909
- var icons = config.icons || {};
910
- return icons[key] || icons["default"];
911
- };
912
- IconManager.getSpriteFrame = function (iconKey, callback) {
913
- var iconConfig = this.getIconConfig(iconKey);
914
- if (!iconConfig) {
915
- callback(null, null);
916
- return;
917
- }
918
- var cacheKey = iconConfig.url || iconConfig.path || iconKey || "default";
919
- if (this.cache[cacheKey]) {
920
- callback(this.cache[cacheKey], iconConfig);
921
- return;
922
- }
923
- if (iconConfig.url) {
924
- this.loadRemote(iconConfig, cacheKey, callback);
925
- return;
926
- }
927
- this.loadLocal(iconConfig, cacheKey, callback);
928
- };
929
- IconManager.setIconTheme = function (iconKey) {
930
- var config = TvUiConfigManager_1.default.getConfig();
931
- if (!config.icons || !config.icons[iconKey])
932
- return;
933
- TvUiConfigManager_1.default.updateConfig({
934
- focus: {
935
- defaultIconKey: iconKey
936
- }
937
- }, true);
938
- };
939
- IconManager.clearCache = function () {
940
- this.cache = {};
941
- };
942
- IconManager.loadLocal = function (iconConfig, cacheKey, callback) {
943
- var _this = this;
944
- if (!iconConfig.path) {
945
- callback(null, iconConfig);
946
- return;
947
- }
948
- cc.loader.loadRes(iconConfig.path, cc.SpriteFrame, function (error, frame) {
949
- if (error || !frame) {
950
- _this.loadFallback(cacheKey, callback);
951
- return;
952
- }
953
- _this.cache[cacheKey] = frame;
954
- callback(frame, iconConfig);
955
- });
956
- };
957
- IconManager.loadRemote = function (iconConfig, cacheKey, callback) {
958
- var _this = this;
959
- var assetManager = cc.assetManager;
960
- if (!assetManager || !assetManager.loadRemote) {
961
- this.loadFallback(cacheKey, callback);
962
- return;
963
- }
964
- assetManager.loadRemote(iconConfig.url, { ext: ".png" }, function (error, texture) {
965
- if (error || !texture) {
966
- _this.loadFallback(cacheKey, callback);
967
- return;
968
- }
969
- var frame = new cc.SpriteFrame(texture);
970
- _this.cache[cacheKey] = frame;
971
- callback(frame, iconConfig);
972
- });
973
- };
974
- IconManager.loadFallback = function (cacheKey, callback) {
975
- var fallback = this.getIconConfig("default");
976
- if (!fallback || fallback.path == cacheKey) {
977
- callback(null, fallback);
978
- return;
979
- }
980
- this.loadLocal(fallback, fallback.path || "default", callback);
981
- };
982
- IconManager.cache = {};
983
- IconManager.inited = false;
984
- return IconManager;
985
- }());
986
- exports.default = IconManager;
987
- });
988
- define("focus/FocusVisualLayer", ["require", "exports", "config/TvUiConfigManager", "icon/IconManager", "focus/FocusManager"], function (require, exports, TvUiConfigManager_2, IconManager_1, FocusManager_1) {
989
- "use strict";
990
- Object.defineProperty(exports, "__esModule", { value: true });
991
- var ccclass = cc._decorator.ccclass;
992
- var FocusVisualLayer = (function (_super) {
993
- __extends(FocusVisualLayer, _super);
994
- function FocusVisualLayer() {
995
- var _this = _super !== null && _super.apply(this, arguments) || this;
996
- _this.graphics = null;
997
- _this.iconNode = null;
998
- _this.iconSprite = null;
999
- _this.currentItem = null;
1000
- _this.currentIconConfig = null;
1001
- _this.inited = false;
1002
- _this.onFocusChanged = function (item) {
1003
- _this.refresh(item);
1004
- };
1005
- _this.onConfigChanged = function () {
1006
- _this.node.zIndex = (TvUiConfigManager_2.default.getConfig().focus || {}).zIndex || 800;
1007
- _this.refresh(_this.currentItem);
1008
- };
1009
- return _this;
1010
- }
1011
- FocusVisualLayer_1 = FocusVisualLayer;
1012
- FocusVisualLayer.create = function (parent) {
1013
- var node = parent.getChildByName("FocusVisualLayer");
1014
- if (!node) {
1015
- node = new cc.Node("FocusVisualLayer");
1016
- parent.addChild(node, 800);
1017
- }
1018
- var layer = node.getComponent(FocusVisualLayer_1);
1019
- if (!layer)
1020
- layer = node.addComponent(FocusVisualLayer_1);
1021
- layer.init();
1022
- return layer;
1023
- };
1024
- FocusVisualLayer.prototype.onDestroy = function () {
1025
- FocusManager_1.default.offFocusChanged(this.onFocusChanged);
1026
- TvUiConfigManager_2.default.offChanged(this.onConfigChanged);
1027
- };
1028
- FocusVisualLayer.prototype.init = function () {
1029
- if (this.inited)
1030
- return;
1031
- this.inited = true;
1032
- this.node.zIndex = (TvUiConfigManager_2.default.getConfig().focus || {}).zIndex || 800;
1033
- this.resizeToParent();
1034
- this.buildView();
1035
- FocusManager_1.default.onFocusChanged(this.onFocusChanged);
1036
- TvUiConfigManager_2.default.onChanged(this.onConfigChanged);
1037
- this.refresh(FocusManager_1.default.getCurrentFocusItem());
1038
- };
1039
- FocusVisualLayer.prototype.update = function () {
1040
- if (!this.currentItem)
1041
- return;
1042
- this.drawFocus(this.currentItem);
1043
- if (this.iconNode && this.iconNode.active && this.currentIconConfig) {
1044
- this.positionIcon(this.currentItem, this.currentIconConfig);
1045
- }
1046
- };
1047
- FocusVisualLayer.prototype.buildView = function () {
1048
- if (!this.graphics) {
1049
- this.graphics = this.node.addComponent(cc.Graphics);
1050
- }
1051
- if (!this.iconNode) {
1052
- this.iconNode = new cc.Node("FocusIcon");
1053
- this.iconNode.zIndex = 2;
1054
- this.iconSprite = this.iconNode.addComponent(cc.Sprite);
1055
- this.iconSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
1056
- this.node.addChild(this.iconNode, 2);
1057
- }
1058
- this.node.active = false;
1059
- };
1060
- FocusVisualLayer.prototype.refresh = function (item) {
1061
- this.currentItem = item;
1062
- if (!item || item.showCursor === false) {
1063
- this.hide();
1064
- return;
1065
- }
1066
- this.node.active = true;
1067
- this.drawFocus(item);
1068
- this.refreshIcon(item);
1069
- };
1070
- FocusVisualLayer.prototype.hide = function () {
1071
- this.node.active = false;
1072
- this.currentItem = null;
1073
- if (this.graphics)
1074
- this.graphics.clear();
1075
- if (this.iconNode)
1076
- this.iconNode.active = false;
1077
- this.currentIconConfig = null;
1078
- };
1079
- FocusVisualLayer.prototype.refreshIcon = function (item) {
1080
- var _this = this;
1081
- var iconKey = item.iconKey || (TvUiConfigManager_2.default.getConfig().focus || {}).defaultIconKey || "default";
1082
- IconManager_1.default.getSpriteFrame(iconKey, function (frame, iconConfig) {
1083
- if (_this.currentItem != item || !_this.iconNode || !_this.iconSprite)
1084
- return;
1085
- if (!frame) {
1086
- _this.iconNode.active = false;
1087
- return;
1088
- }
1089
- _this.iconNode.active = true;
1090
- _this.iconSprite.spriteFrame = frame;
1091
- _this.currentIconConfig = iconConfig || {};
1092
- _this.positionIcon(item, _this.currentIconConfig);
1093
- });
1094
- };
1095
- FocusVisualLayer.prototype.drawFocus = function (item) {
1096
- if (!item || !item.node || !item.node.isValid || !item.node.activeInHierarchy) {
1097
- this.hide();
1098
- return;
1099
- }
1100
- this.resizeToParent();
1101
- var focusConfig = TvUiConfigManager_2.default.getConfig().focus || {};
1102
- if (focusConfig.enabled === false) {
1103
- this.hide();
1104
- return;
1105
- }
1106
- if (!this.graphics)
1107
- return;
1108
- this.graphics.clear();
1109
- if (focusConfig.frameEnabled !== true) {
1110
- return;
1111
- }
1112
- var node = item.node;
1113
- var worldPos = node.parent.convertToWorldSpaceAR(node.position);
1114
- var local = this.node.convertToNodeSpaceAR(worldPos);
1115
- var contentSize = node.getContentSize();
1116
- var scaleX = node.scaleX;
1117
- var scaleY = node.scaleY;
1118
- var width = contentSize.width * scaleX;
1119
- var height = contentSize.height * scaleY;
1120
- var padding = focusConfig.framePadding || 0;
1121
- this.graphics.lineWidth = focusConfig.lineWidth || 4;
1122
- this.graphics.strokeColor = this.parseColor(focusConfig.frameColor || "#ffd451", focusConfig.frameOpacity);
1123
- this.graphics.rect(local.x - width / 2 - padding, local.y - height / 2 - padding, width + padding * 2, height + padding * 2);
1124
- this.graphics.stroke();
1125
- };
1126
- FocusVisualLayer.prototype.positionIcon = function (item, iconConfig) {
1127
- if (!item || !item.node || !item.node.isValid)
1128
- return;
1129
- var focusConfig = TvUiConfigManager_2.default.getConfig().focus || {};
1130
- var node = item.node;
1131
- var worldPos = node.parent.convertToWorldSpaceAR(node.position);
1132
- var local = this.node.convertToNodeSpaceAR(worldPos);
1133
- var contentSize = node.getContentSize();
1134
- var scaleX = node.scaleX;
1135
- var scaleY = node.scaleY;
1136
- var width = contentSize.width * scaleX;
1137
- var height = contentSize.height * scaleY;
1138
- var iconWidth = iconConfig.width || 60;
1139
- var iconHeight = iconConfig.height || 60;
1140
- var offsetX = iconConfig.offsetX;
1141
- var offsetY = iconConfig.offsetY;
1142
- if (offsetX === undefined)
1143
- offsetX = focusConfig.iconOffsetX || 0;
1144
- if (offsetY === undefined)
1145
- offsetY = focusConfig.iconOffsetY || 0;
1146
- if (!this.iconNode)
1147
- return;
1148
- var x = local.x + width / 2 + offsetX;
1149
- var y = local.y + height / 2 + offsetY;
1150
- if ((focusConfig.iconPlacement || "bottomRight") == "bottomRight") {
1151
- y = local.y - height / 2 - offsetY;
1152
- }
1153
- this.iconNode.setContentSize(iconWidth, iconHeight);
1154
- this.iconNode.setPosition(x, y);
1155
- };
1156
- FocusVisualLayer.prototype.resizeToParent = function () {
1157
- var parent = this.node.parent;
1158
- var width = parent && parent.width ? parent.width : (cc.winSize && cc.winSize.width) || 1920;
1159
- var height = parent && parent.height ? parent.height : (cc.winSize && cc.winSize.height) || 1080;
1160
- this.node.setContentSize(width, height);
1161
- this.node.setPosition(0, 0);
1162
- };
1163
- FocusVisualLayer.prototype.parseColor = function (hex, opacity) {
1164
- hex = (hex || "#ffd451").replace("#", "");
1165
- var r = parseInt(hex.substr(0, 2), 16);
1166
- var g = parseInt(hex.substr(2, 2), 16);
1167
- var b = parseInt(hex.substr(4, 2), 16);
1168
- return cc.color(r || 255, g || 212, b || 81, opacity === undefined ? 230 : opacity);
1169
- };
1170
- var FocusVisualLayer_1;
1171
- FocusVisualLayer = FocusVisualLayer_1 = __decorate([
1172
- ccclass
1173
- ], FocusVisualLayer);
1174
- return FocusVisualLayer;
1175
- }(cc.Component));
1176
- exports.default = FocusVisualLayer;
1177
- });
1178
- define("ad/IAdProvider", ["require", "exports"], function (require, exports) {
1179
- "use strict";
1180
- Object.defineProperty(exports, "__esModule", { value: true });
1181
- });
1182
- define("core/NativeBridge", ["require", "exports", "config/TvUiConfigManager"], function (require, exports, TvUiConfigManager_3) {
1183
- "use strict";
1184
- Object.defineProperty(exports, "__esModule", { value: true });
1185
- var callbackId = 100;
1186
- var nativeCallback = null;
1187
- var root = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {});
1188
- function hasBridge() {
1189
- return root.AppBridge && typeof root.AppBridge.call == "function";
1190
- }
1191
- function log(message, data) {
1192
- if (data !== undefined) {
1193
- console.log("[NativeBridge] " + message, data);
1194
- }
1195
- else {
1196
- console.log("[NativeBridge] " + message);
1197
- }
1198
- }
1199
- function normalizeCallbackData(data) {
1200
- if (typeof data == "string") {
1201
- try {
1202
- return JSON.parse(data);
1203
- }
1204
- catch (e) {
1205
- return { message: data };
1206
- }
1207
- }
1208
- return data || {};
1209
- }
1210
- function handleCallback(id, code, data, action) {
1211
- var callbacks = root._tvuiCallbacks || {};
1212
- id = id || root._tvuiLastCallbackId;
1213
- var callback = callbacks[id];
1214
- if (callback) {
1215
- callback(code, data, action);
1216
- delete callbacks[id];
1217
- }
1218
- }
1219
- function bridgeCall(action, data, callback) {
1220
- var id = "cb_" + (++callbackId);
1221
- root._tvuiLastCallbackId = id;
1222
- if (callback) {
1223
- root._tvuiCallbacks = root._tvuiCallbacks || {};
1224
- root._tvuiCallbacks[id] = callback;
1225
- }
1226
- if (!hasBridge()) {
1227
- log("AppBridge not found, skip in preview: " + action);
1228
- if (callback) {
1229
- callback(-1, { message: "AppBridge not found" }, action);
1230
- delete root._tvuiCallbacks[id];
1231
- }
1232
- return;
1233
- }
1234
- root.AppBridge.call(JSON.stringify({
1235
- action: action,
1236
- data: data || {},
1237
- callbackId: id
1238
- }));
1239
- }
1240
- root.onNativeBridgeCallback = function (action, data) {
1241
- data = normalizeCallbackData(data);
1242
- log("native callback: " + action, data);
1243
- switch (action) {
1244
- case "onBridgeCallback":
1245
- case "onDeviceInfo":
1246
- case "onReward":
1247
- case "onAdClosed":
1248
- case "onAdFailed":
1249
- case "onPopupAdLoaded":
1250
- case "onPopupAdClosed":
1251
- case "onPopupAdFailed":
1252
- case "onAggregateReward":
1253
- case "onAggregateAdClosed":
1254
- case "onAggregateAdFailed":
1255
- case "onAggregatePopupAdLoaded":
1256
- case "onAggregatePopupAdClosed":
1257
- case "onAggregatePopupAdFailed":
1258
- case "onRankUploaded":
1259
- case "onRankList":
1260
- handleCallback(data.callbackId || data.callback_id, data.code, data.data || data, action);
1261
- break;
1262
- }
1263
- if (nativeCallback)
1264
- nativeCallback(action, data);
1265
- };
1266
- var NativeBridge = (function () {
1267
- function NativeBridge() {
1268
- }
1269
- NativeBridge.hasBridge = function () {
1270
- return hasBridge();
1271
- };
1272
- NativeBridge.call = function (action, data, callback) {
1273
- bridgeCall(action, data || {}, callback);
1274
- };
1275
- NativeBridge.getDeviceInfo = function (callback) {
1276
- bridgeCall("getDeviceInfo", {}, callback);
1277
- };
1278
- NativeBridge.onGameReady = function () {
1279
- bridgeCall("onGameReady", { version: TvUiConfigManager_3.default.getConfig().version || "1.0.0" });
1280
- };
1281
- NativeBridge.onGamePause = function () {
1282
- bridgeCall("onGamePause", {});
1283
- };
1284
- NativeBridge.onGameResume = function () {
1285
- bridgeCall("onGameResume", {});
1286
- };
1287
- NativeBridge.onExitGame = function () {
1288
- bridgeCall("exitGame", {});
1289
- };
1290
- NativeBridge.uploadRank = function (data, callback) {
1291
- bridgeCall("uploadRank", data, callback);
1292
- };
1293
- NativeBridge.getRankList = function (data, callback) {
1294
- bridgeCall("getRankList", data, callback);
1295
- };
1296
- NativeBridge.setNativeCallback = function (callback) {
1297
- nativeCallback = callback;
1298
- };
1299
- return NativeBridge;
1300
- }());
1301
- exports.default = NativeBridge;
1302
- });
1303
- define("ad/AggregateAdProvider", ["require", "exports", "config/TvUiConfigManager", "core/NativeBridge", "../ad-sdk/ad-sdk"], function (require, exports, TvUiConfigManager_4, NativeBridge_1, ad_sdk_1) {
1304
- "use strict";
1305
- Object.defineProperty(exports, "__esModule", { value: true });
1306
- var AggregateAdProvider = (function () {
1307
- function AggregateAdProvider() {
1308
- this.type = "aggregate";
1309
- }
1310
- AggregateAdProvider.prototype.isAvailable = function () {
1311
- return NativeBridge_1.default.hasBridge();
1312
- };
1313
- AggregateAdProvider.prototype.load = function (data) {
1314
- return this.ensureSdk().then(function () { return data; });
1315
- };
1316
- AggregateAdProvider.prototype.show = function (data) {
1317
- return null;
1318
- };
1319
- AggregateAdProvider.prototype.hide = function (slotId, channel) {
1320
- };
1321
- AggregateAdProvider.prototype.showReward = function (data) {
1322
- var _this = this;
1323
- var options = data.options || {};
1324
- var channel = data.channel || {};
1325
- var runtime = TvUiConfigManager_4.default.getConfig();
1326
- return ad_sdk_1.AdSdk.requestAd({
1327
- adType: ad_sdk_1.AdType.RewardVideo,
1328
- cpId: options.cpId || runtime.cpId || "ppl",
1329
- rewardType: options.reward_type || channel.reward_type || "reward",
1330
- triggerScene: options.trigger_scene || data.slotId,
1331
- extra: options.extra || {}
1332
- }).then(function (result) {
1333
- if (!result || result.isCompleted !== true) {
1334
- if (options.onClose)
1335
- options.onClose(result);
1336
- return { status: "closed", data: result };
1337
- }
1338
- if (options.onSuccess)
1339
- options.onSuccess(result);
1340
- return { status: "success", data: result };
1341
- }).catch(function (error) {
1342
- if (_this.isUserAbandoned(error)) {
1343
- if (options.onClose)
1344
- options.onClose(error);
1345
- return { status: "closed", data: error };
1346
- }
1347
- return { status: "failed", error: error };
1348
- });
1349
- };
1350
- AggregateAdProvider.prototype.ensureSdk = function () {
1351
- var _this = this;
1352
- if (AggregateAdProvider.initialized)
1353
- return Promise.resolve();
1354
- if (AggregateAdProvider.initTask)
1355
- return AggregateAdProvider.initTask;
1356
- var runtime = TvUiConfigManager_4.default.getConfig();
1357
- var adSdkConfig = runtime.adSdk || {};
1358
- var platform = this.getPlatform(adSdkConfig.platform || "xiaomi");
1359
- var adapterConfig = {};
1360
- var customConfig = adSdkConfig.adapterConfig || {};
1361
- var key;
1362
- adapterConfig.cpId = runtime.cpId || "ppl";
1363
- for (key in customConfig)
1364
- adapterConfig[key] = customConfig[key];
1365
- var adapters = {};
1366
- adapters[platform] = adapterConfig;
1367
- AggregateAdProvider.initTask = ad_sdk_1.AdSdk.init({
1368
- platform: platform,
1369
- adapters: adapters
1370
- }).then(function () {
1371
- AggregateAdProvider.initialized = true;
1372
- _this.notifyGameReady(runtime.version || AggregateAdProvider.GAME_VERSION);
1373
- }).catch(function (error) {
1374
- AggregateAdProvider.initTask = null;
1375
- throw error;
1376
- });
1377
- return AggregateAdProvider.initTask;
1378
- };
1379
- AggregateAdProvider.prototype.notifyGameReady = function (version) {
1380
- if (AggregateAdProvider.gameReadyNotified)
1381
- return;
1382
- AggregateAdProvider.gameReadyNotified = true;
1383
- try {
1384
- ad_sdk_1.AdSdk.onGameReady(version || AggregateAdProvider.GAME_VERSION);
1385
- }
1386
- catch (error) {
1387
- console.warn("[AggregateAdProvider] onGameReady failed", error);
1388
- }
1389
- };
1390
- AggregateAdProvider.prototype.getPlatform = function (platform) {
1391
- if (platform == "xiaomi" || !platform)
1392
- return ad_sdk_1.AdPlatform.Xiaomi;
1393
- return platform;
1394
- };
1395
- AggregateAdProvider.prototype.isUserAbandoned = function (error) {
1396
- if (!error)
1397
- return false;
1398
- return error.code == ad_sdk_1.AdErrorCode.UserAbandoned
1399
- || error.code == 1006
1400
- || error.isCompleted === false
1401
- || error.is_completed === false
1402
- || error.message == "Ad closed by user before completion";
1403
- };
1404
- AggregateAdProvider.initialized = false;
1405
- AggregateAdProvider.initTask = null;
1406
- AggregateAdProvider.gameReadyNotified = false;
1407
- AggregateAdProvider.GAME_VERSION = "1.0.0";
1408
- return AggregateAdProvider;
1409
- }());
1410
- exports.default = AggregateAdProvider;
1411
- });
1412
- define("ad/SelfAdProvider", ["require", "exports"], function (require, exports) {
1413
- "use strict";
1414
- Object.defineProperty(exports, "__esModule", { value: true });
1415
- var SelfAdProvider = (function () {
1416
- function SelfAdProvider() {
1417
- this.type = "self";
1418
- }
1419
- SelfAdProvider.prototype.isAvailable = function () {
1420
- return true;
1421
- };
1422
- SelfAdProvider.prototype.load = function (data) {
1423
- return Promise.resolve(data);
1424
- };
1425
- SelfAdProvider.prototype.show = function (data) {
1426
- var channel = data.channel || {};
1427
- var options = data.options || {};
1428
- var path = channel.imagePath || (data.slotConfig.fallback && data.slotConfig.fallback.imagePath);
1429
- if (!path || !options.container) {
1430
- if (options.onLoad)
1431
- options.onLoad({ self: true, slotId: data.slotId });
1432
- return Promise.resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
1433
- }
1434
- var node = options.container;
1435
- var sprite = node.getComponent(cc.Sprite) || node.addComponent(cc.Sprite);
1436
- sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
1437
- return new Promise(function (resolve) {
1438
- cc.loader.loadRes(path, cc.SpriteFrame, function (error, frame) {
1439
- if (error || !frame) {
1440
- resolve({ status: "failed", error: error || { message: "self ad frame missing" } });
1441
- return;
1442
- }
1443
- sprite.spriteFrame = frame;
1444
- node.active = true;
1445
- if (options.onLoad)
1446
- options.onLoad({ self: true, slotId: data.slotId });
1447
- resolve({ status: "loaded", data: { self: true, slotId: data.slotId } });
1448
- });
1449
- });
1450
- };
1451
- SelfAdProvider.prototype.hide = function (_slotId) {
1452
- };
1453
- return SelfAdProvider;
1454
- }());
1455
- exports.default = SelfAdProvider;
1456
- });
1457
- define("ad/MockAdProvider", ["require", "exports"], function (require, exports) {
1458
- "use strict";
1459
- Object.defineProperty(exports, "__esModule", { value: true });
1460
- var MockAdProvider = (function () {
1461
- function MockAdProvider() {
1462
- this.type = "mock";
1463
- }
1464
- MockAdProvider.prototype.isAvailable = function () {
1465
- return true;
1466
- };
1467
- MockAdProvider.prototype.load = function (data) {
1468
- return Promise.resolve(data);
1469
- };
1470
- MockAdProvider.prototype.show = function (data) {
1471
- var options = data.options || {};
1472
- var mode = options.mode || data.slotConfig.mode || "popup";
1473
- console.log("[MockAdProvider] show", data.slotId, mode);
1474
- return new Promise(function (resolve) {
1475
- setTimeout(function () {
1476
- var result = { mock: true, slotId: data.slotId };
1477
- if (mode == "reward") {
1478
- var rewardResult = { isCompleted: true, mock: true, slotId: data.slotId };
1479
- if (options.onSuccess)
1480
- options.onSuccess(rewardResult);
1481
- resolve({ status: "success", data: rewardResult });
1482
- }
1483
- else {
1484
- if (options.onLoad)
1485
- options.onLoad(result);
1486
- resolve({ status: "loaded", data: result });
1487
- }
1488
- }, 0);
1489
- });
1490
- };
1491
- MockAdProvider.prototype.hide = function (slotId) {
1492
- console.log("[MockAdProvider] hide", slotId);
1493
- };
1494
- return MockAdProvider;
1495
- }());
1496
- exports.default = MockAdProvider;
1497
- });
1498
- define("ad/AdManager", ["require", "exports", "config/TvUiConfigManager", "ad/AggregateAdProvider", "ad/SelfAdProvider", "ad/MockAdProvider"], function (require, exports, TvUiConfigManager_5, AggregateAdProvider_1, SelfAdProvider_1, MockAdProvider_1) {
1499
- "use strict";
1500
- Object.defineProperty(exports, "__esModule", { value: true });
1501
- var AdManager = (function () {
1502
- function AdManager() {
1503
- }
1504
- AdManager.init = function () {
1505
- this.providers = {};
1506
- this.registerProvider(new AggregateAdProvider_1.default());
1507
- this.registerProvider(new SelfAdProvider_1.default());
1508
- this.registerProvider(new MockAdProvider_1.default());
1509
- };
1510
- AdManager.registerProvider = function (provider) {
1511
- if (!provider || !provider.type)
1512
- return;
1513
- this.providers[provider.type] = provider;
1514
- };
1515
- AdManager.showSlot = function (slotId, options) {
1516
- if (options === void 0) { options = {}; }
1517
- var slotConfig = this.getSlotConfig(slotId);
1518
- if (!slotConfig || slotConfig.enabled === false) {
1519
- if (options.onFail)
1520
- options.onFail({ message: "ad slot disabled", slotId: slotId });
1521
- return Promise.resolve(false);
1522
- }
1523
- var channels = this.getSortedChannels(slotConfig);
1524
- return this.showByChannels(slotId, slotConfig, options, channels, 0, null).then(function (result) {
1525
- if (result && (result.status == "success" || result.status == "loaded"))
1526
- return true;
1527
- if (result && result.status == "closed")
1528
- return false;
1529
- if (options.onFail) {
1530
- options.onFail((result && result.error) || { message: "all ad channels failed", slotId: slotId });
1531
- }
1532
- return false;
1533
- });
1534
- };
1535
- AdManager.hideSlot = function (slotId) {
1536
- var slotConfig = this.getSlotConfig(slotId);
1537
- var channels = slotConfig ? this.getSortedChannels(slotConfig) : [];
1538
- if (channels.length > 0) {
1539
- for (var i = 0; i < channels.length; i++) {
1540
- var channel = channels[i];
1541
- var provider = channel && this.providers[channel.type];
1542
- if (provider)
1543
- provider.hide(slotId, channel);
1544
- }
1545
- return;
1546
- }
1547
- for (var type in this.providers) {
1548
- if (this.providers.hasOwnProperty(type))
1549
- this.providers[type].hide(slotId);
1550
- }
1551
- };
1552
- AdManager.refreshSlot = function (slotId, options) {
1553
- if (options === void 0) { options = {}; }
1554
- this.hideSlot(slotId);
1555
- return this.showSlot(slotId, options);
1556
- };
1557
- AdManager.showReward = function (options) {
1558
- options = this.mergeOptions(options, { mode: "reward" });
1559
- return this.showSlot((options && options.slotId) || "reward", options);
1560
- };
1561
- AdManager.showPopup = function (options) {
1562
- options = this.mergeOptions(options, { mode: "popup" });
1563
- return this.showSlot((options && options.slotId) || (options && options.trigger_scene) || "popup", options);
1564
- };
1565
- AdManager.hidePopup = function (scene) {
1566
- this.hideSlot(scene || "popup");
1567
- };
1568
- AdManager.getSlotConfig = function (slotId) {
1569
- var config = TvUiConfigManager_5.default.getConfig();
1570
- var ads = config.ads || {};
1571
- return ads[slotId] || ads["popup"] || null;
1572
- };
1573
- AdManager.showByChannels = function (slotId, slotConfig, options, channels, index, lastError) {
1574
- var _this = this;
1575
- if (index >= channels.length) {
1576
- return Promise.resolve({ status: "failed", error: lastError || { message: "ad channels empty", slotId: slotId } });
1577
- }
1578
- var channel = channels[index];
1579
- if (!channel || channel.enabled === false) {
1580
- return this.showByChannels(slotId, slotConfig, options, channels, index + 1, lastError);
1581
- }
1582
- var provider = this.providers[channel.type];
1583
- if (!provider) {
1584
- return this.showByChannels(slotId, slotConfig, options, channels, index + 1, { message: "ad provider missing", channel: channel.type });
1585
- }
1586
- if (!provider.isAvailable()) {
1587
- return this.showByChannels(slotId, slotConfig, options, channels, index + 1, { message: "ad provider unavailable", channel: channel.type });
1588
- }
1589
- var data = {
1590
- slotId: slotId,
1591
- slotConfig: slotConfig,
1592
- channel: channel,
1593
- options: options
1594
- };
1595
- return provider.load(data).then(function (runtimeData) {
1596
- return provider.show(runtimeData);
1597
- }).then(function (result) {
1598
- if (!result || result.status == "failed") {
1599
- if (options && options.mode == "reward")
1600
- return result || { status: "failed", error: lastError };
1601
- return _this.showByChannels(slotId, slotConfig, options, channels, index + 1, result && (result.error || result.data));
1602
- }
1603
- return result;
1604
- }).catch(function (error) {
1605
- if (options && options.mode == "reward")
1606
- return { status: "failed", error: error };
1607
- return _this.showByChannels(slotId, slotConfig, options, channels, index + 1, error);
1608
- });
1609
- };
1610
- AdManager.getSortedChannels = function (slotConfig) {
1611
- var _this = this;
1612
- var channels = [];
1613
- var configured = (slotConfig && slotConfig.channels) || [];
1614
- for (var i = 0; i < configured.length; i++) {
1615
- if (configured[i])
1616
- channels.push(configured[i]);
1617
- }
1618
- if (slotConfig && slotConfig.fallback) {
1619
- channels.push(this.normalizeFallback(slotConfig.fallback));
1620
- }
1621
- if (!this.hasChannelType(channels, "mock")) {
1622
- channels.push({ type: "mock", priority: 100 });
1623
- }
1624
- channels.sort(function (a, b) {
1625
- return _this.getPriority(a) - _this.getPriority(b);
1626
- });
1627
- return channels;
1628
- };
1629
- AdManager.normalizeFallback = function (fallback) {
1630
- if (fallback.type)
1631
- return fallback;
1632
- var result = this.mergeOptions(fallback, {});
1633
- result.type = (fallback.imagePath || fallback.imageUrl) ? "self" : "mock";
1634
- if (result.priority === undefined)
1635
- result.priority = 90;
1636
- return result;
1637
- };
1638
- AdManager.hasChannelType = function (channels, type) {
1639
- for (var i = 0; i < channels.length; i++) {
1640
- if (channels[i] && channels[i].type == type)
1641
- return true;
1642
- }
1643
- return false;
1644
- };
1645
- AdManager.getPriority = function (channel) {
1646
- if (!channel || channel.priority === undefined)
1647
- return 999;
1648
- return channel.priority;
1649
- };
1650
- AdManager.mergeOptions = function (base, extra) {
1651
- var result = {};
1652
- var key;
1653
- base = base || {};
1654
- extra = extra || {};
1655
- for (key in base)
1656
- result[key] = base[key];
1657
- for (key in extra)
1658
- result[key] = extra[key];
1659
- return result;
1660
- };
1661
- AdManager.providers = {};
1662
- return AdManager;
1663
- }());
1664
- exports.default = AdManager;
1665
- });
1666
- define("core/BackManager", ["require", "exports"], function (require, exports) {
1667
- "use strict";
1668
- Object.defineProperty(exports, "__esModule", { value: true });
1669
- var BackManager = (function () {
1670
- function BackManager() {
1671
- }
1672
- BackManager.reset = function () {
1673
- this.handlers = [];
1674
- this.fallback = null;
1675
- };
1676
- BackManager.setFallback = function (handler) {
1677
- this.fallback = handler;
1678
- };
1679
- BackManager.push = function (handler) {
1680
- return;
1681
- if (!handler)
1682
- return;
1683
- this.remove(handler);
1684
- this.handlers.push(handler);
1685
- };
1686
- BackManager.remove = function (handler) {
1687
- return;
1688
- for (var i = this.handlers.length - 1; i >= 0; i--) {
1689
- if (this.handlers[i] == handler)
1690
- this.handlers.splice(i, 1);
1691
- }
1692
- };
1693
- BackManager.handle = function () {
1694
- for (var i = this.handlers.length - 1; i >= 0; i--) {
1695
- var handler = this.handlers[i];
1696
- if (!handler)
1697
- continue;
1698
- var result = handler();
1699
- if (result !== false)
1700
- return true;
1701
- }
1702
- if (this.fallback)
1703
- return this.fallback() !== false;
1704
- return false;
1705
- };
1706
- BackManager.handlers = [];
1707
- BackManager.fallback = null;
1708
- return BackManager;
1709
- }());
1710
- exports.default = BackManager;
1711
- });
1712
- define("input/RemoteInputManager", ["require", "exports", "input/KeyCodeAdapter"], function (require, exports, KeyCodeAdapter_2) {
1713
- "use strict";
1714
- Object.defineProperty(exports, "__esModule", { value: true });
1715
- exports.RemoteInputManager = void 0;
1716
- var RemoteInputManager = (function () {
1717
- function RemoteInputManager() {
1718
- }
1719
- RemoteInputManager.enable = function () {
1720
- if (this.enabled)
1721
- return;
1722
- this.enabled = true;
1723
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
1724
- this.enableDomInput();
1725
- this.focusCanvas();
1726
- };
1727
- RemoteInputManager.disable = function () {
1728
- if (!this.enabled)
1729
- return;
1730
- this.enabled = false;
1731
- cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
1732
- this.disableDomInput();
1733
- this.lastKeyCode = -1;
1734
- this.lastDispatchTime = 0;
1735
- };
1736
- RemoteInputManager.clear = function () {
1737
- this.handlers = {};
1738
- };
1739
- RemoteInputManager.on = function (key, handler) {
1740
- if (!this.handlers[key])
1741
- this.handlers[key] = [];
1742
- this.handlers[key].push(handler);
1743
- };
1744
- RemoteInputManager.off = function (key, handler) {
1745
- var list = this.handlers[key];
1746
- if (!list)
1747
- return;
1748
- var index = list.indexOf(handler);
1749
- if (index >= 0)
1750
- list.splice(index, 1);
1751
- };
1752
- RemoteInputManager.toRemoteKey = function (keyCode) {
1753
- return KeyCodeAdapter_2.default.toRemoteKey(keyCode);
1754
- };
1755
- RemoteInputManager.dispatchKeyCode = function (keyCode) {
1756
- var now = Date.now();
1757
- if (keyCode == this.lastKeyCode && now - this.lastDispatchTime < this.DISPATCH_DEBOUNCE_MS) {
1758
- return false;
1759
- }
1760
- this.lastKeyCode = keyCode;
1761
- this.lastDispatchTime = now;
1762
- var key = KeyCodeAdapter_2.default.toRemoteKey(keyCode);
1763
- var list = this.handlers[key] || [];
1764
- for (var i = list.length - 1; i >= 0; i--) {
1765
- var result = list[i](keyCode);
1766
- if (result !== false)
1767
- return true;
1768
- }
1769
- return false;
1770
- };
1771
- RemoteInputManager.onKeyDown = function (event) {
1772
- this.dispatchKeyCode(event.keyCode);
1773
- };
1774
- RemoteInputManager.enableDomInput = function () {
1775
- if (this.domInputEnabled || typeof window == "undefined")
1776
- return;
1777
- this.domInputEnabled = true;
1778
- window.addEventListener("keydown", this.onDomKeyDown, true);
1779
- };
1780
- RemoteInputManager.disableDomInput = function () {
1781
- if (!this.domInputEnabled || typeof window == "undefined")
1782
- return;
1783
- this.domInputEnabled = false;
1784
- window.removeEventListener("keydown", this.onDomKeyDown, true);
1785
- };
1786
- RemoteInputManager.onDomKeyDown = function (event) {
1787
- var handled = RemoteInputManager.dispatchKeyCode(event.keyCode || event.which);
1788
- if (handled && event.preventDefault)
1789
- event.preventDefault();
1790
- };
1791
- RemoteInputManager.focusCanvas = function () {
1792
- if (typeof document == "undefined")
1793
- return;
1794
- try {
1795
- var canvas = (cc && cc.game && cc.game.canvas) ? cc.game.canvas : document.querySelector("canvas");
1796
- if (canvas) {
1797
- canvas.tabIndex = canvas.tabIndex || 0;
1798
- if (typeof canvas.focus == "function") {
1799
- canvas.focus();
1800
- return;
1801
- }
1802
- }
1803
- if (typeof window != "undefined" && typeof window.focus == "function")
1804
- window.focus();
1805
- }
1806
- catch (e) {
1807
- }
1808
- };
1809
- RemoteInputManager.handlers = {};
1810
- RemoteInputManager.enabled = false;
1811
- RemoteInputManager.domInputEnabled = false;
1812
- RemoteInputManager.lastKeyCode = -1;
1813
- RemoteInputManager.lastDispatchTime = 0;
1814
- RemoteInputManager.DISPATCH_DEBOUNCE_MS = 160;
1815
- return RemoteInputManager;
1816
- }());
1817
- exports.RemoteInputManager = RemoteInputManager;
1818
- });
1819
- define("core/TvUiRoot", ["require", "exports", "config/TvUiConfigManager", "focus/FocusManager", "focus/FocusVisualLayer", "icon/IconManager", "ad/AdManager", "input/KeyCodeAdapter", "core/BackManager", "core/NativeBridge", "input/RemoteInputManager"], function (require, exports, TvUiConfigManager_6, FocusManager_2, FocusVisualLayer_2, IconManager_2, AdManager_1, KeyCodeAdapter_3, BackManager_1, NativeBridge_2, RemoteInputManager_1) {
1820
- "use strict";
1821
- Object.defineProperty(exports, "__esModule", { value: true });
1822
- var ccclass = cc._decorator.ccclass;
1823
- var TvUiRoot = (function (_super) {
1824
- __extends(TvUiRoot, _super);
1825
- function TvUiRoot() {
1826
- var _this = _super !== null && _super.apply(this, arguments) || this;
1827
- _this.visualLayer = null;
1828
- _this.configured = false;
1829
- return _this;
1830
- }
1831
- TvUiRoot_1 = TvUiRoot;
1832
- TvUiRoot.ensure = function (config) {
1833
- if (this.instance && this.instance.node && this.instance.node.isValid) {
1834
- if (config)
1835
- this.instance.configure(config);
1836
- return this.instance;
1837
- }
1838
- var scene = cc.director.getScene();
1839
- var node = new cc.Node("TvUiRoot");
1840
- node.zIndex = 800;
1841
- scene.addChild(node, 800);
1842
- if (cc.game && cc.game.addPersistRootNode) {
1843
- cc.game.addPersistRootNode(node);
1844
- }
1845
- this.instance = node.addComponent(TvUiRoot_1);
1846
- this.instance.configure(config || {});
1847
- return this.instance;
1848
- };
1849
- TvUiRoot.getInstance = function () {
1850
- return this.instance;
1851
- };
1852
- TvUiRoot.setBackHandler = function (handler) {
1853
- this.backHandler = handler;
1854
- if (this.instance)
1855
- this.instance.bindInputHandlers();
1856
- };
1857
- TvUiRoot.prototype.onLoad = function () {
1858
- TvUiRoot_1.instance = this;
1859
- this.resize();
1860
- this.exposeGlobal();
1861
- };
1862
- TvUiRoot.prototype.onDestroy = function () {
1863
- if (TvUiRoot_1.instance == this)
1864
- TvUiRoot_1.instance = null;
1865
- };
1866
- TvUiRoot.prototype.configure = function (config) {
1867
- var _this = this;
1868
- this.configured = true;
1869
- TvUiConfigManager_6.default.init(config || {}, function () {
1870
- _this.applyConfig();
1871
- });
1872
- this.applyConfig();
1873
- };
1874
- TvUiRoot.prototype.applyConfig = function () {
1875
- if (!this.configured)
1876
- return;
1877
- var config = TvUiConfigManager_6.default.getConfig();
1878
- if (cc.view && config.designWidth && config.designHeight) {
1879
- cc.view.setDesignResolutionSize(config.designWidth, config.designHeight, config.resolutionPolicy || cc.ResolutionPolicy.SHOW_ALL);
1880
- }
1881
- this.resize();
1882
- IconManager_2.default.init();
1883
- AdManager_1.default.init();
1884
- this.ensureVisualLayer();
1885
- this.bindInputHandlers();
1886
- this.exposeGlobal();
1887
- };
1888
- TvUiRoot.prototype.ensureVisualLayer = function () {
1889
- var config = TvUiConfigManager_6.default.getConfig();
1890
- if (config.focus && config.focus.enabled === false)
1891
- return;
1892
- this.visualLayer = FocusVisualLayer_2.default.create(this.node);
1893
- };
1894
- TvUiRoot.prototype.bindInputHandlers = function () {
1895
- var config = TvUiConfigManager_6.default.getConfig();
1896
- RemoteInputManager_1.RemoteInputManager.clear();
1897
- if (config.enableRemoteInput === false) {
1898
- RemoteInputManager_1.RemoteInputManager.disable();
1899
- return;
1900
- }
1901
- RemoteInputManager_1.RemoteInputManager.enable();
1902
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Ok, function () { return FocusManager_2.default.confirm(); });
1903
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Left, function () { return FocusManager_2.default.move("left"); });
1904
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Right, function () { return FocusManager_2.default.move("right"); });
1905
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Up, function () { return FocusManager_2.default.move("up"); });
1906
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Down, function () { return FocusManager_2.default.move("down"); });
1907
- RemoteInputManager_1.RemoteInputManager.on(KeyCodeAdapter_3.TvRemoteKey.Back, function () {
1908
- if (TvUiRoot_1.backHandler)
1909
- return TvUiRoot_1.backHandler() !== false;
1910
- return FocusManager_2.default.back();
1911
- });
1912
- };
1913
- TvUiRoot.prototype.resize = function () {
1914
- var width = (cc.winSize && cc.winSize.width) || 1920;
1915
- var height = (cc.winSize && cc.winSize.height) || 1080;
1916
- this.node.setContentSize(width, height);
1917
- this.node.setPosition(0, 0);
1918
- };
1919
- TvUiRoot.prototype.exposeGlobal = function () {
1920
- var root = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : null);
1921
- if (!root)
1922
- return;
1923
- root.TvUiRoot = TvUiRoot_1;
1924
- if (root.TvUi) {
1925
- root.tvui = root.TvUi;
1926
- return;
1927
- }
1928
- if (root.tvui)
1929
- return;
1930
- root.tvui = {
1931
- root: TvUiRoot_1,
1932
- config: TvUiConfigManager_6.default,
1933
- focus: FocusManager_2.default,
1934
- icon: IconManager_2.default,
1935
- ads: AdManager_1.default,
1936
- input: RemoteInputManager_1.RemoteInputManager,
1937
- api: NativeBridge_2.default,
1938
- back: BackManager_1.default
1939
- };
1940
- };
1941
- var TvUiRoot_1;
1942
- TvUiRoot.instance = null;
1943
- TvUiRoot.backHandler = null;
1944
- TvUiRoot = TvUiRoot_1 = __decorate([
1945
- ccclass
1946
- ], TvUiRoot);
1947
- return TvUiRoot;
1948
- }(cc.Component));
1949
- exports.default = TvUiRoot;
1950
- });
1951
- define("core/TvUi", ["require", "exports", "core/TvUiRoot", "core/BackManager", "core/NativeBridge", "config/TvUiConfigManager", "focus/FocusManager", "icon/IconManager", "ad/AdManager", "input/RemoteInputManager"], function (require, exports, TvUiRoot_2, BackManager_2, NativeBridge_3, TvUiConfigManager_7, FocusManager_3, IconManager_3, AdManager_2, RemoteInputManager_2) {
1952
- "use strict";
1953
- Object.defineProperty(exports, "__esModule", { value: true });
1954
- var TvUi = (function () {
1955
- function TvUi() {
1956
- }
1957
- TvUi.init = function (config) {
1958
- TvUiRoot_2.default.ensure(config || {});
1959
- TvUiRoot_2.default.setBackHandler(function () { return BackManager_2.default.handle(); });
1960
- NativeBridge_3.default.setNativeCallback(function (action, data) {
1961
- var runtime = TvUiConfigManager_7.default.getConfig();
1962
- if (runtime.nativeCallback)
1963
- runtime.nativeCallback(action, data);
1964
- });
1965
- var runtime = TvUiConfigManager_7.default.getConfig();
1966
- if (!this.initialized && runtime.enableLifecycle !== false) {
1967
- NativeBridge_3.default.onGameReady();
1968
- cc.game.on(cc.game.EVENT_HIDE, this.onGameHide, this);
1969
- cc.game.on(cc.game.EVENT_SHOW, this.onGameShow, this);
1970
- }
1971
- this.exposeGlobal();
1972
- this.initialized = true;
1973
- };
1974
- TvUi.destroy = function () {
1975
- cc.game.off(cc.game.EVENT_HIDE, this.onGameHide, this);
1976
- cc.game.off(cc.game.EVENT_SHOW, this.onGameShow, this);
1977
- RemoteInputManager_2.RemoteInputManager.disable();
1978
- RemoteInputManager_2.RemoteInputManager.clear();
1979
- TvUiRoot_2.default.setBackHandler(null);
1980
- FocusManager_3.default.reset();
1981
- BackManager_2.default.reset();
1982
- NativeBridge_3.default.setNativeCallback(null);
1983
- this.initialized = false;
1984
- };
1985
- TvUi.exposeGlobal = function () {
1986
- var runtimeRoot = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : null);
1987
- if (!runtimeRoot)
1988
- return;
1989
- runtimeRoot.TvUi = TvUi;
1990
- runtimeRoot.tvui = TvUi;
1991
- };
1992
- TvUi.onGameHide = function () {
1993
- NativeBridge_3.default.onGamePause();
1994
- };
1995
- TvUi.onGameShow = function () {
1996
- NativeBridge_3.default.onGameResume();
1997
- };
1998
- TvUi.root = TvUiRoot_2.default;
1999
- TvUi.config = TvUiConfigManager_7.default;
2000
- TvUi.focus = FocusManager_3.default;
2001
- TvUi.icon = IconManager_3.default;
2002
- TvUi.ads = AdManager_2.default;
2003
- TvUi.api = NativeBridge_3.default;
2004
- TvUi.input = RemoteInputManager_2.RemoteInputManager;
2005
- TvUi.back = BackManager_2.default;
2006
- TvUi.initialized = false;
2007
- return TvUi;
2008
- }());
2009
- exports.default = TvUi;
2010
- });
2011
- define("toast/UIFunctions", ["require", "exports"], function (require, exports) {
2012
- "use strict";
2013
- Object.defineProperty(exports, "__esModule", { value: true });
2014
- var UIFunctions = (function () {
2015
- function UIFunctions() {
2016
- }
2017
- UIFunctions.getChildrenAnimations = function (node) {
2018
- var animations = [];
2019
- var anim = node.getComponent(cc.Animation);
2020
- if (anim)
2021
- animations.push(anim);
2022
- for (var i = 0; i < node.childrenCount; i++) {
2023
- var child = node.children[i];
2024
- var anim = child.getComponent(cc.Animation);
2025
- if (anim)
2026
- animations.push(anim);
2027
- }
2028
- return animations;
2029
- };
2030
- UIFunctions.stopAnimations = function (animations) {
2031
- animations.forEach(function (anim) {
2032
- anim.stop();
2033
- });
2034
- };
2035
- UIFunctions.doShowAnimations = function (animations, finishCallback, target) {
2036
- var maxDuration = 0;
2037
- var maxDurationAnimation = null;
2038
- animations.forEach(function (anim) {
2039
- var clips = anim.getClips();
2040
- if (clips.length > 0) {
2041
- var clip = clips[0];
2042
- var animState = anim.play(clip.name);
2043
- animState.wrapMode = cc.WrapMode.Normal;
2044
- if (clip.duration > maxDuration) {
2045
- maxDuration = clip.duration;
2046
- maxDurationAnimation = anim;
2047
- }
2048
- }
2049
- });
2050
- if (finishCallback) {
2051
- var func_1 = function () {
2052
- if (maxDurationAnimation)
2053
- maxDurationAnimation.off("finished", func_1);
2054
- finishCallback.call(target);
2055
- };
2056
- if (maxDurationAnimation)
2057
- maxDurationAnimation.on("finished", func_1);
2058
- else
2059
- finishCallback.call(target);
2060
- }
2061
- };
2062
- UIFunctions.isAnimationRunning = function (animations) {
2063
- return false;
2064
- };
2065
- UIFunctions.doHideAnimations = function (animations, finishCallback, target) {
2066
- var hasHideAnimation = false;
2067
- var maxDuration = 0;
2068
- var maxDurationAnimation = null;
2069
- animations.forEach(function (anim) {
2070
- var clips = anim.getClips();
2071
- if (clips.length == 2) {
2072
- var clip = clips[clips.length - 1];
2073
- hasHideAnimation = true;
2074
- anim.play(clip.name);
2075
- if (clip.duration > maxDuration) {
2076
- maxDuration = clip.duration;
2077
- maxDurationAnimation = anim;
2078
- }
2079
- }
2080
- else if (clips.length == 1) {
2081
- var clip = clips[0];
2082
- hasHideAnimation = true;
2083
- var animState = anim.play(clip.name);
2084
- animState.wrapMode = cc.WrapMode.Reverse;
2085
- if (clip.duration > maxDuration) {
2086
- maxDuration = clip.duration;
2087
- maxDurationAnimation = anim;
2088
- }
2089
- }
2090
- });
2091
- if (maxDurationAnimation && finishCallback) {
2092
- var func_2 = function () {
2093
- maxDurationAnimation.off("finished", func_2);
2094
- finishCallback.call(target);
2095
- };
2096
- maxDurationAnimation.on("finished", func_2);
2097
- }
2098
- return hasHideAnimation;
2099
- };
2100
- UIFunctions.getToggleIndex = function (toggle) {
2101
- var container = toggle.node.parent;
2102
- for (var i = 0; i < container.childrenCount; i++) {
2103
- var child = container.children[i];
2104
- if (toggle.node == child) {
2105
- return i;
2106
- }
2107
- }
2108
- return -1;
2109
- };
2110
- UIFunctions.selectToggleIndex = function (toggleContainer, index) {
2111
- if (toggleContainer == null) {
2112
- console.warn("[UIFunction.selectToggleIndex] : invalid toggleContainer :");
2113
- return;
2114
- }
2115
- var toggleNode = toggleContainer.children[index];
2116
- if (toggleNode) {
2117
- var toggle = toggleNode.getComponent(cc.Toggle);
2118
- if (toggle) {
2119
- console.log("[UIFunction.selectToggleIndex] :" + index);
2120
- toggle.check();
2121
- }
2122
- }
2123
- else {
2124
- console.warn("[UIFunction.selectToggleIndex] :cannot find toggle with index:" + index);
2125
- }
2126
- };
2127
- UIFunctions.setTouchEnabled = function (node, b) {
2128
- };
2129
- UIFunctions.setButtonEnabled = function (btn, b) {
2130
- btn.node.opacity = b ? 255 : 155;
2131
- btn.interactable = b;
2132
- };
2133
- return UIFunctions;
2134
- }());
2135
- exports.default = UIFunctions;
2136
- });
2137
- define("toast/ToastComponent", ["require", "exports"], function (require, exports) {
2138
- "use strict";
2139
- Object.defineProperty(exports, "__esModule", { value: true });
2140
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
2141
- var ToastComponent = (function (_super) {
2142
- __extends(ToastComponent, _super);
2143
- function ToastComponent() {
2144
- var _this = _super !== null && _super.apply(this, arguments) || this;
2145
- _this.label = null;
2146
- return _this;
2147
- }
2148
- ToastComponent.prototype.onLoad = function () {
2149
- };
2150
- ToastComponent.prototype.start = function () {
2151
- };
2152
- ToastComponent.prototype.hide = function (callback) {
2153
- this.node.active = true;
2154
- this.node.active = false;
2155
- if (callback) {
2156
- callback(this);
2157
- }
2158
- };
2159
- ToastComponent.prototype.show = function (text) {
2160
- this.label.string = text;
2161
- };
2162
- __decorate([
2163
- property(cc.Label),
2164
- __metadata("design:type", cc.Label)
2165
- ], ToastComponent.prototype, "label", void 0);
2166
- ToastComponent = __decorate([
2167
- ccclass
2168
- ], ToastComponent);
2169
- return ToastComponent;
2170
- }(cc.Component));
2171
- exports.default = ToastComponent;
2172
- });
2173
- define("toast/ToastManager", ["require", "exports", "toast/ToastComponent"], function (require, exports, ToastComponent_1) {
2174
- "use strict";
2175
- Object.defineProperty(exports, "__esModule", { value: true });
2176
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
2177
- var ToastManager = (function () {
2178
- function ToastManager() {
2179
- }
2180
- ToastManager_1 = ToastManager;
2181
- ToastManager.prototype.init = function () {
2182
- return __awaiter(this, void 0, void 0, function () {
2183
- var _a;
2184
- return __generator(this, function (_b) {
2185
- switch (_b.label) {
2186
- case 0:
2187
- this.toastPool = new cc.NodePool();
2188
- _a = this;
2189
- return [4, this.loadSpriteFrame('tvui/prefab/Toast')];
2190
- case 1:
2191
- _a.prefab = _b.sent();
2192
- return [2];
2193
- }
2194
- });
2195
- });
2196
- };
2197
- ToastManager.prototype.loadSpriteFrame = function (path) {
2198
- return new Promise(function (resolve, reject) {
2199
- cc.loader.loadRes(path, cc.Prefab, function (err, spriteFrame) {
2200
- if (err) {
2201
- reject(err);
2202
- }
2203
- else {
2204
- resolve(spriteFrame);
2205
- }
2206
- });
2207
- });
2208
- };
2209
- ToastManager.prototype.onDestroy = function () {
2210
- this.toastPool.clear();
2211
- };
2212
- ToastManager.prototype.make = function (text, dur) {
2213
- if (dur === void 0) { dur = 1500; }
2214
- var node = this.toastPool.get();
2215
- var toastComp = null;
2216
- if (node == null) {
2217
- node = cc.instantiate(this.prefab);
2218
- toastComp = node.getComponent(ToastComponent_1.default);
2219
- if (toastComp == null) {
2220
- console.warn("Toast.make : Toast Prefab must contains ToastComponent");
2221
- }
2222
- }
2223
- else {
2224
- toastComp = node.getComponent(ToastComponent_1.default);
2225
- }
2226
- if (node.parent == null)
2227
- cc.director.getScene().addChild(node, cc.macro.MAX_ZINDEX);
2228
- node.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
2229
- this.show(toastComp, text, dur);
2230
- return toastComp;
2231
- };
2232
- ToastManager.prototype.show = function (toastComp, text, dur) {
2233
- var _this = this;
2234
- toastComp.show(text);
2235
- setTimeout(function (_) {
2236
- toastComp.hide(function (_) {
2237
- _this.toastPool.put(toastComp.node);
2238
- console.log("Toast.hide toastpool size:", _this.toastPool.size());
2239
- });
2240
- }, dur);
2241
- };
2242
- var ToastManager_1;
2243
- ToastManager.Inst = new ToastManager_1();
2244
- ToastManager = ToastManager_1 = __decorate([
2245
- ccclass
2246
- ], ToastManager);
2247
- return ToastManager;
2248
- }());
2249
- exports.default = ToastManager;
2250
- });
2251
- define("Info", ["require", "exports", "core/TvUi", "toast/ToastManager"], function (require, exports, TvUi_1, ToastManager_2) {
2252
- "use strict";
2253
- Object.defineProperty(exports, "__esModule", { value: true });
2254
- exports.showRewardVideo = showRewardVideo;
2255
- function getRuntimeTvUi() {
2256
- var root = typeof window != "undefined" ? window : null;
2257
- return TvUi_1.default || (root && (root.TvUi || root.tvui)) || null;
2258
- }
2259
- function showRewardVideo(scene, rewardType, callback, target, hooks) {
2260
- var finishFired = false;
2261
- var fireFinish = function () {
2262
- if (finishFired) {
2263
- return;
2264
- }
2265
- finishFired = true;
2266
- hooks && hooks.onFinish && hooks.onFinish.call(target);
2267
- };
2268
- var onSuccess = function () {
2269
- try {
2270
- callback && callback.call(target);
2271
- }
2272
- finally {
2273
- fireFinish();
2274
- }
2275
- };
2276
- var onClose = function () {
2277
- ToastManager_2.default.Inst.make("必须看完视频,才能获取奖励");
2278
- hooks && hooks.onClose && hooks.onClose.call(target);
2279
- fireFinish();
2280
- };
2281
- var onFail = function () {
2282
- ToastManager_2.default.Inst.make("广告暂不可用,请稍后再试");
2283
- hooks && hooks.onFail && hooks.onFail.call(target);
2284
- fireFinish();
2285
- };
2286
- var tvUi = getRuntimeTvUi();
2287
- if (tvUi && tvUi.ads && tvUi.ads.showReward && tvUi.api && tvUi.api.hasBridge && tvUi.api.hasBridge()) {
2288
- tvUi.ads.showReward({
2289
- scene: scene,
2290
- rewardType: rewardType,
2291
- onSuccess: onSuccess,
2292
- onClose: onClose,
2293
- onFail: onFail,
2294
- onFinish: fireFinish
2295
- });
2296
- return;
2297
- }
2298
- callback && callback.call(target);
2299
- return;
2300
- }
2301
- });
2302
- define("Loader", ["require", "exports"], function (require, exports) {
2303
- "use strict";
2304
- Object.defineProperty(exports, "__esModule", { value: true });
2305
- exports.Loader = void 0;
2306
- var Loader = (function () {
2307
- function Loader() {
2308
- }
2309
- Loader.loadRes = function (path, progressCallback) {
2310
- return __awaiter(this, void 0, void 0, function () {
2311
- return __generator(this, function (_a) {
2312
- return [2, new Promise(function (resolve, reject) {
2313
- cc.loader.loadRes(path, function (completedCount, totalCount, item) {
2314
- if (progressCallback) {
2315
- progressCallback(completedCount / totalCount);
2316
- }
2317
- }, function (error, asset) {
2318
- if (error) {
2319
- reject(error);
2320
- }
2321
- else {
2322
- resolve(asset);
2323
- }
2324
- });
2325
- })];
2326
- });
2327
- });
2328
- };
2329
- Loader.loadResDir = function (dir, progressCallback) {
2330
- return __awaiter(this, void 0, void 0, function () {
2331
- return __generator(this, function (_a) {
2332
- return [2, new Promise(function (resolve, reject) {
2333
- cc.loader.loadResDir(dir, function (completedCount, totalCount, item) {
2334
- if (progressCallback) {
2335
- progressCallback(completedCount / totalCount, completedCount, totalCount);
2336
- }
2337
- }, function (error, assets) {
2338
- if (error) {
2339
- reject(error);
2340
- }
2341
- else {
2342
- resolve(assets);
2343
- }
2344
- });
2345
- })];
2346
- });
2347
- });
2348
- };
2349
- Loader.loadBatch = function (resources, progressCallback) {
2350
- return __awaiter(this, void 0, void 0, function () {
2351
- var results, totalCount, completedCount, loadPromises;
2352
- var _this = this;
2353
- return __generator(this, function (_a) {
2354
- switch (_a.label) {
2355
- case 0:
2356
- results = new Map();
2357
- totalCount = resources.length;
2358
- completedCount = 0;
2359
- loadPromises = resources.map(function (res, index) {
2360
- var key = res.key || res.path;
2361
- return _this.loadRes(res.path)
2362
- .then(function (asset) {
2363
- results.set(key, asset);
2364
- completedCount++;
2365
- if (progressCallback) {
2366
- progressCallback(completedCount / totalCount, completedCount, totalCount);
2367
- }
2368
- })
2369
- .catch(function (error) {
2370
- console.error("Failed to load resource: ".concat(res.path), error);
2371
- completedCount++;
2372
- if (progressCallback) {
2373
- progressCallback(completedCount / totalCount, completedCount, totalCount);
2374
- }
2375
- });
2376
- });
2377
- return [4, Promise.all(loadPromises)];
2378
- case 1:
2379
- _a.sent();
2380
- return [2, results];
2381
- }
2382
- });
2383
- });
2384
- };
2385
- return Loader;
2386
- }());
2387
- exports.Loader = Loader;
2388
- });
2389
- define("PlatformAdapter", ["require", "exports", "BtnExtra", "core/TvUi", "Info", "Loader", "toast/ToastManager"], function (require, exports, BtnExtra_1, TvUi_2, Info_1, Loader_1, ToastManager_3) {
2390
- "use strict";
2391
- Object.defineProperty(exports, "__esModule", { value: true });
2392
- exports.PlatformAdapter = void 0;
2393
- var PlatformAdapter = (function () {
2394
- function PlatformAdapter() {
2395
- }
2396
- PlatformAdapter.init = function () {
2397
- return __awaiter(this, void 0, void 0, function () {
2398
- return __generator(this, function (_a) {
2399
- switch (_a.label) {
2400
- case 0: return [4, ToastManager_3.default.Inst.init()];
2401
- case 1:
2402
- _a.sent();
2403
- TvUi_2.default.init({
2404
- cpId: this.cpId,
2405
- version: this.version,
2406
- designWidth: this.designWidth,
2407
- designHeight: this.designHeight,
2408
- enableCursor: true,
2409
- configPath: "tvui/config/default",
2410
- focus: {
2411
- enabled: true,
2412
- defaultIconKey: "default"
2413
- },
2414
- adSdk: {
2415
- platform: "xiaomi"
2416
- },
2417
- ads: {
2418
- reward: {
2419
- enabled: true,
2420
- mode: "reward",
2421
- channels: [
2422
- { type: "aggregate", priority: 1, reward_type: "reward" },
2423
- { type: "mock", priority: 100 }
2424
- ]
2425
- },
2426
- popup: {
2427
- enabled: true,
2428
- mode: "popup",
2429
- channels: [
2430
- { type: "aggregate", priority: 1 },
2431
- { type: "mock", priority: 100 }
2432
- ]
2433
- },
2434
- game: {
2435
- enabled: true,
2436
- mode: "popup",
2437
- channels: [
2438
- { type: "aggregate", priority: 1 },
2439
- { type: "mock", priority: 100 }
2440
- ]
2441
- }
2442
- }
2443
- });
2444
- return [2];
2445
- }
2446
- });
2447
- });
2448
- };
2449
- PlatformAdapter.showRewardVideo = function (scene, rewardType, callback, target) {
2450
- (0, Info_1.showRewardVideo)(scene, rewardType, callback, target);
2451
- };
2452
- PlatformAdapter.registerButton = function (button) {
2453
- var sprite = button.getComponent(cc.Sprite);
2454
- var btnExtra = button.getComponent(BtnExtra_1.default);
2455
- var onFocus = function () {
2456
- sprite.spriteFrame = btnExtra.hoverSprite;
2457
- };
2458
- var onRomove = function () {
2459
- sprite.spriteFrame = btnExtra.normalSprite;
2460
- };
2461
- TvUi_2.default.focus.register(button, {
2462
- onFocus: onFocus,
2463
- onBlur: onRomove,
2464
- });
2465
- };
2466
- PlatformAdapter.registerButtonByName = function (name, parent) {
2467
- if (parent === void 0) { parent = null; }
2468
- if (!parent)
2469
- parent = cc.director.getScene();
2470
- var button = this.findChildByName(parent, name).getComponent(cc.Button);
2471
- if (!button)
2472
- return;
2473
- this.registerButton(button);
2474
- };
2475
- PlatformAdapter.focusButtonByName = function (name, parent) {
2476
- if (parent === void 0) { parent = null; }
2477
- if (!parent)
2478
- parent = cc.director.getScene();
2479
- var button = this.findChildByName(parent, name).getComponent(cc.Button);
2480
- if (!button)
2481
- return;
2482
- TvUi_2.default.focus.focus(button.node);
2483
- };
2484
- PlatformAdapter.focusButton = function (btn) {
2485
- TvUi_2.default.focus.focus(btn.node);
2486
- };
2487
- PlatformAdapter.findChildByName = function (parent, name) {
2488
- if (parent.name === name) {
2489
- return parent;
2490
- }
2491
- for (var i = 0; i < parent.children.length; i++) {
2492
- var result = this.findChildByName(parent.children[i], name);
2493
- if (result) {
2494
- return result;
2495
- }
2496
- }
2497
- return null;
2498
- };
2499
- PlatformAdapter.showWindow = function (window) {
2500
- TvUi_2.default.focus.pushScope(window.uuid, window);
2501
- TvUi_2.default.focus.registerButtons(window);
2502
- };
2503
- PlatformAdapter.hideWindow = function (window) {
2504
- TvUi_2.default.focus.unregisterByRoot(window);
2505
- TvUi_2.default.focus.popScope(window.uuid);
2506
- };
2507
- PlatformAdapter.refreshWindow = function (window) {
2508
- TvUi_2.default.focus.registerButtons(window);
2509
- };
2510
- PlatformAdapter.showExitWin = function () {
2511
- return __awaiter(this, void 0, void 0, function () {
2512
- var exitPfb, exitWin;
2513
- return __generator(this, function (_a) {
2514
- switch (_a.label) {
2515
- case 0: return [4, Loader_1.Loader.loadRes('tvui/prefab/ExitWin')];
2516
- case 1:
2517
- exitPfb = _a.sent();
2518
- exitWin = cc.instantiate(exitPfb);
2519
- exitWin.parent = cc.director.getScene();
2520
- exitWin.setPosition(cc.v2(cc.winSize.width / 2, cc.winSize.height / 2));
2521
- return [2];
2522
- }
2523
- });
2524
- });
2525
- };
2526
- PlatformAdapter.cpId = "xhbj";
2527
- PlatformAdapter.version = "1.0.0";
2528
- PlatformAdapter.designWidth = 1920;
2529
- PlatformAdapter.designHeight = 1080;
2530
- return PlatformAdapter;
2531
- }());
2532
- exports.PlatformAdapter = PlatformAdapter;
2533
- });
2534
- define("ExitWin", ["require", "exports", "core/TvUi", "PlatformAdapter"], function (require, exports, TvUi_3, PlatformAdapter_1) {
2535
- "use strict";
2536
- Object.defineProperty(exports, "__esModule", { value: true });
2537
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
2538
- var ExitWin = (function (_super) {
2539
- __extends(ExitWin, _super);
2540
- function ExitWin() {
2541
- var _this = _super !== null && _super.apply(this, arguments) || this;
2542
- _this.btnCancel = null;
2543
- _this.btnExit = null;
2544
- return _this;
2545
- }
2546
- ExitWin.prototype.start = function () {
2547
- this.btnCancel.node.on(cc.Node.EventType.TOUCH_END, this.onClickCancel, this);
2548
- this.btnExit.node.on(cc.Node.EventType.TOUCH_END, this.onClickExit, this);
2549
- };
2550
- ExitWin.prototype.onClickCancel = function () {
2551
- this.node.destroy();
2552
- };
2553
- ExitWin.prototype.onClickExit = function () {
2554
- if (TvUi_3.default.api.hasBridge()) {
2555
- TvUi_3.default.api.onExitGame();
2556
- return;
2557
- }
2558
- cc.game.end();
2559
- };
2560
- ExitWin.prototype.onEnable = function () {
2561
- PlatformAdapter_1.PlatformAdapter.showWindow(this.node);
2562
- PlatformAdapter_1.PlatformAdapter.registerButton(this.btnCancel);
2563
- PlatformAdapter_1.PlatformAdapter.registerButton(this.btnExit);
2564
- };
2565
- ExitWin.prototype.onDisable = function () {
2566
- PlatformAdapter_1.PlatformAdapter.hideWindow(this.node);
2567
- };
2568
- __decorate([
2569
- property(cc.Button),
2570
- __metadata("design:type", cc.Button)
2571
- ], ExitWin.prototype, "btnCancel", void 0);
2572
- __decorate([
2573
- property(cc.Button),
2574
- __metadata("design:type", cc.Button)
2575
- ], ExitWin.prototype, "btnExit", void 0);
2576
- ExitWin = __decorate([
2577
- ccclass
2578
- ], ExitWin);
2579
- return ExitWin;
2580
- }(cc.Component));
2581
- exports.default = ExitWin;
2582
- });
2583
- define("ad/AdSlot", ["require", "exports", "ad/AdManager"], function (require, exports, AdManager_3) {
2584
- "use strict";
2585
- Object.defineProperty(exports, "__esModule", { value: true });
2586
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
2587
- var AdSlot = (function (_super) {
2588
- __extends(AdSlot, _super);
2589
- function AdSlot() {
2590
- var _this = _super !== null && _super.apply(this, arguments) || this;
2591
- _this.slotId = "popup";
2592
- _this.showOnLoad = false;
2593
- return _this;
2594
- }
2595
- AdSlot.prototype.onEnable = function () {
2596
- if (this.showOnLoad)
2597
- this.show();
2598
- };
2599
- AdSlot.prototype.onDisable = function () {
2600
- this.hide();
2601
- };
2602
- AdSlot.prototype.show = function () {
2603
- AdManager_3.default.showSlot(this.slotId, { container: this.node });
2604
- };
2605
- AdSlot.prototype.hide = function () {
2606
- AdManager_3.default.hideSlot(this.slotId);
2607
- };
2608
- AdSlot.prototype.refresh = function () {
2609
- AdManager_3.default.refreshSlot(this.slotId, { container: this.node });
2610
- };
2611
- AdSlot.show = function (slotId) {
2612
- return AdManager_3.default.showSlot(slotId);
2613
- };
2614
- AdSlot.hide = function (slotId) {
2615
- AdManager_3.default.hideSlot(slotId);
2616
- };
2617
- AdSlot.refresh = function (slotId) {
2618
- return AdManager_3.default.refreshSlot(slotId);
2619
- };
2620
- __decorate([
2621
- property,
2622
- __metadata("design:type", String)
2623
- ], AdSlot.prototype, "slotId", void 0);
2624
- __decorate([
2625
- property,
2626
- __metadata("design:type", Boolean)
2627
- ], AdSlot.prototype, "showOnLoad", void 0);
2628
- AdSlot = __decorate([
2629
- ccclass
2630
- ], AdSlot);
2631
- return AdSlot;
2632
- }(cc.Component));
2633
- exports.default = AdSlot;
2634
- });
2635
- define("focus/FocusItem", ["require", "exports", "focus/FocusManager"], function (require, exports, FocusManager_4) {
2636
- "use strict";
2637
- Object.defineProperty(exports, "__esModule", { value: true });
2638
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
2639
- var FocusItem = (function (_super) {
2640
- __extends(FocusItem, _super);
2641
- function FocusItem() {
2642
- var _this = _super !== null && _super.apply(this, arguments) || this;
2643
- _this.focusId = "";
2644
- _this.scopeId = "";
2645
- _this.iconKey = "";
2646
- _this.up = "";
2647
- _this.down = "";
2648
- _this.left = "";
2649
- _this.right = "";
2650
- _this.focusScale = 1.08;
2651
- _this.autoRegister = true;
2652
- return _this;
2653
- }
2654
- FocusItem.prototype.onEnable = function () {
2655
- if (this.autoRegister)
2656
- FocusManager_4.default.register(this);
2657
- };
2658
- FocusItem.prototype.onDisable = function () {
2659
- if (this.autoRegister)
2660
- FocusManager_4.default.unregister(this.node);
2661
- };
2662
- FocusItem.prototype.onFocus = function () {
2663
- };
2664
- FocusItem.prototype.onBlur = function () {
2665
- };
2666
- FocusItem.prototype.onConfirm = function () {
2667
- var button = this.node.getComponent(cc.Button);
2668
- if (button && button.interactable) {
2669
- cc.Component.EventHandler.emitEvents(button.clickEvents, null);
2670
- }
2671
- else {
2672
- var event = new cc.Event.EventCustom(cc.Node.EventType.TOUCH_END, true);
2673
- this.node.emit(cc.Node.EventType.TOUCH_END, event);
2674
- }
2675
- };
2676
- __decorate([
2677
- property,
2678
- __metadata("design:type", String)
2679
- ], FocusItem.prototype, "focusId", void 0);
2680
- __decorate([
2681
- property,
2682
- __metadata("design:type", String)
2683
- ], FocusItem.prototype, "scopeId", void 0);
2684
- __decorate([
2685
- property,
2686
- __metadata("design:type", String)
2687
- ], FocusItem.prototype, "iconKey", void 0);
2688
- __decorate([
2689
- property,
2690
- __metadata("design:type", String)
2691
- ], FocusItem.prototype, "up", void 0);
2692
- __decorate([
2693
- property,
2694
- __metadata("design:type", String)
2695
- ], FocusItem.prototype, "down", void 0);
2696
- __decorate([
2697
- property,
2698
- __metadata("design:type", String)
2699
- ], FocusItem.prototype, "left", void 0);
2700
- __decorate([
2701
- property,
2702
- __metadata("design:type", String)
2703
- ], FocusItem.prototype, "right", void 0);
2704
- __decorate([
2705
- property,
2706
- __metadata("design:type", Number)
2707
- ], FocusItem.prototype, "focusScale", void 0);
2708
- __decorate([
2709
- property,
2710
- __metadata("design:type", Boolean)
2711
- ], FocusItem.prototype, "autoRegister", void 0);
2712
- FocusItem = __decorate([
2713
- ccclass
2714
- ], FocusItem);
2715
- return FocusItem;
2716
- }(cc.Component));
2717
- exports.default = FocusItem;
2718
- });
2719
- define("icon/IconConfig", ["require", "exports"], function (require, exports) {
2720
- "use strict";
2721
- Object.defineProperty(exports, "__esModule", { value: true });
2722
- });
2723
- define("toast/TvExitConfirmDialog", ["require", "exports", "core/TvUi"], function (require, exports, TvUi_4) {
2724
- "use strict";
2725
- Object.defineProperty(exports, "__esModule", { value: true });
2726
- var ccclass = cc._decorator.ccclass;
2727
- var TvExitConfirmDialog = (function (_super) {
2728
- __extends(TvExitConfirmDialog, _super);
2729
- function TvExitConfirmDialog() {
2730
- var _this = _super !== null && _super.apply(this, arguments) || this;
2731
- _this.resolver = null;
2732
- _this.closed = false;
2733
- _this.tvFocusScopeId = "modal:tvui/tv_exit_confirm";
2734
- return _this;
2735
- }
2736
- TvExitConfirmDialog_1 = TvExitConfirmDialog;
2737
- TvExitConfirmDialog.show = function (onExitCallback) {
2738
- if (onExitCallback === void 0) { onExitCallback = null; }
2739
- var resolveDialog;
2740
- var promise = new Promise(function (resolve) {
2741
- resolveDialog = resolve;
2742
- });
2743
- TvExitConfirmDialog_1.pendingPromise = promise;
2744
- var parent = TvExitConfirmDialog_1.getDialogParent();
2745
- if (!parent) {
2746
- resolveDialog(false);
2747
- return promise;
2748
- }
2749
- var node = new cc.Node("TvExitConfirmDialog");
2750
- var size = TvExitConfirmDialog_1.getParentSize(parent);
2751
- node.setContentSize(size);
2752
- node.setPosition(0, 0);
2753
- node.zIndex = 5000;
2754
- node.addComponent(cc.BlockInputEvents);
2755
- parent.addChild(node, 5000);
2756
- var dialog = node.addComponent(TvExitConfirmDialog_1);
2757
- TvExitConfirmDialog_1.currentDialog = dialog;
2758
- dialog.open(resolveDialog);
2759
- dialog.onExitCallback = onExitCallback;
2760
- return promise;
2761
- };
2762
- TvExitConfirmDialog.getDialogParent = function () {
2763
- var canvas = cc.find("Canvas");
2764
- if (canvas)
2765
- return canvas;
2766
- var scene = cc.director.getScene();
2767
- return scene;
2768
- };
2769
- TvExitConfirmDialog.getParentSize = function (parent) {
2770
- var width = parent && parent.width ? parent.width : cc.winSize.width;
2771
- var height = parent && parent.height ? parent.height : cc.winSize.height;
2772
- return cc.size(width || 1920, height || 1080);
2773
- };
2774
- TvExitConfirmDialog.clearPending = function (dialog) {
2775
- if (TvExitConfirmDialog_1.currentDialog == dialog) {
2776
- }
2777
- };
2778
- TvExitConfirmDialog.prototype.open = function (resolveDialog) {
2779
- var _this = this;
2780
- this.resolver = resolveDialog;
2781
- this.loadSprites(function (sprites) {
2782
- if (_this.closed || !_this.node || !_this.node.isValid)
2783
- return;
2784
- _this.buildView(sprites);
2785
- _this.registerTvControls();
2786
- }, function () {
2787
- _this.close(false);
2788
- });
2789
- };
2790
- TvExitConfirmDialog.prototype.loadSprites = function (onComplete, onError) {
2791
- if (TvExitConfirmDialog_1.spriteCache) {
2792
- onComplete(TvExitConfirmDialog_1.spriteCache);
2793
- return;
2794
- }
2795
- var result = {};
2796
- var paths = [
2797
- { key: "title", path: "tvui/tv_exit/退出游戏" },
2798
- { key: "frame", path: "tvui/tv_exit/框" },
2799
- { key: "cancelNormal", path: "tvui/tv_exit/取消按钮_普通" },
2800
- { key: "cancelSelected", path: "tvui/tv_exit/取消按钮_选中" },
2801
- { key: "confirmNormal", path: "tvui/tv_exit/确认按钮_普通" },
2802
- { key: "confirmSelected", path: "tvui/tv_exit/确认按钮_选中" }
2803
- ];
2804
- var waiting = paths.length;
2805
- var failed = false;
2806
- var _loop_1 = function (i) {
2807
- var item = paths[i];
2808
- cc.loader.loadRes(item.path, cc.SpriteFrame, function (error, frame) {
2809
- if (failed)
2810
- return;
2811
- if (error || !frame) {
2812
- failed = true;
2813
- console.warn("[TvExitConfirmDialog] load sprite failed:", item.path, error);
2814
- onError();
2815
- return;
2816
- }
2817
- result[item.key] = frame;
2818
- waiting--;
2819
- if (waiting <= 0) {
2820
- TvExitConfirmDialog_1.spriteCache = result;
2821
- onComplete(TvExitConfirmDialog_1.spriteCache);
2822
- }
2823
- });
2824
- };
2825
- for (var i = 0; i < paths.length; i++) {
2826
- _loop_1(i);
2827
- }
2828
- };
2829
- TvExitConfirmDialog.prototype.buildView = function (sprites) {
2830
- var size = TvExitConfirmDialog_1.getParentSize(this.node.parent);
2831
- this.node.setContentSize(size);
2832
- this.createMask(size);
2833
- var frameY = 30;
2834
- var titleY = frameY + 100;
2835
- var buttonY = -150;
2836
- var buttonOffsetX = 195;
2837
- var frameNode = this.createSpriteNode("frame", sprites.frame, 959, 552);
2838
- this.node.addChild(frameNode, 1);
2839
- frameNode.setPosition(0, frameY);
2840
- this.confirmState = this.createDialogButton("confirm", sprites.confirmNormal, sprites.confirmSelected, -buttonOffsetX, buttonY, true);
2841
- this.cancelState = this.createDialogButton("cancel", sprites.cancelNormal, sprites.cancelSelected, buttonOffsetX, buttonY, false);
2842
- frameNode.addChild(this.confirmState.node, 2);
2843
- frameNode.addChild(this.cancelState.node, 2);
2844
- };
2845
- TvExitConfirmDialog.prototype.createMask = function (size) {
2846
- var mask = new cc.Node("mask");
2847
- mask.setContentSize(size);
2848
- mask.addComponent(cc.BlockInputEvents);
2849
- var graphics = mask.addComponent(cc.Graphics);
2850
- graphics.fillColor = cc.color(0, 0, 0, 165);
2851
- graphics.rect(-size.width * 0.5, -size.height * 0.5, size.width, size.height);
2852
- graphics.fill();
2853
- this.node.addChild(mask, 0);
2854
- };
2855
- TvExitConfirmDialog.prototype.createSpriteNode = function (name, frame, width, height) {
2856
- var node = new cc.Node(name);
2857
- node.setContentSize(width, height);
2858
- var sprite = node.addComponent(cc.Sprite);
2859
- sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
2860
- sprite.spriteFrame = frame;
2861
- return node;
2862
- };
2863
- TvExitConfirmDialog.prototype.createDialogButton = function (name, normal, selected, x, y, result) {
2864
- var _this = this;
2865
- var node = this.createSpriteNode(name, normal, 208, 96);
2866
- node.setPosition(x, y);
2867
- var button = node.addComponent(cc.Button);
2868
- button.transition = cc.Button.Transition.NONE;
2869
- var state = {
2870
- node: node,
2871
- sprite: node.getComponent(cc.Sprite),
2872
- normal: normal,
2873
- selected: selected,
2874
- hovered: false,
2875
- pressed: false,
2876
- focused: false
2877
- };
2878
- node.on(cc.Node.EventType.MOUSE_ENTER, function () {
2879
- state.hovered = true;
2880
- _this.refreshButtonState(state);
2881
- }, this);
2882
- node.on(cc.Node.EventType.MOUSE_LEAVE, function () {
2883
- state.hovered = false;
2884
- _this.refreshButtonState(state);
2885
- }, this);
2886
- node.on(cc.Node.EventType.TOUCH_START, function () {
2887
- state.pressed = true;
2888
- _this.refreshButtonState(state);
2889
- }, this);
2890
- node.on(cc.Node.EventType.TOUCH_CANCEL, function () {
2891
- state.pressed = false;
2892
- _this.refreshButtonState(state);
2893
- }, this);
2894
- node.on(cc.Node.EventType.TOUCH_END, function () {
2895
- state.pressed = false;
2896
- _this.refreshButtonState(state);
2897
- _this.close(result);
2898
- }, this);
2899
- return state;
2900
- };
2901
- TvExitConfirmDialog.prototype.refreshButtonState = function (state) {
2902
- if (!state || !state.sprite)
2903
- return;
2904
- var selected = state.focused || state.hovered || state.pressed;
2905
- state.sprite.spriteFrame = selected ? state.selected : state.normal;
2906
- };
2907
- TvExitConfirmDialog.prototype.registerTvControls = function () {
2908
- var _this = this;
2909
- if (!this.tvBackHandler) {
2910
- this.tvBackHandler = function () {
2911
- _this.close(false);
2912
- return true;
2913
- };
2914
- }
2915
- TvUi_4.default.back.push(this.tvBackHandler);
2916
- if (TvUi_4.default.focus.pushScope) {
2917
- TvUi_4.default.focus.pushScope(this.tvFocusScopeId, this.node);
2918
- }
2919
- this.registerFocus(this.confirmState, true);
2920
- this.registerFocus(this.cancelState, false);
2921
- if (this.cancelState && this.cancelState.node) {
2922
- TvUi_4.default.focus.focusNode(this.cancelState.node);
2923
- }
2924
- this.refreshAllButtonStates();
2925
- };
2926
- TvExitConfirmDialog.prototype.registerFocus = function (state, result) {
2927
- var _this = this;
2928
- if (!state || !state.node)
2929
- return;
2930
- TvUi_4.default.focus.register(state.node, {
2931
- root: this.node,
2932
- focusScale: 1,
2933
- onClick: function () {
2934
- _this.close(result);
2935
- },
2936
- onFocus: function () {
2937
- _this.setFocusedState(state);
2938
- },
2939
- onBlur: function () {
2940
- state.focused = false;
2941
- _this.refreshAllButtonStates();
2942
- }
2943
- });
2944
- };
2945
- TvExitConfirmDialog.prototype.setFocusedState = function (focusedState) {
2946
- if (this.confirmState)
2947
- this.confirmState.focused = this.confirmState == focusedState;
2948
- if (this.cancelState)
2949
- this.cancelState.focused = this.cancelState == focusedState;
2950
- this.refreshAllButtonStates();
2951
- };
2952
- TvExitConfirmDialog.prototype.refreshAllButtonStates = function () {
2953
- this.refreshButtonState(this.confirmState);
2954
- this.refreshButtonState(this.cancelState);
2955
- };
2956
- TvExitConfirmDialog.prototype.unregisterTvControls = function () {
2957
- TvUi_4.default.focus.unregisterByRoot(this.node);
2958
- if (TvUi_4.default.focus.popScope) {
2959
- TvUi_4.default.focus.popScope(this.tvFocusScopeId);
2960
- }
2961
- if (this.tvBackHandler) {
2962
- TvUi_4.default.back.remove(this.tvBackHandler);
2963
- this.tvBackHandler = null;
2964
- }
2965
- };
2966
- TvExitConfirmDialog.prototype.close = function (confirmed) {
2967
- if (this.closed)
2968
- return;
2969
- this.finish(confirmed);
2970
- if (this.node && this.node.isValid) {
2971
- this.node.destroy();
2972
- }
2973
- };
2974
- TvExitConfirmDialog.prototype.finish = function (confirmed) {
2975
- if (this.closed)
2976
- return;
2977
- this.closed = true;
2978
- this.unregisterTvControls();
2979
- TvExitConfirmDialog_1.clearPending(this);
2980
- if (this.onExitCallback && confirmed) {
2981
- this.onExitCallback(confirmed);
2982
- return;
2983
- }
2984
- var resolveDialog = this.resolver;
2985
- this.resolver = null;
2986
- if (confirmed) {
2987
- if (TvUi_4.default.api.hasBridge()) {
2988
- TvUi_4.default.api.onExitGame();
2989
- return;
2990
- }
2991
- if (!TvUi_4.default.api.hasBridge() && cc.game && cc.game.end) {
2992
- cc.game.end();
2993
- }
2994
- }
2995
- };
2996
- TvExitConfirmDialog.prototype.onDestroy = function () {
2997
- if (!this.closed) {
2998
- this.finish(false);
2999
- return;
3000
- }
3001
- this.unregisterTvControls();
3002
- };
3003
- var TvExitConfirmDialog_1;
3004
- TvExitConfirmDialog = TvExitConfirmDialog_1 = __decorate([
3005
- ccclass
3006
- ], TvExitConfirmDialog);
3007
- return TvExitConfirmDialog;
3008
- }(cc.Component));
3009
- exports.default = TvExitConfirmDialog;
3010
- });