widget_list.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { _decorator, Component, instantiate, Node, Prefab, ScrollView } from 'cc';
  2. import { config } from '../config';
  3. import { widget_item } from './widget_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('widget_list')
  6. export class widget_list extends Component {
  7. @property(Prefab) item_prefab:Prefab = null;
  8. protected start(): void {
  9. this.initView()
  10. }
  11. public initView(){
  12. config.init()
  13. this.node.getComponent(ScrollView).content.removeAllChildren()
  14. config.Widget_Type.forEach((v,k)=>{
  15. let item:Node = instantiate(this.item_prefab)
  16. item.parent = this.node.getComponent(ScrollView).content
  17. item.getComponent(widget_item).initWidgetType()
  18. item.getComponent(widget_item).initView(v)
  19. })
  20. }
  21. public getWidgetDataByType(type:number){
  22. let content = this.node.getComponent(ScrollView).content
  23. for (let index = 0; index < content.children.length; index++) {
  24. const element = content.children[index];
  25. if(element.getComponent(widget_item).getData().type==type){
  26. return element.getComponent(widget_item).getData()
  27. }
  28. }
  29. }
  30. public getWidgetByType(type:number){
  31. let content = this.node.getComponent(ScrollView).content
  32. for (let index = 0; index < content.children.length; index++) {
  33. const element = content.children[index];
  34. let data = element.getComponent(widget_item).getData()
  35. if(data.type==type){
  36. return element
  37. }
  38. }
  39. }
  40. }