ui_layer.ts 11 KB

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