ui_layer.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
  2. import { att_count_down, event_item, task_data, widget_item_data } from '../../data/data';
  3. import { config } from '../config';
  4. import { ui_base } from './ui/ui_base';
  5. import { sound_text_content } from './ui/sound_text_content';
  6. import { gameManager } from './gameManager';
  7. import { ui_manifestations } from './tips/ui_manifestations';
  8. import { tools } from '../tools';
  9. import { ClientEvent } from '../clientEvent';
  10. import { taskServce } from './TaskSchedule/taskServce';
  11. import { count_down } from './ui/count_down';
  12. import { fail_ani } from './ui/fail_ani';
  13. import { content_rule_and_tips } from './tips/content_rule_and_tips';
  14. import { back_title } from './ui/back_title';
  15. import { boss_tips } from './tips/boss_tips';
  16. const { ccclass, property } = _decorator;
  17. @ccclass('ui_layer')
  18. export class ui_layer extends Component {
  19. @property(Node) ui_content:Node = null;
  20. @property(Prefab) not_have_interact_prefab:Prefab = null;
  21. @property(Prefab) interact_input_prefab:Prefab = null;
  22. @property(Prefab) interact_page_prefab:Prefab = null;
  23. @property(Prefab) interact_puzzle_prefab:Prefab = null;
  24. @property(Prefab) pointer_ding_wei_prefab:Prefab = null;
  25. @property(Prefab) wei_chi_pointer_prefab:Prefab = null;
  26. @property(Prefab) interact_scene_prefab:Prefab = null;
  27. @property(Prefab) count_down_prefab:Prefab = null;
  28. @property(Prefab) boss_info_data_prefab:Prefab = null;
  29. @property(Node) ui_manifestations:Node = null;
  30. @property(Node) content_rule_and_tips:Node = null;
  31. @property(Node) content_count_down:Node = null;
  32. @property(Node) back_title_node:Node = null;
  33. @property(Node) boss_tips:Node = null;
  34. private mUIList:Map<number,Node> = new Map;
  35. private mCountDownLlist:Map<number,widget_item_data> = new Map;
  36. private mData:widget_item_data[] = null;
  37. private mAttCountDown:count_down = null;
  38. public initUi(ui_widge_list:widget_item_data[]){
  39. this.mData = ui_widge_list;
  40. this.loadAllUi()
  41. let scene_des = ""
  42. this.back_title_node.getComponent(back_title).initView(scene_des,this.onBack.bind(this))
  43. ClientEvent.on(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
  44. ClientEvent.on(config.EventRun.ON_SHOW_RULE_BTN,this.onChangeShowRuleStatus.bind(this),this)
  45. }
  46. public unInit(){
  47. this.mAttCountDown = null;
  48. this.mData = null;
  49. this.mCountDownLlist.clear()
  50. this.mUIList.clear()
  51. this.content_count_down.removeAllChildren()
  52. this.ui_content.removeAllChildren()
  53. this.ui_manifestations.active = false;
  54. this.content_rule_and_tips.active =false;
  55. this.boss_tips.active = false;
  56. ClientEvent.off(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
  57. ClientEvent.off(config.EventRun.ON_SHOW_RULE_BTN,this.onChangeShowRuleStatus.bind(this),this)
  58. }
  59. onBack(){
  60. if(gameManager.Singleton.getLevelData()!=null){
  61. gameManager.Singleton.backGameList()
  62. }
  63. }
  64. protected onDestroy(): void {
  65. ClientEvent.off(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
  66. }
  67. loadAllUi(){
  68. this.ui_content.removeAllChildren()
  69. for (let index = 0; index < this.mData.length; index++) {
  70. const ui_data = this.mData[index];
  71. let item: Node = null;
  72. switch (ui_data.att.top_data.top_ui_type) {
  73. case config.top_view_type.not_have_interact:
  74. item = instantiate(this.not_have_interact_prefab)
  75. break;
  76. case config.top_view_type.interact_input:
  77. item = instantiate(this.interact_input_prefab)
  78. break;
  79. case config.top_view_type.interact_page:
  80. item = instantiate(this.interact_page_prefab)
  81. break;
  82. case config.top_view_type.interact_puzzle:
  83. item = instantiate(this.interact_puzzle_prefab)
  84. break;
  85. case config.top_view_type.pointer_ding_wei:
  86. item = instantiate(this.pointer_ding_wei_prefab)
  87. break;
  88. case config.top_view_type.wei_chi_pointer:
  89. item = instantiate(this.wei_chi_pointer_prefab)
  90. break;
  91. case config.top_view_type.interact_scene:
  92. item = instantiate(this.interact_scene_prefab)
  93. break;
  94. case config.top_view_type.boss_info:
  95. item = instantiate(this.boss_info_data_prefab)
  96. break;
  97. }
  98. if(item!=null){
  99. item.parent = this.ui_content;
  100. item.getComponent(ui_base).initView(ui_data)
  101. this.mUIList.set(ui_data.att.id,item)
  102. }
  103. }
  104. }
  105. initCountDownList(list:widget_item_data[]){
  106. this.mCountDownLlist.clear()
  107. for (let index = 0; index < list.length; index++) {
  108. const widget = list[index];
  109. this.mCountDownLlist.set(widget.att.id,widget);
  110. }
  111. }
  112. beActive(widgetId:number,event:event_item){
  113. if(event.type===config.event_type.top_view){
  114. let ui = this.mUIList.get(widgetId)
  115. if(ui){
  116. ui.getComponent(ui_base).show()
  117. }else{
  118. tools.showToast(`配置弹窗错误!${widgetId}`)
  119. }
  120. }else if(event.type===config.event_type.active_event){
  121. let time_count = this.mCountDownLlist.get(widgetId)
  122. if(time_count!=null){
  123. if(this.mAttCountDown==null){
  124. this.createCountDown(time_count)
  125. }
  126. }
  127. }else if(event.type===config.event_type.stop_active_event){
  128. let time_count = this.mCountDownLlist.get(widgetId)
  129. if(time_count!=null){
  130. if(this.mAttCountDown==null){
  131. this.createCountDown(time_count)
  132. }
  133. }
  134. }else if(event.type===config.event_type.hide){
  135. let ui = this.mUIList.get(widgetId)
  136. if(ui){
  137. ui.getComponent(ui_base).hide()
  138. }
  139. }else if(event.type===config.event_type.show_scene_title){
  140. this.back_title_node.getComponent(back_title).updateTitle(event.event_item_show_scene_title_data.title)
  141. }
  142. }
  143. createCountDown(data:widget_item_data){
  144. let item = instantiate(this.count_down_prefab)
  145. item.parent = this.content_count_down;
  146. item.position = new Vec3(data.att.x,data.att.y)
  147. this.mAttCountDown = item.getComponent(count_down)
  148. this.mAttCountDown.init(data.att.count_down,this.onCountDownOver.bind(this))
  149. this.mAttCountDown.startCountDown()
  150. ClientEvent.dispatchEvent(config.EventRun.ON_COUNT_DOWN_START,this.mAttCountDown.getData().start_event_id)
  151. ClientEvent.on(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT,this.onCountDownListening.bind(this),this)
  152. }
  153. onCountDownListening(event_id:number){
  154. if(this.mAttCountDown!=null){
  155. let att_count_down_data = this.mAttCountDown.getData()
  156. if(att_count_down_data.start_event_id===event_id){
  157. // tools.showToast("完成了所有的收集")
  158. let finish_id = this.mAttCountDown.getData().finish_event_id;
  159. if(finish_id!=-1){
  160. gameManager.Singleton.exeEvent(finish_id)
  161. }else{
  162. tools.showToast("没有配置完成的倒计时事件")
  163. }
  164. this.onCountDownOver(false)
  165. }
  166. }
  167. }
  168. onCountDownOver(isFail:boolean){
  169. let fail_event_id = this.mAttCountDown.getData().fail_event_id
  170. if(isFail){
  171. if(fail_event_id!=-1){
  172. ClientEvent.dispatchEvent(config.EventRun.ON_COUNT_DOWN_FAIL,fail_event_id)
  173. }else{
  174. tools.showToast("配置倒计时失败事件错误!")
  175. }
  176. }else{
  177. }
  178. this.mAttCountDown.node.removeFromParent()
  179. this.mAttCountDown = null;
  180. ClientEvent.off(config.EventRun.ON_WIDGET_FINISH_COLLECT_EVENT,this.onCountDownListening.bind(this),this)
  181. }
  182. initTaskUi(data:task_data){
  183. this.ui_manifestations.active = false;
  184. this.content_rule_and_tips.active = false;
  185. switch (data.type) {
  186. case config.task_type.zhao_xi_jie:
  187. if(data._zhao_xi_jie_data==null){
  188. return tools.showToast("找细节玩法没有配置!");
  189. }
  190. this.ui_manifestations.active = true;
  191. this.ui_manifestations.getComponent(ui_manifestations).initView(data._zhao_xi_jie_data)
  192. break;
  193. case config.task_type.guo_ju_qing:
  194. if(data._guo_ju_qing==null){
  195. return tools.showToast("过剧情玩法没有配置!");
  196. }
  197. this.content_rule_and_tips.active = true;
  198. this.content_rule_and_tips.getComponent(content_rule_and_tips).initView(()=>{
  199. if(gameManager.Singleton.IsOpenRuleStatus()){
  200. gameManager.Singleton.showTips()
  201. }else{
  202. gameManager.Singleton.showFindRuleTips()
  203. }
  204. },()=>{
  205. gameManager.Singleton.showRule()
  206. },data._guo_ju_qing.binding_event_id==-1)
  207. break;
  208. case config.task_type.guo_ju_qing_not_rule:
  209. console.log('ui_layer initTaskUi 过剧情-无规则 过剧情-无规则')
  210. break;
  211. case config.task_type.da_guai:
  212. if(data._da_guai==null){
  213. return tools.showToast("打boss玩法没有配置!");
  214. }
  215. let scene_data = gameManager.Singleton.getSceneManager().getSceneData()
  216. let res = scene_data.att.scene_rule_tips_data.tips_data.tips_tips.res;
  217. if(res.length<=0){
  218. }else{
  219. this.boss_tips.active = true;
  220. this.boss_tips.getComponent(boss_tips).initView(this.onClickBossTips.bind(this))
  221. }
  222. break;
  223. }
  224. }
  225. onClickBossTips(){
  226. gameManager.Singleton.showTips()
  227. }
  228. onChangeShowRuleStatus(){
  229. gameManager.Singleton.showRule()
  230. this.content_rule_and_tips.getComponent(content_rule_and_tips).showRuleBtn()
  231. }
  232. }