home_bottom.ts 5.3 KB

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