rank.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { _decorator, Component, instantiate, Node, Prefab, ScrollView } from 'cc';
  2. import { uiManager } from '../../manager/uiManager';
  3. import { rank_list_item } from './rank_list_item';
  4. import { rank_my_info } from './rank_my_info';
  5. import { rank_list_top } from './rank_list_top';
  6. import { userDataManager } from '../../manager/userDataManager';
  7. import { GameManager } from '../../GameManager';
  8. import { rank_classify } from './rank_classify';
  9. import { config } from '../../config';
  10. import { ClientEvent } from '../../lib/clientEvent';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('rank')
  13. export class rank extends Component {
  14. @property(Node) btn_back:Node = null;
  15. @property(Node) classify_node:Node = null;
  16. @property(Node) list:Node = null;
  17. @property(Node) list_top:Node = null;
  18. @property(Node) list_content:Node = null;
  19. @property(Prefab) rank_list_item:Prefab = null;
  20. @property(Node) my_info_node:Node = null;
  21. @property(Node) btn_quarter_box:Node = null;
  22. private m_onReloadCountryDataCallback = null;
  23. onReloadCountryDataCallback(cb) {
  24. this.m_onReloadCountryDataCallback = cb
  25. }
  26. start() {
  27. uiManager.Instance().onButtonListen(this.btn_back, ()=>{
  28. this.close()
  29. ClientEvent.dispatchEvent(config.UI_EVENT.HOME_DID_BECOME_ACTIVE)
  30. })
  31. uiManager.Instance().onButtonListen(this.btn_quarter_box, ()=>{
  32. uiManager.Instance().showUi(config.UI.ui_quarter_rank_view)
  33. })
  34. let type = 1
  35. this.classify_node.getComponent(rank_classify).init(type,this.onClassifyItem.bind(this))
  36. this.loadView(type)
  37. }
  38. onClassifyItem(type:number) {
  39. this.loadView(type)
  40. }
  41. loadView(type:number) {
  42. let id = 0
  43. if(type==1) {
  44. id = 0
  45. this.btn_quarter_box.active = true
  46. } else if(type==2) {
  47. id = userDataManager.user_data.region_pid
  48. this.btn_quarter_box.active = false
  49. } else if(type==3) {
  50. id = userDataManager.user_data.region_id
  51. this.btn_quarter_box.active = false
  52. }
  53. GameManager.requestRankList(id,(d_content)=>{
  54. // console.log('排行列表 id=',id, '数据=',d_content)
  55. if(id==0) {
  56. if(this.m_onReloadCountryDataCallback!=null) {
  57. this.m_onReloadCountryDataCallback(d_content)
  58. }
  59. }
  60. this.reloadListTop(d_content, type)
  61. this.reloadListContent(d_content, type)
  62. this.reloadMyInfo(type)
  63. }, true)
  64. }
  65. reloadListTop(data_list, type:number) {
  66. this.list_top.getComponent(rank_list_top).initView(data_list, type)
  67. }
  68. reloadListContent(data_list, type:number) {
  69. this.list_content.removeAllChildren()
  70. if(data_list.length < 3) {
  71. return
  72. }
  73. for (let index = 3; index < data_list.length; index++) {
  74. const element = data_list[index]
  75. let item = instantiate(this.rank_list_item)
  76. item.parent = this.list_content;
  77. item.getComponent(rank_list_item).initView(element,index,type)
  78. }
  79. this.list.getComponent(ScrollView).scrollToTop()
  80. }
  81. reloadMyInfo(type:number) {
  82. let stype = 0
  83. if(type==1) {
  84. stype = 0
  85. } else if(type==2) {
  86. stype = 1
  87. } else if(type==3) {
  88. stype = 2
  89. }
  90. GameManager.requestMineRank(stype, (d_content)=>{
  91. // console.log('个人排行 stype=',stype,'数据=',d_content)
  92. this.my_info_node.getComponent(rank_my_info).initView(d_content)
  93. })
  94. }
  95. close() {
  96. this.node.removeFromParent()
  97. }
  98. }