edit_event_view.ts 6.1 KB

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