home.ts 6.6 KB

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