home_bottom.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { _decorator, Component, Label, Node, Animation } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { config } from '../../config';
  4. import { user_info_view } from '../user_info_view';
  5. import { home_bottom_rank_item } from './home_bottom_rank_item';
  6. import { GameManager } from '../../GameManager';
  7. import { tools } from '../../tools';
  8. import { home_honor } from './home_honor';
  9. import { home_bottom_countdown } from './home_bottom_countdown';
  10. import { unLock_view } from '../unLock_view';
  11. import { userDataManager } from '../../manager/userDataManager';
  12. import { home_tt_sidebar } from './home_tt_sidebar';
  13. import { SdkUtil } from '../../sdkUtil';
  14. import { ClientEvent } from '../../lib/clientEvent';
  15. import { rank } from '../rank/rank';
  16. const { ccclass, property } = _decorator;
  17. @ccclass('home_bottom')
  18. export class home_bottom extends Component {
  19. @property(Node) img_honor:Node = null
  20. @property(Node) btn_wenhao:Node = null
  21. @property(Node) btn_gengduo:Node = null
  22. @property(Node) rank1_node:Node = null
  23. @property(Node) rank2_node:Node = null
  24. @property(Node) rank3_node:Node = null
  25. @property(Node) lab_week_score:Node = null
  26. @property(Node) img_loudou:Node = null
  27. @property(Node) btn_wuxiancishu:Node = null
  28. @property(Node) countdown_node:Node = null
  29. @property(Node) tt_btn_gift:Node = null
  30. @property(Node) tt_sidebar:Node = null
  31. private m_d_content = null
  32. private rank_item_list:home_bottom_rank_item[] = []
  33. start() {
  34. uiManager.Instance().onButtonListen(this.btn_wenhao, ()=>{
  35. uiManager.Instance().showUi(config.UI.ui_gameplay_view)
  36. })
  37. uiManager.Instance().onButtonListen(this.btn_gengduo, ()=>{
  38. this.node.parent.active = false
  39. uiManager.Instance().showUi(config.UI.rank, null, (node:Node)=>{
  40. node.getComponent(rank).onReloadCountryDataCallback((d_content)=>{
  41. this.reloadCountryRankData(d_content)
  42. })
  43. this.node.parent.active = true
  44. })
  45. })
  46. uiManager.Instance().onButtonListen(this.btn_wuxiancishu, ()=>{
  47. if(userDataManager.getUserIsFreeAds()) {
  48. return
  49. }
  50. uiManager.Instance().showUi(config.UI.ui_unLock_view, null, (node:Node)=>{
  51. node.getComponent(unLock_view).initView((v:unLock_view)=>{
  52. this.reloadCountdown()
  53. })
  54. })
  55. })
  56. uiManager.Instance().onButtonListen(this.tt_btn_gift, ()=>{
  57. this.onClickTTGift()
  58. })
  59. this.rank_item_list.push(this.rank1_node.getComponent(home_bottom_rank_item))
  60. this.rank_item_list.push(this.rank2_node.getComponent(home_bottom_rank_item))
  61. this.rank_item_list.push(this.rank3_node.getComponent(home_bottom_rank_item))
  62. }
  63. public init() {
  64. this.reloadWeekScore()
  65. this.reloadHonorData()
  66. this.reloadCountdown()
  67. this.requestCountryRankData()
  68. this.reloadTTSidebar()
  69. }
  70. public reloadWeekScore() {
  71. this.lab_week_score.getComponent(Label).string = tools.mine_rank_data.score + ''
  72. }
  73. public reloadHonorData() {
  74. this.img_honor.getComponent(home_honor).initView()
  75. }
  76. private reloadCountdown() {
  77. this.countdown_node.getComponent(home_bottom_countdown).startTime((is_active)=>{
  78. this.btn_wuxiancishu.active = !is_active
  79. if(is_active) {
  80. this.img_loudou.getComponent(Animation).play()
  81. } else {
  82. this.img_loudou.getComponent(Animation).stop()
  83. }
  84. })
  85. }
  86. public requestCountryRankData(){
  87. GameManager.requestRankList(0, (d_content)=>{
  88. this.reloadCountryRankData(d_content)
  89. })
  90. }
  91. public reloadCountryRankData(d_content) {
  92. this.m_d_content = d_content
  93. if(d_content.length>0) {
  94. let rank_data = d_content[0]
  95. this.loadRankItemData(0,rank_data)
  96. }
  97. if(d_content.length>1) {
  98. let rank_data = d_content[1]
  99. this.loadRankItemData(1,rank_data)
  100. }
  101. if(d_content.length>2) {
  102. let rank_data = d_content[2]
  103. this.loadRankItemData(2,rank_data)
  104. }
  105. }
  106. public checkIsMineCountryRank() {
  107. if(this.m_d_content==undefined||this.m_d_content==null) {
  108. return
  109. }
  110. for (let index = 0; index < this.m_d_content.length; index++) {
  111. const element = this.m_d_content[index]
  112. if(element.user_id==userDataManager.user_data.id) {
  113. this.loadRankItemData(index,element)
  114. break
  115. }
  116. }
  117. }
  118. private loadRankItemData(index:number, rank_data) {
  119. this.rank_item_list[index].initView(rank_data, this.onClickRankGotoUserInfo.bind(this))
  120. }
  121. private onClickRankGotoUserInfo(item:home_bottom_rank_item) {
  122. let data = item.getData()
  123. if(data == null) {
  124. return
  125. }
  126. uiManager.Instance().showUi(config.UI.ui_user_info_view, null, (node:Node)=>{
  127. node.getComponent(user_info_view).initView(data)
  128. })
  129. }
  130. private reloadTTSidebar() {
  131. this.tt_btn_gift.active = false
  132. if(SdkUtil.ttCheckSceneShowRewards()==false || userDataManager.user_data.tt_sidebar_reward_status==1) {
  133. return
  134. }
  135. this.tt_btn_gift.active = true
  136. this.tt_btn_gift.getComponent(Animation).play()
  137. }
  138. private onClickTTGift() {
  139. let isToEnterFromSidebar = SdkUtil.ttCheckToEnterFromSidebar()
  140. this.tt_sidebar.getComponent(home_tt_sidebar).show(isToEnterFromSidebar, (r:home_tt_sidebar)=>{
  141. SdkUtil.ttNavToSidebarScene()
  142. r.close()
  143. },(r:home_tt_sidebar)=>{
  144. GameManager.requestTTSidebarUserReward(config.USER_TT_SIDEBAR_REWARD.SYNC, (d_content)=>{
  145. userDataManager.user_data.tt_sidebar_reward_status = d_content.status
  146. this.tt_btn_gift.active = false
  147. this.tt_btn_gift.getComponent(Animation).stop()
  148. this.ttSidebarReward()
  149. r.close()
  150. })
  151. })
  152. }
  153. private ttSidebarReward() {
  154. let add_seconds = 60*30 //30分钟
  155. userDataManager.addUserFreeAdsSeconds(add_seconds)
  156. this.reloadCountdown()
  157. }
  158. }