results.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { http } from '../http';
  3. import { config } from '../config';
  4. import { audioManager } from '../manager/audioManager';
  5. import { user_results } from '../data';
  6. import { ClientEvent } from '../lib/clientEvent';
  7. import { results_unlock_car } from './results_unlock_car';
  8. import { base_ui } from '../fw/base_ui';
  9. import { GameManager } from '../GameManager';
  10. import { dataManager } from '../manager/dataManager';
  11. import { results_new_car } from './results_new_car';
  12. import { btn_relife } from './btn_relife';
  13. import { userDataManager } from '../manager/userDataManager';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('results')
  16. export class results extends base_ui {
  17. @property(Node) btn_restart:Node = null
  18. @property(Node) lab_scores:Node = null
  19. @property(Node) btn_back_home:Node = null
  20. @property(Node) btn_video_reLife:Node = null
  21. @property(Node) unlock_car:Node = null
  22. @property(Node) btn_share:Node = null
  23. @property(Node) lab_des:Node = null
  24. @property(Node) spr_title:Node = null
  25. @property(Node) lab_free_num:Node = null
  26. @property(results_new_car) res_new_car:results_new_car = null
  27. private call_back = null
  28. private back_home_cb = null
  29. @property(SpriteFrame) TITLE_SF_LIST:SpriteFrame[] = []
  30. start() {
  31. this.onButtonListen(this.btn_restart,()=>{
  32. if(this.call_back!=null){
  33. GameManager.checkPlayGame(this.node,()=>{
  34. this.call_back(false)
  35. this.close()
  36. })
  37. }
  38. // this.onClickRestart()
  39. })
  40. this.onButtonListen(this.btn_back_home,()=>{
  41. if(this.back_home_cb){
  42. this.back_home_cb()
  43. }
  44. })
  45. this.onButtonListen(this.btn_video_reLife,()=>{
  46. GameManager.showVideoAd(config.ADS_TYPE.GAME_RELIFE_VIDEO, ()=>{
  47. if(this.call_back){
  48. this.call_back(true)
  49. this.close()
  50. }
  51. })
  52. })
  53. this.onButtonListen(this.btn_share,()=>{
  54. GameManager.gameOverResultsShare()
  55. })
  56. }
  57. protected close(): void {
  58. this.unlock_car.getComponent(results_unlock_car).hide()
  59. this.node.active = false;
  60. }
  61. setTitleSpr(scores:number){
  62. let index = dataManager.getGameEndPrompt(scores)
  63. if(index!=-1){
  64. this.spr_title.getComponent(Sprite).spriteFrame = this.TITLE_SF_LIST[index]
  65. }else{
  66. this.spr_title.getComponent(Sprite).spriteFrame = null
  67. }
  68. }
  69. public show(scores:number,jiesuan_finish_cb,call,back_home_cb,isReLife:boolean){
  70. this.back_home_cb = back_home_cb
  71. this.btn_video_reLife.active = isReLife
  72. this.setTitleSpr(scores)
  73. let free_num = dataManager.getTodayUserGameFreeCount()
  74. // if(free_num<=0){
  75. // this.btn_video_reLife.getComponent(btn_relife).showStatus(true)
  76. // }else{
  77. // this.btn_video_reLife.getComponent(btn_relife).showStatus(false)
  78. // }
  79. // if(free_num<=0){
  80. // this.btn_video_reLife.getComponent(btn_relife).showStatus(true)
  81. // }else{
  82. // this.btn_video_reLife.getComponent(btn_relife).showStatus(false)
  83. // }
  84. if(userDataManager.getUserIsFreeAds()) {
  85. this.lab_free_num.getComponent(Label).string = ''
  86. } else {
  87. let show_count = dataManager.getTodayGameFreeTotalCount() - free_num
  88. if(show_count<0) { show_count = 0 }
  89. this.lab_free_num.getComponent(Label).string = `今日免费 ${show_count} 次`
  90. }
  91. http.post(config.API.sync_integral,{"integral":scores},(err,data)=>{
  92. if(!err){
  93. let d = JSON.parse(data)
  94. if(d.code===config.status.SUCCESS){
  95. let res:user_results = d.content
  96. if(res.obtain_list.length<=0){
  97. this.unlock_car.getComponent(results_unlock_car).hide()
  98. console.log("啥也没获取到")
  99. }else{
  100. // this.unlock_car.getComponent(results_unlock_car).show(res.default_car_id)
  101. ClientEvent.dispatchEvent(config.UI_EVENT.GET_NEW_CAR,res)
  102. this.res_new_car.show(scores,res)
  103. }
  104. this.lab_des.getComponent(Label).string=`已超过全国${res.ratio}的司机`
  105. ClientEvent.dispatchEvent(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,res)
  106. }
  107. // http.get(config.STATIC_API.regions,(e,d)=>{
  108. // console.log("regions",d)
  109. // })
  110. // http.get(config.STATIC_API.rankings(0),(err,data)=>{
  111. // console.log("rankings",data)
  112. // })
  113. }
  114. jiesuan_finish_cb()
  115. })
  116. audioManager.Instance().playSound(config.AUDIO.win)
  117. this.node.active = true
  118. this.lab_scores.getComponent(Label).string =scores+""
  119. this.call_back = call
  120. }
  121. }