rank_list_top.ts 4.8 KB

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