home.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import { dataManager } from '../../manager/dataManager';
  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. @property(Node) temp_btn_qd:Node = null
  21. @property(Node) temp_btn_bb:Node = null
  22. @property(Node) temp_btn_yj:Node = null
  23. protected start(): void {
  24. uiManager.Instance().onButtonListen(this.btn_start_game,()=>{
  25. GameManager.checkPlayGame(this.node,()=>{
  26. tools.playGame(()=>{
  27. this.node.parent.active = true
  28. })
  29. this.node.parent.active = false
  30. })
  31. })
  32. ClientEvent.on(config.UI_EVENT.GET_NEW_CAR,this.onGetNewCar.bind(this),this)
  33. ClientEvent.on(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR,this.onUpdateUserDefaultCar.bind(this),this)
  34. ClientEvent.on(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,this.onGameOverSettleAccount.bind(this),this)
  35. ClientEvent.on(config.EVENT_TYPE.MSG_GUANGBO_RANK,this.onMsgGuangboRank.bind(this),this)
  36. uiManager.Instance().onButtonListen(this.temp_btn_qd,()=>{
  37. uiManager.Instance().showUi(config.UI.ui_sign_view)
  38. })
  39. uiManager.Instance().onButtonListen(this.temp_btn_bb,()=>{
  40. uiManager.Instance().showUi(config.UI.bag)
  41. })
  42. uiManager.Instance().onButtonListen(this.temp_btn_yj,()=>{
  43. uiManager.Instance().showUi(config.UI.ui_mailbox)
  44. })
  45. }
  46. onGameOverSettleAccount(res:user_results){
  47. // 更新本周分数、荣誉
  48. tools.mine_rank_data.score = res.max_integral
  49. this.bottom.getComponent(home_bottom).reloadWeekScore()
  50. tools.mine_rank_data.city_badge_status = res.city_badge_status
  51. tools.mine_rank_data.province_badge_status = res.province_badge_status
  52. tools.mine_rank_data.nationwide_badge_status = res.nationwide_badge_status
  53. this.bottom.getComponent(home_bottom).reloadHonorData()
  54. }
  55. onGetNewCar(res:user_results){
  56. // 更新默认车
  57. // userDataManager.user_car_list.default_car_id = res.default_car_id
  58. // console.log("获取新车:",dataManager.getUserCarInfo(userDataManager.user_car_list.default_car_id))
  59. // 更新用户解锁车列表
  60. userDataManager.user_car_list.car_list = res.unlock_car_list
  61. // 更新首页车
  62. this.home_car.getComponent(home_car).updateCar()
  63. // 检查我在排行中,更换车数据
  64. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  65. }
  66. onUpdateUserDefaultCar() {
  67. // 更新首页车
  68. this.home_car.getComponent(home_car).updateCar()
  69. // 检查我在排行中,更换车数据
  70. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  71. }
  72. onMsgGuangboRank(msg) {
  73. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  74. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  75. if(msg.ranking_list.length>0) {
  76. for (let index = 0; index < msg.ranking_list.length; index++) {
  77. const element = msg.ranking_list[index]
  78. if(element.user_id==userDataManager.user_data.id) {
  79. tools.mine_rank_data.nationwide_badge_status = 1
  80. this.bottom.getComponent(home_bottom).reloadHonorData()
  81. break
  82. }
  83. }
  84. }
  85. }
  86. public init(){
  87. this.top.getComponent(home_top).init()
  88. this.home_car.getComponent(home_car).updateCar()
  89. this.bottom.getComponent(home_bottom).init()
  90. }
  91. }