@cc-component/cc-ex-component 1.7.4 → 1.7.6
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { UIOpacity, tween, Vec3 } from 'cc';
|
|
2
2
|
import { _decorator, Component, Node } from 'cc';
|
|
3
3
|
import { BaseReference } from './BaseReference';
|
|
4
|
+
import { UITransform } from 'cc';
|
|
5
|
+
import { view } from 'cc';
|
|
6
|
+
import { Widget } from 'cc';
|
|
4
7
|
const { ccclass, property } = _decorator;
|
|
5
8
|
|
|
6
9
|
@ccclass('BaseWindow')
|
|
@@ -27,6 +30,9 @@ export class BaseWindow extends BaseReference {
|
|
|
27
30
|
protected onLoad(): void {
|
|
28
31
|
this.maskOpacity = this.node.getChildByName('mask')?.getComponent(UIOpacity)
|
|
29
32
|
this.root = this.node.getChildByName('root')
|
|
33
|
+
this.resetMaskSize()
|
|
34
|
+
this.maskAinm(true)
|
|
35
|
+
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
/**
|
|
@@ -46,6 +52,7 @@ export class BaseWindow extends BaseReference {
|
|
|
46
52
|
* @param param.time 关闭的按钮的时间
|
|
47
53
|
*/
|
|
48
54
|
public pop(param?: { is_anim?: boolean, param?: any, finish?: Function }) {
|
|
55
|
+
//this.maskAinm(false)
|
|
49
56
|
this.paramClose = param;
|
|
50
57
|
this.param?.callBack?.(param?.param)//回调方法
|
|
51
58
|
if (param?.is_anim && this.root && this.maskOpacity) {
|
|
@@ -61,8 +68,6 @@ export class BaseWindow extends BaseReference {
|
|
|
61
68
|
/**打开动画-可重写动画*/
|
|
62
69
|
public showAnim() {
|
|
63
70
|
this.root.setScale(0.001, 0.001);
|
|
64
|
-
this.maskOpacity.opacity = 0;
|
|
65
|
-
tween(this.maskOpacity).to(0.2, { opacity: 255 }).start()
|
|
66
71
|
tween(this.root)
|
|
67
72
|
.to(0.068, { scale: new Vec3(1.15, 1.15, 1.15) })
|
|
68
73
|
.to(0.088, { scale: new Vec3(0.88, 0.88, 0.88) })
|
|
@@ -71,7 +76,6 @@ export class BaseWindow extends BaseReference {
|
|
|
71
76
|
}
|
|
72
77
|
/**关闭动画-可重写动画*/
|
|
73
78
|
public hideAnim() {
|
|
74
|
-
tween(this.maskOpacity).to(0.2, { opacity: 0 }).start()
|
|
75
79
|
//销毁动画
|
|
76
80
|
tween(this.root)
|
|
77
81
|
.to(0.1, { scale: new Vec3(1.028, 1.028, 1.028) })
|
|
@@ -86,11 +90,27 @@ export class BaseWindow extends BaseReference {
|
|
|
86
90
|
this.paramClose?.param?.finish()
|
|
87
91
|
setTimeout(() => { if (this.node && this.node.isValid) { this.destroyWindow() } });
|
|
88
92
|
}
|
|
93
|
+
maskAinm(show: boolean) {
|
|
94
|
+
if (!this.maskOpacity) return
|
|
95
|
+
if (show) {
|
|
96
|
+
this.maskOpacity.opacity = 0;
|
|
97
|
+
tween(this.maskOpacity).to(0.2, { opacity: 255 }).start()
|
|
98
|
+
} else {
|
|
99
|
+
tween(this.maskOpacity).to(0.2, { opacity: 0 }).start()
|
|
100
|
+
}
|
|
101
|
+
}
|
|
89
102
|
/**关闭事件-当系统级关闭所有打开的界面时。如果关闭界面时需要执行自己的业务逻辑,重写此方法
|
|
90
103
|
* eventName:关闭方法名称
|
|
91
104
|
* param:参数
|
|
92
105
|
*/
|
|
93
106
|
closeEvent(): { eventName: string, param?: any } { return null }
|
|
107
|
+
|
|
108
|
+
resetMaskSize() {
|
|
109
|
+
if (!this.maskOpacity) return
|
|
110
|
+
const widget = this.maskOpacity.node.getComponent(Widget);
|
|
111
|
+
widget.left = -view.getVisibleSize().width
|
|
112
|
+
widget.right = -view.getVisibleSize().width
|
|
113
|
+
}
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
|
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;
|
|
@@ -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
|
}
|