widget_list.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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).initView(v)
  18. })
  19. }
  20. public getWidgetDataByType(type:number){
  21. let content = this.node.getComponent(ScrollView).content
  22. for (let index = 0; index < content.children.length; index++) {
  23. const element = content.children[index];
  24. if(element.getComponent(widget_item).getData().type==type){
  25. return element.getComponent(widget_item).getData()
  26. }
  27. }
  28. }
  29. public getWidgetByType(type:number){
  30. let content = this.node.getComponent(ScrollView).content
  31. for (let index = 0; index < content.children.length; index++) {
  32. const element = content.children[index];
  33. let data = element.getComponent(widget_item).getData()
  34. if(data.type==type){
  35. return element
  36. }
  37. }
  38. }
  39. }