rank.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Component, instantiate, Node, Prefab, ScrollView, Sprite, SpriteFrame } 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 { ClientEvent } from '../../lib/clientEvent';
  9. import { config } from '../../config';
  10. import { rank_classify } from './rank_classify';
  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. 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. let type = 1
  30. this.classify_node.getComponent(rank_classify).init(type,this.onClassifyItem.bind(this))
  31. this.loadView(type)
  32. }
  33. onClassifyItem(type:number) {
  34. this.loadView(type)
  35. }
  36. loadView(type:number) {
  37. let id = 0
  38. if(type==1) {
  39. id = 0
  40. } else if(type==2) {
  41. id = userDataManager.user_data.region_pid
  42. } else if(type==3) {
  43. id = userDataManager.user_data.region_id
  44. }
  45. GameManager.requestRankList(id,(d_content)=>{
  46. // console.log('排行列表 id=',id, '数据=',d_content)
  47. if(id==0) {
  48. if(this.m_onReloadCountryDataCallback!=null) {
  49. this.m_onReloadCountryDataCallback(d_content)
  50. }
  51. }
  52. this.reloadListTop(d_content)
  53. this.reloadListContent(d_content)
  54. this.reloadMyInfo(type)
  55. })
  56. }
  57. reloadListTop(data_list) {
  58. this.list_top.getComponent(rank_list_top).initView(data_list)
  59. }
  60. reloadListContent(data_list) {
  61. this.list_content.removeAllChildren()
  62. if(data_list.length < 3) {
  63. return
  64. }
  65. for (let index = 3; index < data_list.length; index++) {
  66. const element = data_list[index]
  67. let item = instantiate(this.rank_list_item)
  68. item.parent = this.list_content;
  69. item.getComponent(rank_list_item).initView(element,index)
  70. }
  71. this.list.getComponent(ScrollView).scrollToTop()
  72. }
  73. reloadMyInfo(type:number) {
  74. let stype = 0
  75. if(type==1) {
  76. stype = 0
  77. } else if(type==2) {
  78. stype = 1
  79. } else if(type==3) {
  80. stype = 2
  81. }
  82. GameManager.requestMineRank(stype, (d_content)=>{
  83. // console.log('个人排行 stype=',stype,'数据=',d_content)
  84. this.my_info_node.getComponent(rank_my_info).initView(d_content)
  85. })
  86. }
  87. close() {
  88. this.node.removeFromParent()
  89. }
  90. }