rank.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. const { ccclass, property } = _decorator;
  11. @ccclass('rank')
  12. export class rank extends Component {
  13. @property(Node) btn_back:Node = null;
  14. @property(Node) btn_country:Node = null;
  15. @property(Node) btn_province:Node = null;
  16. @property(Node) btn_city:Node = null;
  17. @property(Node) list:Node = null;
  18. @property(Node) list_top:Node = null;
  19. @property(Node) list_content:Node = null;
  20. @property(Prefab) rank_list_item:Prefab = null;
  21. @property(Node) my_info_node:Node = null;
  22. @property(SpriteFrame) sf_country_selected:SpriteFrame = null;
  23. @property(SpriteFrame) sf_country_unselected:SpriteFrame = null;
  24. @property(SpriteFrame) sf_province_selected:SpriteFrame = null;
  25. @property(SpriteFrame) sf_province_unselected:SpriteFrame = null;
  26. @property(SpriteFrame) sf_city_selected:SpriteFrame = null;
  27. @property(SpriteFrame) sf_city_unselected:SpriteFrame = null;
  28. private m_onReloadCountryDataCallback = null;
  29. onReloadCountryDataCallback(cb) {
  30. this.m_onReloadCountryDataCallback = cb
  31. }
  32. start() {
  33. uiManager.Instance().onButtonListen(this.btn_back, ()=>{
  34. this.close()
  35. })
  36. uiManager.Instance().onButtonListen(this.btn_country, ()=>{
  37. this.onClassifyItem(1)
  38. })
  39. uiManager.Instance().onButtonListen(this.btn_province, ()=>{
  40. this.onClassifyItem(2)
  41. })
  42. uiManager.Instance().onButtonListen(this.btn_city, ()=>{
  43. this.onClassifyItem(3)
  44. })
  45. this.onClassifyItem(1)
  46. }
  47. onClassifyItem(type:number) {
  48. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_unselected
  49. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_unselected
  50. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_unselected
  51. switch (type) {
  52. case 1:
  53. this.btn_country.getComponent(Sprite).spriteFrame = this.sf_country_selected
  54. break;
  55. case 2:
  56. this.btn_province.getComponent(Sprite).spriteFrame = this.sf_province_selected
  57. break;
  58. case 3:
  59. this.btn_city.getComponent(Sprite).spriteFrame = this.sf_city_selected
  60. break;
  61. default:
  62. break;
  63. }
  64. this.loadView(type)
  65. }
  66. loadView(type:number) {
  67. let id = 0
  68. if(type==1) {
  69. id = 0
  70. } else if(type==2) {
  71. id = userDataManager.user_data.region_pid
  72. } else if(type==3) {
  73. id = userDataManager.user_data.region_id
  74. }
  75. GameManager.requestRankList(id,(d_content)=>{
  76. // console.log('排行列表 id=',id, '数据=',d_content)
  77. if(id==0) {
  78. if(this.m_onReloadCountryDataCallback!=null) {
  79. this.m_onReloadCountryDataCallback(d_content)
  80. }
  81. }
  82. this.reloadListTop(d_content)
  83. this.reloadListContent(d_content)
  84. this.reloadMyInfo(type)
  85. })
  86. }
  87. reloadListTop(data_list) {
  88. this.list_top.getComponent(rank_list_top).initView(data_list)
  89. }
  90. reloadListContent(data_list) {
  91. this.list_content.removeAllChildren()
  92. if(data_list.length < 3) {
  93. return
  94. }
  95. for (let index = 3; index < data_list.length; index++) {
  96. const element = data_list[index]
  97. let item = instantiate(this.rank_list_item)
  98. item.parent = this.list_content;
  99. item.getComponent(rank_list_item).initView(element,index)
  100. }
  101. this.list.getComponent(ScrollView).scrollToTop()
  102. }
  103. reloadMyInfo(type:number) {
  104. let stype = 0
  105. if(type==1) {
  106. stype = 0
  107. } else if(type==2) {
  108. stype = 1
  109. } else if(type==3) {
  110. stype = 2
  111. }
  112. GameManager.requestMineRank(stype, (d_content)=>{
  113. // console.log('个人排行 stype=',stype,'数据=',d_content)
  114. this.my_info_node.getComponent(rank_my_info).initView(d_content)
  115. })
  116. }
  117. close() {
  118. this.node.removeFromParent()
  119. }
  120. }