home.ts 2.5 KB

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