rank.ts 3.4 KB

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