edit_event_view.ts 7.3 KB

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