home_bottom.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. start() {
  32. uiManager.Instance().onButtonListen(this.btn_wenhao, ()=>{
  33. uiManager.Instance().showUi(config.UI.ui_gameplay_view)
  34. })
  35. uiManager.Instance().onButtonListen(this.btn_gengduo, ()=>{
  36. this.node.parent.active = false
  37. uiManager.Instance().showUi(config.UI.rank, null, (node:Node)=>{
  38. node.getComponent(rank).onReloadCountryDataCallback((d_content)=>{
  39. this.reloadCountryRankData(d_content)
  40. })
  41. this.node.parent.active = true
  42. })
  43. })
  44. uiManager.Instance().onButtonListen(this.btn_wuxiancishu, ()=>{
  45. if(userDataManager.getUserIsFreeAds()) {
  46. return
  47. }
  48. uiManager.Instance().showUi(config.UI.ui_unLock_view, null, (node:Node)=>{
  49. node.getComponent(unLock_view).initView((v:unLock_view)=>{
  50. this.reloadCountdown()
  51. })
  52. })
  53. })
  54. uiManager.Instance().onButtonListen(this.tt_btn_gift, ()=>{
  55. this.onClickTTLihe()
  56. })
  57. }
  58. public init() {
  59. this.reloadWeekScore()
  60. this.reloadHonorData()
  61. this.reloadCountdown()
  62. this.requestCountryRankData()
  63. this.reloadTTSidebar()
  64. }
  65. public reloadWeekScore() {
  66. this.lab_week_score.getComponent(Label).string = tools.mine_rank_data.score + ''
  67. }
  68. public reloadHonorData() {
  69. this.img_honor.getComponent(home_honor).initView()
  70. }
  71. private reloadCountdown() {
  72. this.countdown_node.getComponent(home_bottom_countdown).startTime((is_active)=>{
  73. this.btn_wuxiancishu.active = !is_active
  74. if(is_active) {
  75. this.img_loudou.getComponent(Animation).play()
  76. } else {
  77. this.img_loudou.getComponent(Animation).stop()
  78. }
  79. })
  80. }
  81. public requestCountryRankData(){
  82. GameManager.requestRankList(0, (d_content)=>{
  83. this.reloadCountryRankData(d_content)
  84. })
  85. }
  86. public reloadCountryRankData(d_content) {
  87. if(d_content.length>0) {
  88. let rank_data = d_content[0]
  89. this.rank1_node.getComponent(home_bottom_rank_item).initView(rank_data, this.onClickRankGotoUserInfo.bind(this))
  90. }
  91. if(d_content.length>1) {
  92. let rank_data = d_content[1]
  93. this.rank2_node.getComponent(home_bottom_rank_item).initView(rank_data, this.onClickRankGotoUserInfo.bind(this))
  94. }
  95. if(d_content.length>2) {
  96. let rank_data = d_content[2]
  97. this.rank3_node.getComponent(home_bottom_rank_item).initView(rank_data, this.onClickRankGotoUserInfo.bind(this))
  98. }
  99. }
  100. private onClickRankGotoUserInfo(item:home_bottom_rank_item) {
  101. let data = item.getData()
  102. if(data == null) {
  103. return
  104. }
  105. uiManager.Instance().showUi(config.UI.ui_user_info_view, null, (node:Node)=>{
  106. node.getComponent(user_info_view).initView(data)
  107. })
  108. }
  109. private reloadTTSidebar() {
  110. this.tt_btn_gift.active = false
  111. if(SdkUtil.ttCheckSceneShowRewards()==false || userDataManager.user_data.tt_sidebar_reward_status==1) {
  112. return
  113. }
  114. this.tt_btn_gift.active = true
  115. this.tt_btn_gift.getComponent(Animation).play()
  116. }
  117. private onClickTTLihe() {
  118. let isToEnterFromSidebar = SdkUtil.ttCheckToEnterFromSidebar()
  119. this.tt_sidebar.getComponent(home_tt_sidebar).show(isToEnterFromSidebar, (r:home_tt_sidebar)=>{
  120. SdkUtil.ttNavToSidebarScene()
  121. r.close()
  122. },(r:home_tt_sidebar)=>{
  123. GameManager.requestTTSidebarUserReward(config.USER_TT_SIDEBAR_REWARD.SYNC, (d_content)=>{
  124. userDataManager.user_data.tt_sidebar_reward_status = d_content.status
  125. this.tt_btn_gift.active = false
  126. this.tt_btn_gift.getComponent(Animation).stop()
  127. this.ttSidebarReward()
  128. r.close()
  129. })
  130. })
  131. }
  132. private ttSidebarReward() {
  133. let add_seconds = 60*30 //30分钟
  134. userDataManager.addUserFreeAdsSeconds(add_seconds)
  135. this.reloadCountdown()
  136. }
  137. }