select_sound_list.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { _decorator, Component, instantiate, Label, Node, Prefab } from 'cc';
  2. import { select_res_list_item } from '../select_res_list_item';
  3. import { control } from './control';
  4. import { config } from '../config';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('select_sound_list')
  7. export class select_sound_list extends Component {
  8. @property(Node) content:Node = null;
  9. @property(Prefab) item_prefab:Prefab = null;
  10. @property(Node) btn_sure:Node = null;
  11. @property(Node) btn_close:Node = null;
  12. @property(Node) lab_title:Node = null;
  13. private m_call_back = null;
  14. private m_cur_select_item:select_res_list_item = null;
  15. public initView(call){
  16. this.m_call_back = call;
  17. this.btn_sure.on(Node.EventType.TOUCH_END,()=>{
  18. if(this.m_call_back!=null){
  19. this.m_call_back(this.m_cur_select_item.getData())
  20. }
  21. this.close()
  22. })
  23. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  24. this.close()
  25. })
  26. let res_list = control.Singleton.getResDataByType(config.select_res_btn_type.SOUND_LIST)
  27. for (let index = 0; index < res_list.length; index++) {
  28. const element = res_list[index];
  29. let item = instantiate(this.item_prefab)
  30. item.parent = this.content;
  31. item.getComponent(select_res_list_item).initView(element,this.onItemClick.bind(this),false)
  32. if(index ===0){
  33. this.m_cur_select_item = item.getComponent(select_res_list_item);
  34. this.m_cur_select_item.selectStatus()
  35. this.lab_title.getComponent(Label).string = this.m_cur_select_item.getData().name
  36. }else{
  37. item.getComponent(select_res_list_item).unSelectStatus()
  38. }
  39. }
  40. }
  41. close(){
  42. this.node.removeFromParent()
  43. }
  44. onItemClick(item:select_res_list_item){
  45. this.unSelectAll()
  46. this.m_cur_select_item = item
  47. this.lab_title.getComponent(Label).string = this.m_cur_select_item.getData().name
  48. this.m_cur_select_item.selectStatus()
  49. }
  50. unSelectAll(){
  51. for (let index = 0; index < this.content.children.length; index++) {
  52. const element = this.content.children[index];
  53. element.getComponent(select_res_list_item).unSelectStatus()
  54. }
  55. }
  56. }