res_list.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Component, instantiate, Node, Prefab, ScrollView } from 'cc';
  2. import { bag_item_data } from '../../data/data';
  3. import { config } from '../config';
  4. import { img_item } from './img_item';
  5. import { control } from './control';
  6. import { sound_item } from './sound_item';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('res_list')
  9. export class res_list extends Component {
  10. private item_prefab:Prefab = null;
  11. private m_type:number = 0;
  12. private m_data:bag_item_data[] = []
  13. public initView(pf:Prefab,type:number,data:bag_item_data[]){
  14. this.item_prefab = pf;
  15. this.m_data = data;
  16. this.m_type = type;
  17. this.node.getComponent(ScrollView).content.removeAllChildren()
  18. for (let index = 0; index < this.m_data.length; index++) {
  19. const element = this.m_data[index];
  20. let url = element.url;
  21. let name = element.name;
  22. let item = instantiate(this.item_prefab)
  23. item.parent = this.node.getComponent(ScrollView).content;
  24. if(this.m_type===config.select_res_btn_type.SOUND_LIST){
  25. item.getComponent(sound_item).initView(config.select_res_btn_type.SOUND_LIST,element,name,control.mp3_cache.get(name))
  26. }else{
  27. item.getComponent(img_item).initView(this.m_type,element,name,control.res_map.get(name))
  28. }
  29. }
  30. }
  31. public getType(){
  32. return this.m_type;
  33. }
  34. public getData(){
  35. return this.m_data;
  36. }
  37. }