home.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.UI_EVENT.UPDATE_USER_INFO,this.onUpdateUserInfo.bind(this),this)
  34. ClientEvent.on(config.UI_EVENT.UPDATE_RED_DOT_STATUS,this.onUpdateRedDotStatus.bind(this),this)
  35. ClientEvent.on(config.EVENT_TYPE.MSG_DATA,this.onMsgData.bind(this),this)
  36. }
  37. public init(){
  38. this.top.getComponent(home_top).init()
  39. this.home_car.getComponent(home_car).updateCar()
  40. this.bottom.getComponent(home_bottom).init()
  41. this.modules.getComponent(home_modules).init()
  42. }
  43. onGameOverSettleAccount(res:user_results){
  44. // 更新本周分数、荣誉
  45. tools.mine_rank_data.score = res.max_integral
  46. this.bottom.getComponent(home_bottom).reloadWeekScore()
  47. tools.mine_rank_data.city_badge_status = res.city_badge_status
  48. tools.mine_rank_data.province_badge_status = res.province_badge_status
  49. tools.mine_rank_data.nationwide_badge_status = res.nationwide_badge_status
  50. this.bottom.getComponent(home_bottom).reloadHonorData()
  51. }
  52. onGetNewCar(res:user_results){
  53. // 更新默认车
  54. // userDataManager.user_car_list.default_car_id = res.default_car_id
  55. // console.log("获取新车:",dataManager.getUserCarInfo(userDataManager.user_car_list.default_car_id))
  56. // 更新用户解锁车列表
  57. userDataManager.user_car_list.car_list = res.unlock_car_list
  58. // 更新首页车
  59. this.home_car.getComponent(home_car).updateCar()
  60. // 检查我在排行中,更换车数据
  61. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  62. }
  63. onUpdateUserDefaultCar() {
  64. // 更新首页车
  65. this.home_car.getComponent(home_car).updateCar()
  66. // 检查我在排行中,更换车数据
  67. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  68. }
  69. onUpdateUserInfo() {
  70. this.top.getComponent(home_top).reloadUserInfo()
  71. }
  72. onUpdateRedDotStatus(type:number) {
  73. switch (type) {
  74. case config.RED_DOT_TYPE.announcement:
  75. this.updateAnnouncementRedDotStatus()
  76. break;
  77. case config.RED_DOT_TYPE.sign:
  78. this.updateSignRedDotStatus()
  79. break;
  80. case config.RED_DOT_TYPE.mail:
  81. this.updateMailRedDotStatus()
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. onMsgData(data) {
  88. let msg = data.msg
  89. switch (data.action) {
  90. case config.MSG_TYPE.guangbo:
  91. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  92. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  93. if(msg.ranking_list.length>0) {
  94. for (let index = 0; index < msg.ranking_list.length; index++) {
  95. const element = msg.ranking_list[index]
  96. if(element.user_id==userDataManager.user_data.id) {
  97. tools.mine_rank_data.nationwide_badge_status = 1
  98. this.bottom.getComponent(home_bottom).reloadHonorData()
  99. break
  100. }
  101. }
  102. }
  103. break;
  104. case config.MSG_TYPE.announcement:
  105. tools.user_red_dot_data.bulletin_red_dot = msg.bulletin_red_dot
  106. this.updateAnnouncementRedDotStatus()
  107. break
  108. case config.MSG_TYPE.mail:
  109. tools.user_red_dot_data.mail_unread_number = msg.mail_unread_number
  110. this.updateMailRedDotStatus()
  111. break
  112. default:
  113. break;
  114. }
  115. }
  116. private updateAnnouncementRedDotStatus() {
  117. if(tools.user_red_dot_data.bulletin_red_dot==1) {
  118. this.modules.getComponent(home_modules).showRedDotGonggao(true)
  119. } else {
  120. this.modules.getComponent(home_modules).showRedDotGonggao(false)
  121. }
  122. }
  123. private updateSignRedDotStatus() {
  124. if(tools.user_red_dot_data.sign_red_dot==1) {
  125. this.modules.getComponent(home_modules).showRedDotQiandao(true)
  126. } else {
  127. this.modules.getComponent(home_modules).showRedDotQiandao(false)
  128. }
  129. }
  130. private updateMailRedDotStatus() {
  131. if(tools.user_red_dot_data.mail_unread_number>0) {
  132. this.modules.getComponent(home_modules).showRedDotYoujian(true)
  133. } else {
  134. this.modules.getComponent(home_modules).showRedDotYoujian(false)
  135. }
  136. }
  137. }