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.
- package/drres/focus/focus_1/gesture.atlas +34 -0
- package/drres/focus/focus_1/gesture.atlas.meta +6 -0
- package/drres/focus/focus_1/gesture.json +1 -0
- package/drres/focus/focus_1/gesture.json.meta +10 -0
- package/drres/focus/focus_1/gesture.png +0 -0
- package/drres/{icons/pointer-yellow-60.png.meta → focus/focus_1/gesture.png.meta} +14 -14
- package/drres/focus/focus_1.meta +13 -0
- package/drres/focus/focus_2/gesture.atlas +41 -0
- package/drres/focus/focus_2/gesture.atlas.meta +6 -0
- package/drres/focus/focus_2/gesture.json +1 -0
- package/drres/focus/focus_2/gesture.json.meta +10 -0
- package/drres/focus/focus_2/gesture.png +0 -0
- package/drres/{icons/pointer-blue-60.png.meta → focus/focus_2/gesture.png.meta} +13 -13
- package/drres/focus/focus_2.meta +13 -0
- package/drres/focus/focus_3/gesture.atlas +34 -0
- package/drres/focus/focus_3/gesture.atlas.meta +6 -0
- package/drres/focus/focus_3/gesture.json +1 -0
- package/drres/focus/focus_3/gesture.json.meta +10 -0
- package/drres/focus/focus_3/gesture.png +0 -0
- package/drres/{icons/pointer-pink-60.png.meta → focus/focus_3/gesture.png.meta} +12 -12
- package/drres/focus/focus_3.meta +13 -0
- package/drres/focus/focus_4/gesture.atlas +20 -0
- package/drres/focus/focus_4/gesture.atlas.meta +6 -0
- package/drres/focus/focus_4/gesture.json +1 -0
- package/drres/focus/focus_4/gesture.json.meta +10 -0
- package/drres/focus/focus_4/gesture.png +0 -0
- package/drres/focus/focus_4/gesture.png.meta +38 -0
- package/drres/focus/focus_4.meta +13 -0
- package/drres/focus.meta +13 -0
- package/drres/prefab/ExitWin.prefab +2 -2
- package/drres/prefab/Toast.prefab +378 -378
- package/drscript/{ad/AdManager.ts.meta → BtnExtra.ts.meta} +1 -1
- package/drscript/Define.ts +17 -2
- package/drscript/{ad/AdSlot.ts.meta → Define.ts.meta} +1 -1
- package/drscript/{ad/AggregateAdProvider.ts.meta → ExitWin.ts.meta} +1 -1
- package/drscript/GameAnalytics.ts +37 -118
- package/drscript/{ad/IAdProvider.ts.meta → GameAnalytics.ts.meta} +1 -1
- package/drscript/HelperWin.ts.meta +10 -0
- package/drscript/Info.ts.meta +10 -0
- package/drscript/InternalUitl.ts.meta +10 -0
- package/drscript/KeyAdapter.ts +133 -0
- package/drscript/KeyAdapter.ts.meta +10 -0
- package/drscript/Loader.ts.meta +10 -0
- package/drscript/PlatformAdapter.ts +178 -192
- package/drscript/PlatformAdapter.ts.meta +10 -0
- package/drscript/README.md +91 -805
- package/drscript/README.md.meta +6 -0
- package/drscript/UIAdapter.ts +324 -0
- package/drscript/UIAdapter.ts.meta +10 -0
- package/drscript/WebBridge.ts +1 -1
- package/drscript/WebBridge.ts.meta +10 -0
- package/drscript/ad-sdk/reporters/superset-lewo.js +6 -0
- package/drscript/ad-sdk/types/enums.d.ts +1 -0
- package/drscript/ad-sdk.meta +13 -0
- package/drscript/ad.meta +13 -0
- package/drscript/component/AlertTip.ts +25 -0
- package/drscript/component/AlertTip.ts.meta +10 -0
- package/drscript/component/BtnExtra.ts +17 -0
- package/drscript/component/BtnExtra.ts.meta +10 -0
- package/drscript/{ExitWin.ts → component/ExitWin.ts} +6 -8
- package/drscript/component/ExitWin.ts.meta +10 -0
- package/drscript/{HelperWin.ts → component/HelperWin.ts} +5 -19
- package/drscript/component/HelperWin.ts.meta +10 -0
- package/drscript/component.meta +13 -0
- package/drscript/config.meta +13 -0
- package/drscript/core.meta +13 -0
- package/drscript/focus/FocusItem.ts +1 -19
- package/drscript/focus/FocusManager.ts +132 -170
- package/drscript/focus/FocusVisualLayer.ts +74 -163
- package/drscript/focus.meta +13 -0
- package/drscript/input/KeyboardMove.ts +40 -11
- package/drscript/input/KeyboardMove.ts.meta +10 -0
- package/drscript/input.meta +13 -0
- package/drscript/interface.meta +13 -0
- package/drscript/pinyin.meta +13 -0
- package/drscript/toast.meta +13 -0
- package/drscript/virtualgamepad.meta +13 -0
- package/package.json +1 -1
- package/drres/config/default.json +0 -108
- package/drres/config/default.json.meta +0 -6
- package/drres/icons/pointer-blue-60.png +0 -0
- package/drres/icons/pointer-pink-60.png +0 -0
- package/drres/icons/pointer-white-60.png +0 -0
- package/drres/icons/pointer-yellow-60.png +0 -0
- package/drscript/Info.ts +0 -78
- package/drscript/InternalUitl.ts +0 -65
- package/drscript/ad/AdManager.ts +0 -174
- package/drscript/ad/AdSlot.ts +0 -44
- package/drscript/ad/AggregateAdProvider.ts +0 -149
- package/drscript/ad/IAdProvider.ts +0 -39
- package/drscript/ad/MockAdProvider.ts +0 -36
- package/drscript/ad/MockAdProvider.ts.meta +0 -10
- package/drscript/ad/SelfAdProvider.ts +0 -41
- package/drscript/ad/SelfAdProvider.ts.meta +0 -10
- package/drscript/config/TvUiConfig.ts +0 -155
- package/drscript/config/TvUiConfig.ts.meta +0 -10
- package/drscript/config/TvUiConfigManager.ts +0 -133
- package/drscript/config/TvUiConfigManager.ts.meta +0 -10
- package/drscript/core/BackManager.ts +0 -38
- package/drscript/core/BackManager.ts.meta +0 -10
- package/drscript/core/NativeBridge.ts +0 -137
- package/drscript/core/NativeBridge.ts.meta +0 -10
- package/drscript/core/TvUi.ts +0 -69
- package/drscript/core/TvUi.ts.meta +0 -10
- package/drscript/core/TvUiRoot.ts +0 -137
- package/drscript/core/TvUiRoot.ts.meta +0 -10
- package/drscript/icon/IconConfig.ts +0 -7
- package/drscript/icon/IconConfig.ts.meta +0 -10
- package/drscript/icon/IconManager.ts +0 -97
- package/drscript/icon/IconManager.ts.meta +0 -10
- package/drscript/input/KeyCodeAdapter.ts +0 -23
- package/drscript/input/RemoteInputManager.ts +0 -105
- package/drscript/interface/ILobbyBridge.ts +0 -5
- package/drscript/toast/ToastComponent.ts +0 -35
- package/drscript/toast/ToastComponent.ts.meta +0 -10
- package/drscript/toast/ToastManager.ts +0 -66
- package/drscript/toast/ToastManager.ts.meta +0 -10
- package/drscript/toast/TvExitConfirmDialog.ts +0 -334
- package/drscript/toast/TvExitConfirmDialog.ts.meta +0 -10
- package/drscript/toast/UIFunctions.ts +0 -150
- package/drscript/toast/UIFunctions.ts.meta +0 -10
package/drscript/Define.ts
CHANGED
|
@@ -21,7 +21,22 @@ export enum EVideoScene {
|
|
|
21
21
|
Boost = "boost"
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export enum
|
|
24
|
+
export enum FingerStyle {
|
|
25
25
|
Default = "default",
|
|
26
|
-
White = "white"
|
|
26
|
+
White = "white",
|
|
27
|
+
Gold = "gold",
|
|
28
|
+
Blue = "blue"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export enum AnalyticsEvent {
|
|
32
|
+
GameLoading = "game_loading",
|
|
33
|
+
StartGameButton = "start_game_button",
|
|
34
|
+
WatchVideoContinueButton = "watch_video_continue_button",
|
|
35
|
+
ReplayButton = "replay_button",
|
|
36
|
+
RewardVideoAd = "reward_video_ad",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export enum AnalyticsAction {
|
|
40
|
+
Exposure = "exposure",
|
|
41
|
+
Click = "click",
|
|
27
42
|
}
|
|
@@ -1,45 +1,17 @@
|
|
|
1
1
|
import { ActionType, Reporter, IReportItem } from "./ad-sdk/ad-sdk";
|
|
2
|
+
import { AnalyticsEvent, AnalyticsAction } from "./Define";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
XiaomiTv = "xiaomi",
|
|
5
|
-
Lewo = "lewo",
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export enum AnalyticsEvent {
|
|
9
|
-
GameLoading = "game_loading",
|
|
10
|
-
StartGameButton = "start_game_button",
|
|
11
|
-
WatchVideoContinueButton = "watch_video_continue_button",
|
|
12
|
-
ReplayButton = "replay_button",
|
|
13
|
-
RewardVideoAd = "reward_video_ad",
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export enum AnalyticsAction {
|
|
17
|
-
Exposure = "exposure",
|
|
18
|
-
Click = "click",
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface GameAnalyticsConfig {
|
|
22
|
-
platform?: GameAnalyticsPlatform | string;
|
|
23
|
-
app_item?: string;
|
|
24
|
-
content_type?: string;
|
|
25
|
-
content_id?: string;
|
|
26
|
-
content_title?: string;
|
|
27
|
-
user_id?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface AnalyticsEventDefinition {
|
|
31
|
-
elementPosition: string;
|
|
32
|
-
exposureEventName?: string;
|
|
33
|
-
clickEventName?: string;
|
|
34
|
-
}
|
|
4
|
+
const REPORT_URL = "https://sup.daoran.tv/bi-api/api/game/lewo/batch";
|
|
35
5
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
6
|
+
/** 事件定义:element_position + 曝光/点击事件名 */
|
|
7
|
+
const EVENT_MAP: Record<AnalyticsEvent, { ep: string; expose: string; click?: string }> = {
|
|
8
|
+
[AnalyticsEvent.GameLoading]: { ep: "game_loading", expose: "game_loading_expose" },
|
|
9
|
+
[AnalyticsEvent.StartGameButton]: { ep: "start_game_button", expose: "start_game_expose", click: "start_game_click" },
|
|
10
|
+
[AnalyticsEvent.WatchVideoContinueButton]: { ep: "watch_video_continue_button", expose: "watch_video_continue_expose", click: "watch_video_continue_click" },
|
|
11
|
+
[AnalyticsEvent.ReplayButton]: { ep: "replay_button", expose: "replay_expose", click: "replay_click" },
|
|
12
|
+
[AnalyticsEvent.RewardVideoAd]: { ep: "reward_video_ad", expose: "ad_expose" },
|
|
39
13
|
};
|
|
40
14
|
|
|
41
|
-
const REPORT_URL = "https://sup.daoran.tv/bi-api/api/game/lewo/batch";
|
|
42
|
-
|
|
43
15
|
export default class GameAnalytics {
|
|
44
16
|
private static initialized: boolean = false;
|
|
45
17
|
private static loadingReported: boolean = false;
|
|
@@ -48,49 +20,23 @@ export default class GameAnalytics {
|
|
|
48
20
|
private static reportMaxSize: number = 50;
|
|
49
21
|
private static reportKey = "game_analytics_report_cache";
|
|
50
22
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
exposureEventName: "start_game_expose",
|
|
59
|
-
clickEventName: "start_game_click",
|
|
60
|
-
},
|
|
61
|
-
watch_video_continue_button: {
|
|
62
|
-
elementPosition: "watch_video_continue_button",
|
|
63
|
-
exposureEventName: "watch_video_continue_expose",
|
|
64
|
-
clickEventName: "watch_video_continue_click",
|
|
65
|
-
},
|
|
66
|
-
replay_button: {
|
|
67
|
-
elementPosition: "replay_button",
|
|
68
|
-
exposureEventName: "replay_expose",
|
|
69
|
-
clickEventName: "replay_click",
|
|
70
|
-
},
|
|
71
|
-
reward_video_ad: {
|
|
72
|
-
elementPosition: "reward_video_ad",
|
|
73
|
-
exposureEventName: "ad_expose",
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
public static init(config: GameAnalyticsConfig = {}): void {
|
|
78
|
-
if (this.initialized) {
|
|
79
|
-
if (config.user_id !== undefined) this.setUserId(config.user_id);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
23
|
+
public static init(config: {
|
|
24
|
+
app_item: string;
|
|
25
|
+
content_type?: string;
|
|
26
|
+
content_id?: string;
|
|
27
|
+
content_title?: string;
|
|
28
|
+
}): void {
|
|
29
|
+
if (GameAnalytics.initialized) return;
|
|
82
30
|
|
|
83
31
|
try {
|
|
84
|
-
const platform = config.platform || GameAnalyticsPlatform.XiaomiTv;
|
|
85
32
|
Reporter.init({
|
|
86
33
|
report_url: REPORT_URL,
|
|
87
|
-
app_item: config.app_item
|
|
34
|
+
app_item: config.app_item,
|
|
88
35
|
content_type: config.content_type || "游戏",
|
|
89
|
-
content_id: config.content_id || "
|
|
90
|
-
content_title: config.content_title || "
|
|
36
|
+
content_id: config.content_id || "",
|
|
37
|
+
content_title: config.content_title || "",
|
|
91
38
|
});
|
|
92
|
-
|
|
93
|
-
if (config.user_id !== undefined) this.setUserId(config.user_id);
|
|
39
|
+
GameAnalytics.initialized = true;
|
|
94
40
|
var httpReq = new XMLHttpRequest();
|
|
95
41
|
httpReq.open("POST", 'https://sup.daoran.tv/bi-api/api/config/get');
|
|
96
42
|
httpReq.setRequestHeader("Content-Type", "application/json");
|
|
@@ -109,15 +55,6 @@ export default class GameAnalytics {
|
|
|
109
55
|
}
|
|
110
56
|
}
|
|
111
57
|
|
|
112
|
-
public static setUserId(userId: string): void {
|
|
113
|
-
if (!this.initialized) return;
|
|
114
|
-
try {
|
|
115
|
-
Reporter.setCommonInfo({ user_id: userId || "" });
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.warn("[GameAnalytics] set user id failed", error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
58
|
public static reportLoadingOnce(): void {
|
|
122
59
|
if (this.loadingReported) return;
|
|
123
60
|
this.loadingReported = true;
|
|
@@ -136,26 +73,23 @@ export default class GameAnalytics {
|
|
|
136
73
|
adRequestId?: string
|
|
137
74
|
): void {
|
|
138
75
|
if (!this.initialized) return;
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
? definition.exposureEventName
|
|
143
|
-
: definition && definition.clickEventName;
|
|
144
|
-
if (!definition || !eventName) {
|
|
76
|
+
const def = EVENT_MAP[event];
|
|
77
|
+
const eventName = action === AnalyticsAction.Exposure ? def.expose : def.click;
|
|
78
|
+
if (!def || !eventName) {
|
|
145
79
|
console.warn("[GameAnalytics] unsupported event/action", event, action);
|
|
146
80
|
return;
|
|
147
81
|
}
|
|
148
82
|
|
|
149
83
|
try {
|
|
150
84
|
const reportItem: any = {
|
|
151
|
-
element_position:
|
|
85
|
+
element_position: def.ep,
|
|
152
86
|
action_type: action === AnalyticsAction.Exposure
|
|
153
87
|
? ActionType.Exposure
|
|
154
88
|
: ActionType.Click,
|
|
155
89
|
event_name: eventName,
|
|
156
90
|
};
|
|
157
|
-
if (event === AnalyticsEvent.RewardVideoAd) {
|
|
158
|
-
reportItem.ad_request_id = adRequestId
|
|
91
|
+
if (event === AnalyticsEvent.RewardVideoAd && adRequestId) {
|
|
92
|
+
reportItem.ad_request_id = adRequestId;
|
|
159
93
|
}
|
|
160
94
|
var reportCache: IReportItem[] = null;
|
|
161
95
|
const cache = localStorage.getItem(this.reportKey);
|
|
@@ -173,25 +107,22 @@ export default class GameAnalytics {
|
|
|
173
107
|
}
|
|
174
108
|
}
|
|
175
109
|
|
|
176
|
-
public static reportBatch(
|
|
177
|
-
events
|
|
178
|
-
): void {
|
|
179
|
-
if (!this.initialized) return;
|
|
180
|
-
|
|
110
|
+
public static reportBatch(events: AnalyticsEvent[]): void {
|
|
111
|
+
if (!this.initialized || events.length === 0) return;
|
|
181
112
|
try {
|
|
182
|
-
|
|
113
|
+
const items: IReportItem[] = [];
|
|
183
114
|
for (const e of events) {
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
element_position:
|
|
115
|
+
const def = EVENT_MAP[e];
|
|
116
|
+
if (!def) continue;
|
|
117
|
+
const item: any = {
|
|
118
|
+
element_position: def.ep,
|
|
188
119
|
action_type: ActionType.Exposure,
|
|
189
|
-
event_name:
|
|
120
|
+
event_name: def.expose,
|
|
121
|
+
ad_request_id: "",
|
|
190
122
|
};
|
|
191
|
-
|
|
192
|
-
reportArr.push(reportItem);
|
|
123
|
+
items.push(item);
|
|
193
124
|
}
|
|
194
|
-
Reporter.reportBatch(
|
|
125
|
+
if (items.length > 0) Reporter.reportBatch(items);
|
|
195
126
|
} catch (error) {
|
|
196
127
|
console.warn("[GameAnalytics] report failed", error);
|
|
197
128
|
}
|
|
@@ -199,7 +130,6 @@ export default class GameAnalytics {
|
|
|
199
130
|
|
|
200
131
|
private static reportBatchCache(): void {
|
|
201
132
|
if (!this.initialized) return;
|
|
202
|
-
|
|
203
133
|
var reportCache: IReportItem[] = null;
|
|
204
134
|
const cache = localStorage.getItem(this.reportKey);
|
|
205
135
|
if (cache) {
|
|
@@ -217,15 +147,4 @@ export default class GameAnalytics {
|
|
|
217
147
|
localStorage.setItem(this.reportKey, JSON.stringify(reportCache));
|
|
218
148
|
}
|
|
219
149
|
}
|
|
220
|
-
|
|
221
|
-
static getAppItem(platform: string): string {
|
|
222
|
-
const normalizedPlatform = (platform || "").toLowerCase();
|
|
223
|
-
const appItem = APP_ITEM_BY_PLATFORM[normalizedPlatform];
|
|
224
|
-
if (appItem) return appItem;
|
|
225
|
-
console.warn(
|
|
226
|
-
"[GameAnalytics] unknown platform, fallback to Xiaomi TV app_item=25",
|
|
227
|
-
platform
|
|
228
|
-
);
|
|
229
|
-
return APP_ITEM_BY_PLATFORM[GameAnalyticsPlatform.XiaomiTv];
|
|
230
|
-
}
|
|
231
150
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { AdSdk, KeyCode, KeyAction } from "./ad-sdk/ad-sdk";
|
|
2
|
+
import FocusManager from "./focus/FocusManager";
|
|
3
|
+
|
|
4
|
+
/** 按键适配 - 统一处理遥控器、键盘、AdSdk 输入事件 */
|
|
5
|
+
export class KeyAdapter {
|
|
6
|
+
private static keyHandler: ((event: { key: KeyCode, action: KeyAction }) => void) | null = null;
|
|
7
|
+
private static keyboardBound: boolean = false;
|
|
8
|
+
|
|
9
|
+
/** 防重复:记录上次处理的按键,同一按键在 150ms 内忽略重复 */
|
|
10
|
+
private static lastKey: string = "";
|
|
11
|
+
private static lastAction: string = "";
|
|
12
|
+
private static lastTime: number = 0;
|
|
13
|
+
private static readonly DEDUP_MS = 150;
|
|
14
|
+
|
|
15
|
+
private static readonly KEYBOARD_MAP: { [keyCode: number]: KeyCode } = {
|
|
16
|
+
0: KeyCode.Back,
|
|
17
|
+
4: KeyCode.Back,
|
|
18
|
+
6: KeyCode.Back,
|
|
19
|
+
8: KeyCode.Back,
|
|
20
|
+
13: KeyCode.Enter,
|
|
21
|
+
19: KeyCode.Up,
|
|
22
|
+
20: KeyCode.Down,
|
|
23
|
+
21: KeyCode.Left,
|
|
24
|
+
22: KeyCode.Right,
|
|
25
|
+
23: KeyCode.Enter,
|
|
26
|
+
27: KeyCode.Back,
|
|
27
|
+
32: KeyCode.Enter,
|
|
28
|
+
37: KeyCode.Left,
|
|
29
|
+
38: KeyCode.Up,
|
|
30
|
+
39: KeyCode.Right,
|
|
31
|
+
40: KeyCode.Down,
|
|
32
|
+
65: KeyCode.Left, // A
|
|
33
|
+
66: KeyCode.Enter, // B
|
|
34
|
+
68: KeyCode.Right, // D
|
|
35
|
+
80: KeyCode.Enter, // P (Pause)
|
|
36
|
+
83: KeyCode.Down, // S
|
|
37
|
+
87: KeyCode.Up, // W
|
|
38
|
+
1000: KeyCode.Left,
|
|
39
|
+
1001: KeyCode.Right,
|
|
40
|
+
1003: KeyCode.Up,
|
|
41
|
+
1004: KeyCode.Down,
|
|
42
|
+
1005: KeyCode.Enter,
|
|
43
|
+
10009: KeyCode.Back,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** 初始化输入监听 */
|
|
47
|
+
static init() {
|
|
48
|
+
if (KeyAdapter.keyHandler) return;
|
|
49
|
+
KeyAdapter.keyHandler = (event) => {
|
|
50
|
+
KeyAdapter.dispatchKey(event.key, event.action);
|
|
51
|
+
};
|
|
52
|
+
AdSdk.onKeyEvent(KeyAdapter.keyHandler);
|
|
53
|
+
|
|
54
|
+
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, KeyAdapter.onKeyboardDown, KeyAdapter);
|
|
55
|
+
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, KeyAdapter.onKeyboardUp, KeyAdapter);
|
|
56
|
+
KeyAdapter.keyboardBound = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 销毁输入监听 */
|
|
60
|
+
static destroy() {
|
|
61
|
+
if (KeyAdapter.keyHandler) {
|
|
62
|
+
AdSdk.offKeyEvent(KeyAdapter.keyHandler);
|
|
63
|
+
KeyAdapter.keyHandler = null;
|
|
64
|
+
}
|
|
65
|
+
if (KeyAdapter.keyboardBound) {
|
|
66
|
+
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, KeyAdapter.onKeyboardDown, KeyAdapter);
|
|
67
|
+
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, KeyAdapter.onKeyboardUp, KeyAdapter);
|
|
68
|
+
KeyAdapter.keyboardBound = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private static onKeyboardDown(event: cc.Event.EventKeyboard) {
|
|
73
|
+
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
74
|
+
if (key) KeyAdapter.dispatchKey(key, KeyAction.Down);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private static onKeyboardUp(event: cc.Event.EventKeyboard) {
|
|
78
|
+
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
79
|
+
if (key) KeyAdapter.dispatchKey(key, KeyAction.Up);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private static dispatchKey(key: KeyCode, action: KeyAction) {
|
|
83
|
+
// console.log(`[KeyAdapter] dispatchKey: ${key}, action: ${action}`);
|
|
84
|
+
// 防重复:同一按键+动作在 150ms 内重复触发则不处理
|
|
85
|
+
let now = Date.now();
|
|
86
|
+
if (key === KeyAdapter.lastKey && action === KeyAdapter.lastAction && now - KeyAdapter.lastTime < KeyAdapter.DEDUP_MS) {
|
|
87
|
+
console.log(`[KeyAdapter] ignore duplicate: ${key}, ${action}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
KeyAdapter.lastKey = key as string;
|
|
91
|
+
KeyAdapter.lastAction = action as string;
|
|
92
|
+
KeyAdapter.lastTime = now;
|
|
93
|
+
// 外部回调,优先执行,可用于拦截或扩展按键逻辑
|
|
94
|
+
if (action === KeyAction.Down) {
|
|
95
|
+
if (KeyAdapter.onKeyDown) KeyAdapter.onKeyDown(key);
|
|
96
|
+
} else {
|
|
97
|
+
if (KeyAdapter.onKeyUp) KeyAdapter.onKeyUp(key);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (action !== KeyAction.Down) return;
|
|
101
|
+
|
|
102
|
+
switch (key) {
|
|
103
|
+
case KeyCode.Enter:
|
|
104
|
+
FocusManager.confirm();
|
|
105
|
+
break;
|
|
106
|
+
case KeyCode.Left:
|
|
107
|
+
FocusManager.move(KeyCode.Left);
|
|
108
|
+
break;
|
|
109
|
+
case KeyCode.Right:
|
|
110
|
+
FocusManager.move(KeyCode.Right);
|
|
111
|
+
break;
|
|
112
|
+
case KeyCode.Up:
|
|
113
|
+
FocusManager.move(KeyCode.Up);
|
|
114
|
+
break;
|
|
115
|
+
case KeyCode.Down:
|
|
116
|
+
FocusManager.move(KeyCode.Down);
|
|
117
|
+
break;
|
|
118
|
+
case KeyCode.Back:
|
|
119
|
+
// 返回键由 UIAdapter 处理,通过回调注入
|
|
120
|
+
if (KeyAdapter.onBack) KeyAdapter.onBack();
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 返回键回调(由 UIAdapter 注入) */
|
|
126
|
+
static onBack: (() => void) | null = null;
|
|
127
|
+
|
|
128
|
+
/** 按键按下回调,在默认处理逻辑前执行 */
|
|
129
|
+
static onKeyDown: ((key: KeyCode) => void) | null = null;
|
|
130
|
+
|
|
131
|
+
/** 按键抬起回调,在默认处理逻辑前执行 */
|
|
132
|
+
static onKeyUp: ((key: KeyCode) => void) | null = null;
|
|
133
|
+
}
|