ui_layer.ts 12 KB

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