results.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. const { ccclass, property } = _decorator;
  12. @ccclass('results')
  13. export class results extends Component {
  14. @property(Node) btn_restart:Node = null
  15. @property(Node) lab_scores:Node = null
  16. @property(Node) btn_back_home:Node = null
  17. @property(Node) btn_video_reLife:Node = null
  18. @property(Node) unlock_car:Node = null
  19. @property(Node) btn_share:Node = null
  20. @property(Node) lab_des:Node = null
  21. private call_back = null
  22. private back_home_cb = null
  23. start() {
  24. uiManager.Instance().onButtonListen(this.btn_restart,()=>{
  25. if(this.call_back!=null){
  26. this.call_back()
  27. this.close()
  28. }
  29. })
  30. uiManager.Instance().onButtonListen(this.btn_back_home,()=>{
  31. if(this.back_home_cb){
  32. this.back_home_cb()
  33. }
  34. })
  35. uiManager.Instance().onButtonListen(this.btn_video_reLife,()=>{
  36. SdkUtil.showVideoAd(config.ADS_CONFIG.GAME_RELIFE_VIDEO,()=>{
  37. if(this.call_back){
  38. this.call_back(true)
  39. this.close()
  40. }
  41. })
  42. })
  43. uiManager.Instance().onButtonListen(this.btn_share,()=>{
  44. SdkUtil.shareGame(config.ADS_CONFIG.GAME_RELIFE_SHARE_TITLE,()=>{
  45. // if(this.call_back){
  46. // this.call_back(true)
  47. // this.close()
  48. // }
  49. })
  50. })
  51. }
  52. private close(){
  53. this.node.active = false;
  54. }
  55. public show(scores:number,call,back_home_cb,isFristOverGame:boolean){
  56. this.back_home_cb = back_home_cb
  57. this.btn_video_reLife.active = isFristOverGame
  58. http.post(config.API.sync_integral,{"integral":scores},(err,data)=>{
  59. if(!err){
  60. let d = JSON.parse(data)
  61. if(d.code===config.status.SUCCESS){
  62. let res:user_results = d.content
  63. if(res.obtain_list.length<=0){
  64. this.unlock_car.getComponent(results_unlock_car).hide()
  65. console.log("啥也没获取到")
  66. }else{
  67. this.unlock_car.getComponent(results_unlock_car).show(res.default_car_id)
  68. ClientEvent.dispatchEvent(config.UI_EVENT.GET_NEW_CAR,res)
  69. }
  70. this.lab_des.getComponent(Label).string=`已超过全国${res.ratio}的司机`
  71. ClientEvent.dispatchEvent(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,res)
  72. }
  73. // http.get(config.STATIC_API.regions,(e,d)=>{
  74. // console.log("regions",d)
  75. // })
  76. // http.get(config.STATIC_API.rankings(0),(err,data)=>{
  77. // console.log("rankings",data)
  78. // })
  79. }
  80. })
  81. audioManager.Instance().playSound(config.AUDIO.win)
  82. this.node.active = true
  83. this.lab_scores.getComponent(Label).string =scores+""
  84. this.call_back = call
  85. }
  86. }