results.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  72. // http.get(config.STATIC_API.regions,(e,d)=>{
  73. // console.log("regions",d)
  74. // })
  75. // http.get(config.STATIC_API.rankings(0),(err,data)=>{
  76. // console.log("rankings",data)
  77. // })
  78. }
  79. })
  80. audioManager.Instance().playSound(config.AUDIO.win)
  81. this.node.active = true
  82. this.lab_scores.getComponent(Label).string =scores+""
  83. this.call_back = call
  84. }
  85. }