@cc-component/cc-ex-component 1.3.0 → 1.3.2

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.
@@ -0,0 +1,90 @@
1
+ import { UIOpacity, tween, Vec3 } from 'cc';
2
+ import { _decorator, Component, Node } from 'cc';
3
+ import { BaseReference } from './BaseReference';
4
+ import { Button } from 'cc';
5
+ const { ccclass, property } = _decorator;
6
+
7
+ @ccclass('BaseWindow')
8
+ export class BaseWindow extends BaseReference {
9
+ maskOpacity: UIOpacity;
10
+ root: Node;
11
+ /**关闭事件-当系统级关闭所有打开的界面时。如果关闭界面时需要执行自己的业务逻辑,使用此属性
12
+ * eventName:关闭方法名称
13
+ * param:参数
14
+ */
15
+ closeEvent: { eventName: string, param?: any };
16
+ /**参数*/
17
+ param: any;
18
+ /**关闭参数 */
19
+ paramClose: { is_anim?: boolean, param?: any, finish?: Function };
20
+
21
+ protected onLoad(): void {
22
+ this.maskOpacity = this.node.getChildByName('mask')?.getComponent(UIOpacity)
23
+ this.root = this.node.getChildByName('root')
24
+ }
25
+
26
+ /**
27
+ * 显示弹窗特效(主动调用)
28
+ */
29
+ public open() {
30
+ if (!this.root || !this.maskOpacity) { return }
31
+ this.showAnim()
32
+ }
33
+ /**
34
+ * 关闭界面
35
+ * @param param
36
+ * @param param.is_anim 是否有动画
37
+ * @param param.param 关闭参数
38
+ * @param param.finish 关闭完成回调
39
+ * @param param.comp 关闭的按钮组件
40
+ * @param param.time 关闭的按钮的时间
41
+ */
42
+ public close(param?: { is_anim?: boolean, param?: any, finish?: Function }) {
43
+ this.paramClose = param;
44
+ this.param?.callBack?.(param?.param)//回调方法
45
+ if (param?.is_anim && this.root && this.maskOpacity) {
46
+ this.hideAnim()
47
+ } else {
48
+ param?.finish?.()
49
+ this.destroyWindow()
50
+ }
51
+ }
52
+
53
+ destroyWindow() { this.node.destroy(); }
54
+
55
+ /**打开动画-可重写动画*/
56
+ public showAnim() {
57
+ this.root.setScale(0.001, 0.001);
58
+ this.maskOpacity.opacity = 0;
59
+ tween(this.maskOpacity).to(0.2, { opacity: 255 }).start()
60
+ tween(this.root)
61
+ .to(0.068, { scale: new Vec3(1.15, 1.15, 1.15) })
62
+ .to(0.088, { scale: new Vec3(0.88, 0.88, 0.88) })
63
+ .to(0.088, { scale: new Vec3(1, 1, 1) })
64
+ .start();
65
+ }
66
+ /**关闭动画-可重写动画*/
67
+ public hideAnim() {
68
+ tween(this.maskOpacity).to(0.2, { opacity: 0 }).start()
69
+ //销毁动画
70
+ tween(this.root)
71
+ .to(0.1, { scale: new Vec3(1.028, 1.028, 1.028) })
72
+ .to(0.1, { scale: new Vec3(0.001, 0.001, 0.001) })
73
+ .call(() => {
74
+ this.paramClose.param?.finish()
75
+ setTimeout(() => { if (this.node && this.node.isValid) { this.destroyWindow() } });
76
+ })
77
+ .start();
78
+ }
79
+ }
80
+
81
+
82
+
83
+ // BaseWindow.ts
84
+ // export function BaseWindowMixin<T extends new (...args: any[]) => Component>(Base: T) {
85
+ // return class extends Base {
86
+ // show() { /* 你的显示逻辑 */ }
87
+ // close() { /* 你的关闭逻辑 */ }
88
+ // // ... 其他方法
89
+ // };
90
+ // }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "739e9cf6-12f0-43c6-93af-edd2d8705a29",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -27,7 +27,6 @@ export class ReferenceComponent extends Component {
27
27
  @property({ displayName: "复制属性" })
28
28
  private get refresh() { return this._refresh; }
29
29
  private set refresh(val: boolean) {
30
- console.error('打印了')
31
30
  if (EDITOR_NOT_IN_PREVIEW) {
32
31
  this.initNodeList();
33
32
  this.genCode();
@@ -85,6 +84,8 @@ export class ReferenceComponent extends Component {
85
84
  comList2 = ["YXCollectionView", "TableView"]
86
85
  comList_base = ["EditBox", "Toggle", "ToggleContainer", "Slider", "Button", "ProgressBar"]
87
86
 
87
+ /** 生成代码基础窗口名称 */
88
+ public baseWindowName = "BaseWindow"
88
89
  skipList = ["Button"]//跳过按钮类型
89
90
  protected onLoad(): void {
90
91
  if (EDITOR_NOT_IN_PREVIEW) {//处理编辑器逻辑
@@ -343,9 +344,10 @@ ${sx_this}
343
344
  /** 生成引用节点的获取代码 并复制到剪切板 */
344
345
  private genCodeVmDataAll() {
345
346
  if (!EDITOR_NOT_IN_PREVIEW) return;
347
+ this.baseWindowName = ExComponentModule.ResetBaseWindow('', true)
346
348
  let importStr = `
347
349
  import { Label, RichText, ProgressBar, Sprite, EditBox, Toggle, Slider, ToggleContainer, Button, math, SpriteFrame, _decorator , Node} from 'cc';
348
- import { ViewModel, BindViewModel, BindTable, BindCollect, Bind, Ref, BaseViewModelData, YXCollectionView, YXFlowLayout, TableView, BaseReference } from 'db://assets/pkg-export/@cc-component/cc-ex-component';
350
+ import { ViewModel, BindViewModel, BindTable, BindCollect, Bind, Ref, BaseViewModelData, YXCollectionView, YXFlowLayout, TableView, BaseWindow } from 'db://assets/pkg-export/@cc-component/cc-ex-component';
349
351
  const { ccclass, property } = _decorator;`
350
352
 
351
353
  if (this.isComDebug) {
@@ -378,7 +380,7 @@ const { ccclass, property } = _decorator;
378
380
  const classView = `
379
381
  @BindViewModel(${className}Data)
380
382
  @ccclass('${className}')
381
- export class ${className} extends ViewModel(BaseReference) {${sx.text}\n${onload}\n\n${sx.event}\n}`
383
+ export class ${className} extends ViewModel(${this.baseWindowName}) {${sx.text}\n${onload}\n\n${sx.event}\n}`
382
384
 
383
385
  text += classView
384
386
 
@@ -119,6 +119,11 @@ declare module 'cc' {
119
119
  fromHEX(hex: string);
120
120
  }
121
121
  interface Node {
122
+ /**
123
+ * 禁用按钮
124
+ * @param enable
125
+ * @param time 禁用后xx秒后恢复,不传一直禁用
126
+ */
122
127
  enable(enable: boolean, time?: number): void;
123
128
  }
124
129
  interface Label {
@@ -622,6 +627,18 @@ sp.Skeleton.prototype.fromHEX = function (this: sp.Skeleton, hex: string): void
622
627
  const label = this;
623
628
  label.color = (new Color()).fromHEX(hex)
624
629
  };
630
+
631
+
632
+ // 保存原始方法
633
+ const originalOnTouchEnded = Button.prototype["_onTouchEnded"];
634
+ // 重写 _onTouchEnded
635
+ Button.prototype["_onTouchEnded"] = function (...args: any[]) {
636
+ // 播放点击音效
637
+ ExComponentModule.Emit(this);
638
+ // 调用原始逻辑
639
+ return originalOnTouchEnded.apply(this, args);
640
+ };
641
+
625
642
  export { };
626
643
 
627
644
 
@@ -0,0 +1,38 @@
1
+ import { Button } from "cc";
2
+
3
+
4
+ export class ExComponentModule {
5
+ static _instance: ExComponentModule;
6
+ static get Ins() {
7
+ if (!this._instance) {
8
+ this._instance = new ExComponentModule();
9
+ }
10
+ return this._instance;
11
+ }
12
+
13
+ param: { click: (comp: Button) => void }
14
+ ResetBaseWindow: string = "BaseWindow";
15
+ static Init() {
16
+
17
+ }
18
+
19
+ static OnButtonClick(param: { click: (comp: Button) => void }) {
20
+ ExComponentModule.Ins.param = param
21
+ }
22
+ static Emit(btn: Button) {
23
+ ExComponentModule.Ins.param.click(btn)
24
+ }
25
+
26
+ static ResetBaseWindow(name?: string, isGet?: boolean) {
27
+ if (!isGet) ExComponentModule.Ins.ResetBaseWindow = name
28
+ return ExComponentModule.Ins.ResetBaseWindow
29
+ }
30
+
31
+
32
+ }
33
+ window.ExComponentModule = ExComponentModule;
34
+
35
+
36
+ export function ResetBaseWindow(path?: string) {
37
+ return function (target: any) { ExComponentModule.ResetBaseWindow(path) }
38
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "52b81889-807f-4ef9-a4a9-9e1c65bf5f66",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,13 @@
1
+ import { Button } from "cc";
2
+ declare global {
3
+ namespace ExComponentModule {
4
+ /**初始化 */
5
+ function Init();
6
+ /**监听所有按钮的点击事件 */
7
+ function OnButtonClick(param: { click: (comp: Button) => void });
8
+ function ResetBaseWindow(name?: string, isGet?: boolean);
9
+ /**组件:内部使用方法 */
10
+ function Emit(btn: Button);
11
+
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "4.0.24",
3
+ "importer": "typescript",
4
+ "imported": true,
5
+ "uuid": "3305619d-58c5-407d-adb3-38b2311b1991",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "ver": "1.2.0",
3
+ "importer": "directory",
4
+ "imported": true,
5
+ "uuid": "ea52192e-26a9-4174-8b32-d4f103aafbd4",
6
+ "files": [],
7
+ "subMetas": {},
8
+ "userData": {}
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-ex-component",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",