results.ts 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { _decorator, Component, Label, Node } from 'cc';
  2. import { http } from '../http';
  3. import { config } from '../config';
  4. import { audioManager } from '../manager/audioManager';
  5. import { uiManager } from '../manager/uiManager';
  6. import { user_results } from '../data';
  7. import { userDataManager } from '../manager/userDataManager';
  8. import { ClientEvent } from '../lib/clientEvent';
  9. import { SdkUtil } from '../sdkUtil';
  10. import { results_unlock_car } from './results_unlock_car';
  11. import { base_ui } from '../fw/base_ui';
  12. import { GameManager } from '../GameManager';
  13. import { restart_view } from '../ui/restart_view';
  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. private call_back = null
  25. private back_home_cb = null
  26. start() {
  27. this.onButtonListen(this.btn_restart,()=>{
  28. if(this.call_back!=null){
  29. GameManager.checkPlayGame(this.node,()=>{
  30. this.call_back(false)
  31. this.close()
  32. })
  33. }
  34. // this.onClickRestart()
  35. })
  36. this.onButtonListen(this.btn_back_home,()=>{
  37. if(this.back_home_cb){
  38. this.back_home_cb()
  39. }
  40. })
  41. this.onButtonListen(this.btn_video_reLife,()=>{
  42. GameManager.showVideoAd(config.ADS_TYPE.GAME_RELIFE_VIDEO, ()=>{
  43. if(this.call_back){
  44. this.call_back(true)
  45. this.close()
  46. }
  47. })
  48. })
  49. this.onButtonListen(this.btn_share,()=>{
  50. // SdkUtil.shareGame('',()=>{
  51. // if(this.call_back){
  52. // this.call_back(true)
  53. // this.close()
  54. // }
  55. // })
  56. })
  57. }
  58. protected close(): void {
  59. this.node.active = false;
  60. }
  61. public show(scores:number,call,back_home_cb,isReLife:boolean){
  62. this.back_home_cb = back_home_cb
  63. this.btn_video_reLife.active = isReLife
  64. http.post(config.API.sync_integral,{"integral":scores},(err,data)=>{
  65. if(!err){
  66. let d = JSON.parse(data)
  67. if(d.code===config.status.SUCCESS){
  68. let res:user_results = d.content
  69. if(res.obtain_list.length<=0){
  70. this.unlock_car.getComponent(results_unlock_car).hide()
  71. console.log("啥也没获取到")
  72. }else{
  73. this.unlock_car.getComponent(results_unlock_car).show(res.default_car_id)
  74. ClientEvent.dispatchEvent(config.UI_EVENT.GET_NEW_CAR,res)
  75. }
  76. this.lab_des.getComponent(Label).string=`已超过全国${res.ratio}的司机`
  77. ClientEvent.dispatchEvent(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,res)
  78. }
  79. // http.get(config.STATIC_API.regions,(e,d)=>{
  80. // console.log("regions",d)
  81. // })
  82. // http.get(config.STATIC_API.rankings(0),(err,data)=>{
  83. // console.log("rankings",data)
  84. // })
  85. }
  86. })
  87. audioManager.Instance().playSound(config.AUDIO.win)
  88. this.node.active = true
  89. this.lab_scores.getComponent(Label).string =scores+""
  90. this.call_back = call
  91. }
  92. }