results.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. const { ccclass, property } = _decorator;
  13. @ccclass('results')
  14. export class results extends base_ui {
  15. @property(Node) btn_restart:Node = null
  16. @property(Node) lab_scores:Node = null
  17. @property(Node) btn_back_home:Node = null
  18. @property(Node) btn_video_reLife:Node = null
  19. @property(Node) unlock_car:Node = null
  20. @property(Node) btn_share:Node = null
  21. @property(Node) lab_des:Node = null
  22. @property(Node) spr_title:Node = null
  23. @property(results_new_car) res_new_car:results_new_car = null
  24. private call_back = null
  25. private back_home_cb = null
  26. @property(SpriteFrame) TITLE_SF_LIST:SpriteFrame[] = []
  27. start() {
  28. this.onButtonListen(this.btn_restart,()=>{
  29. if(this.call_back!=null){
  30. GameManager.checkPlayGame(this.node,()=>{
  31. this.call_back(false)
  32. this.close()
  33. })
  34. }
  35. // this.onClickRestart()
  36. })
  37. this.onButtonListen(this.btn_back_home,()=>{
  38. if(this.back_home_cb){
  39. this.back_home_cb()
  40. }
  41. })
  42. this.onButtonListen(this.btn_video_reLife,()=>{
  43. GameManager.showVideoAd(config.ADS_TYPE.GAME_RELIFE_VIDEO, ()=>{
  44. if(this.call_back){
  45. this.call_back(true)
  46. this.close()
  47. }
  48. })
  49. })
  50. this.onButtonListen(this.btn_share,()=>{
  51. GameManager.gameOverResultsShare()
  52. })
  53. }
  54. protected close(): void {
  55. this.unlock_car.getComponent(results_unlock_car).hide()
  56. this.node.active = false;
  57. }
  58. setTitleSpr(scores:number){
  59. let index = dataManager.getGameEndPrompt(scores)
  60. if(index!=-1){
  61. this.spr_title.getComponent(Sprite).spriteFrame = this.TITLE_SF_LIST[index]
  62. }else{
  63. this.spr_title.getComponent(Sprite).spriteFrame = null
  64. }
  65. }
  66. public show(scores:number,jiesuan_finish_cb,call,back_home_cb,isReLife:boolean){
  67. this.back_home_cb = back_home_cb
  68. this.btn_video_reLife.active = isReLife
  69. scores = 600
  70. this.setTitleSpr(scores)
  71. http.post(config.API.sync_integral,{"integral":scores},(err,data)=>{
  72. if(!err){
  73. let d = JSON.parse(data)
  74. if(d.code===config.status.SUCCESS){
  75. let res:user_results = d.content
  76. if(res.obtain_list.length<=0){
  77. this.unlock_car.getComponent(results_unlock_car).hide()
  78. console.log("啥也没获取到")
  79. }else{
  80. // this.unlock_car.getComponent(results_unlock_car).show(res.default_car_id)
  81. ClientEvent.dispatchEvent(config.UI_EVENT.GET_NEW_CAR,res)
  82. this.res_new_car.show(scores,res)
  83. }
  84. this.lab_des.getComponent(Label).string=`已超过全国${res.ratio}的司机`
  85. ClientEvent.dispatchEvent(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,res)
  86. }
  87. // http.get(config.STATIC_API.regions,(e,d)=>{
  88. // console.log("regions",d)
  89. // })
  90. // http.get(config.STATIC_API.rankings(0),(err,data)=>{
  91. // console.log("rankings",data)
  92. // })
  93. }
  94. jiesuan_finish_cb()
  95. })
  96. audioManager.Instance().playSound(config.AUDIO.win)
  97. this.node.active = true
  98. this.lab_scores.getComponent(Label).string =scores+""
  99. this.call_back = call
  100. }
  101. }