@cc-component/cc-ex-component 1.7.6 → 1.7.8
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/assets/core/ViewModel.ts +15 -9
- package/assets/ex/ExCommon.ts +29 -0
- package/package.json +1 -1
package/assets/core/ViewModel.ts
CHANGED
|
@@ -416,11 +416,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
416
416
|
const sx = data.propertyKey;
|
|
417
417
|
com_btn.node.off(Button.EventType.CLICK, com_btn[touch_click]);
|
|
418
418
|
tempData.skip = true;
|
|
419
|
-
const btnCall = (btn) => {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
419
|
+
const btnCall = (btn: Button) => {
|
|
420
|
+
if (btn.interactable) {
|
|
421
|
+
tempData.value = btn.node.active
|
|
422
|
+
self.viewModel[sx] = tempData
|
|
423
|
+
data.event?.call(self)
|
|
424
|
+
self[`onClick_${sx}`]?.(btn)
|
|
425
|
+
}
|
|
424
426
|
}
|
|
425
427
|
com_btn[touch_click] = btnCall
|
|
426
428
|
com_btn.node.on(Button.EventType.CLICK, btnCall);
|
|
@@ -430,7 +432,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
430
432
|
if (data.touchStart && !com_btn[touch_start]) {
|
|
431
433
|
com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
|
|
432
434
|
const call_start = (btn) => {
|
|
433
|
-
|
|
435
|
+
if (btn.interactable)
|
|
436
|
+
data.touchStart?.call(self, btn)
|
|
434
437
|
}
|
|
435
438
|
com_btn[touch_start] = call_start
|
|
436
439
|
com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
|
|
@@ -439,7 +442,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
439
442
|
if (data.touchMove && !com_btn[touch_start]) {
|
|
440
443
|
com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
|
|
441
444
|
const call_start = (btn) => {
|
|
442
|
-
|
|
445
|
+
if (btn.interactable)
|
|
446
|
+
data.touchMove?.call(self, btn)
|
|
443
447
|
}
|
|
444
448
|
com_btn[touch_start] = call_start
|
|
445
449
|
com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
|
|
@@ -448,7 +452,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
448
452
|
if (data.touchEnd && !com_btn[touch_start]) {
|
|
449
453
|
com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
|
|
450
454
|
const call_start = (btn) => {
|
|
451
|
-
|
|
455
|
+
if (btn.interactable)
|
|
456
|
+
data.touchEnd?.call(self, btn)
|
|
452
457
|
}
|
|
453
458
|
com_btn[touch_start] = call_start
|
|
454
459
|
com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
|
|
@@ -457,7 +462,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
457
462
|
if (data.touchCancel && !com_btn[touch_start]) {
|
|
458
463
|
com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
|
|
459
464
|
const call_start = (btn) => {
|
|
460
|
-
|
|
465
|
+
if (btn.interactable)
|
|
466
|
+
data.touchCancel?.call(self, btn)
|
|
461
467
|
}
|
|
462
468
|
com_btn[touch_start] = call_start
|
|
463
469
|
com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
|
package/assets/ex/ExCommon.ts
CHANGED
|
@@ -171,6 +171,16 @@ declare module 'cc' {
|
|
|
171
171
|
* 确保组件存在 不存在则添加
|
|
172
172
|
*/
|
|
173
173
|
ensureComponent<T extends Component>(className: string): T;
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
interface Button {
|
|
178
|
+
/**
|
|
179
|
+
* 禁用按钮
|
|
180
|
+
* @param enable
|
|
181
|
+
* @param time 禁用后xx秒后恢复,不传一直禁用
|
|
182
|
+
*/
|
|
183
|
+
enable(enable: boolean, time?: number): void;
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
interface Animation {
|
|
@@ -642,6 +652,25 @@ Node.prototype.enable = function (this: Node, enable: boolean, time?: number): v
|
|
|
642
652
|
}
|
|
643
653
|
};
|
|
644
654
|
|
|
655
|
+
Button.prototype.enable = function (this: Button, enable: boolean, time?: number): void {
|
|
656
|
+
if (this.isValid) {
|
|
657
|
+
const btn = this
|
|
658
|
+
if (btn) {
|
|
659
|
+
if (time) {
|
|
660
|
+
btn.interactable = enable;
|
|
661
|
+
if (!enable) {
|
|
662
|
+
setTimeout(() => {
|
|
663
|
+
if (btn && btn.isValid)
|
|
664
|
+
btn.interactable = true;
|
|
665
|
+
}, time)
|
|
666
|
+
}
|
|
667
|
+
} else {
|
|
668
|
+
btn.interactable = enable;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
|
|
645
674
|
Node.prototype.touchStartAnim = function (this: Node, scale?: number, time?: number): void {
|
|
646
675
|
if (this.isValid) {
|
|
647
676
|
const btn = this
|