home.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. import { SdkUtil } from '../../sdkUtil';
  14. const { ccclass, property } = _decorator;
  15. @ccclass('home')
  16. export class home extends Component {
  17. @property(Node) home_car:Node = null
  18. @property(Node) top:Node = null
  19. @property(Node) bottom:Node = null
  20. @property(Node) modules:Node = null
  21. @property(Node) btn_start_game:Node = null
  22. protected start(): void {
  23. uiManager.Instance().onButtonListen(this.btn_start_game,()=>{
  24. GameManager.checkPlayGame(this.node,()=>{
  25. tools.playGame(()=>{
  26. this.node.parent.active = true
  27. ClientEvent.dispatchEvent(config.UI_EVENT.HOME_DID_BECOME_ACTIVE)
  28. })
  29. this.node.parent.active = false
  30. ClientEvent.dispatchEvent(config.UI_EVENT.HOME_DID_BECOME_INACTIVE)
  31. })
  32. })
  33. ClientEvent.on(config.UI_EVENT.HOME_DID_BECOME_ACTIVE,this.homeDidBecomeActive.bind(this),this)
  34. ClientEvent.on(config.UI_EVENT.HOME_DID_BECOME_INACTIVE,this.homeDidBecomeInactive.bind(this),this)
  35. ClientEvent.on(config.UI_EVENT.UPDATE_GAME_FREE_COUNT,this.onUpdateGameFreeCount.bind(this),this)
  36. ClientEvent.on(config.UI_EVENT.GAME_OVER_SETTLE_ACCOUNT,this.onGameOverSettleAccount.bind(this),this)
  37. ClientEvent.on(config.UI_EVENT.GET_NEW_CAR,this.onGetNewCar.bind(this),this)
  38. ClientEvent.on(config.UI_EVENT.UPDATE_USER_DEFAULT_CAR,this.onUpdateUserDefaultCar.bind(this),this)
  39. ClientEvent.on(config.UI_EVENT.UPDATE_USER_INFO,this.onUpdateUserInfo.bind(this),this)
  40. ClientEvent.on(config.UI_EVENT.UPDATE_USER_AVATAR_BORDER,this.onUpdateUserAvatarBorder.bind(this),this)
  41. ClientEvent.on(config.UI_EVENT.UPDATE_RED_DOT_STATUS,this.onUpdateRedDotStatus.bind(this),this)
  42. ClientEvent.on(config.EVENT_TYPE.MSG_DATA,this.onMsgData.bind(this),this)
  43. SdkUtil.showGridGamePanel()
  44. }
  45. public init(){
  46. this.top.getComponent(home_top).init()
  47. this.home_car.getComponent(home_car).updateCar()
  48. this.bottom.getComponent(home_bottom).init()
  49. this.modules.getComponent(home_modules).init()
  50. }
  51. homeDidBecomeActive() {
  52. // console.log('home 活跃的 活跃的 活跃的')
  53. SdkUtil.showGridGamePanel()
  54. }
  55. homeDidBecomeInactive() {
  56. // console.log('home 不活跃的 不活跃的 不活跃的')
  57. this.modules.getComponent(home_modules).hideGengduoView()
  58. SdkUtil.hideGridGamePanel()
  59. }
  60. onUpdateGameFreeCount() {
  61. this.bottom.getComponent(home_bottom).reloadGameFreeCount()
  62. }
  63. onGameOverSettleAccount(res:user_results){
  64. // 更新本周分数、荣誉
  65. tools.mine_rank_data.score = res.max_integral
  66. this.bottom.getComponent(home_bottom).reloadWeekScore()
  67. tools.mine_rank_data.city_badge_status = res.city_badge_status
  68. tools.mine_rank_data.province_badge_status = res.province_badge_status
  69. tools.mine_rank_data.nationwide_badge_status = res.nationwide_badge_status
  70. this.bottom.getComponent(home_bottom).reloadHonorData()
  71. }
  72. onGetNewCar(res:user_results){
  73. // 更新默认车
  74. // userDataManager.user_car_list.default_car_id = res.default_car_id
  75. // console.log("获取新车:",dataManager.getUserCarInfo(userDataManager.user_car_list.default_car_id))
  76. // 更新用户解锁车列表
  77. userDataManager.user_car_list.car_list = res.unlock_car_list
  78. // 更新首页车
  79. this.home_car.getComponent(home_car).updateCar()
  80. // 检查我在排行中,更换车数据
  81. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  82. }
  83. onUpdateUserDefaultCar() {
  84. // 更新首页车
  85. this.home_car.getComponent(home_car).updateCar()
  86. // 检查我在排行中,更换车数据
  87. this.bottom.getComponent(home_bottom).checkIsMineCountryRank()
  88. }
  89. onUpdateUserInfo() {
  90. this.top.getComponent(home_top).reloadUserInfo()
  91. }
  92. onUpdateUserAvatarBorder() {
  93. this.top.getComponent(home_top).reloadUserAvatarBorder()
  94. }
  95. onUpdateRedDotStatus(type:number) {
  96. switch (type) {
  97. case config.RED_DOT_TYPE.announcement:
  98. this.updateAnnouncementRedDotStatus()
  99. break;
  100. case config.RED_DOT_TYPE.sign:
  101. this.updateSignRedDotStatus()
  102. break;
  103. case config.RED_DOT_TYPE.mail:
  104. this.updateMailRedDotStatus()
  105. break;
  106. default:
  107. break;
  108. }
  109. }
  110. onMsgData(data) {
  111. let msg = data.msg
  112. switch (data.action) {
  113. case config.MSG_TYPE.guangbo:
  114. this.top.getComponent(home_top).reloadGuangboData(msg.notice_list)
  115. this.bottom.getComponent(home_bottom).reloadCountryRankData(msg.ranking_list)
  116. if(msg.ranking_list.length>0) {
  117. for (let index = 0; index < msg.ranking_list.length; index++) {
  118. const element = msg.ranking_list[index]
  119. if(element.user_id==userDataManager.user_data.id) {
  120. tools.mine_rank_data.nationwide_badge_status = 1
  121. this.bottom.getComponent(home_bottom).reloadHonorData()
  122. break
  123. }
  124. }
  125. }
  126. break;
  127. case config.MSG_TYPE.announcement:
  128. userDataManager.user_red_dot_data.bulletin_red_dot = msg.bulletin_red_dot
  129. this.updateAnnouncementRedDotStatus()
  130. break
  131. case config.MSG_TYPE.mail:
  132. userDataManager.user_red_dot_data.mail_unread_number = msg.mail_unread_number
  133. this.updateMailRedDotStatus()
  134. break
  135. default:
  136. break;
  137. }
  138. }
  139. private updateAnnouncementRedDotStatus() {
  140. if(userDataManager.user_red_dot_data.bulletin_red_dot==1) {
  141. this.modules.getComponent(home_modules).showRedDotGonggao(true)
  142. } else {
  143. this.modules.getComponent(home_modules).showRedDotGonggao(false)
  144. }
  145. }
  146. private updateSignRedDotStatus() {
  147. if(userDataManager.user_red_dot_data.sign_red_dot==1) {
  148. this.modules.getComponent(home_modules).showRedDotQiandao(true)
  149. } else {
  150. this.modules.getComponent(home_modules).showRedDotQiandao(false)
  151. }
  152. }
  153. private updateMailRedDotStatus() {
  154. if(userDataManager.user_red_dot_data.mail_unread_number>0) {
  155. this.modules.getComponent(home_modules).showRedDotYoujian(true)
  156. } else {
  157. this.modules.getComponent(home_modules).showRedDotYoujian(false)
  158. }
  159. }
  160. }