rank_list_top.ts 6.8 KB

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