rank_list_top.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { _decorator, Canvas, Component, Label, Node, Size, Sprite, UITransform } from 'cc';
  2. import { rankData } from '../../data';
  3. import { tools } from '../../tools';
  4. import { imageCacheManager } from '../../manager/imageCacheManager';
  5. import { base_ui } from '../../fw/base_ui';
  6. import { uiManager } from '../../manager/uiManager';
  7. import { config } from '../../config';
  8. import { user_info_view } from '../user_info_view';
  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) two_node = null;
  18. @property(Node) two_lab_name:Node = null;
  19. @property(Node) two_img_avatar:Node = null;
  20. @property(Node) two_lab_score:Node = null;
  21. @property(Node) two_img_car:Node = null;
  22. @property(Node) three_node = null;
  23. @property(Node) three_lab_name:Node = null;
  24. @property(Node) three_img_avatar:Node = null;
  25. @property(Node) three_lab_score:Node = null;
  26. @property(Node) three_img_car:Node = null;
  27. private m_one_data:rankData = null
  28. private m_two_data:rankData = null
  29. private m_three_data:rankData = null
  30. protected start(): void {
  31. this.onButtonListen(this.one_node, ()=>{
  32. this.onClickRankGotoUserInfo(this.m_one_data)
  33. })
  34. this.onButtonListen(this.two_node, ()=>{
  35. this.onClickRankGotoUserInfo(this.m_two_data)
  36. })
  37. this.onButtonListen(this.three_node, ()=>{
  38. this.onClickRankGotoUserInfo(this.m_three_data)
  39. })
  40. }
  41. initView(data_list:rankData[]) {
  42. this.clearAll()
  43. if(data_list.length>0) {
  44. this.m_one_data = data_list[0]
  45. this.setLabName(this.one_lab_name, this.m_one_data)
  46. this.setImgAvatar(this.one_img_avatar, this.m_one_data)
  47. this.setLabScore(this.one_lab_score, this.m_one_data)
  48. this.setImgCar(this.one_img_car, this.m_one_data)
  49. }
  50. if(data_list.length>1) {
  51. this.m_two_data = data_list[1]
  52. this.setLabName(this.two_lab_name, this.m_two_data)
  53. this.setImgAvatar(this.two_img_avatar, this.m_two_data)
  54. this.setLabScore(this.two_lab_score, this.m_two_data)
  55. this.setImgCar(this.two_img_car, this.m_two_data)
  56. }
  57. if(data_list.length>2) {
  58. this.m_three_data = data_list[2]
  59. this.setLabName(this.three_lab_name, this.m_three_data)
  60. this.setImgAvatar(this.three_img_avatar, this.m_three_data)
  61. this.setLabScore(this.three_lab_score, this.m_three_data)
  62. this.setImgCar(this.three_img_car, this.m_three_data)
  63. }
  64. }
  65. private clearAll() {
  66. this.one_lab_name.getComponent(Label).string = ''
  67. this.one_img_avatar.getComponent(Sprite).spriteFrame = null
  68. this.one_lab_score.getComponent(Label).string = ''
  69. this.one_img_car.getComponent(Sprite).spriteFrame = null
  70. this.two_lab_name.getComponent(Label).string = ''
  71. this.two_img_avatar.getComponent(Sprite).spriteFrame = null
  72. this.two_lab_score.getComponent(Label).string = ''
  73. this.two_img_car.getComponent(Sprite).spriteFrame = null
  74. this.three_lab_name.getComponent(Label).string = ''
  75. this.three_img_avatar.getComponent(Sprite).spriteFrame = null
  76. this.three_lab_score.getComponent(Label).string = ''
  77. this.three_img_car.getComponent(Sprite).spriteFrame = null
  78. }
  79. private setLabName(node:Node, data:rankData) {
  80. let lab_component = node.getComponent(Label)
  81. if(data.nickName.length>5) {
  82. lab_component.string = data.nickName.substring(0,5) + '...'
  83. lab_component.horizontalAlign = Label.HorizontalAlign.LEFT
  84. } else {
  85. lab_component.horizontalAlign = Label.HorizontalAlign.CENTER
  86. lab_component.string = data.nickName
  87. }
  88. }
  89. private setImgAvatar(node:Node, data:rankData) {
  90. tools.loadRemoteImg(data.avatarUrl, (r)=>{
  91. node.getComponent(Sprite).spriteFrame = r.sf
  92. })
  93. }
  94. private setLabScore(node:Node, data:rankData) {
  95. node.getComponent(Label).string = data.score + '分'
  96. }
  97. private setImgCar(node:Node, data:rankData) {
  98. node.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.car_id)
  99. }
  100. private onClickRankGotoUserInfo(data:rankData) {
  101. if(data == null) {
  102. return
  103. }
  104. uiManager.Instance().showUi(config.UI.ui_user_info_view, null, (node:Node)=>{
  105. node.getComponent(user_info_view).initView(data)
  106. })
  107. }
  108. }