home.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 { dataManager } from '../../manager/dataManager';
  11. import { user_results } from '../../data';
  12. import { GameManager } from '../../GameManager';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('home')
  15. export class home extends Component {
  16. @property(Node) home_car:Node = null
  17. @property(Node) top:Node = null
  18. @property(Node) bottom:Node = null
  19. @property(Node) btn_start_game:Node = null
  20. protected start(): void {
  21. uiManager.Instance().onButtonListen(this.btn_start_game,()=>{
  22. tools.playGame(()=>{
  23. this.node.parent.active = true
  24. })
  25. this.node.parent.active = false
  26. })
  27. ClientEvent.on(config.UI_EVENT.GET_NEW_CAR,this.onGetNewCar.bind(this),this)
  28. ClientEvent.on(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR,this.onUpdateUserDefaultCar.bind(this),this)
  29. ClientEvent.on(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,this.onGameOverSettleAccount.bind(this),this)
  30. }
  31. onGameOverSettleAccount(res:user_results){
  32. // 更新本周分数
  33. tools.mine_rank_data.score = res.max_integral
  34. this.bottom.getComponent(home_bottom).reloadWeekScore()
  35. }
  36. onGetNewCar(res:user_results){
  37. // 更新默认车
  38. userDataManager.user_car_list.default_car_id = res.default_car_id
  39. // console.log("获取新车:",dataManager.getCarInfoById(userDataManager.user_car_list.default_car_id))
  40. // 更新用户解锁车列表
  41. userDataManager.user_car_list.car_list = res.unlock_car_list
  42. // 更新首页车
  43. this.home_car.getComponent(home_car).updateCar()
  44. }
  45. onUpdateUserDefaultCar() {
  46. this.home_car.getComponent(home_car).updateCar()
  47. }
  48. public init(){
  49. this.top.getComponent(home_top).init()
  50. this.home_car.getComponent(home_car).updateCar()
  51. this.bottom.getComponent(home_bottom).init()
  52. this.everyTenMinutesUpdate()
  53. }
  54. private everyTenMinutesUpdate() {
  55. this.unscheduleAllCallbacks()
  56. this.schedule(()=>{
  57. this.bottom.getComponent(home_bottom).reloadCountryRankData()
  58. },600)
  59. }
  60. }