drgame-cc 1.0.45 → 1.0.46

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.
Files changed (121) hide show
  1. package/drres/focus/focus_1/gesture.atlas +34 -0
  2. package/drres/focus/focus_1/gesture.atlas.meta +6 -0
  3. package/drres/focus/focus_1/gesture.json +1 -0
  4. package/drres/focus/focus_1/gesture.json.meta +10 -0
  5. package/drres/focus/focus_1/gesture.png +0 -0
  6. package/drres/{icons/pointer-yellow-60.png.meta → focus/focus_1/gesture.png.meta} +14 -14
  7. package/drres/focus/focus_1.meta +13 -0
  8. package/drres/focus/focus_2/gesture.atlas +41 -0
  9. package/drres/focus/focus_2/gesture.atlas.meta +6 -0
  10. package/drres/focus/focus_2/gesture.json +1 -0
  11. package/drres/focus/focus_2/gesture.json.meta +10 -0
  12. package/drres/focus/focus_2/gesture.png +0 -0
  13. package/drres/{icons/pointer-blue-60.png.meta → focus/focus_2/gesture.png.meta} +13 -13
  14. package/drres/focus/focus_2.meta +13 -0
  15. package/drres/focus/focus_3/gesture.atlas +34 -0
  16. package/drres/focus/focus_3/gesture.atlas.meta +6 -0
  17. package/drres/focus/focus_3/gesture.json +1 -0
  18. package/drres/focus/focus_3/gesture.json.meta +10 -0
  19. package/drres/focus/focus_3/gesture.png +0 -0
  20. package/drres/{icons/pointer-pink-60.png.meta → focus/focus_3/gesture.png.meta} +12 -12
  21. package/drres/focus/focus_3.meta +13 -0
  22. package/drres/focus/focus_4/gesture.atlas +20 -0
  23. package/drres/focus/focus_4/gesture.atlas.meta +6 -0
  24. package/drres/focus/focus_4/gesture.json +1 -0
  25. package/drres/focus/focus_4/gesture.json.meta +10 -0
  26. package/drres/focus/focus_4/gesture.png +0 -0
  27. package/drres/focus/focus_4/gesture.png.meta +38 -0
  28. package/drres/focus/focus_4.meta +13 -0
  29. package/drres/focus.meta +13 -0
  30. package/drres/prefab/ExitWin.prefab +2 -2
  31. package/drres/prefab/Toast.prefab +378 -378
  32. package/drscript/{ad/AdManager.ts.meta → BtnExtra.ts.meta} +1 -1
  33. package/drscript/Define.ts +17 -2
  34. package/drscript/{ad/AdSlot.ts.meta → Define.ts.meta} +1 -1
  35. package/drscript/{ad/AggregateAdProvider.ts.meta → ExitWin.ts.meta} +1 -1
  36. package/drscript/GameAnalytics.ts +37 -118
  37. package/drscript/{ad/IAdProvider.ts.meta → GameAnalytics.ts.meta} +1 -1
  38. package/drscript/HelperWin.ts.meta +10 -0
  39. package/drscript/Info.ts.meta +10 -0
  40. package/drscript/InternalUitl.ts.meta +10 -0
  41. package/drscript/KeyAdapter.ts +133 -0
  42. package/drscript/KeyAdapter.ts.meta +10 -0
  43. package/drscript/Loader.ts.meta +10 -0
  44. package/drscript/PlatformAdapter.ts +178 -192
  45. package/drscript/PlatformAdapter.ts.meta +10 -0
  46. package/drscript/README.md +91 -805
  47. package/drscript/README.md.meta +6 -0
  48. package/drscript/UIAdapter.ts +324 -0
  49. package/drscript/UIAdapter.ts.meta +10 -0
  50. package/drscript/WebBridge.ts +1 -1
  51. package/drscript/WebBridge.ts.meta +10 -0
  52. package/drscript/ad-sdk/reporters/superset-lewo.js +6 -0
  53. package/drscript/ad-sdk/types/enums.d.ts +1 -0
  54. package/drscript/ad-sdk.meta +13 -0
  55. package/drscript/ad.meta +13 -0
  56. package/drscript/component/AlertTip.ts +25 -0
  57. package/drscript/component/AlertTip.ts.meta +10 -0
  58. package/drscript/component/BtnExtra.ts +17 -0
  59. package/drscript/component/BtnExtra.ts.meta +10 -0
  60. package/drscript/{ExitWin.ts → component/ExitWin.ts} +6 -8
  61. package/drscript/component/ExitWin.ts.meta +10 -0
  62. package/drscript/{HelperWin.ts → component/HelperWin.ts} +5 -19
  63. package/drscript/component/HelperWin.ts.meta +10 -0
  64. package/drscript/component.meta +13 -0
  65. package/drscript/config.meta +13 -0
  66. package/drscript/core.meta +13 -0
  67. package/drscript/focus/FocusItem.ts +1 -19
  68. package/drscript/focus/FocusManager.ts +132 -170
  69. package/drscript/focus/FocusVisualLayer.ts +74 -163
  70. package/drscript/focus.meta +13 -0
  71. package/drscript/input/KeyboardMove.ts +40 -11
  72. package/drscript/input/KeyboardMove.ts.meta +10 -0
  73. package/drscript/input.meta +13 -0
  74. package/drscript/interface.meta +13 -0
  75. package/drscript/pinyin.meta +13 -0
  76. package/drscript/toast.meta +13 -0
  77. package/drscript/virtualgamepad.meta +13 -0
  78. package/package.json +1 -1
  79. package/drres/config/default.json +0 -108
  80. package/drres/config/default.json.meta +0 -6
  81. package/drres/icons/pointer-blue-60.png +0 -0
  82. package/drres/icons/pointer-pink-60.png +0 -0
  83. package/drres/icons/pointer-white-60.png +0 -0
  84. package/drres/icons/pointer-yellow-60.png +0 -0
  85. package/drscript/Info.ts +0 -78
  86. package/drscript/InternalUitl.ts +0 -65
  87. package/drscript/ad/AdManager.ts +0 -174
  88. package/drscript/ad/AdSlot.ts +0 -44
  89. package/drscript/ad/AggregateAdProvider.ts +0 -149
  90. package/drscript/ad/IAdProvider.ts +0 -39
  91. package/drscript/ad/MockAdProvider.ts +0 -36
  92. package/drscript/ad/MockAdProvider.ts.meta +0 -10
  93. package/drscript/ad/SelfAdProvider.ts +0 -41
  94. package/drscript/ad/SelfAdProvider.ts.meta +0 -10
  95. package/drscript/config/TvUiConfig.ts +0 -155
  96. package/drscript/config/TvUiConfig.ts.meta +0 -10
  97. package/drscript/config/TvUiConfigManager.ts +0 -133
  98. package/drscript/config/TvUiConfigManager.ts.meta +0 -10
  99. package/drscript/core/BackManager.ts +0 -38
  100. package/drscript/core/BackManager.ts.meta +0 -10
  101. package/drscript/core/NativeBridge.ts +0 -137
  102. package/drscript/core/NativeBridge.ts.meta +0 -10
  103. package/drscript/core/TvUi.ts +0 -69
  104. package/drscript/core/TvUi.ts.meta +0 -10
  105. package/drscript/core/TvUiRoot.ts +0 -137
  106. package/drscript/core/TvUiRoot.ts.meta +0 -10
  107. package/drscript/icon/IconConfig.ts +0 -7
  108. package/drscript/icon/IconConfig.ts.meta +0 -10
  109. package/drscript/icon/IconManager.ts +0 -97
  110. package/drscript/icon/IconManager.ts.meta +0 -10
  111. package/drscript/input/KeyCodeAdapter.ts +0 -23
  112. package/drscript/input/RemoteInputManager.ts +0 -105
  113. package/drscript/interface/ILobbyBridge.ts +0 -5
  114. package/drscript/toast/ToastComponent.ts +0 -35
  115. package/drscript/toast/ToastComponent.ts.meta +0 -10
  116. package/drscript/toast/ToastManager.ts +0 -66
  117. package/drscript/toast/ToastManager.ts.meta +0 -10
  118. package/drscript/toast/TvExitConfirmDialog.ts +0 -334
  119. package/drscript/toast/TvExitConfirmDialog.ts.meta +0 -10
  120. package/drscript/toast/UIFunctions.ts +0 -150
  121. package/drscript/toast/UIFunctions.ts.meta +0 -10
@@ -1,137 +0,0 @@
1
- import TvUiConfigManager from "../config/TvUiConfigManager";
2
-
3
- export type NativeCallback = (action: string, data?: any) => void;
4
- export type NativeBridgeCallback = (code: number, data?: any, action?: string) => void;
5
-
6
- declare const global: any;
7
-
8
- let callbackId = 100;
9
- let nativeCallback: NativeCallback | null = null;
10
- const root: any = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : {});
11
-
12
- function hasBridge(): boolean {
13
- return root.AppBridge && typeof root.AppBridge.call == "function";
14
- }
15
-
16
- function log(message: string, data?: any) {
17
- if (data !== undefined) {
18
- console.log("[NativeBridge] " + message, data);
19
- } else {
20
- console.log("[NativeBridge] " + message);
21
- }
22
- }
23
-
24
- function normalizeCallbackData(data: any): any {
25
- if (typeof data == "string") {
26
- try {
27
- return JSON.parse(data);
28
- } catch (e) {
29
- return { message: data };
30
- }
31
- }
32
- return data || {};
33
- }
34
-
35
- function handleCallback(id: string, code: number, data: any, action: string) {
36
- const callbacks = root._tvuiCallbacks || {};
37
- id = id || root._tvuiLastCallbackId;
38
- const callback: NativeBridgeCallback = callbacks[id];
39
- if (callback) {
40
- callback(code, data, action);
41
- delete callbacks[id];
42
- }
43
- }
44
-
45
- function bridgeCall(action: string, data?: any, callback?: NativeBridgeCallback) {
46
- const id = "cb_" + (++callbackId);
47
- root._tvuiLastCallbackId = id;
48
- if (callback) {
49
- root._tvuiCallbacks = root._tvuiCallbacks || {};
50
- root._tvuiCallbacks[id] = callback;
51
- }
52
-
53
- if (!hasBridge()) {
54
- log("AppBridge not found, skip in preview: " + action);
55
- if (callback) {
56
- callback(-1, { message: "AppBridge not found" }, action);
57
- delete root._tvuiCallbacks[id];
58
- }
59
- return;
60
- }
61
-
62
- root.AppBridge.call(JSON.stringify({
63
- action: action,
64
- data: data || {},
65
- callbackId: id
66
- }));
67
- }
68
-
69
- root.onNativeBridgeCallback = function (action: string, data?: any) {
70
- data = normalizeCallbackData(data);
71
- log("native callback: " + action, data);
72
-
73
- switch (action) {
74
- case "onBridgeCallback":
75
- case "onDeviceInfo":
76
- case "onReward":
77
- case "onAdClosed":
78
- case "onAdFailed":
79
- case "onPopupAdLoaded":
80
- case "onPopupAdClosed":
81
- case "onPopupAdFailed":
82
- case "onAggregateReward":
83
- case "onAggregateAdClosed":
84
- case "onAggregateAdFailed":
85
- case "onAggregatePopupAdLoaded":
86
- case "onAggregatePopupAdClosed":
87
- case "onAggregatePopupAdFailed":
88
- case "onRankUploaded":
89
- case "onRankList":
90
- handleCallback(data.callbackId || data.callback_id, data.code, data.data || data, action);
91
- break;
92
- }
93
-
94
- if (nativeCallback) nativeCallback(action, data);
95
- };
96
-
97
- export default class NativeBridge {
98
- public static hasBridge(): boolean {
99
- return hasBridge();
100
- }
101
-
102
- public static call(action: string, data?: any, callback?: NativeBridgeCallback) {
103
- bridgeCall(action, data || {}, callback);
104
- }
105
-
106
- public static getDeviceInfo(callback?: NativeBridgeCallback) {
107
- bridgeCall("getDeviceInfo", {}, callback);
108
- }
109
-
110
- public static onGameReady() {
111
- bridgeCall("onGameReady", { version: TvUiConfigManager.getConfig().version || "1.0.0" });
112
- }
113
-
114
- public static onGamePause() {
115
- bridgeCall("onGamePause", {});
116
- }
117
-
118
- public static onGameResume() {
119
- bridgeCall("onGameResume", {});
120
- }
121
-
122
- public static onExitGame() {
123
- bridgeCall("exitGame", {});
124
- }
125
-
126
- public static uploadRank(data: any, callback?: NativeBridgeCallback) {
127
- bridgeCall("uploadRank", data, callback);
128
- }
129
-
130
- public static getRankList(data: any, callback?: NativeBridgeCallback) {
131
- bridgeCall("getRankList", data, callback);
132
- }
133
-
134
- public static setNativeCallback(callback: NativeCallback | null) {
135
- nativeCallback = callback;
136
- }
137
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "23f5ad95-4e6a-4517-a60e-1daf14dc6992",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }
@@ -1,69 +0,0 @@
1
- import TvUiRoot from "./TvUiRoot";
2
- import BackManager from "./BackManager";
3
- import NativeBridge from "./NativeBridge";
4
- import TvUiConfigManager from "../config/TvUiConfigManager";
5
- import { TvUiConfig } from "../config/TvUiConfig";
6
- import FocusManager from "../focus/FocusManager";
7
- import IconManager from "../icon/IconManager";
8
- import AdManager from "../ad/AdManager";
9
- import { RemoteInputManager } from "../input/RemoteInputManager";
10
-
11
- declare const global: any;
12
-
13
- export default class TvUi {
14
- public static root = TvUiRoot;
15
- public static config = TvUiConfigManager;
16
- public static focus = FocusManager;
17
- public static icon = IconManager;
18
- public static ads = AdManager;
19
- public static api = NativeBridge;
20
- public static input = RemoteInputManager;
21
- public static back = BackManager;
22
- private static initialized: boolean = false;
23
-
24
- public static init(config?: TvUiConfig) {
25
- TvUiRoot.ensure(config || {});
26
- TvUiRoot.setBackHandler(() => BackManager.handle());
27
- NativeBridge.setNativeCallback((action: string, data?: any) => {
28
- let runtime = TvUiConfigManager.getConfig();
29
- if (runtime.nativeCallback) runtime.nativeCallback(action, data);
30
- });
31
-
32
- let runtime = TvUiConfigManager.getConfig();
33
- if (!this.initialized && runtime.enableLifecycle !== false) {
34
- NativeBridge.onGameReady();
35
- cc.game.on(cc.game.EVENT_HIDE, this.onGameHide, this);
36
- cc.game.on(cc.game.EVENT_SHOW, this.onGameShow, this);
37
- }
38
-
39
- this.exposeGlobal();
40
- this.initialized = true;
41
- }
42
-
43
- public static destroy() {
44
- cc.game.off(cc.game.EVENT_HIDE, this.onGameHide, this);
45
- cc.game.off(cc.game.EVENT_SHOW, this.onGameShow, this);
46
- RemoteInputManager.disable();
47
- RemoteInputManager.clear();
48
- TvUiRoot.setBackHandler(null);
49
- FocusManager.reset();
50
- BackManager.reset();
51
- NativeBridge.setNativeCallback(null);
52
- this.initialized = false;
53
- }
54
-
55
- private static exposeGlobal() {
56
- let runtimeRoot: any = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : null);
57
- if (!runtimeRoot) return;
58
- runtimeRoot.TvUi = TvUi;
59
- runtimeRoot.drres = TvUi;
60
- }
61
-
62
- private static onGameHide() {
63
- NativeBridge.onGamePause();
64
- }
65
-
66
- private static onGameShow() {
67
- NativeBridge.onGameResume();
68
- }
69
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "0d25bee6-8496-40bc-9c93-918fdcec9541",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }
@@ -1,137 +0,0 @@
1
- import TvUiConfigManager from "../config/TvUiConfigManager";
2
- import { TvUiConfig } from "../config/TvUiConfig";
3
- import FocusManager from "../focus/FocusManager";
4
- import FocusVisualLayer from "../focus/FocusVisualLayer";
5
- import IconManager from "../icon/IconManager";
6
- import AdManager from "../ad/AdManager";
7
- import { TvRemoteKey } from "../input/KeyCodeAdapter";
8
- import BackManager from "./BackManager";
9
- import NativeBridge from "./NativeBridge";
10
- import { RemoteInputManager } from "../input/RemoteInputManager";
11
-
12
- declare const global: any;
13
-
14
- const { ccclass } = cc._decorator;
15
-
16
- @ccclass
17
- export default class TvUiRoot extends cc.Component {
18
- private static instance: TvUiRoot | null = null;
19
- private static backHandler: (() => boolean | void) | null = null;
20
- private visualLayer: FocusVisualLayer | null = null;
21
- private configured: boolean = false;
22
-
23
- public static ensure(config?: TvUiConfig): TvUiRoot {
24
- if (this.instance && this.instance.node && this.instance.node.isValid) {
25
- if (config) this.instance.configure(config);
26
- return this.instance;
27
- }
28
- let scene = cc.director.getScene();
29
- let node = new cc.Node("TvUiRoot");
30
- node.zIndex = 800;
31
- scene.addChild(node, 800);
32
- if (cc.game && cc.game.addPersistRootNode) {
33
- cc.game.addPersistRootNode(node);
34
- }
35
- this.instance = node.addComponent(TvUiRoot);
36
- this.instance.configure(config || {});
37
- return this.instance;
38
- }
39
-
40
- public static getInstance(): TvUiRoot | null {
41
- return this.instance;
42
- }
43
-
44
- public static setBackHandler(handler: (() => boolean | void) | null) {
45
- this.backHandler = handler;
46
- if (this.instance) this.instance.bindInputHandlers();
47
- }
48
-
49
- onLoad() {
50
- TvUiRoot.instance = this;
51
- this.resize();
52
- this.exposeGlobal();
53
- }
54
-
55
- onDestroy() {
56
- if (TvUiRoot.instance == this) TvUiRoot.instance = null;
57
- }
58
-
59
- public configure(config?: TvUiConfig) {
60
- this.configured = true;
61
- TvUiConfigManager.init(config || {}, () => {
62
- this.applyConfig();
63
- });
64
- this.applyConfig();
65
- }
66
-
67
- private applyConfig() {
68
- if (!this.configured) return;
69
- let config = TvUiConfigManager.getConfig();
70
- if (cc.view && config.designWidth && config.designHeight) {
71
- cc.view.setDesignResolutionSize(
72
- config.designWidth,
73
- config.designHeight,
74
- config.resolutionPolicy || cc.ResolutionPolicy.SHOW_ALL
75
- );
76
- }
77
- this.resize();
78
- IconManager.init();
79
- AdManager.init();
80
- this.ensureVisualLayer();
81
- this.bindInputHandlers();
82
- this.exposeGlobal();
83
- }
84
-
85
- private ensureVisualLayer() {
86
- let config = TvUiConfigManager.getConfig();
87
- if (config.focus && config.focus.enabled === false) return;
88
- this.visualLayer = FocusVisualLayer.create(this.node);
89
- }
90
-
91
- private bindInputHandlers() {
92
- let config = TvUiConfigManager.getConfig();
93
- RemoteInputManager.clear();
94
- if (config.enableRemoteInput === false) {
95
- RemoteInputManager.disable();
96
- return;
97
- }
98
- RemoteInputManager.enable();
99
- RemoteInputManager.on(TvRemoteKey.Ok, () => FocusManager.confirm());
100
- RemoteInputManager.on(TvRemoteKey.Left, () => FocusManager.move("left"));
101
- RemoteInputManager.on(TvRemoteKey.Right, () => FocusManager.move("right"));
102
- RemoteInputManager.on(TvRemoteKey.Up, () => FocusManager.move("up"));
103
- RemoteInputManager.on(TvRemoteKey.Down, () => FocusManager.move("down"));
104
- RemoteInputManager.on(TvRemoteKey.Back, () => {
105
- if (TvUiRoot.backHandler) return TvUiRoot.backHandler() !== false;
106
- return FocusManager.back();
107
- });
108
- }
109
-
110
- private resize() {
111
- let width = (cc.winSize && cc.winSize.width) || 1920;
112
- let height = (cc.winSize && cc.winSize.height) || 1080;
113
- this.node.setContentSize(width, height);
114
- this.node.setPosition(0, 0);
115
- }
116
-
117
- private exposeGlobal() {
118
- let root: any = typeof window !== "undefined" ? window : (typeof global !== "undefined" ? global : null);
119
- if (!root) return;
120
- root.TvUiRoot = TvUiRoot;
121
- if (root.TvUi) {
122
- root.drres = root.TvUi;
123
- return;
124
- }
125
- if (root.drres) return;
126
- root.drres = {
127
- root: TvUiRoot,
128
- config: TvUiConfigManager,
129
- focus: FocusManager,
130
- icon: IconManager,
131
- ads: AdManager,
132
- input: RemoteInputManager,
133
- api: NativeBridge,
134
- back: BackManager
135
- };
136
- }
137
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "7cc13983-d1c0-4935-b8b0-a21c9517068b",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }
@@ -1,7 +0,0 @@
1
- import { TvUiIconItem } from "../config/TvUiConfig";
2
-
3
- export interface IconConfigMap {
4
- [key: string]: TvUiIconItem;
5
- }
6
-
7
- export { TvUiIconItem };
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "659ede6c-34f4-4272-86ea-8378054aa441",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }
@@ -1,97 +0,0 @@
1
- import TvUiConfigManager from "../config/TvUiConfigManager";
2
- import { TvUiIconItem } from "../config/TvUiConfig";
3
-
4
- type SpriteFrameCallback = (spriteFrame: cc.SpriteFrame | null, config?: TvUiIconItem | null) => void;
5
-
6
- export default class IconManager {
7
- private static cache: { [key: string]: cc.SpriteFrame } = {};
8
- private static inited: boolean = false;
9
-
10
- public static init() {
11
- if (this.inited) return;
12
- this.inited = true;
13
- TvUiConfigManager.onChanged(() => {
14
- this.cache = {};
15
- });
16
- }
17
-
18
- public static getIconConfig(iconKey?: string): TvUiIconItem | null {
19
- let config = TvUiConfigManager.getConfig();
20
- let key = iconKey || (config.focus && config.focus.defaultIconKey) || "default";
21
- let icons = config.icons || {};
22
- return icons[key] || icons["default"];
23
- }
24
-
25
- public static getSpriteFrame(iconKey: string, callback: SpriteFrameCallback) {
26
- let iconConfig = this.getIconConfig(iconKey);
27
- if (!iconConfig) {
28
- callback(null, null);
29
- return;
30
- }
31
- let cacheKey = iconConfig.url || iconConfig.path || iconKey || "default";
32
- if (this.cache[cacheKey]) {
33
- callback(this.cache[cacheKey], iconConfig);
34
- return;
35
- }
36
- if (iconConfig.url) {
37
- this.loadRemote(iconConfig, cacheKey, callback);
38
- return;
39
- }
40
- this.loadLocal(iconConfig, cacheKey, callback);
41
- }
42
-
43
- public static setIconTheme(iconKey: string) {
44
- let config = TvUiConfigManager.getConfig();
45
- if (!config.icons || !config.icons[iconKey]) return;
46
- TvUiConfigManager.updateConfig({
47
- focus: {
48
- defaultIconKey: iconKey
49
- }
50
- }, true);
51
- }
52
-
53
- public static clearCache() {
54
- this.cache = {};
55
- }
56
-
57
- private static loadLocal(iconConfig: TvUiIconItem, cacheKey: string, callback: SpriteFrameCallback) {
58
- if (!iconConfig.path) {
59
- callback(null, iconConfig);
60
- return;
61
- }
62
- cc.loader.loadRes(iconConfig.path, cc.SpriteFrame, (error: Error, frame: cc.SpriteFrame) => {
63
- if (error || !frame) {
64
- this.loadFallback(cacheKey, callback);
65
- return;
66
- }
67
- this.cache[cacheKey] = frame;
68
- callback(frame, iconConfig);
69
- });
70
- }
71
-
72
- private static loadRemote(iconConfig: TvUiIconItem, cacheKey: string, callback: SpriteFrameCallback) {
73
- let assetManager = (cc as any).assetManager;
74
- if (!assetManager || !assetManager.loadRemote) {
75
- this.loadFallback(cacheKey, callback);
76
- return;
77
- }
78
- assetManager.loadRemote(iconConfig.url, { ext: ".png" }, (error: Error, texture: cc.Texture2D) => {
79
- if (error || !texture) {
80
- this.loadFallback(cacheKey, callback);
81
- return;
82
- }
83
- let frame = new cc.SpriteFrame(texture);
84
- this.cache[cacheKey] = frame;
85
- callback(frame, iconConfig);
86
- });
87
- }
88
-
89
- private static loadFallback(cacheKey: string, callback: SpriteFrameCallback) {
90
- let fallback = this.getIconConfig("default");
91
- if (!fallback || fallback.path == cacheKey) {
92
- callback(null, fallback);
93
- return;
94
- }
95
- this.loadLocal(fallback, fallback.path || "default", callback);
96
- }
97
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "7bde5c2c-b6f9-4c2a-a12e-a1caecb38483",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }
@@ -1,23 +0,0 @@
1
- export enum TvRemoteKey {
2
- Back = "back",
3
- Ok = "ok",
4
- Left = "left",
5
- Right = "right",
6
- Up = "up",
7
- Down = "down",
8
- Pause = "pause",
9
- Unknown = "unknown"
10
- }
11
-
12
- export default class KeyCodeAdapter {
13
- public static toRemoteKey(keyCode: number): TvRemoteKey {
14
- if ([0, 4, 6, 8, 27, 10009].indexOf(keyCode) >= 0) return TvRemoteKey.Back;
15
- if ([13, 23, 66, 1005].indexOf(keyCode) >= 0) return TvRemoteKey.Ok;
16
- if ([80].indexOf(keyCode) >= 0) return TvRemoteKey.Pause;
17
- if ([21, 37, 1000].indexOf(keyCode) >= 0) return TvRemoteKey.Left;
18
- if ([19, 38, 1003].indexOf(keyCode) >= 0) return TvRemoteKey.Up;
19
- if ([22, 39, 1001].indexOf(keyCode) >= 0) return TvRemoteKey.Right;
20
- if ([20, 40, 1004].indexOf(keyCode) >= 0) return TvRemoteKey.Down;
21
- return TvRemoteKey.Unknown;
22
- }
23
- }
@@ -1,105 +0,0 @@
1
- import KeyCodeAdapter, { TvRemoteKey } from "./KeyCodeAdapter";
2
-
3
-
4
- type KeyHandler = (keyCode: number) => boolean | void;
5
-
6
- export class RemoteInputManager {
7
- private static handlers: { [key: string]: KeyHandler[] } = {};
8
- private static enabled: boolean = false;
9
- private static domInputEnabled: boolean = false;
10
- private static lastKeyCode: number = -1;
11
- private static lastDispatchTime: number = 0;
12
- private static readonly DISPATCH_DEBOUNCE_MS: number = 160;
13
-
14
- public static enable() {
15
- if (this.enabled) return;
16
- this.enabled = true;
17
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
18
- this.enableDomInput();
19
- this.focusCanvas();
20
- }
21
-
22
- public static disable() {
23
- if (!this.enabled) return;
24
- this.enabled = false;
25
- cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
26
- this.disableDomInput();
27
- this.lastKeyCode = -1;
28
- this.lastDispatchTime = 0;
29
- }
30
-
31
- public static clear() {
32
- this.handlers = {};
33
- }
34
-
35
- public static on(key: TvRemoteKey, handler: KeyHandler) {
36
- if (!this.handlers[key]) this.handlers[key] = [];
37
- this.handlers[key].push(handler);
38
- }
39
-
40
- public static off(key: TvRemoteKey, handler: KeyHandler) {
41
- let list = this.handlers[key];
42
- if (!list) return;
43
- let index = list.indexOf(handler);
44
- if (index >= 0) list.splice(index, 1);
45
- }
46
-
47
- public static toRemoteKey(keyCode: number): TvRemoteKey {
48
- return KeyCodeAdapter.toRemoteKey(keyCode);
49
- }
50
-
51
- public static dispatchKeyCode(keyCode: number): boolean {
52
- let now = Date.now();
53
- if (keyCode == this.lastKeyCode && now - this.lastDispatchTime < this.DISPATCH_DEBOUNCE_MS) {
54
- return false;
55
- }
56
- this.lastKeyCode = keyCode;
57
- this.lastDispatchTime = now;
58
-
59
- let key = KeyCodeAdapter.toRemoteKey(keyCode);
60
- let list = this.handlers[key] || [];
61
- for (let i = list.length - 1; i >= 0; i--) {
62
- let result = list[i](keyCode);
63
- if (result !== false) return true;
64
- }
65
- return false;
66
- }
67
-
68
- private static onKeyDown(event: cc.Event.EventKeyboard) {
69
- // ToastManager.Inst.make("按键key=" + event.keyCode, 3000);
70
- this.dispatchKeyCode(event.keyCode);
71
- }
72
-
73
- private static enableDomInput() {
74
- if (this.domInputEnabled || typeof window == "undefined") return;
75
- this.domInputEnabled = true;
76
- window.addEventListener("keydown", this.onDomKeyDown, true);
77
- }
78
-
79
- private static disableDomInput() {
80
- if (!this.domInputEnabled || typeof window == "undefined") return;
81
- this.domInputEnabled = false;
82
- window.removeEventListener("keydown", this.onDomKeyDown, true);
83
- }
84
-
85
- private static onDomKeyDown(event: KeyboardEvent) {
86
- let handled = RemoteInputManager.dispatchKeyCode(event.keyCode || event.which);
87
- if (handled && event.preventDefault) event.preventDefault();
88
- }
89
-
90
- private static focusCanvas() {
91
- if (typeof document == "undefined") return;
92
- try {
93
- let canvas = (cc && cc.game && cc.game.canvas) ? cc.game.canvas : document.querySelector("canvas");
94
- if (canvas) {
95
- (canvas as any).tabIndex = (canvas as any).tabIndex || 0;
96
- if (typeof (canvas as any).focus == "function") {
97
- (canvas as any).focus();
98
- return;
99
- }
100
- }
101
- if (typeof window != "undefined" && typeof window.focus == "function") window.focus();
102
- } catch (e) {
103
- }
104
- }
105
- }
@@ -1,5 +0,0 @@
1
- declare interface ILobbyBridge {
2
- /** 退出游戏 */
3
- exitGame(): void;
4
- }
5
-
@@ -1,35 +0,0 @@
1
- import UIFunctions from "./UIFunctions";
2
-
3
-
4
- const { ccclass, property } = cc._decorator;
5
-
6
- @ccclass
7
- export default class ToastComponent extends cc.Component {
8
- @property(cc.Label)
9
- label: cc.Label = null;
10
- // animations: cc.Animation[] = [];
11
-
12
- onLoad() {
13
- // this.animations = UIFunctions.getChildrenAnimations(this.node);
14
- }
15
-
16
- start() {
17
-
18
- }
19
-
20
- hide(callback): any {
21
- this.node.active = true;
22
- // if (!UIFunctions.doHideAnimations(this.animations, callback)) {
23
- // }
24
- this.node.active = false;
25
- // this.node.removeFromParent();
26
- if (callback) {
27
- callback(this);
28
- }
29
- }
30
- show(text: any): any {
31
- this.label.string = text;
32
- // UIFunctions.doShowAnimations(this.animations);
33
- }
34
- // update (dt) {}
35
- }
@@ -1,10 +0,0 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "980bfc04-1c34-40a0-87e1-e14557bf69d6",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
10
- }