@cc-component/cc-ex-component 1.7.5 → 1.7.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.
package/assets/core/ViewModel.ts
CHANGED
|
@@ -18,6 +18,8 @@ import { YXCollectionView, YXIndexPath } from '../lib/collectView/lib_collect/yx
|
|
|
18
18
|
import { EventTouch } from 'cc';
|
|
19
19
|
import { YXPagelayout } from '../lib/collectView/lib_collect/yx-page-layout';
|
|
20
20
|
import { SpriteFrame } from 'cc';
|
|
21
|
+
import { tween } from 'cc';
|
|
22
|
+
import { v3 } from 'cc';
|
|
21
23
|
|
|
22
24
|
interface IBindingData extends ITableViewEvents, IBindingDataEvents {
|
|
23
25
|
dataPath: string;
|
|
@@ -202,6 +204,10 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
202
204
|
touch_end = 'CALL_TOUCH_END'
|
|
203
205
|
touch_cancel = 'CALL_TOUCH_CANCEL'
|
|
204
206
|
|
|
207
|
+
touch_start_scale = 'touch_start_scale'
|
|
208
|
+
touch_end_scale = 'touch_end_scale'
|
|
209
|
+
touch_cancel_scale = 'touch_cancel_scale'
|
|
210
|
+
|
|
205
211
|
touch_click = 'CALL_CLICK'
|
|
206
212
|
touch_slide = 'CALL_SLIDE_EVENT'
|
|
207
213
|
touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
@@ -313,6 +319,27 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
313
319
|
refreshData(key: string, value: any) {
|
|
314
320
|
|
|
315
321
|
}
|
|
322
|
+
|
|
323
|
+
resetButtonScale(btn: Button) {
|
|
324
|
+
if (btn.transition === Button.Transition.SCALE && ExComponentModule.EmitAnim()) {
|
|
325
|
+
btn.node.off(Node.EventType.TOUCH_START, btn[this.touch_start_scale]);
|
|
326
|
+
btn.node.off(Node.EventType.TOUCH_END, btn[this.touch_end_scale]);
|
|
327
|
+
btn.node.off(Node.EventType.TOUCH_CANCEL, btn[this.touch_end_scale]);
|
|
328
|
+
const scale = btn.zoomScale;
|
|
329
|
+
btn[this.touch_start_scale] = () => {
|
|
330
|
+
tween(btn.node).to(btn.duration, { scale: v3(scale, scale, scale) }).start()
|
|
331
|
+
}
|
|
332
|
+
btn[this.touch_end_scale] = () => {
|
|
333
|
+
tween(btn.node).to(btn.duration, { scale: v3(1, 1, 1) }).start()
|
|
334
|
+
}
|
|
335
|
+
btn.node.on(Node.EventType.TOUCH_START, btn[this.touch_start_scale])
|
|
336
|
+
btn.node.on(Node.EventType.TOUCH_END, btn[this.touch_end_scale])
|
|
337
|
+
btn.node.on(Node.EventType.TOUCH_CANCEL, btn[this.touch_end_scale])
|
|
338
|
+
btn.transition = Button.Transition.NONE;
|
|
339
|
+
// ExComponentModule.EmitAnim(btn as Button)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
316
343
|
onTouch() {
|
|
317
344
|
const map = bindingMap.get(this.className)
|
|
318
345
|
for (const [propertyKey, value] of map) {
|
|
@@ -328,6 +355,15 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
328
355
|
for (const [propertyKey, value] of map) {
|
|
329
356
|
const com_btn = this[propertyKey];
|
|
330
357
|
if (!com_btn) { continue }
|
|
358
|
+
|
|
359
|
+
if (com_btn[this.touch_start_scale]) {
|
|
360
|
+
com_btn.node.off(Node.EventType.TOUCH_START, com_btn[this.touch_start_scale]);
|
|
361
|
+
com_btn.node.off(Node.EventType.TOUCH_END, com_btn[this.touch_end_scale]);
|
|
362
|
+
com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[this.touch_end_scale]);
|
|
363
|
+
com_btn[this.touch_start_scale] = null
|
|
364
|
+
com_btn[this.touch_end_scale] = null
|
|
365
|
+
|
|
366
|
+
}
|
|
331
367
|
if (com_btn[this.touch_click]) {
|
|
332
368
|
com_btn.node.off(Button.EventType.CLICK, com_btn[this.touch_click]);
|
|
333
369
|
com_btn[this.touch_click] = null
|
|
@@ -371,6 +407,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
371
407
|
|
|
372
408
|
touch(data: IBindingData, com_btn: Component, value: any, self: any) {
|
|
373
409
|
if (data.type === "cc.Button") {
|
|
410
|
+
//(com_btn as Button).duration = 2
|
|
411
|
+
this.resetButtonScale(com_btn as Button)
|
|
374
412
|
const tempData = { value: value, skip: false }
|
|
375
413
|
//点击
|
|
376
414
|
const touch_click = this.touch_click;
|
|
@@ -378,11 +416,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
378
416
|
const sx = data.propertyKey;
|
|
379
417
|
com_btn.node.off(Button.EventType.CLICK, com_btn[touch_click]);
|
|
380
418
|
tempData.skip = true;
|
|
381
|
-
const btnCall = (btn) => {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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
|
+
}
|
|
386
426
|
}
|
|
387
427
|
com_btn[touch_click] = btnCall
|
|
388
428
|
com_btn.node.on(Button.EventType.CLICK, btnCall);
|
|
@@ -392,7 +432,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
392
432
|
if (data.touchStart && !com_btn[touch_start]) {
|
|
393
433
|
com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
|
|
394
434
|
const call_start = (btn) => {
|
|
395
|
-
|
|
435
|
+
if (btn.interactable)
|
|
436
|
+
data.touchStart?.call(self, btn)
|
|
396
437
|
}
|
|
397
438
|
com_btn[touch_start] = call_start
|
|
398
439
|
com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
|
|
@@ -401,7 +442,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
401
442
|
if (data.touchMove && !com_btn[touch_start]) {
|
|
402
443
|
com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
|
|
403
444
|
const call_start = (btn) => {
|
|
404
|
-
|
|
445
|
+
if (btn.interactable)
|
|
446
|
+
data.touchMove?.call(self, btn)
|
|
405
447
|
}
|
|
406
448
|
com_btn[touch_start] = call_start
|
|
407
449
|
com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
|
|
@@ -410,7 +452,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
410
452
|
if (data.touchEnd && !com_btn[touch_start]) {
|
|
411
453
|
com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
|
|
412
454
|
const call_start = (btn) => {
|
|
413
|
-
|
|
455
|
+
if (btn.interactable)
|
|
456
|
+
data.touchEnd?.call(self, btn)
|
|
414
457
|
}
|
|
415
458
|
com_btn[touch_start] = call_start
|
|
416
459
|
com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
|
|
@@ -419,7 +462,8 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
419
462
|
if (data.touchCancel && !com_btn[touch_start]) {
|
|
420
463
|
com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
|
|
421
464
|
const call_start = (btn) => {
|
|
422
|
-
|
|
465
|
+
if (btn.interactable)
|
|
466
|
+
data.touchCancel?.call(self, btn)
|
|
423
467
|
}
|
|
424
468
|
com_btn[touch_start] = call_start
|
|
425
469
|
com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
|
|
@@ -13,6 +13,7 @@ export class ExComponentModule {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
param: { click: (comp: Button) => void }
|
|
16
|
+
paramAnim: { enable: boolean }
|
|
16
17
|
paramSprite: { loadSprite: (param: { bundle: string, path: string }) => Promise<SpriteFrame>, getSprite: (param: { bundle: string, path: string }) => SpriteFrame }
|
|
17
18
|
paramSpine: { loadSpine: (param: { bundle: string, path: string }) => Promise<sp.SkeletonData>, getSpine: (param: { bundle: string, path: string }) => sp.SkeletonData }
|
|
18
19
|
paramUIWindow: { onLoad: (config: any, viewModel: any) => void }
|
|
@@ -22,11 +23,13 @@ export class ExComponentModule {
|
|
|
22
23
|
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
static EnableButtonScale(param: { enable: boolean }) {
|
|
27
|
+
ExComponentModule.Ins.paramAnim = param
|
|
28
|
+
}
|
|
25
29
|
static OnButtonClick(param: { click: (comp: Button) => void }) {
|
|
26
30
|
ExComponentModule.Ins.param = param
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
30
33
|
static ResetBaseWindow(name?: string, isGet?: boolean) {
|
|
31
34
|
if (!isGet) ExComponentModule.Ins.ResetBaseWindow = name
|
|
32
35
|
return ExComponentModule.Ins.ResetBaseWindow
|
|
@@ -46,6 +49,9 @@ export class ExComponentModule {
|
|
|
46
49
|
static Emit(btn: Button) {
|
|
47
50
|
ExComponentModule.Ins.param.click(btn)
|
|
48
51
|
}
|
|
52
|
+
static EmitAnim() {
|
|
53
|
+
return ExComponentModule.Ins.paramAnim?.enable
|
|
54
|
+
}
|
|
49
55
|
|
|
50
56
|
static async EmitLoadSprite(param: any): Promise<SpriteFrame> {
|
|
51
57
|
return ExComponentModule.Ins.paramSprite?.loadSprite?.(param)
|
|
@@ -2,10 +2,23 @@ import { SpriteFrame } from "cc";
|
|
|
2
2
|
import { sp } from "cc";
|
|
3
3
|
import { Sprite } from "cc";
|
|
4
4
|
import { Button } from "cc";
|
|
5
|
+
interface IConfig {
|
|
6
|
+
module: string,
|
|
7
|
+
layer: string,
|
|
8
|
+
path: string,
|
|
9
|
+
bundle: string,
|
|
10
|
+
name?: string,/**窗口名称 */
|
|
11
|
+
index?: number,
|
|
12
|
+
is_load_sub?: boolean,
|
|
13
|
+
/**是否记录-不记录可重复打开窗口 */
|
|
14
|
+
is_record?: boolean,
|
|
15
|
+
}
|
|
5
16
|
declare global {
|
|
6
17
|
namespace ExComponentModule {
|
|
7
18
|
/**初始化 */
|
|
8
19
|
function Init();
|
|
20
|
+
/**开启按钮缩放 */
|
|
21
|
+
function EnableButtonScale(param: { enable: boolean });
|
|
9
22
|
/**监听所有按钮的点击事件 */
|
|
10
23
|
function OnButtonClick(param: { click: (comp: Button) => void });
|
|
11
24
|
/**监听加载图片 */
|
|
@@ -14,37 +27,15 @@ declare global {
|
|
|
14
27
|
/**重置基础窗口 */
|
|
15
28
|
function ResetBaseWindow(name?: string, isGet?: boolean);
|
|
16
29
|
/**监听UI onLoad 给模块manager 赋值 */
|
|
17
|
-
function OnVMManager(param: {
|
|
18
|
-
onLoad: (config: {
|
|
19
|
-
module: string,
|
|
20
|
-
layer: string,
|
|
21
|
-
path: string,
|
|
22
|
-
bundle: string,
|
|
23
|
-
name?: string,/**窗口名称 */
|
|
24
|
-
index?: number,
|
|
25
|
-
is_load_sub?: boolean,
|
|
26
|
-
/**是否记录-不记录可重复打开窗口 */
|
|
27
|
-
is_record?: boolean,
|
|
28
|
-
}, viewModel: any) => void
|
|
29
|
-
});
|
|
30
|
+
function OnVMManager(param: { onLoad: (config: IConfig, viewModel: any) => void });
|
|
30
31
|
/**组件:内部使用方法 */
|
|
31
32
|
function Emit(btn: Button);
|
|
33
|
+
function EmitAnim();
|
|
32
34
|
//#region 组件:内部使用方法----------------
|
|
33
35
|
function EmitLoadSprite(param: any): Promise<SpriteFrame>;
|
|
34
36
|
function EmitGetSprite(param: any): SpriteFrame;
|
|
35
37
|
function EmitLoadSpine(param: any): Promise<sp.SkeletonData>;
|
|
36
38
|
function EmitGetSpine(param: any): sp.SkeletonData;
|
|
37
|
-
function EmitUIWindow(param:
|
|
38
|
-
module: string,
|
|
39
|
-
layer: string,
|
|
40
|
-
path: string,
|
|
41
|
-
bundle: string,
|
|
42
|
-
name?: string,/**窗口名称 */
|
|
43
|
-
name_ui?: string,/**窗口名称 */
|
|
44
|
-
index?: number,
|
|
45
|
-
is_load_sub?: boolean,
|
|
46
|
-
/**是否记录-不记录可重复打开窗口 */
|
|
47
|
-
is_record?: boolean,
|
|
48
|
-
}, viewModel: any);
|
|
39
|
+
function EmitUIWindow(param: IConfig, viewModel: any);
|
|
49
40
|
}
|
|
50
41
|
}
|