drgame-cc 1.0.16 → 1.0.18
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/build-templates/web-mobile/bg.png +0 -0
- package/build-templates/web-mobile/index.html +3 -3
- package/build-templates/web-mobile/jz-jdt-3.png +0 -0
- package/build-templates/web-mobile/jz-jdt-4.png +0 -0
- package/build-templates/web-mobile/logo.png +0 -0
- package/build-templates/web-mobile/style-mobile.css +85 -73
- package/drscript/PlatformAdapter.ts +11 -0
- package/drscript/focus/FocusManager.ts +8 -8
- package/drscript/focus/FocusVisualLayer.ts +40 -40
- package/drscript/input/KeyboardMove.ts +55 -0
- package/drscript/virtualgamepad/VirtualGamepadClient.ts +214 -0
- package/drscript/virtualgamepad/VirtualGamepadClient.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts +70 -0
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadManager.ts +809 -0
- package/drscript/virtualgamepad/VirtualGamepadManager.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts +346 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts.meta +10 -0
- package/package.json +4 -4
- package/scripts/sync-back.js +85 -0
- package/build-templates/web-mobile/bg1.jpg +0 -0
- package/build-templates/web-mobile/splash_en - /345/211/257/346/234/254.png +0 -0
- package/drscript/README - /345/211/257/346/234/254.md" +0 -814
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import VirtualGamepadManager, { VirtualGamepadControlInput, VirtualGamepadMoveInput, VirtualGamepadStatus } from "./VirtualGamepadManager";
|
|
2
|
+
|
|
3
|
+
const FIGHT_UI_OK_LONG_PRESS_SECONDS = 1.25;
|
|
4
|
+
const VIRTUAL_GAMEPAD_TOP_Z_INDEX = cc.macro.MAX_ZINDEX;
|
|
5
|
+
const VIRTUAL_GAMEPAD_PANEL_WIDTH = 420;
|
|
6
|
+
const VIRTUAL_GAMEPAD_PANEL_HEIGHT = 450;
|
|
7
|
+
const VIRTUAL_GAMEPAD_SUN_CODE_SIZE = 230;
|
|
8
|
+
const VIRTUAL_GAMEPAD_BADGE_WIDTH = 230;
|
|
9
|
+
const VIRTUAL_GAMEPAD_BADGE_HEIGHT = 48;
|
|
10
|
+
|
|
11
|
+
export class VirtualGamepadView extends cc.Component {
|
|
12
|
+
private _virtualGamepadPanel: cc.Node | null = null;
|
|
13
|
+
private _virtualGamepadBadge: cc.Node | null = null;
|
|
14
|
+
private _virtualGamepadSunCodeSprite: cc.Sprite | null = null;
|
|
15
|
+
private _virtualGamepadSunCodeLoadingLabel: cc.Label | null = null;
|
|
16
|
+
private _virtualGamepadSunCodeSource: string = "";
|
|
17
|
+
private _virtualGamepadSunCodeLoading: string = "";
|
|
18
|
+
private _virtualGamepadSunCodeLoadSerial: number = 0;
|
|
19
|
+
private _virtualGamepadStatusLabel: cc.Label | null = null;
|
|
20
|
+
private _virtualGamepadRoomLabel: cc.Label | null = null;
|
|
21
|
+
private _virtualGamepadIdentityLabel: cc.Label | null = null;
|
|
22
|
+
private _virtualGamepadBadgeLabel: cc.Label | null = null;
|
|
23
|
+
private _virtualGamepadStatusHandler: ((status: VirtualGamepadStatus) => void) | null = null;
|
|
24
|
+
private _virtualGamepadMoveHandler: ((input: VirtualGamepadMoveInput) => void) | null = null;
|
|
25
|
+
private _virtualGamepadConfirmHandler: ((pressed: boolean, raw?: any) => void) | null = null;
|
|
26
|
+
private _virtualGamepadControlHandler: ((input: VirtualGamepadControlInput) => void) | null = null;
|
|
27
|
+
private _virtualGamepadButtonHandler: ((input: VirtualGamepadControlInput) => void) | null = null;
|
|
28
|
+
private _virtualGamepadBackHandler: ((input: VirtualGamepadControlInput) => void) | null = null;
|
|
29
|
+
private _virtualGamepadMoving: boolean = false;
|
|
30
|
+
|
|
31
|
+
protected onEnable(): void {
|
|
32
|
+
this.registerVirtualGamepadView();
|
|
33
|
+
this.registerVirtualGamepadInput();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected onDisable(): void {
|
|
37
|
+
this.unregisterVirtualGamepadView();
|
|
38
|
+
this.unregisterVirtualGamepadInput();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private registerVirtualGamepadView() {
|
|
42
|
+
this.ensureVirtualGamepadNodes();
|
|
43
|
+
if (!this._virtualGamepadStatusHandler) {
|
|
44
|
+
this._virtualGamepadStatusHandler = (status: VirtualGamepadStatus) => this.refreshVirtualGamepadView(status);
|
|
45
|
+
VirtualGamepadManager.getInstance().onStatus(this._virtualGamepadStatusHandler);
|
|
46
|
+
}
|
|
47
|
+
VirtualGamepadManager.getInstance().start();
|
|
48
|
+
this.refreshVirtualGamepadView(VirtualGamepadManager.getInstance().getStatus());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private unregisterVirtualGamepadView() {
|
|
52
|
+
if (this._virtualGamepadStatusHandler) {
|
|
53
|
+
VirtualGamepadManager.getInstance().offStatus(this._virtualGamepadStatusHandler);
|
|
54
|
+
this._virtualGamepadStatusHandler = null;
|
|
55
|
+
}
|
|
56
|
+
VirtualGamepadManager.getInstance().setGameState("ended");
|
|
57
|
+
VirtualGamepadManager.getInstance().stop();
|
|
58
|
+
if (this._virtualGamepadPanel && this._virtualGamepadPanel.isValid) {
|
|
59
|
+
this._virtualGamepadPanel.destroy();
|
|
60
|
+
}
|
|
61
|
+
if (this._virtualGamepadBadge && this._virtualGamepadBadge.isValid) {
|
|
62
|
+
this._virtualGamepadBadge.destroy();
|
|
63
|
+
}
|
|
64
|
+
this._virtualGamepadPanel = null;
|
|
65
|
+
this._virtualGamepadBadge = null;
|
|
66
|
+
this._virtualGamepadSunCodeSprite = null;
|
|
67
|
+
this._virtualGamepadSunCodeLoadingLabel = null;
|
|
68
|
+
this._virtualGamepadSunCodeSource = "";
|
|
69
|
+
this._virtualGamepadSunCodeLoading = "";
|
|
70
|
+
this._virtualGamepadSunCodeLoadSerial++;
|
|
71
|
+
this._virtualGamepadStatusLabel = null;
|
|
72
|
+
this._virtualGamepadRoomLabel = null;
|
|
73
|
+
this._virtualGamepadIdentityLabel = null;
|
|
74
|
+
this._virtualGamepadBadgeLabel = null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private registerVirtualGamepadInput() {
|
|
78
|
+
// if (!this._virtualGamepadMoveHandler) {
|
|
79
|
+
// this._virtualGamepadMoveHandler = (input: VirtualGamepadMoveInput) => this.applyVirtualGamepadMove(input);
|
|
80
|
+
// VirtualGamepadManager.getInstance().onMove(this._virtualGamepadMoveHandler);
|
|
81
|
+
// }
|
|
82
|
+
// if (!this._virtualGamepadConfirmHandler) {
|
|
83
|
+
// this._virtualGamepadConfirmHandler = (pressed: boolean, raw?: any) => this.applyVirtualGamepadConfirm(pressed, raw);
|
|
84
|
+
// VirtualGamepadManager.getInstance().onConfirm(this._virtualGamepadConfirmHandler);
|
|
85
|
+
// }
|
|
86
|
+
// if (!this._virtualGamepadControlHandler) {
|
|
87
|
+
// this._virtualGamepadControlHandler = (input: VirtualGamepadControlInput) => this.logVirtualGamepadControlInput(input);
|
|
88
|
+
// VirtualGamepadManager.getInstance().onControl(this._virtualGamepadControlHandler);
|
|
89
|
+
// }
|
|
90
|
+
// if (!this._virtualGamepadButtonHandler) {
|
|
91
|
+
// this._virtualGamepadButtonHandler = (input: VirtualGamepadControlInput) => this.applyVirtualGamepadButton(input);
|
|
92
|
+
// VirtualGamepadManager.getInstance().onButton(this._virtualGamepadButtonHandler);
|
|
93
|
+
// }
|
|
94
|
+
// if (!this._virtualGamepadBackHandler) {
|
|
95
|
+
// this._virtualGamepadBackHandler = (input: VirtualGamepadControlInput) => this.applyVirtualGamepadBack(input);
|
|
96
|
+
// VirtualGamepadManager.getInstance().onBack(this._virtualGamepadBackHandler);
|
|
97
|
+
// }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private unregisterVirtualGamepadInput() {
|
|
101
|
+
if (this._virtualGamepadMoveHandler) {
|
|
102
|
+
VirtualGamepadManager.getInstance().offMove(this._virtualGamepadMoveHandler);
|
|
103
|
+
this._virtualGamepadMoveHandler = null;
|
|
104
|
+
}
|
|
105
|
+
if (this._virtualGamepadConfirmHandler) {
|
|
106
|
+
VirtualGamepadManager.getInstance().offConfirm(this._virtualGamepadConfirmHandler);
|
|
107
|
+
this._virtualGamepadConfirmHandler = null;
|
|
108
|
+
}
|
|
109
|
+
if (this._virtualGamepadControlHandler) {
|
|
110
|
+
VirtualGamepadManager.getInstance().offControl(this._virtualGamepadControlHandler);
|
|
111
|
+
this._virtualGamepadControlHandler = null;
|
|
112
|
+
}
|
|
113
|
+
if (this._virtualGamepadButtonHandler) {
|
|
114
|
+
VirtualGamepadManager.getInstance().offButton(this._virtualGamepadButtonHandler);
|
|
115
|
+
this._virtualGamepadButtonHandler = null;
|
|
116
|
+
}
|
|
117
|
+
if (this._virtualGamepadBackHandler) {
|
|
118
|
+
VirtualGamepadManager.getInstance().offBack(this._virtualGamepadBackHandler);
|
|
119
|
+
this._virtualGamepadBackHandler = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private ensureVirtualGamepadNodes() {
|
|
124
|
+
if (this._virtualGamepadPanel && this._virtualGamepadPanel.isValid) {
|
|
125
|
+
this.refreshVirtualGamepadLayout();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this._virtualGamepadPanel = new cc.Node("virtualGamepadPanel");
|
|
129
|
+
this._virtualGamepadPanel.setContentSize(VIRTUAL_GAMEPAD_PANEL_WIDTH, VIRTUAL_GAMEPAD_PANEL_HEIGHT);
|
|
130
|
+
this._virtualGamepadPanel.zIndex = VIRTUAL_GAMEPAD_TOP_Z_INDEX;
|
|
131
|
+
this._virtualGamepadPanel.parent = this.getVirtualGamepadTopParent();
|
|
132
|
+
this.drawRectBg(this._virtualGamepadPanel, VIRTUAL_GAMEPAD_PANEL_WIDTH, VIRTUAL_GAMEPAD_PANEL_HEIGHT, new cc.Color(12, 20, 32, 242));
|
|
133
|
+
|
|
134
|
+
let accent = new cc.Node("accent");
|
|
135
|
+
accent.parent = this._virtualGamepadPanel;
|
|
136
|
+
accent.y = VIRTUAL_GAMEPAD_PANEL_HEIGHT * 0.5 - 3;
|
|
137
|
+
this.drawRectBg(accent, VIRTUAL_GAMEPAD_PANEL_WIDTH, 6, new cc.Color(38, 190, 196, 255));
|
|
138
|
+
|
|
139
|
+
let title = this.createVirtualGamepadLabel("title", "手机虚拟手柄", 28, cc.Color.WHITE);
|
|
140
|
+
title.node.parent = this._virtualGamepadPanel;
|
|
141
|
+
title.node.y = 192;
|
|
142
|
+
|
|
143
|
+
let subtitle = this.createVirtualGamepadLabel("subtitle", "微信扫码,手机即手柄", 17, new cc.Color(87, 214, 205, 255));
|
|
144
|
+
subtitle.node.parent = this._virtualGamepadPanel;
|
|
145
|
+
subtitle.node.y = 158;
|
|
146
|
+
|
|
147
|
+
let qrFrame = new cc.Node("qrFrame");
|
|
148
|
+
qrFrame.parent = this._virtualGamepadPanel;
|
|
149
|
+
qrFrame.y = 18;
|
|
150
|
+
this.drawVirtualGamepadQrFrame(qrFrame, 246);
|
|
151
|
+
|
|
152
|
+
let sunCodeNode = new cc.Node("sunCode");
|
|
153
|
+
sunCodeNode.parent = qrFrame;
|
|
154
|
+
sunCodeNode.zIndex = 1;
|
|
155
|
+
sunCodeNode.setContentSize(VIRTUAL_GAMEPAD_SUN_CODE_SIZE, VIRTUAL_GAMEPAD_SUN_CODE_SIZE);
|
|
156
|
+
this._virtualGamepadSunCodeSprite = sunCodeNode.addComponent(cc.Sprite);
|
|
157
|
+
this._virtualGamepadSunCodeSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
|
158
|
+
this._virtualGamepadSunCodeSprite.node.active = false;
|
|
159
|
+
|
|
160
|
+
this._virtualGamepadSunCodeLoadingLabel = this.createVirtualGamepadLabel(
|
|
161
|
+
"sunCodeLoading",
|
|
162
|
+
"太阳码生成中\n请稍候...",
|
|
163
|
+
19,
|
|
164
|
+
new cc.Color(75, 101, 130, 255)
|
|
165
|
+
);
|
|
166
|
+
this._virtualGamepadSunCodeLoadingLabel.node.parent = qrFrame;
|
|
167
|
+
this._virtualGamepadSunCodeLoadingLabel.node.setContentSize(210, 72);
|
|
168
|
+
|
|
169
|
+
this._virtualGamepadStatusLabel = this.createVirtualGamepadLabel("status", "等待手柄扫码连接", 20, new cc.Color(255, 210, 82, 255));
|
|
170
|
+
this._virtualGamepadStatusLabel.node.parent = this._virtualGamepadPanel;
|
|
171
|
+
this._virtualGamepadStatusLabel.node.y = -124;
|
|
172
|
+
|
|
173
|
+
this._virtualGamepadRoomLabel = this.createVirtualGamepadLabel("room", "", 16, new cc.Color(193, 207, 226, 255));
|
|
174
|
+
this._virtualGamepadRoomLabel.node.parent = this._virtualGamepadPanel;
|
|
175
|
+
this._virtualGamepadRoomLabel.node.y = -156;
|
|
176
|
+
|
|
177
|
+
this._virtualGamepadIdentityLabel = this.createVirtualGamepadLabel("identity", "", 16, new cc.Color(141, 163, 191, 255));
|
|
178
|
+
this._virtualGamepadIdentityLabel.node.parent = this._virtualGamepadPanel;
|
|
179
|
+
this._virtualGamepadIdentityLabel.node.y = -184;
|
|
180
|
+
|
|
181
|
+
this._virtualGamepadBadge = new cc.Node("virtualGamepadBadge");
|
|
182
|
+
this._virtualGamepadBadge.setContentSize(VIRTUAL_GAMEPAD_BADGE_WIDTH, VIRTUAL_GAMEPAD_BADGE_HEIGHT);
|
|
183
|
+
this._virtualGamepadBadge.zIndex = VIRTUAL_GAMEPAD_TOP_Z_INDEX;
|
|
184
|
+
this._virtualGamepadBadge.parent = this.getVirtualGamepadTopParent();
|
|
185
|
+
this.drawRectBg(this._virtualGamepadBadge, 230, 48, new cc.Color(24, 160, 91, 238));
|
|
186
|
+
this._virtualGamepadBadgeLabel = this.createVirtualGamepadLabel("badgeText", "手柄已连接", 20, cc.Color.WHITE);
|
|
187
|
+
this._virtualGamepadBadgeLabel.node.parent = this._virtualGamepadBadge;
|
|
188
|
+
this._virtualGamepadBadge.active = false;
|
|
189
|
+
|
|
190
|
+
this.refreshVirtualGamepadLayout();
|
|
191
|
+
this.bringVirtualGamepadToTop();
|
|
192
|
+
this.scheduleOnce(() => this.bringVirtualGamepadToTop(), 0);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private refreshVirtualGamepadLayout() {
|
|
196
|
+
let size: cc.Size = cc.winSize;
|
|
197
|
+
if (this._virtualGamepadPanel) {
|
|
198
|
+
this._virtualGamepadPanel.x = size.width - VIRTUAL_GAMEPAD_PANEL_WIDTH / 2;
|
|
199
|
+
this._virtualGamepadPanel.y = size.height - VIRTUAL_GAMEPAD_PANEL_HEIGHT / 2;
|
|
200
|
+
}
|
|
201
|
+
if (this._virtualGamepadBadge) {
|
|
202
|
+
this._virtualGamepadBadge.x = size.width - VIRTUAL_GAMEPAD_BADGE_WIDTH / 2;
|
|
203
|
+
this._virtualGamepadBadge.y = size.height - VIRTUAL_GAMEPAD_BADGE_HEIGHT / 2;
|
|
204
|
+
}
|
|
205
|
+
this.bringVirtualGamepadToTop();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private refreshVirtualGamepadView(status: VirtualGamepadStatus) {
|
|
209
|
+
this.ensureVirtualGamepadNodes();
|
|
210
|
+
this.refreshVirtualGamepadSunCode(status);
|
|
211
|
+
if (this._virtualGamepadStatusLabel) {
|
|
212
|
+
this._virtualGamepadStatusLabel.string = status.statusText;
|
|
213
|
+
this._virtualGamepadStatusLabel.node.color = this.getVirtualGamepadStatusColor(status);
|
|
214
|
+
}
|
|
215
|
+
if (this._virtualGamepadRoomLabel) {
|
|
216
|
+
this._virtualGamepadRoomLabel.string = "房间 " + status.roomId;
|
|
217
|
+
}
|
|
218
|
+
if (this._virtualGamepadIdentityLabel) {
|
|
219
|
+
this._virtualGamepadIdentityLabel.string = "身份 " + status.identityText;
|
|
220
|
+
}
|
|
221
|
+
if (this._virtualGamepadBadgeLabel) {
|
|
222
|
+
this._virtualGamepadBadgeLabel.string = status.statusText;
|
|
223
|
+
}
|
|
224
|
+
if (this._virtualGamepadPanel) {
|
|
225
|
+
this._virtualGamepadPanel.active = !status.controllerConnected;
|
|
226
|
+
}
|
|
227
|
+
if (this._virtualGamepadBadge) {
|
|
228
|
+
this._virtualGamepadBadge.active = status.controllerConnected;
|
|
229
|
+
}
|
|
230
|
+
this.bringVirtualGamepadToTop();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private refreshVirtualGamepadSunCode(status: VirtualGamepadStatus) {
|
|
234
|
+
let sprite = this._virtualGamepadSunCodeSprite;
|
|
235
|
+
let loadingLabel = this._virtualGamepadSunCodeLoadingLabel;
|
|
236
|
+
let source = status.sunCodeState == "ready" ? status.sunCodeDataUrl : "";
|
|
237
|
+
if (!sprite || !sprite.node || !cc.isValid(sprite.node)) return;
|
|
238
|
+
if (!source) {
|
|
239
|
+
sprite.node.active = false;
|
|
240
|
+
if (loadingLabel && loadingLabel.node && cc.isValid(loadingLabel.node)) {
|
|
241
|
+
loadingLabel.string = "太阳码生成中\n请稍候...";
|
|
242
|
+
loadingLabel.node.active = true;
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (this._virtualGamepadSunCodeSource == source && sprite.spriteFrame) {
|
|
247
|
+
sprite.node.active = true;
|
|
248
|
+
if (loadingLabel && loadingLabel.node) loadingLabel.node.active = false;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (this._virtualGamepadSunCodeLoading == source) return;
|
|
252
|
+
|
|
253
|
+
sprite.node.active = false;
|
|
254
|
+
if (loadingLabel && loadingLabel.node && cc.isValid(loadingLabel.node)) {
|
|
255
|
+
loadingLabel.string = "太阳码加载中\n请稍候...";
|
|
256
|
+
loadingLabel.node.active = true;
|
|
257
|
+
}
|
|
258
|
+
this._virtualGamepadSunCodeLoading = source;
|
|
259
|
+
let loadSerial = ++this._virtualGamepadSunCodeLoadSerial;
|
|
260
|
+
let imageType = source.indexOf("data:image/png") == 0 ? "png" : "jpg";
|
|
261
|
+
cc.loader.load({ url: source, type: imageType }, (error: Error, texture: cc.Texture2D) => {
|
|
262
|
+
if (loadSerial != this._virtualGamepadSunCodeLoadSerial) return;
|
|
263
|
+
this._virtualGamepadSunCodeLoading = "";
|
|
264
|
+
let currentSprite = this._virtualGamepadSunCodeSprite;
|
|
265
|
+
if (error || !texture || !currentSprite || !currentSprite.node || !cc.isValid(currentSprite.node)) {
|
|
266
|
+
console.warn("[VirtualGamepad][SunCode] image decode failed", error && (error.message || error));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
currentSprite.spriteFrame = new cc.SpriteFrame(texture);
|
|
270
|
+
currentSprite.sizeMode = cc.Sprite.SizeMode.CUSTOM;
|
|
271
|
+
currentSprite.node.setContentSize(VIRTUAL_GAMEPAD_SUN_CODE_SIZE, VIRTUAL_GAMEPAD_SUN_CODE_SIZE);
|
|
272
|
+
currentSprite.node.active = true;
|
|
273
|
+
let currentLoadingLabel = this._virtualGamepadSunCodeLoadingLabel;
|
|
274
|
+
if (currentLoadingLabel && currentLoadingLabel.node && cc.isValid(currentLoadingLabel.node)) {
|
|
275
|
+
currentLoadingLabel.node.active = false;
|
|
276
|
+
}
|
|
277
|
+
this._virtualGamepadSunCodeSource = source;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private getVirtualGamepadTopParent(): cc.Node {
|
|
282
|
+
return cc.director.getScene() || this.node.parent || this.node;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private bringVirtualGamepadToTop() {
|
|
286
|
+
this.placeVirtualGamepadNodeOnTop(this._virtualGamepadPanel);
|
|
287
|
+
this.placeVirtualGamepadNodeOnTop(this._virtualGamepadBadge);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private placeVirtualGamepadNodeOnTop(node: cc.Node | null) {
|
|
291
|
+
if (!node || !cc.isValid(node)) return;
|
|
292
|
+
let topParent = this.getVirtualGamepadTopParent();
|
|
293
|
+
if (topParent && cc.isValid(topParent) && node.parent != topParent) {
|
|
294
|
+
let worldPos = node.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
295
|
+
node.parent = topParent;
|
|
296
|
+
node.setPosition(topParent.convertToNodeSpaceAR(worldPos));
|
|
297
|
+
}
|
|
298
|
+
if (node.zIndex != VIRTUAL_GAMEPAD_TOP_Z_INDEX) {
|
|
299
|
+
node.zIndex = VIRTUAL_GAMEPAD_TOP_Z_INDEX;
|
|
300
|
+
}
|
|
301
|
+
if (node.parent && node.getSiblingIndex() != node.parent.childrenCount - 1) {
|
|
302
|
+
node.setSiblingIndex(node.parent.childrenCount - 1);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private createVirtualGamepadLabel(name: string, text: string, fontSize: number, color: cc.Color): cc.Label {
|
|
307
|
+
let node = new cc.Node(name);
|
|
308
|
+
node.setContentSize(390, fontSize + 10);
|
|
309
|
+
let label = node.addComponent(cc.Label);
|
|
310
|
+
label.string = text;
|
|
311
|
+
label.fontSize = fontSize;
|
|
312
|
+
label.lineHeight = fontSize + 8;
|
|
313
|
+
label.horizontalAlign = cc.Label.HorizontalAlign.CENTER;
|
|
314
|
+
label.verticalAlign = cc.Label.VerticalAlign.CENTER;
|
|
315
|
+
label.overflow = cc.Label.Overflow.SHRINK;
|
|
316
|
+
label.node.color = color;
|
|
317
|
+
return label;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private getVirtualGamepadStatusColor(status: VirtualGamepadStatus): cc.Color {
|
|
321
|
+
if (status.controllerConnected) return new cc.Color(83, 218, 141, 255);
|
|
322
|
+
if (status.connectionState == "error") return new cc.Color(255, 112, 112, 255);
|
|
323
|
+
if (status.connectionState == "open" || status.connectionState == "joined") return new cc.Color(87, 214, 205, 255);
|
|
324
|
+
return new cc.Color(255, 210, 82, 255);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private drawVirtualGamepadQrFrame(node: cc.Node, size: number) {
|
|
328
|
+
node.setContentSize(size, size);
|
|
329
|
+
let graphics = node.addComponent(cc.Graphics);
|
|
330
|
+
graphics.fillColor = cc.Color.WHITE;
|
|
331
|
+
graphics.rect(-size * 0.5, -size * 0.5, size, size);
|
|
332
|
+
graphics.fill();
|
|
333
|
+
graphics.lineWidth = 2;
|
|
334
|
+
graphics.strokeColor = new cc.Color(87, 214, 205, 255);
|
|
335
|
+
graphics.rect(-size * 0.5, -size * 0.5, size, size);
|
|
336
|
+
graphics.stroke();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private drawRectBg(node: cc.Node, width: number, height: number, color: cc.Color) {
|
|
340
|
+
let graphics = node.getComponent(cc.Graphics) || node.addComponent(cc.Graphics);
|
|
341
|
+
graphics.clear();
|
|
342
|
+
graphics.fillColor = color;
|
|
343
|
+
graphics.rect(-width * node.anchorX, -height * node.anchorY, width, height);
|
|
344
|
+
graphics.fill();
|
|
345
|
+
}
|
|
346
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drgame-cc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "道然游戏适配包",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"gulp-inject-string": "^1.1.2",
|
|
30
30
|
"gulp-minify": "^3.1.0",
|
|
31
31
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
32
|
-
"rimraf": "^5.0.0"
|
|
33
|
-
"typescript": "5.9.3"
|
|
32
|
+
"rimraf": "^5.0.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
35
|
+
"typescript": "5.9.3",
|
|
36
36
|
"fs-extra": "^11.2.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"drres/**/*",
|
|
43
43
|
"drscript/**/*",
|
|
44
44
|
"build-templates/**/*",
|
|
45
|
-
"scripts
|
|
45
|
+
"scripts/**/*",
|
|
46
46
|
"bin/**/*"
|
|
47
47
|
],
|
|
48
48
|
"engines": {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fse = require('fs-extra');
|
|
6
|
+
|
|
7
|
+
// ============================================================
|
|
8
|
+
// 1. 包自身根目录 / 宿主项目根目录
|
|
9
|
+
// ============================================================
|
|
10
|
+
const pkgRoot = path.resolve(__dirname, '..');
|
|
11
|
+
const projectRoot = path.resolve(__dirname, '..', '..', '..');
|
|
12
|
+
|
|
13
|
+
// ============================================================
|
|
14
|
+
// 2. 解析命令行参数(与 postinstall.js 一致)
|
|
15
|
+
// 支持: <path> | --cocos-path <path> | --cocos-path=<path> | -p <path>
|
|
16
|
+
// ============================================================
|
|
17
|
+
function resolveCocosPath(argv) {
|
|
18
|
+
const args = argv.slice(2);
|
|
19
|
+
for (let i = 0; i < args.length; i++) {
|
|
20
|
+
const a = args[i];
|
|
21
|
+
if (a.startsWith('--cocos-path=')) {
|
|
22
|
+
return a.slice('--cocos-path='.length);
|
|
23
|
+
}
|
|
24
|
+
if (a === '--cocos-path' || a === '-p') {
|
|
25
|
+
const next = args[i + 1];
|
|
26
|
+
if (next && !next.startsWith('-')) {
|
|
27
|
+
return next;
|
|
28
|
+
}
|
|
29
|
+
} else if (!a.startsWith('-') && a.length > 0) {
|
|
30
|
+
return a;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const argPath = resolveCocosPath(process.argv);
|
|
37
|
+
let COCOS_ROOT = argPath || projectRoot;
|
|
38
|
+
if (!path.isAbsolute(COCOS_ROOT)) {
|
|
39
|
+
COCOS_ROOT = path.resolve(process.cwd(), COCOS_ROOT);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('开始反向同步(Cocos 项目 -> npm 包)');
|
|
43
|
+
console.log(`源目录(宿主): ${COCOS_ROOT}`);
|
|
44
|
+
console.log(`目标目录(包): ${pkgRoot}`);
|
|
45
|
+
console.log(`Cocos 路径来源: ${argPath ? '命令行参数' : '默认(node_modules 父目录)'}`);
|
|
46
|
+
|
|
47
|
+
// ============================================================
|
|
48
|
+
// 3. 反向拷贝:与 postinstall.js 完全对称
|
|
49
|
+
// COCOS_ROOT/build-templates -> pkgRoot/build-templates
|
|
50
|
+
// COCOS_ROOT/assets/resources/drres -> pkgRoot/drres
|
|
51
|
+
// COCOS_ROOT/assets/drscript -> pkgRoot/drscript
|
|
52
|
+
// ============================================================
|
|
53
|
+
const jobs = [
|
|
54
|
+
{
|
|
55
|
+
name: 'build-templates',
|
|
56
|
+
src: path.join(COCOS_ROOT, 'build-templates'),
|
|
57
|
+
dest: path.join(pkgRoot, 'build-templates'),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'drres',
|
|
61
|
+
src: path.join(COCOS_ROOT, 'assets', 'resources', 'drres'),
|
|
62
|
+
dest: path.join(pkgRoot, 'drres'),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'drscript',
|
|
66
|
+
src: path.join(COCOS_ROOT, 'assets', 'drscript'),
|
|
67
|
+
dest: path.join(pkgRoot, 'drscript'),
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
for (const job of jobs) {
|
|
73
|
+
if (fs.existsSync(job.src)) {
|
|
74
|
+
fse.copySync(job.src, job.dest, { overwrite: true });
|
|
75
|
+
console.log(`[OK] ${job.name} 反向同步完成`);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(`[SKIP] 源目录不存在,跳过: ${job.src}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.log('反向同步完成!');
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('反向同步失败:', error.message);
|
|
83
|
+
console.error(error.stack);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
Binary file
|
|
Binary file
|