rank_list_top.ts 6.2 KB

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