@cc-component/cc-guide 1.0.0

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 (60) hide show
  1. package/.cc-ex-component.md +12 -0
  2. package/assets/guide/common/GuideTool.ts +33 -0
  3. package/assets/guide/common/GuideTool.ts.meta +9 -0
  4. package/assets/guide/common/Log.ts +82 -0
  5. package/assets/guide/common/Log.ts.meta +9 -0
  6. package/assets/guide/common/ViewUtil.ts +163 -0
  7. package/assets/guide/common/ViewUtil.ts.meta +9 -0
  8. package/assets/guide/common.meta +9 -0
  9. package/assets/guide/guide/Guide.ts +42 -0
  10. package/assets/guide/guide/Guide.ts.meta +9 -0
  11. package/assets/guide/guide/GuideCenter.ts +364 -0
  12. package/assets/guide/guide/GuideCenter.ts.meta +9 -0
  13. package/assets/guide/guide/GuideSDK.ts +71 -0
  14. package/assets/guide/guide/GuideSDK.ts.meta +9 -0
  15. package/assets/guide/guide/model/GuideCommon.ts +27 -0
  16. package/assets/guide/guide/model/GuideCommon.ts.meta +9 -0
  17. package/assets/guide/guide/model/GuideModelComp.ts +161 -0
  18. package/assets/guide/guide/model/GuideModelComp.ts.meta +9 -0
  19. package/assets/guide/guide/model/ITableGuide.ts +32 -0
  20. package/assets/guide/guide/model/ITableGuide.ts.meta +9 -0
  21. package/assets/guide/guide/model/ITableNPC.ts +10 -0
  22. package/assets/guide/guide/model/ITableNPC.ts.meta +9 -0
  23. package/assets/guide/guide/model.meta +12 -0
  24. package/assets/guide/guide/view/GuideTest.ts +150 -0
  25. package/assets/guide/guide/view/GuideTest.ts.meta +9 -0
  26. package/assets/guide/guide/view/GuideViewComp.ts +299 -0
  27. package/assets/guide/guide/view/GuideViewComp.ts.meta +9 -0
  28. package/assets/guide/guide/view/GuideViewItem.ts +104 -0
  29. package/assets/guide/guide/view/GuideViewItem.ts.meta +9 -0
  30. package/assets/guide/guide/view/GuideViewMask.ts +342 -0
  31. package/assets/guide/guide/view/GuideViewMask.ts.meta +9 -0
  32. package/assets/guide/guide/view/GuideViewPrompt.ts +178 -0
  33. package/assets/guide/guide/view/GuideViewPrompt.ts.meta +9 -0
  34. package/assets/guide/guide/view/PolygonMask.ts +161 -0
  35. package/assets/guide/guide/view/PolygonMask.ts.meta +9 -0
  36. package/assets/guide/guide/view/touch.ts.meta +9 -0
  37. package/assets/guide/guide/view.meta +12 -0
  38. package/assets/guide/guide.meta +9 -0
  39. package/assets/guide/interface/GuideModule.ts +54 -0
  40. package/assets/guide/interface/GuideModule.ts.meta +1 -0
  41. package/assets/guide/interface/Interface.ts +44 -0
  42. package/assets/guide/interface/Interface.ts.meta +9 -0
  43. package/assets/guide/interface/guide/mask.prefab +716 -0
  44. package/assets/guide/interface/guide/mask.prefab.meta +13 -0
  45. package/assets/guide/interface/guide/prompt.prefab +1524 -0
  46. package/assets/guide/interface/guide/prompt.prefab.meta +13 -0
  47. package/assets/guide/interface/guide/skeleton.atlas +20 -0
  48. package/assets/guide/interface/guide/skeleton.atlas.meta +12 -0
  49. package/assets/guide/interface/guide/skeleton.json +1 -0
  50. package/assets/guide/interface/guide/skeleton.json.meta +13 -0
  51. package/assets/guide/interface/guide/skeleton.png +0 -0
  52. package/assets/guide/interface/guide/skeleton.png.meta +134 -0
  53. package/assets/guide/interface/guide.meta +9 -0
  54. package/assets/guide/interface.meta +1 -0
  55. package/assets/guide.meta +11 -0
  56. package/assets.meta +9 -0
  57. package/index.ts +5 -0
  58. package/index.ts.meta +9 -0
  59. package/package.json +19 -0
  60. package/package.json.meta +11 -0
@@ -0,0 +1,342 @@
1
+ /*
2
+ * @Author: dgflash
3
+ * @Date: 2021-07-03 16:13:17
4
+ * @LastEditors: dgflash
5
+ * @LastEditTime: 2022-09-06 10:13:17
6
+ */
7
+ import { Component, EventTouch, instantiate, Node, Prefab, UITransform, v2, Widget, _decorator } from "cc";
8
+
9
+ import { GuideModelComp } from "../model/GuideModelComp";
10
+ import { PolygonMask } from "./PolygonMask";
11
+ import { UIOpacity } from "cc";
12
+ import { Sprite } from "cc";
13
+ import { tween } from "cc";
14
+ import { Tween } from "cc";
15
+ import { GuideViewItem } from "./GuideViewItem";
16
+ import { v3 } from "cc";
17
+ import { ViewUtil } from "../../common/ViewUtil";
18
+ import { Log } from "../../common/Log";
19
+
20
+ const { ccclass, property } = _decorator;
21
+
22
+ /** 新后引导遮罩逻辑 */
23
+ @ccclass('GuideViewMask')
24
+ export class GuideViewMask extends Component {
25
+ model: GuideModelComp = null!;
26
+
27
+ private bg: Node = null!;
28
+ private mask: Node = null!;
29
+ private mask_pm: PolygonMask = null!;
30
+ private mask_widget: Widget = null!;
31
+ clickMask: Function;
32
+ op: UIOpacity
33
+ big_sp: Sprite;
34
+ is_show: boolean = false;
35
+ bg_op: UIOpacity;
36
+ is_anim_start: boolean = false;
37
+ is_anim_hide: boolean = false;
38
+ delayAction: Function;
39
+
40
+ dispatchEvent: Function
41
+
42
+ protected onLoad(): void {
43
+
44
+
45
+ }
46
+ start() {
47
+ var prefab: Prefab = GuideModule.GuideCenter.getAsset(this.model.res_mask)
48
+ const mask = instantiate(prefab);
49
+ mask.parent = this.node;
50
+
51
+ this.mask = mask.getChildByPath("mask")!
52
+ this.bg = this.mask.getChildByPath("bg")!;
53
+ this.big_sp = mask.getChildByName("big_sp")!.getComponent(Sprite);
54
+ this.mask_pm = this.mask.getComponent(PolygonMask)!;
55
+ this.mask_widget = this.bg.getComponent(Widget)!;
56
+ //this.node.active = false;
57
+ this.op = this.node.addComponent(UIOpacity)
58
+ this.bg_op = this.bg.getComponent(UIOpacity)
59
+ this.showNode(false, false, true)
60
+
61
+ }
62
+
63
+ /** 显示引导 */
64
+ show(width: number, height: number) {
65
+ //this.node.active = true;
66
+ this.showNode(true)
67
+
68
+ this.mask_widget.target = this.node;
69
+ this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
70
+ this.mask_pm.draw(width, height, this.model.currentPrompt.data.showType);
71
+ this.refesh(this.model.currentPrompt.data.showType);
72
+ if (this.model.currentPrompt && this.model.currentPrompt.data.backgroundImage) {
73
+ if (this.model.current_bg !== this.model.currentPrompt.data.backgroundImage) {
74
+ GuideModule.GuideCenter.LoadSprite(this.big_sp, GuideModule.GuideCenter.spriteRootPath(this.model.currentPrompt.data.backgroundImage), () => {
75
+ //if (this.big_sp && this.big_sp.isValid)
76
+ // this.big_sp.fitHeight()
77
+ });
78
+ } else {
79
+ this.big_sp.spriteFrame = null;
80
+ }
81
+ } else {
82
+ this.big_sp.spriteFrame = null;
83
+ }
84
+ }
85
+
86
+ /** 隐藏引导 */
87
+ hide() {
88
+ this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this);
89
+ //this.node.active = false;
90
+ this.showNode(false)
91
+
92
+ }
93
+
94
+ /** 绘制遮罩 */
95
+ draw(btn: Node, isCircle: boolean = true) {
96
+ if (isCircle) {
97
+ this.drawRectangleMask2(btn);
98
+ } else {
99
+ this.drawRectangleMask(btn);
100
+ }
101
+ }
102
+ private drawRectangleMask2(btn: Node) {
103
+ // 定义规制区域的位置
104
+ var left_top = this.mask_pm.polygon.points[0];
105
+ var left_bottom = this.mask_pm.polygon.points[3];
106
+ var right_top = this.mask_pm.polygon.points[2];
107
+ var right_bottom = this.mask_pm.polygon.points[1];
108
+
109
+ // 绘制引导可点击区域
110
+ var uit = btn.getComponent(UITransform)!;
111
+ var size = this.node.getComponent(UITransform)!.contentSize;
112
+ var widthHalf = size.width / 2;
113
+ var heightHalf = size.height / 2;
114
+
115
+ var left_x = uit.contentSize.width * uit.anchorX;
116
+ var right_x = uit.contentSize.width * (1 - uit.anchorX);
117
+ var left_y = uit.contentSize.height * uit.anchorY;
118
+ var right_y = uit.contentSize.height * (1 - uit.anchorY);
119
+
120
+ left_top.x = btn.worldPosition.x - widthHalf - left_x;
121
+ left_top.y = btn.worldPosition.y - heightHalf - left_y;
122
+ left_bottom.x = btn.worldPosition.x - widthHalf - left_x;
123
+ left_bottom.y = btn.worldPosition.y - heightHalf + right_y;
124
+ right_top.x = btn.worldPosition.x - widthHalf + right_x;
125
+ right_top.y = btn.worldPosition.y - heightHalf + right_y;
126
+ right_bottom.x = btn.worldPosition.x - widthHalf + right_x;
127
+ right_bottom.y = btn.worldPosition.y - heightHalf - left_y;
128
+
129
+ this.show(uit.width, uit.height);
130
+ // this.show(254 , 254);
131
+
132
+ }
133
+
134
+ /** 绘制矩形遮罩 */
135
+ private drawRectangleMask(btn: Node) {
136
+ // 定义规制区域的位置
137
+ var left_top = this.mask_pm.polygon.points[0];
138
+ var left_bottom = this.mask_pm.polygon.points[3];
139
+ var right_top = this.mask_pm.polygon.points[2];
140
+ var right_bottom = this.mask_pm.polygon.points[1];
141
+
142
+ // 绘制引导可点击区域
143
+ var uit = btn.getComponent(UITransform)!;
144
+ var size = this.node.getComponent(UITransform)!.contentSize;
145
+ var widthHalf = size.width / 2;
146
+ var heightHalf = size.height / 2;
147
+
148
+ var left_x = uit.contentSize.width * uit.anchorX;
149
+ var right_x = uit.contentSize.width * (1 - uit.anchorX);
150
+ var left_y = uit.contentSize.height * uit.anchorY;
151
+ var right_y = uit.contentSize.height * (1 - uit.anchorY);
152
+
153
+ left_top.x = btn.worldPosition.x - widthHalf - left_x;
154
+ left_top.y = btn.worldPosition.y - heightHalf - left_y;
155
+ left_bottom.x = btn.worldPosition.x - widthHalf - left_x;
156
+ left_bottom.y = btn.worldPosition.y - heightHalf + right_y;
157
+ right_top.x = btn.worldPosition.x - widthHalf + right_x;
158
+ right_top.y = btn.worldPosition.y - heightHalf + right_y;
159
+ right_bottom.x = btn.worldPosition.x - widthHalf + right_x;
160
+ right_bottom.y = btn.worldPosition.y - heightHalf - left_y;
161
+
162
+ this.show(uit.width, uit.height);
163
+ }
164
+
165
+
166
+
167
+ /** 事件模拟触发目标按钮触摸事件 */
168
+ private onTouchEnd(event: EventTouch) {
169
+ var btn = this.model.current;
170
+ if (btn && btn.isValid) {
171
+ var touchPos = ViewUtil.calculateScreenPosToSpacePos(event, this.node);
172
+ touchPos = ViewUtil.calculateASpaceToBSpacePos(this.node, btn.parent!, touchPos);
173
+ var uiPos = v2(touchPos.x, touchPos.y);
174
+ const view = btn.getComponent(GuideViewItem)
175
+ const target_node = view.findNode()
176
+ let is_hace: boolean = false
177
+ if (target_node && target_node.isValid) {
178
+ const rect1 = target_node.getComponent(UITransform)!.getBoundingBox();
179
+ is_hace = rect1.contains(uiPos) && target_node.activeInHierarchy
180
+ }
181
+
182
+ //引导
183
+ // 判断触摸点是否在按钮上
184
+ var rect = btn.getComponent(UITransform)!.getBoundingBox();
185
+ if (is_hace) {
186
+ event['_other_button'] = true;
187
+ }
188
+ if ((rect.contains(uiPos) && btn.activeInHierarchy || is_hace)) {
189
+ this.is_anim_hide = false
190
+ // 模拟触摸点击事件
191
+ // const listeners = btn['_eventProcessor']['capturingTarget']["_callbackTable"]["touch-end"]["callbackInfos"];
192
+ // if (listeners) {
193
+ // Log.error(listeners)
194
+ // if (listeners) {
195
+ // listeners.forEach((listener) => {
196
+ // if (listener.callback && listener.target) {
197
+ // listener.callback.call(listener.target, event);
198
+ // }
199
+ // });
200
+ // }
201
+ // }
202
+
203
+ // btn.emit(Node.EventType.TOUCH_END, event)
204
+
205
+
206
+ this.dispatchEvent(event, btn)
207
+ // btn.dispatchEvent(event);
208
+
209
+ }
210
+ else {
211
+ this.onClickMask()
212
+ this.clickMask?.()
213
+ }
214
+ } else {
215
+ Log.error('引导出问题了,赶紧查看:', this.model.step)
216
+ }
217
+ }
218
+
219
+
220
+ onClickMask() {
221
+ const ShowType = this.model.currentPrompt.data.showType
222
+ switch (ShowType) {
223
+ case 0:
224
+ this.bg_op.opacity = 255;
225
+ break;
226
+ case 1:
227
+ this.bg_op.opacity = 255;
228
+ break;
229
+ case 2:
230
+ this.bg_op.opacity = 255;
231
+ break;
232
+ case 3:
233
+ this.bg_op.opacity = 255;
234
+ this.hideUI(false)
235
+ break;
236
+ case 4:
237
+ this.showBGAnim(true, () => {
238
+ const delayAction = () => {
239
+ this.is_anim_hide = false
240
+ }
241
+ this.delayAction = delayAction
242
+ this.scheduleOnce(delayAction, 1)
243
+ })
244
+ break;
245
+ default:
246
+ break;
247
+ }
248
+
249
+
250
+
251
+ }
252
+
253
+
254
+ hideUI(isShow = true) {
255
+ this.bg.active = isShow
256
+ }
257
+
258
+ showBGAnim(is_show: boolean, callback?: Function) {
259
+ if (this.bg_op) {
260
+ if (is_show) {
261
+ this.bg_op.opacity = 255;
262
+ Tween.stopAllByTarget(this.mask)
263
+ this.mask.scale = v3(10, 10, 1)
264
+ this.unschedule(this.delayAction)
265
+ tween(this.mask).to(0.2, { scale: v3(1, 1, 1) }).call(() => { callback?.() }).start();
266
+ tween(this.bg_op).to(0.2, { opacity: 255 }).call(() => { }).start();
267
+ } else {
268
+ this.bg_op.opacity = 0;
269
+ }
270
+ }
271
+ }
272
+
273
+ refesh(ShowType: number) {
274
+
275
+ // 0 = 有对话框 有手
276
+ // 1 = 仅小手
277
+ // 2 = 仅对话框
278
+ // 3 = 都无
279
+ this.hideUI(true)
280
+
281
+ switch (ShowType) {
282
+ case 0:
283
+ this.bg_op.opacity = 255;
284
+ break;
285
+ case 1:
286
+ this.bg_op.opacity = 255;
287
+ break;
288
+ case 2:
289
+ this.bg_op.opacity = 255;
290
+ break;
291
+ case 3:
292
+ this.bg_op.opacity = 255;
293
+ this.hideUI(false)
294
+ break;
295
+ case 4:
296
+ if (!this.is_anim_hide) {
297
+ this.is_anim_hide = true
298
+ this.showBGAnim(false)
299
+ }
300
+ break;
301
+ default:
302
+ break;
303
+ }
304
+ }
305
+
306
+
307
+ showNode(is_show: boolean, is_anim = true, is_init: boolean = false) {
308
+ if (this.op) {
309
+ this.startAnim(is_show, is_anim, is_init)
310
+ }
311
+ this.is_show = is_show
312
+ }
313
+
314
+ isGuideShow() {
315
+ return this.is_show//this.op.opacity > 1
316
+ }
317
+
318
+ startAnim(is_show, is_anim, is_init: boolean = false) {
319
+ if (this.is_show === is_show && !is_init) {
320
+ return
321
+ }
322
+ if (is_anim) {
323
+ //Tween.stopAllByTarget(this.op)
324
+ if (is_show) {
325
+ this.op.opacity = 255
326
+ // tween(this.op).to(0.2, { opacity: 255 }).start();
327
+ }
328
+ else {
329
+ this.op.opacity = 0
330
+ //tween(this.op).to(0.1, { opacity: 0 }).start();
331
+ }
332
+ } else {
333
+ if (is_show) {
334
+ this.op.opacity = 255
335
+ } else {
336
+ this.op.opacity = 0
337
+ // tween(this.op).to(0.1, { opacity: 0 }).start();
338
+ }
339
+ }
340
+ }
341
+
342
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "6d04bfaf-bb69-4fcd-8139-f8f514b50407",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,178 @@
1
+ /*
2
+ * @Author: dgflash
3
+ * @Date: 2021-07-03 16:13:17
4
+ * @LastEditors: dgflash
5
+ * @LastEditTime: 2022-09-06 10:17:14
6
+ */
7
+ import { Component, Label, Node, Prefab, UITransform, Vec3, _decorator, instantiate } from "cc";
8
+ import { GuideModelComp } from "../model/GuideModelComp";
9
+ import { v3 } from "cc";
10
+ import { Sprite } from "cc";
11
+ import { Widget } from "cc";
12
+ import { sp } from "cc";
13
+ import { UIOpacity } from "cc";
14
+ import { view } from "cc";
15
+
16
+ const { ccclass, property } = _decorator;
17
+
18
+ /** 新手引导提示逻辑 */
19
+ @ccclass('GuideViewPrompt')
20
+ export class GuideViewPrompt extends Component {
21
+ model: GuideModelComp = null!;
22
+
23
+ private prompt: Node = null!;
24
+ private content: Label = null!;
25
+ private root: Node = null!;
26
+ private hard: Node = null!;
27
+ private hard_op: UIOpacity = null!;
28
+
29
+ private root_wg: Widget = null!;
30
+
31
+ parUT: UITransform;
32
+ spr_role_center: Sprite = null;
33
+ lbl_roleName: Label;
34
+ prompt_op: UIOpacity;
35
+ test_lb: Label;
36
+ start() {
37
+ var prefab: Prefab = GuideModule.GuideCenter.getAsset(this.model.res_prompt)
38
+ this.prompt = instantiate(prefab);
39
+ this.prompt.parent = GuideModule.GuideCenter.node;
40
+ this.prompt_op = this.prompt.addComponent(UIOpacity);
41
+ this.root = this.prompt.getChildByPath("root");
42
+
43
+ this.content = this.root.getChildByName("content").getComponent(Label);
44
+ this.hard = this.prompt.getChildByName("hard");
45
+ this.hard_op = this.hard.getComponent(UIOpacity);
46
+ this.parUT = this.root.parent.parent.getComponent(UITransform);
47
+ this.spr_role_center = this.root.getChildByPath("ren_mask_node/spr_role_center").getComponent(Sprite);
48
+ this.lbl_roleName = this.root.getChildByPath("dialogNode/Sprite/lbl_roleName").getComponent(Label);
49
+ this.root_wg = this.root.getComponent(Widget);
50
+
51
+ this.hide();
52
+ // this.node.addChild(this.root);
53
+ // this.scheduleOnce(() => {
54
+ // this.root.setSiblingIndex(10);
55
+ // })
56
+
57
+ this.loadSkel()
58
+ }
59
+
60
+ protected update(dt: number): void {
61
+
62
+ if (!this.spr_role_center) { return }
63
+ const size = this.spr_role_center.node.parent.getComponent(UITransform).contentSize
64
+ }
65
+ loadSkel() {
66
+ // Log.warn("1加载引导动画")
67
+ // const sp1 = this.hard.getChildByPath('UI/skeleton').getComponent(sp.Skeleton)
68
+ // MiddleCenter.LoadSpine(sp1, "guide/spine/guide/skeleton", {
69
+ // bundle: "guide", callback: () => {
70
+ // sp1.setAnimation(0, 'idle', true)
71
+ // Log.warn("2加载引导动画")
72
+ // }
73
+ // })
74
+ }
75
+
76
+ /** 显示引导提示动画 */
77
+ show(btn: Node) {
78
+ // 提示位置修正到显示对象中心
79
+ var pos = btn.worldPosition.clone();
80
+ var offset: Vec3 = new Vec3();
81
+ var uit = btn.getComponent(UITransform)!;
82
+ offset.x = uit.contentSize.width * 0.5 - uit.contentSize.width * uit.anchorX;
83
+ offset.y = uit.contentSize.height * 0.5 - uit.contentSize.height * uit.anchorY;
84
+ pos = pos.add(offset);
85
+
86
+ // 0=有对话框 有手
87
+ // 1=仅小手
88
+ // 2=仅对话框
89
+ // 3=都无
90
+ let is_show = true;
91
+ let is_ui = !this.model.is_week
92
+ //Log.warn("7引导打印")
93
+
94
+
95
+ switch (this.model.currentPrompt.data.showType) {
96
+ case 0:
97
+ is_show = true;
98
+ break;
99
+ case 1:
100
+ is_show = true;
101
+ is_ui = false
102
+ break;
103
+ case 2:
104
+ is_show = false;
105
+ break;
106
+ case 3:
107
+ is_show = false;
108
+ is_ui = false
109
+ break;
110
+ case 4:
111
+ is_show = true;
112
+ is_ui = false
113
+ break;
114
+ default:
115
+ is_show = false;
116
+ break;
117
+ }
118
+ //Log.warn("8引导打印", this.model.step)
119
+ //this.prompt.active = true;
120
+ this.hideNode(true)
121
+
122
+ this.prompt.setSiblingIndex(this.prompt.parent!.children.length);
123
+ this.prompt.worldPosition = pos;
124
+ this.hideHard(is_show)
125
+ this.hideUI(is_ui)
126
+
127
+ }
128
+
129
+
130
+ /** 显示提示词 */
131
+ showPrompt() {
132
+ var data = this.model.prompts[this.model.step];
133
+ if (!data) { return }
134
+ if (this.content.string !== data.data.contentKey && this.model.npc_icon) {
135
+
136
+ GuideModule.GuideCenter.LoadSprite(this.spr_role_center, GuideModule.GuideCenter.spriteRootPath(this.model.npc_icon))
137
+ }
138
+ if (this.model.npc_icon) {
139
+ this.spr_role_center.node.active = true
140
+ } else {
141
+ this.spr_role_center.node.active = false
142
+ }
143
+
144
+ this.lbl_roleName.string = this.model.npc_name ?? "";
145
+ this.content.string = data.data.contentKey;
146
+ this.prompt.updateWorldTransform()
147
+
148
+ // 将本地坐标转换为世界坐标
149
+ const localPos = v3(0, data.data.dialogY - view.getVisibleSize().height * 0.5, 0);
150
+ const worldPos = this.parUT.convertToWorldSpaceAR(localPos) || localPos;
151
+ this.root.worldPosition = worldPos
152
+ // this.root_wg.isAlignBottom = true;
153
+ // this.root_wg.bottom = data.data.DialogPosY //- 1920 * 0.5
154
+ //Log.log(view.getVisibleSize().height)
155
+ }
156
+
157
+ hide() {
158
+ //this.prompt.active = false;
159
+ this.hideNode(false)
160
+ }
161
+
162
+
163
+ hideUI(isShow: boolean) {
164
+ this.root.active = isShow
165
+ }
166
+ hideHard(isShow: boolean) {
167
+ //this.hard.active = isShow;
168
+ this.hard_op.opacity = isShow ? 255 : 0;
169
+ }
170
+
171
+ hideNode(isShow: boolean) {
172
+ //this.hard.active = isShow;
173
+
174
+ if (this.prompt_op)
175
+ this.prompt_op.opacity = isShow ? 255 : 0;
176
+ }
177
+
178
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "199a434a-26a4-4455-8e2f-e60644722498",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,161 @@
1
+ /*
2
+ * @Author: dgflash
3
+ * @Date: 2022-03-23 10:31:06
4
+ * @LastEditors: dgflash
5
+ * @LastEditTime: 2022-09-06 10:13:58
6
+ */
7
+ import * as cc from "cc";
8
+ import { Color } from "cc";
9
+ import { UITransform } from "cc";
10
+ import { Vec3 } from "cc";
11
+ import { Size } from "cc";
12
+ import { Graphics } from "cc";
13
+ import { GraphicsComponent } from "cc";
14
+ import { Sprite } from "cc";
15
+ import { Component, Mask, _decorator } from "cc";
16
+ const { ccclass, property, executeInEditMode, requireComponent } = _decorator;
17
+
18
+ /** 多边形遮罩编辑 */
19
+ @ccclass("PolygonMask")
20
+ @executeInEditMode
21
+ @requireComponent([cc.PolygonCollider2D, cc.Mask])
22
+ export class PolygonMask extends Component {
23
+ /** 遮罩组件 */
24
+ mask: Mask = null!;
25
+ /** 用于编辑器中自定义位置的拖拽操作,如果不用物理引擎时,可考虑换成一个数据结构 */
26
+ polygon: cc.PolygonCollider2D = null!;
27
+ //quan: Sprite;
28
+
29
+ size: { width: number, height: number } = { width: 0, height: 0 }
30
+ /**
31
+ * 0=有对话框 有手
32
+ * 1=仅小手
33
+ * 2=仅对话框
34
+ * 3=都无
35
+ */
36
+ ShowType: number = -1
37
+ onLoad() {
38
+ this.mask = this.getComponent(cc.Mask)!;
39
+ this.polygon = this.getComponent(cc.PolygonCollider2D)!;
40
+ // this.quan = this.node.getChildByName('quan').getComponent(Sprite)!;
41
+ // this.quan.node.parent = this.node.parent;
42
+ // this.quan.node.active = false;
43
+ if (this.mask.type !== cc.Mask.Type.GRAPHICS_STENCIL) {
44
+ cc.error("PolygonMask: mask type must be graphics_stencil");
45
+ return;
46
+ }
47
+
48
+ // 监听 point 修改
49
+ // @ts-ignore
50
+ let old_value = this.polygon["_points"];
51
+ Object.defineProperty(this.polygon, "_points", {
52
+ get: () => old_value,
53
+ set: (new_value) => {
54
+ old_value = new_value;
55
+ // 更新遮罩
56
+ this.draw(0, 0, this.ShowType)
57
+ },
58
+ });
59
+ }
60
+
61
+ /** 绘制遮罩 */
62
+ draw(width: number, height: number, ShowType: number): void {
63
+ if (width > 0) {
64
+ this.size.width = width
65
+ this.size.height = height
66
+ }
67
+ if (ShowType > -1) {
68
+ this.ShowType = ShowType
69
+ }
70
+ this.circle()
71
+ return
72
+ if (this.mask.type !== cc.Mask.Type.GRAPHICS_STENCIL) {
73
+ return;
74
+ }
75
+
76
+ var g: any = this.mask.subComp;
77
+ g.clear();
78
+ g.moveTo(
79
+ this.polygon.points[0].x,
80
+ this.polygon.points[0].y
81
+ );
82
+ for (let k_n = 1; k_n < this.polygon.points.length; ++k_n) {
83
+ g.lineTo(
84
+ this.polygon.points[k_n].x,
85
+ this.polygon.points[k_n].y
86
+ );
87
+ }
88
+ g.close();
89
+ g.stroke();
90
+ g.fill();
91
+ }
92
+
93
+ circle() {
94
+ const value = Math.max(this.size.width, this.size.height)
95
+ // let radius = value * 0.5 + 100;
96
+ // const pos = this.polygon.points[0]
97
+ // const x = pos.x + this.size.width * 0.5
98
+ // const y = pos.y + this.size.height * 0.5
99
+ //this.drawCircle( x, y, radius);
100
+
101
+ // this.quan.node.getComponent(UITransform).contentSize = new Size(radius*2 , radius*2 )
102
+ // this.quan.node.position = new Vec3(x, y, 0)
103
+
104
+ //this.drawCircleWithBlur(0, 0, 200);
105
+
106
+ const radius = 254 * 0.5
107
+ const width = 320 + 30
108
+ const pos = this.polygon.points[0]
109
+ const x = pos.x + this.size.width * 0.5
110
+ const y = pos.y + this.size.height * 0.5
111
+ // const tr = this.node.getComponent(UITransform)
112
+ // tr.anchorX = 0.5
113
+ // tr.anchorY = 0.8
114
+
115
+ // 0 = 有对话框 有手
116
+ // 1 = 仅小手
117
+ // 2 = 仅对话框
118
+ // 3 = 都无
119
+ this.node.position = new Vec3(x, y, 0);
120
+
121
+ switch (this.ShowType) {
122
+ case 0:
123
+ this.drawCircle(0, 0, radius);
124
+ break;
125
+ case 1:
126
+ this.drawCircle(0, 0, radius);
127
+ break;
128
+ case 2:
129
+ this.drawCircle(0, 0, 1);
130
+ break;
131
+ case 3:
132
+ this.drawCircle(0, 0, 1);
133
+ break;
134
+ case 4:
135
+ //this.drawCircle(x, y, radius);
136
+ this.drawCircle(0, 0, radius);
137
+ break;
138
+ default:
139
+ this.drawCircle(0, 0, radius);
140
+ break;
141
+ }
142
+ }
143
+
144
+ /** 绘制圆形遮罩 */
145
+ drawCircle(centerX: number, centerY: number, radius: number): void {
146
+ if (this.mask.type !== cc.Mask.Type.GRAPHICS_STENCIL) {
147
+ return;
148
+ }
149
+
150
+ var g: Graphics = this.mask.subComp as any;
151
+ g.clear();
152
+
153
+ // 使用Canvas的arc方法绘制圆形
154
+ g.circle(centerX, centerY, radius);
155
+
156
+
157
+ g.close();
158
+ g.stroke();
159
+ g.fill();
160
+ }
161
+ }