home.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. onUpdateUserDefaultCar() {
  52. this.home_car.getComponent(home_car).updateCar()
  53. // 刷新排行
  54. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  55. }
  56. onMsgGuangboRank(msg) {
  57. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  58. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  59. if(msg.ranking_list.length>0) {
  60. for (let index = 0; index < msg.ranking_list.length; index++) {
  61. const element = msg.ranking_list[index]
  62. if(element.user_id==userDataManager.user_data.id) {
  63. tools.mine_rank_data.nationwide_badge_status = 1
  64. this.bottom.getComponent(home_bottom).reloadHonorData()
  65. break
  66. }
  67. }
  68. }
  69. }
  70. public init(){
  71. this.top.getComponent(home_top).init()
  72. this.home_car.getComponent(home_car).updateCar()
  73. this.bottom.getComponent(home_bottom).init()
  74. }
  75. }