@cc-component/cc-ex-component 1.2.7 → 1.2.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.
@@ -1,4 +1,5 @@
1
1
  import { Sprite } from "cc";
2
+ import { assetManager } from "cc";
2
3
  import { Enum } from "cc";
3
4
  import { _decorator, Component, js, Node } from "cc";
4
5
  import { EDITOR_NOT_IN_PREVIEW } from "cc/env";
@@ -25,6 +26,7 @@ export class ReferenceComponent extends Component {
25
26
  @property({ displayName: "复制属性" })
26
27
  private get refresh() { return this._refresh; }
27
28
  private set refresh(val: boolean) {
29
+ console.error('打印了')
28
30
  if (EDITOR_NOT_IN_PREVIEW) {
29
31
  this.initNodeList();
30
32
  this.genCode();
@@ -187,6 +189,7 @@ export class ReferenceComponent extends Component {
187
189
  text += line;
188
190
  });
189
191
  Editor.Clipboard.write("text", text);
192
+
190
193
  console.log("已复制到剪切板");
191
194
  }
192
195
 
@@ -194,8 +197,8 @@ export class ReferenceComponent extends Component {
194
197
  private genCodeBind(isCopy: boolean = true, isClass: boolean = false) {
195
198
  if (!EDITOR_NOT_IN_PREVIEW) return;
196
199
  let text = "";
197
- let eventStr: string = " //#region 事件"
198
- let pix = "onClick_"
200
+ let eventStr: string = " //#region ⚠️ ------------方法事件"
201
+ let pix = "private onClick_"
199
202
  // const com = this.node.components.find(v => { return v.reference })
200
203
  // const match = com.name.match(/<([^>]+)>/);
201
204
  // const className = match && match[1] ? match[1] : "any"
@@ -203,15 +206,16 @@ export class ReferenceComponent extends Component {
203
206
  let data = `${className}Data`
204
207
  let iinterface = `I${className}Data`
205
208
  //console.error("[MLogger Error]", className)
206
- const viewModel = `
209
+ const viewModel =
210
+ `\n //#region ⚠️ ------------自动生成属性
207
211
  // ✅ 外部界面调用,刷新UI
208
212
  public refreshUI(data: ${iinterface}) { super.refreshUI(data); }
209
213
 
210
- //#region ✅ 使用新装饰器(自动响应式 + 路径推导)
214
+ // ✅ 使用新装饰器(自动响应式 + 路径推导)
211
215
  @BindViewModel(${className}Data)
212
216
  viewModel: ${className}Data;`
213
217
  text += viewModel + "\n\n"
214
- text += ` //#region ✅ UI属性`
218
+ text += ` // ✅ UI属性`
215
219
  //生成get属性
216
220
  this.nodes.forEach(data => {
217
221
  let key = data.key;
@@ -250,7 +254,7 @@ export class ReferenceComponent extends Component {
250
254
  }
251
255
 
252
256
  let bind = `${bind_pix}("${name}"${this.comList.includes(type) ? event : ""})`
253
- if (isClass) {
257
+ if (true) {
254
258
  bind = `${bind_pix}("${name}"${this.comList2.includes(type) ? event : ""})`
255
259
  }
256
260
  if (this.comList_base.includes(type)) {
@@ -265,12 +269,16 @@ export class ReferenceComponent extends Component {
265
269
  let line = ` ${bind} @Ref ${name}: ${type};`
266
270
  text += line;
267
271
  });
272
+ text += `\n //#endregion END`
268
273
 
274
+ text += `\n\n //#region ⚠️ ------------自定义属性`
275
+ text += `\n\n //#endregion END`
269
276
 
270
277
  if (isCopy) {
271
278
  Editor.Clipboard.write("text", text);
272
279
  console.log("已复制到剪切板");
273
280
  }
281
+ eventStr += `\n //#endregion END`
274
282
  return { text: text, event: eventStr }
275
283
 
276
284
  }
@@ -280,33 +288,33 @@ export class ReferenceComponent extends Component {
280
288
  if (!EDITOR_NOT_IN_PREVIEW) return;
281
289
  let text = ""
282
290
  let sx_this = ''
283
- let sx = ' \n'
291
+ let sx = ''
284
292
  const className = this.node.name
285
293
 
286
294
  let data = `${className}Data`
287
295
  let iinterface = `I${className}Data`
288
296
 
289
297
  //生成get属性
290
- this.nodes.forEach(data => {
298
+ this.nodes.forEach((data, index) => {
291
299
  let key = data.key;
292
300
  let name = key[0].toLowerCase() + key.substring(1);
293
301
  const type = this.getPropertyType(data.com)
294
302
  //@ts-ignore
295
303
  let line = ` ${name}: ${this.getDataTypeByComponentType(type)};`//`private get ${name}() { return this.rc.get("${key}", ${this.getPropertyType(data.node)}); }`;
296
- sx += line + "\n";
304
+ sx += line + "" + (index < this.nodes.length - 1 ? "\n" : "");
297
305
 
298
306
  let line_sx = ` this.${name} = ${this.getDataTypeByComponentTypeValue(type)}`
299
- sx_this += line_sx + '\n'
307
+ sx_this += line_sx + (index < this.nodes.length - 1 ? "\n" : "");
300
308
  });
301
309
 
302
310
  text = `
303
- //#region 数据接口
311
+ //#region ⚠️ ------------数据接口
304
312
  export interface ${iinterface} {
305
313
  ${sx}
306
314
  }
307
- `;
315
+ //#endregion END`;
308
316
  text += `
309
- //#region 数据VM
317
+ //#region ⚠️ ------------数据对象
310
318
  class ${data} extends BaseViewModelData implements ${iinterface} {
311
319
  ${sx}
312
320
 
@@ -315,7 +323,7 @@ ${sx}
315
323
  ${sx_this}
316
324
  }
317
325
  }
318
- `;
326
+ //#endregion END`;
319
327
  if (isCopy) {
320
328
  Editor.Clipboard.write("text", text);
321
329
  console.log("已复制到剪切板");
@@ -331,7 +339,7 @@ ${sx_this}
331
339
  private genCodeVmDataAll() {
332
340
  if (!EDITOR_NOT_IN_PREVIEW) return;
333
341
  let importStr = `
334
- import { Label, RichText, ProgressBar, Sprite, EditBox, Toggle, Slider, ToggleContainer, Button, math, SpriteFrame, _decorator } from 'cc';
342
+ import { Label, RichText, ProgressBar, Sprite, EditBox, Toggle, Slider, ToggleContainer, Button, math, SpriteFrame, _decorator , Node} from 'cc';
335
343
  import { ViewModel, BindViewModel, BindTable, BindCollect, Bind, Ref, BaseViewModelData, YXCollectionView, YXFlowLayout, TableView, BaseReference } from 'db://assets/pkg-export/@cc-component/cc-ex-component';
336
344
  const { ccclass, property } = _decorator;`
337
345
 
@@ -354,7 +362,7 @@ const { ccclass, property } = _decorator;
354
362
 
355
363
  let iinterface = `I${className}Data`
356
364
  const onload = `
357
- //#region 初始化
365
+ //#region ⚠️ ------------初始化
358
366
  onLoad(): void {
359
367
 
360
368
  }
@@ -446,5 +454,4 @@ export class ${className} extends ViewModel(BaseReference) {${sx.text}\n${onload
446
454
  };
447
455
  return typeMap[compType] ?? 'any'; // 默认 fallback
448
456
  }
449
-
450
457
  }
@@ -15,6 +15,7 @@ import { TableView } from '../lib/tableView/TableView';
15
15
  import { YXFlowLayout } from '../lib/collectView/lib_collect/yx-flow-layout';
16
16
  import { math } from 'cc';
17
17
  import { YXCollectionView, YXIndexPath } from '../lib/collectView/lib_collect/yx-collection-view';
18
+ import { EventTouch } from 'cc';
18
19
 
19
20
  interface IBindingData extends ITableViewEvents, IBindingDataEvents {
20
21
  dataPath: string;
@@ -25,8 +26,12 @@ interface IBindingData extends ITableViewEvents, IBindingDataEvents {
25
26
 
26
27
 
27
28
  interface IBindingDataEvents {
28
- reset?: Function;
29
- event?: Function;
29
+ reset?: (self: any, value: any, com: Component) => void;
30
+ event?: (self: any) => void;
31
+ touchStart?: (self: any, event: EventTouch) => void;
32
+ touchMove?: (self: any, event: EventTouch) => void;
33
+ touchEnd?: (self: any, event: EventTouch) => void;
34
+ touchCancel?: (self: any, event: EventTouch) => void;
30
35
  }
31
36
 
32
37
 
@@ -310,8 +315,9 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
310
315
  } else
311
316
  com_btn.node.active = value ?? true;
312
317
 
313
- //事件
314
- com_btn.node.off(Button.EventType.CLICK, com_btn['btnCall']);
318
+ //事件点击
319
+ const touch_click = 'CallClick'
320
+ com_btn.node.off(Button.EventType.CLICK, com_btn[touch_click]);
315
321
  tempData.skip = true;
316
322
  const btnCall = (btn) => {
317
323
  tempData.value = btn.node.active
@@ -319,8 +325,46 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
319
325
  data.event?.(self)
320
326
  self[`onClick_${sx}`]?.(btn)
321
327
  }
322
- com_btn['btnCall'] = btnCall
323
- com_btn.node.on(Button.EventType.CLICK, com_btn['btnCall']);
328
+ com_btn[touch_click] = btnCall
329
+ com_btn.node.on(Button.EventType.CLICK, com_btn[touch_click]);
330
+
331
+ //touch
332
+ if (data.touchStart) {
333
+ const touch_start = 'CALL_TOUCH_START'
334
+ com_btn.node.off(Node.EventType.TOUCH_START, com_btn[touch_start]);
335
+ const call_start = (btn) => {
336
+ data.touchStart?.(self, btn)
337
+ }
338
+ com_btn[touch_start] = call_start
339
+ com_btn.node.on(Node.EventType.TOUCH_START, com_btn[touch_start]);
340
+ }
341
+ if (data.touchMove) {
342
+ const touch_start = 'CALL_TOUCH_MOVE'
343
+ com_btn.node.off(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
344
+ const call_start = (btn) => {
345
+ data.touchMove?.(self, btn)
346
+ }
347
+ com_btn[touch_start] = call_start
348
+ com_btn.node.on(Node.EventType.TOUCH_MOVE, com_btn[touch_start]);
349
+ }
350
+ if (data.touchEnd) {
351
+ const touch_start = 'CALL_TOUCH_END'
352
+ com_btn.node.off(Node.EventType.TOUCH_END, com_btn[touch_start]);
353
+ const call_start = (btn) => {
354
+ data.touchEnd?.(self, btn)
355
+ }
356
+ com_btn[touch_start] = call_start
357
+ com_btn.node.on(Node.EventType.TOUCH_END, com_btn[touch_start]);
358
+ }
359
+ if (data.touchCancel) {
360
+ const touch_start = 'CALL_TOUCH_CANCEL'
361
+ com_btn.node.off(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
362
+ const call_start = (btn) => {
363
+ data.touchCancel?.(self, btn)
364
+ }
365
+ com_btn[touch_start] = call_start
366
+ com_btn.node.on(Node.EventType.TOUCH_CANCEL, com_btn[touch_start]);
367
+ }
324
368
  break;
325
369
  case 'cc.ProgressBar':
326
370
  if (data.reset) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-ex-component",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",