home.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { _decorator, Component, Node } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { home_car } from './home_car';
  4. import { home_top } from './home_top';
  5. import { home_bottom } from './home_bottom';
  6. import { tools } from '../../tools';
  7. import { ClientEvent } from '../../lib/clientEvent';
  8. import { config } from '../../config';
  9. import { userDataManager } from '../../manager/userDataManager';
  10. import { user_results } from '../../data';
  11. import { GameManager } from '../../GameManager';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('home')
  14. export class home extends Component {
  15. @property(Node) home_car:Node = null
  16. @property(Node) top:Node = null
  17. @property(Node) bottom:Node = null
  18. @property(Node) btn_start_game:Node = null
  19. protected start(): void {
  20. uiManager.Instance().onButtonListen(this.btn_start_game,()=>{
  21. GameManager.checkPlayGame(this.node,()=>{
  22. tools.playGame(()=>{
  23. this.node.parent.active = true
  24. })
  25. this.node.parent.active = false
  26. })
  27. })
  28. ClientEvent.on(config.UI_EVENT.GET_NEW_CAR,this.onGetNewCar.bind(this),this)
  29. ClientEvent.on(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR,this.onUpdateUserDefaultCar.bind(this),this)
  30. ClientEvent.on(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,this.onGameOverSettleAccount.bind(this),this)
  31. ClientEvent.on(config.EVENT_TYPE.MSG_GUANGBO_RANK,this.onMsgGuangboRank.bind(this),this)
  32. }
  33. onGameOverSettleAccount(res:user_results){
  34. // 更新本周分数、荣誉
  35. tools.mine_rank_data.score = res.max_integral
  36. this.bottom.getComponent(home_bottom).reloadWeekScore()
  37. tools.mine_rank_data.city_badge_status = res.city_badge_status
  38. tools.mine_rank_data.province_badge_status = res.province_badge_status
  39. tools.mine_rank_data.nationwide_badge_status = res.nationwide_badge_status
  40. this.bottom.getComponent(home_bottom).reloadHonorData()
  41. }
  42. onGetNewCar(res:user_results){
  43. // 更新默认车
  44. userDataManager.user_car_list.default_car_id = res.default_car_id
  45. // console.log("获取新车:",dataManager.getCarInfoById(userDataManager.user_car_list.default_car_id))
  46. // 更新用户解锁车列表
  47. userDataManager.user_car_list.car_list = res.unlock_car_list
  48. // 更新首页车
  49. this.home_car.getComponent(home_car).updateCar()
  50. // 检查我在排行中,更换车数据
  51. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  52. }
  53. onUpdateUserDefaultCar() {
  54. // 更新首页车
  55. this.home_car.getComponent(home_car).updateCar()
  56. // 检查我在排行中,更换车数据
  57. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  58. }
  59. onMsgGuangboRank(msg) {
  60. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  61. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  62. if(msg.ranking_list.length>0) {
  63. for (let index = 0; index < msg.ranking_list.length; index++) {
  64. const element = msg.ranking_list[index]
  65. if(element.user_id==userDataManager.user_data.id) {
  66. tools.mine_rank_data.nationwide_badge_status = 1
  67. this.bottom.getComponent(home_bottom).reloadHonorData()
  68. break
  69. }
  70. }
  71. }
  72. }
  73. public init(){
  74. this.top.getComponent(home_top).init()
  75. this.home_car.getComponent(home_car).updateCar()
  76. this.bottom.getComponent(home_bottom).init()
  77. }
  78. }