select_res_list.ts 2.6 KB

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