scene_select_list.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { main } from '../main';
  3. import { scene_item_data } from '../../data/data';
  4. import { scene_select_list_item } from './scene_select_list_item';
  5. import { ClientEvent } from '../clientEvent';
  6. import { config } from '../config';
  7. import { tools } from '../tools';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('scene_select_list')
  10. export class scene_select_list extends Component {
  11. @property(Prefab) scene_select_list_item_prefab:Prefab = null;
  12. @property(Node) content:Node = null;
  13. private cur_select_index = 0;
  14. private m_main:main = null;
  15. public initView(_main:main){
  16. this.m_main = _main;
  17. this.content.removeAllChildren()
  18. this.onUpdateSceneList()
  19. ClientEvent.off(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
  20. ClientEvent.on(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
  21. }
  22. onUpdateSceneList(is_move:boolean = false){
  23. let list = this.m_main.control_view.get_bag_data().content;
  24. if(is_move==false) {
  25. this.cur_select_index = list.length>0?list.length-1:0;
  26. }
  27. this.content.removeAllChildren()
  28. for (let index = 0; index < list.length; index++) {
  29. const element:scene_item_data = list[index];
  30. let item = instantiate(this.scene_select_list_item_prefab)
  31. item.parent = this.content;
  32. let scene_select_list_item_component = item.getComponent(scene_select_list_item)
  33. scene_select_list_item_component.initView(list.length,element,this.onItemSelect.bind(this),index)
  34. scene_select_list_item_component.moveCallback(this.onItemMoveClick.bind(this))
  35. }
  36. this.updaetSelectStatus()
  37. }
  38. onItemSelect(item:scene_select_list_item){
  39. if(item.getSelect()){
  40. }else{
  41. this.cur_select_index = item.getIndex()
  42. this.updaetSelectStatus()
  43. }
  44. }
  45. onItemMoveClick(item:scene_select_list_item, is_up:boolean) {
  46. // let list = this.m_main.control_view.get_bag_data().content;
  47. // let c_index = item.getIndex()
  48. // let c_data = list[c_index]
  49. // let move_index=-1;
  50. // if(is_up) {
  51. // move_index = c_index - 1
  52. // this.cur_select_index -=1
  53. // } else {
  54. // move_index = c_index + 1
  55. // this.cur_select_index +=1
  56. // }
  57. // if(move_index == -1) {return}
  58. // let move_data = list[move_index]
  59. // list[c_index] = move_data
  60. // list[move_index] = c_data
  61. // this.onUpdateSceneList(true)
  62. }
  63. updaetSelectStatus(){
  64. for (let index = 0; index < this.content.children.length; index++) {
  65. const element = this.content.children[index];
  66. element.getComponent(scene_select_list_item).setIsSelect(element.getComponent(scene_select_list_item).getIndex()==this.cur_select_index)
  67. element.getComponent(scene_select_list_item).updatSelectStatus()
  68. }
  69. ClientEvent.dispatchEvent(config.Event.UpdateEditScene)
  70. }
  71. public getCurSelectScene(){
  72. if(this.content.children.length<=0){
  73. return null;
  74. }
  75. return this.content.children[this.cur_select_index].getComponent(scene_select_list_item).getData()
  76. }
  77. public getCurSelectSceneIndex(){
  78. return this.cur_select_index;
  79. }
  80. }