ui_layer.ts 13 KB

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