home.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 { home_modules } from './home_modules';
  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) modules:Node = null
  20. @property(Node) btn_start_game:Node = null
  21. protected start(): void {
  22. uiManager.Instance().onButtonListen(this.btn_start_game,()=>{
  23. GameManager.checkPlayGame(this.node,()=>{
  24. tools.playGame(()=>{
  25. this.node.parent.active = true
  26. })
  27. this.node.parent.active = false
  28. })
  29. })
  30. ClientEvent.on(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,this.onGameOverSettleAccount.bind(this),this)
  31. ClientEvent.on(config.UI_EVENT.GET_NEW_CAR,this.onGetNewCar.bind(this),this)
  32. ClientEvent.on(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR,this.onUpdateUserDefaultCar.bind(this),this)
  33. ClientEvent.on(config.EVENT_TYPE.MSG_GUANGBO_RANK,this.onMsgGuangboRank.bind(this),this)
  34. ClientEvent.on(config.UI_EVENT.UPDATE_USER_INFO,this.onUpdateUserInfo.bind(this),this)
  35. ClientEvent.on(config.UI_EVENT.UPDATE_SIGN_RED_DOT_STATUS,this.onUpdateSignRedDotStatus.bind(this),this)
  36. ClientEvent.on(config.UI_EVENT.UPDATE_MAIL_RED_DOT_STATUS,this.onUpdateMailRedDotStatus.bind(this),this)
  37. ClientEvent.on(config.UI_EVENT.UPDATE_ANNOUNCEMENT_RED_DOT_STATUS,this.onUpdateAnnouncementRedDotStatus.bind(this),this)
  38. }
  39. public init(){
  40. this.top.getComponent(home_top).init()
  41. this.home_car.getComponent(home_car).updateCar()
  42. this.bottom.getComponent(home_bottom).init()
  43. this.modules.getComponent(home_modules).init()
  44. }
  45. onGameOverSettleAccount(res:user_results){
  46. // 更新本周分数、荣誉
  47. tools.mine_rank_data.score = res.max_integral
  48. this.bottom.getComponent(home_bottom).reloadWeekScore()
  49. tools.mine_rank_data.city_badge_status = res.city_badge_status
  50. tools.mine_rank_data.province_badge_status = res.province_badge_status
  51. tools.mine_rank_data.nationwide_badge_status = res.nationwide_badge_status
  52. this.bottom.getComponent(home_bottom).reloadHonorData()
  53. }
  54. onGetNewCar(res:user_results){
  55. // 更新默认车
  56. // userDataManager.user_car_list.default_car_id = res.default_car_id
  57. // console.log("获取新车:",dataManager.getUserCarInfo(userDataManager.user_car_list.default_car_id))
  58. // 更新用户解锁车列表
  59. userDataManager.user_car_list.car_list = res.unlock_car_list
  60. // 更新首页车
  61. this.home_car.getComponent(home_car).updateCar()
  62. // 检查我在排行中,更换车数据
  63. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  64. }
  65. onUpdateUserDefaultCar() {
  66. // 更新首页车
  67. this.home_car.getComponent(home_car).updateCar()
  68. // 检查我在排行中,更换车数据
  69. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  70. }
  71. onMsgGuangboRank(msg) {
  72. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  73. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  74. if(msg.ranking_list.length>0) {
  75. for (let index = 0; index < msg.ranking_list.length; index++) {
  76. const element = msg.ranking_list[index]
  77. if(element.user_id==userDataManager.user_data.id) {
  78. tools.mine_rank_data.nationwide_badge_status = 1
  79. this.bottom.getComponent(home_bottom).reloadHonorData()
  80. break
  81. }
  82. }
  83. }
  84. }
  85. onUpdateUserInfo() {
  86. this.top.getComponent(home_top).reloadUserInfo()
  87. }
  88. onUpdateSignRedDotStatus(is_show:boolean) {
  89. this.modules.getComponent(home_modules).showRedDotQiandao(is_show)
  90. }
  91. onUpdateMailRedDotStatus(stype:number) {
  92. let is_show = true
  93. if(stype==1) { //一键领取
  94. is_show = false
  95. } else {
  96. if(tools.user_red_dot_data.mail_unread_number>0) {
  97. tools.user_red_dot_data.mail_unread_number -=1
  98. if(tools.user_red_dot_data.mail_unread_number<=0) {
  99. is_show = false
  100. }
  101. }
  102. }
  103. console.log('mail_red_dot number=',tools.user_red_dot_data.mail_unread_number,'is_show=',is_show)
  104. this.modules.getComponent(home_modules).showRedDotYoujian(is_show)
  105. }
  106. onUpdateAnnouncementRedDotStatus(is_show:boolean) {
  107. this.modules.getComponent(home_modules).showRedDotGonggao(is_show)
  108. }
  109. }