edit_event_view.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import { _decorator, Component, EditBox, instantiate, Node, Prefab, Size, UITransform, Vec3 } from 'cc';
  2. import { config } from '../../config';
  3. import { edit_event_view_select_btn } from './edit_event_view_select_btn';
  4. import { Attributes } from '../Attributes';
  5. import { event_item } from '../../../data/data';
  6. import { event_item_view } from './event_item_view';
  7. import { control } from '../control';
  8. import { main } from '../../main';
  9. import { ClientEvent } from '../../clientEvent';
  10. import { tools } from '../../tools';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('edit_event_view')
  13. export class edit_event_view extends Component {
  14. @property(Prefab) event_item_prefab:Prefab = null;
  15. @property(Node) btn_close:Node = null;
  16. @property(Node) result_scrollview:Node = null;
  17. @property(Node) content:Node = null;
  18. @property(Node) type_content:Node = null;
  19. @property(Node) type_btn:Node = null;
  20. @property(Node) search_node:Node = null;
  21. @property(Node) search_id_editbox:Node = null;
  22. @property(Node) search_id_btn:Node = null;
  23. @property(Node) search_content_editbox:Node = null;
  24. @property(Node) search_content_btn:Node = null;
  25. private m_cur_select_type:number = -1;
  26. private m_search_item_list:event_item[] = []
  27. protected start(): void {
  28. this.search_id_btn.on(Node.EventType.TOUCH_END, ()=> {
  29. let id_string = tools.trimLeftAndRightblank(this.search_id_editbox.getComponent(EditBox).string)
  30. this.search_id_editbox.getComponent(EditBox).string = id_string
  31. if(id_string.length<=0) {
  32. return tools.showToast('请输入id')
  33. }
  34. this.searchAction(id_string,true)
  35. },this)
  36. this.search_content_btn.on(Node.EventType.TOUCH_END, ()=> {
  37. let content_string = tools.trimLeftAndRightblank(this.search_content_editbox.getComponent(EditBox).string)
  38. this.search_content_editbox.getComponent(EditBox).string = content_string
  39. if(content_string.length<=0) {
  40. return tools.showToast('请输入内容')
  41. }
  42. this.searchAction(content_string,false)
  43. },this)
  44. }
  45. public show(){
  46. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  47. this.node.removeFromParent()
  48. })
  49. this.type_content.removeAllChildren()
  50. let btn = instantiate(this.type_btn)
  51. btn.getComponent(edit_event_view_select_btn).initView(-1,"全部",this.onTypeItemClick.bind(this))
  52. btn.getComponent(edit_event_view_select_btn).selectStatus()
  53. btn.parent = this.type_content
  54. let btn_search = instantiate(this.type_btn)
  55. btn_search.getComponent(edit_event_view_select_btn).initView(-2,"搜索",this.onTypeItemClick.bind(this))
  56. btn_search.getComponent(edit_event_view_select_btn).unselectStatus()
  57. btn_search.parent = this.type_content
  58. config.event_type_map.forEach((v,k)=>{
  59. let item = instantiate(this.type_btn)
  60. item.parent = this.type_content
  61. item.getComponent(edit_event_view_select_btn).initView(k,v,this.onTypeItemClick.bind(this))
  62. })
  63. this.m_cur_select_type = -1;
  64. this.updateView()
  65. }
  66. allBtnUnSelect(){
  67. for (let index = 0; index < this.type_content.children.length; index++) {
  68. const element = this.type_content.children[index];
  69. element.getComponent(edit_event_view_select_btn).unselectStatus()
  70. }
  71. }
  72. onTypeItemClick(item:edit_event_view_select_btn){
  73. this.allBtnUnSelect()
  74. item.selectStatus()
  75. if(this.m_cur_select_type!=item.getType()){
  76. this.m_cur_select_type = item.getType()
  77. this.updateView()
  78. }
  79. }
  80. updateView(){
  81. this.content.removeAllChildren()
  82. let list;
  83. let result_scrollview_size = new Size(this.result_scrollview.getComponent(UITransform).width, 700)
  84. if(this.m_cur_select_type == -2) {
  85. this.search_node.active = true
  86. list = this.m_search_item_list
  87. } else {
  88. this.search_node.active = false
  89. result_scrollview_size.height = 800
  90. list = this.getEventListByType()
  91. }
  92. this.result_scrollview.getComponent(UITransform).setContentSize(result_scrollview_size)
  93. for (let index = 0; index < list.length; index++) {
  94. const element = list[index];
  95. let item = instantiate(this.event_item_prefab)
  96. item.parent = this.content;
  97. item.getComponent(event_item_view).initView(element.type,element,this.onDeleteItem.bind(this))
  98. }
  99. }
  100. public onDeleteItem(item:event_item){
  101. let task_data = main.Singleton.edit_scene_view.getTaskData()
  102. if(task_data!=null){
  103. for (let index = 0; index < task_data.event_list.length; index++) {
  104. const element = task_data.event_list[index];
  105. if(element.event_id===item.event_id){
  106. task_data.event_list.splice(index,1)
  107. this.updateView()
  108. ClientEvent.dispatchEvent(config.Event.UpdateEditScene)
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. getEventListByType(){
  115. let list = Attributes.Singleton.getEventList()
  116. if(this.m_cur_select_type==-1){
  117. return list;
  118. }else{
  119. let temp:event_item[] = []
  120. for (let index = 0; index < list.length; index++) {
  121. const element = list[index];
  122. if(element.type==this.m_cur_select_type){
  123. temp.push(element)
  124. }
  125. }
  126. return temp;
  127. }
  128. }
  129. searchAction(string:string, isSearchID:boolean) {
  130. // console.log('string=',string)
  131. this.m_search_item_list.splice(0, this.m_search_item_list.length)
  132. if(isSearchID) {
  133. this.searchData(parseInt(string))
  134. } else {
  135. let check_yes = false
  136. let list = Attributes.Singleton.getEventList()
  137. for(let i=0; i<list.length; i++) {
  138. const element = list[i]
  139. if(element.event_name.indexOf(string)!=-1) {
  140. if(element.event_id!=0) {
  141. this.searchData(element.event_id)
  142. check_yes = true
  143. }
  144. break
  145. }
  146. }
  147. if(check_yes==false) {
  148. tools.showToast('搜索的内容不存在')
  149. }
  150. }
  151. this.searchCreateItem()
  152. }
  153. private searchData(id:number) {
  154. let list = Attributes.Singleton.getEventList()
  155. for(let i=0; i<list.length; i++) {
  156. const element = list[i]
  157. if(element.event_id == id) {
  158. // console.log('触发下个事件的id=',element.success.trigger_event_id)
  159. this.m_search_item_list.push(element)
  160. let trigger_event_id = element.success.trigger_event_id
  161. if(trigger_event_id != -1) {
  162. this.searchData(trigger_event_id)
  163. }
  164. break
  165. }
  166. }
  167. if(this.m_search_item_list.length == 0) {
  168. tools.showToast('搜索的id不存在')
  169. }
  170. }
  171. private searchCreateItem() {
  172. this.content.removeAllChildren()
  173. for (let index = 0; index < this.m_search_item_list.length; index++) {
  174. const element = this.m_search_item_list[index];
  175. let item = instantiate(this.event_item_prefab)
  176. item.parent = this.content;
  177. item.getComponent(event_item_view).initView(element.type,element,this.onDeleteItem.bind(this))
  178. }
  179. }
  180. }