@cc-component/cc-ex-component 1.3.4 → 1.3.7

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.
@@ -39,7 +39,7 @@ export class BaseWindow extends BaseReference {
39
39
  * @param param.comp 关闭的按钮组件
40
40
  * @param param.time 关闭的按钮的时间
41
41
  */
42
- public close(param?: { is_anim?: boolean, param?: any, finish?: Function }) {
42
+ public pop(param?: { is_anim?: boolean, param?: any, finish?: Function }) {
43
43
  this.paramClose = param;
44
44
  this.param?.callBack?.(param?.param)//回调方法
45
45
  if (param?.is_anim && this.root && this.maskOpacity) {
@@ -265,7 +265,7 @@ export class ReferenceComponent extends Component {
265
265
 
266
266
  eventStr += `
267
267
  ${pix}${name}(comp: ${type === "ToggleContainer" ? "Toggle" : type}) {
268
-
268
+ ${name === 'close' ? ' super.pop()' : ''}
269
269
  }\n`
270
270
 
271
271
  }
@@ -348,6 +348,7 @@ ${sx_this}
348
348
  let importStr = `
349
349
  import { Label, RichText, ProgressBar, Sprite, EditBox, Toggle, Slider, ToggleContainer, Button, math, SpriteFrame, _decorator , Node} from 'cc';
350
350
  import { ViewModel, BindViewModel, BindTable, BindCollect, Bind, Ref, BaseViewModelData, YXCollectionView, YXFlowLayout, TableView, BaseWindow } from 'db://assets/pkg-export/@cc-component/cc-ex-component';
351
+ import { ${this.baseWindowName}} } from 'db://assets/start/Interface/custom/${this.baseWindowName}';
351
352
  const { ccclass, property } = _decorator;`
352
353
 
353
354
  if (this.isComDebug) {
@@ -87,6 +87,7 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
87
87
  if (!bindingMap.has(className)) {
88
88
  bindingMap.set(className, new Map());
89
89
  }
90
+ this.className = className;
90
91
  //console.log('onLoad我的', this.node.name)
91
92
  if (!this._bindings) this._bindings = [];
92
93
 
@@ -192,8 +193,17 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
192
193
  return class extends Base {
193
194
  // 绑定关系存储
194
195
  _bindings: { uiProp: string; dataPath: string }[] = [];
195
-
196
196
  viewModel: any
197
+ touch_start = 'CALL_TOUCH_START'
198
+ touch_move = 'CALL_TOUCH_MOVE'
199
+ touch_end = 'CALL_TOUCH_END'
200
+ touch_cancel = 'CALL_TOUCH_CANCEL'
201
+
202
+ touch_click = 'CALL_CLICK'
203
+ touch_slide = 'CALL_SLIDE_EVENT'
204
+ touch_toggle = 'CALL_TOGGLE_EVENT'
205
+ touch_editbox = 'CALL_EDITBOX_EVENT'
206
+ className: string = ''
197
207
  // 创建响应式数据
198
208
  _makeReactive<T extends object>(obj: T, pathPrefix: string): T {
199
209
  const self = this as any;
@@ -266,6 +276,181 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
266
276
  }
267
277
 
268
278
 
279
+
280
+ protected onEnable(): void {
281
+ this.onTouch()
282
+ }
283
+
284
+ protected onDisable(): void {
285
+ this.offTouch()
286
+ }
287
+
288
+ onTouch() {
289
+ const map = bindingMap.get(this.className)
290
+ for (const [propertyKey, value] of map) {
291
+ const com = this[propertyKey];
292
+ const value_data = this._getNestedValue(this, value.dataPath);
293
+ const data = map.get(propertyKey)
294
+ this.touch(data, com, value_data, this);
295
+ }
296
+ }
297
+
298
+ offTouch() {
299
+ const map = bindingMap.get(this.className)
300
+ for (const [propertyKey, value] of map) {
301
+ const com_btn = this[propertyKey];
302
+ if (com_btn[this.touch_click]) {
303
+ com_btn.node.off(Button.EventType.CLICK, com_btn[this.touch_click]);
304
+ com_btn[this.touch_click] = null
305
+ }
306
+ if (com_btn[this.touch_start]) {
307
+ com_btn.node.off(Node.EventType.TOUCH_START, com_btn[this.touch_start]);
308
+ com_btn[this.touch_start] = null
309
+ }
310
+ if (com_btn[this.touch_move]) {
311
+ com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[this.touch_move]);
312
+ com_btn[this.touch_move] = null
313
+ }
314
+ if (com_btn[this.touch_end]) {
315
+ com_btn.node.off(Node.EventType.TOUCH_END, com_btn[this.touch_end]);
316
+ com_btn[this.touch_end] = null
317
+ }
318
+
319
+ if (com_btn[this.touch_cancel]) {
320
+ com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[this.touch_cancel]);
321
+ com_btn[this.touch_cancel] = null
322
+ }
323
+
324
+ if (com_btn[this.touch_slide]) {
325
+ com_btn.node.off("slide", com_btn[this.touch_slide], this)
326
+ com_btn[this.touch_slide] = null
327
+ }
328
+
329
+ if (com_btn[this.touch_toggle]) {
330
+ com_btn.node.off(Toggle.EventType.TOGGLE, com_btn[this.touch_toggle], self)
331
+ com_btn[this.touch_toggle] = null
332
+ }
333
+
334
+ if (com_btn[this.touch_editbox]) {
335
+ com_btn.node.off("text-changed", com_btn[this.touch_editbox], self)
336
+ com_btn[this.touch_editbox] = null
337
+ }
338
+
339
+ }
340
+ }
341
+
342
+
343
+ touch(data: IBindingData, com_btn: Component, value: any, self: any) {
344
+ if (data.type === "cc.Button") {
345
+ const tempData = { value: value, skip: false }
346
+ //点击
347
+ const touch_click = this.touch_click;
348
+ if (!com_btn[touch_click]) {
349
+ const sx = data.propertyKey;
350
+ com_btn.node.off(Button.EventType.CLICK, com_btn[touch_click]);
351
+ tempData.skip = true;
352
+ const btnCall = (btn) => {
353
+ tempData.value = btn.node.active
354
+ self.viewModel[sx] = tempData
355
+ data.event?.(self)
356
+ self[`onClick_${sx}`]?.(btn)
357
+ }
358
+ com_btn[touch_click] = btnCall
359
+ com_btn.node.on(Button.EventType.CLICK, btnCall);
360
+ }
361
+ //事件
362
+ let touch_start = this.touch_start
363
+ if (data.touchStart && !com_btn[touch_start]) {
364
+ com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
365
+ const call_start = (btn) => {
366
+ data.touchStart?.(self, btn)
367
+ }
368
+ com_btn[touch_start] = call_start
369
+ com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
370
+ }
371
+ touch_start = this.touch_move
372
+ if (data.touchMove && !com_btn[touch_start]) {
373
+ com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
374
+ const call_start = (btn) => {
375
+ data.touchMove?.(self, btn)
376
+ }
377
+ com_btn[touch_start] = call_start
378
+ com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
379
+ }
380
+ touch_start = this.touch_end
381
+ if (data.touchEnd && !com_btn[touch_start]) {
382
+ com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
383
+ const call_start = (btn) => {
384
+ data.touchEnd?.(self, btn)
385
+ }
386
+ com_btn[touch_start] = call_start
387
+ com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
388
+ }
389
+ touch_start = this.touch_cancel
390
+ if (data.touchCancel && !com_btn[touch_start]) {
391
+ com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
392
+ const call_start = (btn) => {
393
+ data.touchCancel?.(self, btn)
394
+ }
395
+ com_btn[touch_start] = call_start
396
+ com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
397
+ }
398
+ }
399
+ else if (data.type === 'cc.Slider') {
400
+ const tempData = { value: value, skip: false }
401
+ //事件
402
+ const touch_click = this.touch_slide
403
+ if (!com_btn[touch_click]) {
404
+ const sx = data.propertyKey;
405
+ com_btn.node.off("slide", com_btn[touch_click], self)
406
+ tempData.skip = true;
407
+ const slideCall = (slider) => {
408
+ tempData.value = slider.progress
409
+ self.viewModel[sx] = tempData
410
+ data.event?.(self)
411
+ self[`onClick_${sx}`]?.(slider)
412
+ }
413
+ com_btn[touch_click] = slideCall
414
+ com_btn.node.on('slide', slideCall, self);
415
+ }
416
+ }
417
+ else if (data.type === 'cc.Toggle') {
418
+ const tempData = { value: value, skip: false }
419
+ //事件
420
+ const touch_click = this.touch_toggle
421
+ if (!com_btn[touch_click]) {
422
+ const sx = data.propertyKey;
423
+ com_btn.node.off(Toggle.EventType.TOGGLE, com_btn[touch_click], self)
424
+ tempData.skip = true;
425
+ const toggleCall = (toggle) => {
426
+ tempData.value = toggle.isChecked
427
+ self.viewModel[sx] = tempData
428
+ data.event?.(self)
429
+ self[`onClick_${sx}`]?.(toggle)
430
+ }
431
+ com_btn[touch_click] = toggleCall
432
+ com_btn.node.on(Toggle.EventType.TOGGLE, toggleCall, self);
433
+ }
434
+ }
435
+ else if (data.type === 'cc.EditBox') {
436
+ const tempData = { value: value, skip: false }
437
+ //事件
438
+ const touch_click = this.touch_editbox
439
+ if (!com_btn[touch_click]) {
440
+ const sx = data.propertyKey;
441
+ com_btn.node.off("text-changed", com_btn[touch_click], self)
442
+ tempData.skip = true;
443
+ const ebCall = (editbox: EditBox) => {
444
+ tempData.value = editbox.textLabel.string
445
+ self.viewModel[sx] = tempData
446
+ data.event?.(self)
447
+ self[`onClick_${sx}`]?.(editbox)
448
+ }
449
+ com_btn[touch_click] = ebCall
450
+ com_btn.node.on('text-changed', ebCall, self);
451
+ }
452
+ }
453
+ }
269
454
  };
270
455
  }
271
456
 
@@ -303,61 +488,6 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
303
488
  data.reset(self, value, com);
304
489
  } else
305
490
  com_btn.node.active = value ?? true;
306
-
307
- //事件点击
308
-
309
- const touch_click = 'CallClick'
310
- if (!com_btn[touch_click]) {
311
- const sx = data.propertyKey;
312
- com_btn.node.off(Button.EventType.CLICK, com_btn[touch_click]);
313
- tempData.skip = true;
314
- const btnCall = (btn) => {
315
- tempData.value = btn.node.active
316
- self.viewModel[sx] = tempData
317
- data.event?.(self)
318
- self[`onClick_${sx}`]?.(btn)
319
- }
320
- com_btn[touch_click] = btnCall
321
- com_btn.node.on(Button.EventType.CLICK, btnCall);
322
- }
323
-
324
- //touch
325
- let touch_start = 'CALL_TOUCH_START'
326
- if (data.touchStart && !com_btn[touch_start]) {
327
- com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
328
- const call_start = (btn) => {
329
- data.touchStart?.(self, btn)
330
- }
331
- com_btn[touch_start] = call_start
332
- com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
333
- }
334
- touch_start = 'CALL_TOUCH_MOVE'
335
- if (data.touchMove && !com_btn[touch_start]) {
336
- com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
337
- const call_start = (btn) => {
338
- data.touchMove?.(self, btn)
339
- }
340
- com_btn[touch_start] = call_start
341
- com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
342
- }
343
- touch_start = 'CALL_TOUCH_END'
344
- if (data.touchEnd && !com_btn[touch_start]) {
345
- com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
346
- const call_start = (btn) => {
347
- data.touchEnd?.(self, btn)
348
- }
349
- com_btn[touch_start] = call_start
350
- com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
351
- }
352
- touch_start = 'CALL_TOUCH_CANCEL'
353
- if (data.touchCancel && !com_btn[touch_start]) {
354
- com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
355
- const call_start = (btn) => {
356
- data.touchCancel?.(self, btn)
357
- }
358
- com_btn[touch_start] = call_start
359
- com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
360
- }
361
491
  break;
362
492
  case 'cc.ProgressBar':
363
493
  if (data.reset) {
@@ -378,22 +508,6 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
378
508
  data.reset(self, value, com);
379
509
  } else
380
510
  if (value != undefined && value !== null) com_sld.progress = Number(value) || 0;
381
-
382
- //事件
383
- const touch_click = 'slideCall'
384
- if (!com_sld[touch_click]) {
385
- const sx = data.propertyKey;
386
- com_sld.node.off("slide", com_sld[touch_click], self)
387
- tempData.skip = true;
388
- const slideCall = (slider) => {
389
- tempData.value = slider.progress
390
- self.viewModel[sx] = tempData
391
- data.event?.(self)
392
- self[`onClick_${sx}`]?.(slider)
393
- }
394
- com_sld[touch_click] = slideCall
395
- com_sld.node.on('slide', slideCall, self);
396
- }
397
511
  }
398
512
  break;
399
513
  case 'cc.Toggle':
@@ -403,22 +517,6 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
403
517
  data.reset(self, value, com);
404
518
  } else
405
519
  if (value != undefined && value !== null) com_tg.isChecked = Boolean(value);
406
-
407
- //事件
408
- const touch_click = 'toggleCall'
409
- if (!com_tg[touch_click]) {
410
- const sx = data.propertyKey;
411
- com_tg.node.off(Toggle.EventType.TOGGLE, com_tg[touch_click], self)
412
- tempData.skip = true;
413
- const toggleCall = (toggle) => {
414
- tempData.value = toggle.isChecked
415
- self.viewModel[sx] = tempData
416
- data.event?.(self)
417
- self[`onClick_${sx}`]?.(toggle)
418
- }
419
- com_tg[touch_click] = toggleCall
420
- com_tg.node.on(Toggle.EventType.TOGGLE, toggleCall, self);
421
- }
422
520
  }
423
521
  break;
424
522
  case 'cc.EditBox':
@@ -428,22 +526,6 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
428
526
  data.reset(self, value, com);
429
527
  } else
430
528
  if (value != undefined && value !== null) com_eb.string = value?.toString() || '';
431
-
432
- //事件
433
- const touch_click = 'ebCall'
434
- if (!com_eb[touch_click]) {
435
- const sx = data.propertyKey;
436
- com_eb.node.off("text-changed", com_eb[touch_click], self)
437
- tempData.skip = true;
438
- const ebCall = (editbox: EditBox) => {
439
- tempData.value = editbox.textLabel.string
440
- self.viewModel[sx] = tempData
441
- data.event?.(self)
442
- self[`onClick_${sx}`]?.(editbox)
443
- }
444
- com_eb[touch_click] = ebCall
445
- com_eb.node.on('text-changed', ebCall, self);
446
- }
447
529
  }
448
530
  break;
449
531
  case 'cc.ToggleContainer':
@@ -452,7 +534,6 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
452
534
  if (data.reset) {
453
535
  data.reset(self, value, com);
454
536
  }
455
-
456
537
  //事件
457
538
  if (com_tgc.checkEvents.length <= 0) {
458
539
  const sx = data.propertyKey;
@@ -6,6 +6,7 @@ import { TweenManager } from "./ExTween";
6
6
  import { Slider } from "cc";
7
7
  import { ProgressBar, tween, Sprite, view, v3, Button, Label, Animation } from "cc";
8
8
  import { Color } from "cc";
9
+ import { EventTouch } from "cc";
9
10
 
10
11
  declare global {
11
12
  interface String {
@@ -632,11 +633,13 @@ sp.Skeleton.prototype.fromHEX = function (this: sp.Skeleton, hex: string): void
632
633
  // 保存原始方法
633
634
  const originalOnTouchEnded = Button.prototype["_onTouchEnded"];
634
635
  // 重写 _onTouchEnded
635
- Button.prototype["_onTouchEnded"] = function (...args: any[]) {
636
+ Button.prototype["_onTouchEnded"] = function (event: EventTouch) {
636
637
  // 播放点击音效
637
638
  ExComponentModule.Emit(this);
639
+ this.node.emit('click', this)
638
640
  // 调用原始逻辑
639
- return originalOnTouchEnded.apply(this, args);
641
+ // EventHandler.emitEvents(this.clickEvents, event);
642
+ return originalOnTouchEnded.call(this, event);
640
643
  };
641
644
 
642
645
  export { };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "name": "@cc-component/cc-ex-component",
3
- "version": "1.3.4",
4
- "engine": ">=3.8.6",
5
- "description": "系统组件添加常用扩展方法",
6
- "main": "index.ts",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "https://gitee.com/YangFanHome/cc-ex-component"
13
- },
14
- "publishConfig": {
15
- "access": "public",
16
- "registry": "https://registry.npmjs.org"
17
- },
18
- "license": "MIT"
1
+ {
2
+ "name": "@cc-component/cc-ex-component",
3
+ "version": "1.3.7",
4
+ "engine": ">=3.8.6",
5
+ "description": "系统组件添加常用扩展方法",
6
+ "main": "index.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://gitee.com/YangFanHome/cc-ex-component"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org"
17
+ },
18
+ "license": "MIT"
19
19
  }