home_bottom.ts 7.2 KB

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