home.ts 3.3 KB

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