rank_list_top.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { _decorator, Canvas, Component, Label, Node, Size, Sprite, UITransform } from 'cc';
  2. import { rankData } from '../../data';
  3. import { tools } from '../../tools';
  4. import { base_ui } from '../../fw/base_ui';
  5. import { uiManager } from '../../manager/uiManager';
  6. import { config } from '../../config';
  7. import { user_info_view } from '../user_info_view';
  8. import { GameManager } from '../../GameManager';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('rank_list_top')
  11. export class rank_list_top extends base_ui {
  12. @property(Node) one_node = null;
  13. @property(Node) one_lab_name:Node = null;
  14. @property(Node) one_img_avatar:Node = null;
  15. @property(Node) one_lab_score:Node = null;
  16. @property(Node) one_img_car:Node = null;
  17. @property(Node) one_region_bg:Node = null;
  18. @property(Node) one_lab_region:Node = null;
  19. @property(Node) two_node = null;
  20. @property(Node) two_lab_name:Node = null;
  21. @property(Node) two_img_avatar:Node = null;
  22. @property(Node) two_lab_score:Node = null;
  23. @property(Node) two_img_car:Node = null;
  24. @property(Node) two_region_bg:Node = null;
  25. @property(Node) two_lab_region:Node = null;
  26. @property(Node) three_node = null;
  27. @property(Node) three_lab_name:Node = null;
  28. @property(Node) three_img_avatar:Node = null;
  29. @property(Node) three_lab_score:Node = null;
  30. @property(Node) three_img_car:Node = null;
  31. @property(Node) three_region_bg:Node = null;
  32. @property(Node) three_lab_region:Node = null;
  33. private m_one_data:rankData = null
  34. private m_two_data:rankData = null
  35. private m_three_data:rankData = null
  36. protected start(): void {
  37. this.onButtonListen(this.one_node, ()=>{
  38. this.onClickRankGotoUserInfo(this.m_one_data)
  39. })
  40. this.onButtonListen(this.two_node, ()=>{
  41. this.onClickRankGotoUserInfo(this.m_two_data)
  42. })
  43. this.onButtonListen(this.three_node, ()=>{
  44. this.onClickRankGotoUserInfo(this.m_three_data)
  45. })
  46. }
  47. initView(data_list:rankData[], type:number) {
  48. this.clearAll()
  49. if(data_list.length>0) {
  50. this.m_one_data = data_list[0]
  51. this.setLabName(this.one_lab_name, this.m_one_data,7)
  52. this.setImgAvatar(this.one_img_avatar, this.m_one_data)
  53. this.setLabScore(this.one_lab_score, this.m_one_data)
  54. this.setImgCar(this.one_img_car, this.m_one_data)
  55. this.setRegion(this.one_region_bg, this.one_lab_region, this.m_one_data, type)
  56. }
  57. if(data_list.length>1) {
  58. this.m_two_data = data_list[1]
  59. this.setLabName(this.two_lab_name, this.m_two_data,6)
  60. this.setImgAvatar(this.two_img_avatar, this.m_two_data)
  61. this.setLabScore(this.two_lab_score, this.m_two_data)
  62. this.setImgCar(this.two_img_car, this.m_two_data)
  63. this.setRegion(this.two_region_bg, this.two_lab_region, this.m_two_data, type)
  64. }
  65. if(data_list.length>2) {
  66. this.m_three_data = data_list[2]
  67. this.setLabName(this.three_lab_name, this.m_three_data,5)
  68. this.setImgAvatar(this.three_img_avatar, this.m_three_data)
  69. this.setLabScore(this.three_lab_score, this.m_three_data)
  70. this.setImgCar(this.three_img_car, this.m_three_data)
  71. this.setRegion(this.three_region_bg, this.three_lab_region, this.m_three_data, type)
  72. }
  73. }
  74. private clearAll() {
  75. this.one_lab_name.getComponent(Label).string = ''
  76. this.one_img_avatar.getComponent(Sprite).spriteFrame = null
  77. this.one_lab_score.getComponent(Label).string = ''
  78. this.one_img_car.getComponent(Sprite).spriteFrame = null
  79. this.one_lab_region.getComponent(Label).string = ''
  80. this.two_lab_name.getComponent(Label).string = ''
  81. this.two_img_avatar.getComponent(Sprite).spriteFrame = null
  82. this.two_lab_score.getComponent(Label).string = ''
  83. this.two_img_car.getComponent(Sprite).spriteFrame = null
  84. this.two_lab_region.getComponent(Label).string = ''
  85. this.three_lab_name.getComponent(Label).string = ''
  86. this.three_img_avatar.getComponent(Sprite).spriteFrame = null
  87. this.three_lab_score.getComponent(Label).string = ''
  88. this.three_img_car.getComponent(Sprite).spriteFrame = null
  89. this.three_lab_region.getComponent(Label).string = ''
  90. }
  91. private setLabName(node:Node, data:rankData, cut_num:number) {
  92. tools.labelCutString(node,data.nickName,cut_num)
  93. }
  94. private setImgAvatar(node:Node, data:rankData) {
  95. tools.loadRemoteImg(data.avatarUrl, (r)=>{
  96. node.getComponent(Sprite).spriteFrame = r.sf
  97. })
  98. }
  99. private setLabScore(node:Node, data:rankData) {
  100. node.getComponent(Label).string = data.score + '分'
  101. }
  102. private setImgCar(node:Node, data:rankData) {
  103. node.getComponent(Sprite).spriteFrame = GameManager.getUserRankCarSf(data.car_id, data.user_id)
  104. }
  105. private setRegion(bg_node:Node, node:Node, data:rankData, type:number) {
  106. if(type==3) { // 市排行隐藏
  107. bg_node.active = false
  108. } else {
  109. bg_node.active = true
  110. }
  111. tools.substringRankRegionName(node, data.city_name)
  112. }
  113. private onClickRankGotoUserInfo(data:rankData) {
  114. if(data == null) {
  115. return
  116. }
  117. uiManager.Instance().showUi(config.UI.ui_user_info_view, null, (node:Node)=>{
  118. node.getComponent(user_info_view).initView(data)
  119. })
  120. }
  121. }