scene_select_list.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. import { Attributes } from './Attributes';
  9. import { copy_scene } from './copy_scene';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('scene_select_list')
  12. export class scene_select_list extends Component {
  13. @property(Prefab) scene_select_list_item_prefab:Prefab = null;
  14. @property(Node) content:Node = null;
  15. private cur_select_index = 0;
  16. private m_main:main = null;
  17. public initView(_main:main){
  18. this.m_main = _main;
  19. this.content.removeAllChildren()
  20. this.onUpdateSceneList()
  21. ClientEvent.off(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
  22. ClientEvent.on(config.Event.UpdateSceneList,this.onUpdateSceneList,this)
  23. }
  24. onUpdateSceneList(is_move:boolean = false){
  25. let list = this.m_main.control_view.get_bag_data().content;
  26. if(is_move==false) {
  27. this.cur_select_index = list.length>0?list.length-1:0;
  28. }
  29. this.content.removeAllChildren()
  30. for (let index = 0; index < list.length; index++) {
  31. const element:scene_item_data = list[index];
  32. let item = instantiate(this.scene_select_list_item_prefab)
  33. item.parent = this.content;
  34. let scene_select_list_item_component = item.getComponent(scene_select_list_item)
  35. scene_select_list_item_component.initView(list.length,element,this.onItemSelect.bind(this),index)
  36. scene_select_list_item_component.moveCallback(this.onItemMoveClick.bind(this))
  37. scene_select_list_item_component.copyCallback(this.onItemCopyClick.bind(this))
  38. }
  39. this.updaetSelectStatus()
  40. }
  41. onItemSelect(item:scene_select_list_item){
  42. if(item.getSelect()){
  43. }else{
  44. this.cur_select_index = item.getIndex()
  45. this.updaetSelectStatus()
  46. }
  47. }
  48. onItemMoveClick(item:scene_select_list_item, is_up:boolean) {
  49. let list = this.m_main.control_view.get_bag_data().content;
  50. let c_index = item.getIndex()
  51. let c_data = list[c_index]
  52. let move_index=-1;
  53. if(is_up) {
  54. move_index = c_index - 1
  55. if(item.getSelect()) {
  56. this.cur_select_index -=1
  57. } else {
  58. this.cur_select_index +=1
  59. }
  60. } else {
  61. move_index = c_index + 1
  62. if(item.getSelect()) {
  63. this.cur_select_index +=1
  64. } else {
  65. this.cur_select_index -=1
  66. }
  67. }
  68. if(move_index == -1) {return}
  69. let move_data = list[move_index]
  70. list[c_index] = move_data
  71. list[move_index] = c_data
  72. this.onUpdateSceneList(true)
  73. }
  74. onItemCopyClick(item:scene_select_list_item) {
  75. let c_index = item.getIndex()
  76. let list = this.m_main.control_view.get_bag_data().content;
  77. let c_data = list[c_index]
  78. // console.log('c_data=',c_data)
  79. tools.show_copy_scene(c_data.scene_diy_name, (scene_name:string, copy_scene_view:copy_scene)=> {
  80. let copy_data = JSON.parse(JSON.stringify(c_data)) //深拷贝
  81. copy_data.scene_diy_name = scene_name
  82. for(let i=0; i<copy_data.page_list.length; i++) {
  83. let i_page_item = copy_data.page_list[i]
  84. i_page_item.att.id = config.getNewId()
  85. for(let j=0; j<i_page_item.page_list.length; j++) {
  86. let j_page_item = i_page_item.page_list[j]
  87. j_page_item.att.id = i_page_item.att.id
  88. }
  89. for(let j=0; j<i_page_item.page_widget_list.length; j++) {
  90. let j_page_widget_item = i_page_item.page_widget_list[j]
  91. j_page_widget_item.att.id = config.getNewId()
  92. }
  93. }
  94. // console.log('copy_data=',copy_data)
  95. this.m_main.control_view.push_scene_data(copy_data)
  96. this.onUpdateSceneList()
  97. copy_scene_view.close()
  98. })
  99. }
  100. updaetSelectStatus(){
  101. for (let index = 0; index < this.content.children.length; index++) {
  102. const element = this.content.children[index];
  103. element.getComponent(scene_select_list_item).setIsSelect(element.getComponent(scene_select_list_item).getIndex()==this.cur_select_index)
  104. element.getComponent(scene_select_list_item).updatSelectStatus()
  105. }
  106. ClientEvent.dispatchEvent(config.Event.UpdateEditScene)
  107. }
  108. public getCurSelectScene(){
  109. if(this.content.children.length<=0){
  110. return null;
  111. }
  112. return this.content.children[this.cur_select_index].getComponent(scene_select_list_item).getData()
  113. }
  114. public getCurSelectSceneIndex(){
  115. return this.cur_select_index;
  116. }
  117. }