home.ts 6.3 KB

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