ui_rank_item.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { _decorator, Color, Component, Graphics, Label, Mask, Node, Size, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { aa } from '../../scripts/aa';
  3. import { ch } from '../../ch/ch';
  4. const { ccclass, property } = _decorator;
  5. const tSize = new Size(54, 54)
  6. @ccclass('ui_rank_item')
  7. export class ui_rank_item extends Component {
  8. @property(Node)
  9. private star1: Node;
  10. @property(Node)
  11. private star2: Node;
  12. @property(Node)
  13. private star3: Node;
  14. @property(Node)
  15. private star4: Node;
  16. @property(Node)
  17. private my: Node;
  18. @property(Label)
  19. private rank_txt: Label;
  20. @property(Label)
  21. private name_txt: Label;
  22. @property(Label)
  23. private type1_txt: Label;
  24. @property(Sprite)
  25. private head: Sprite;
  26. @property(SpriteFrame)
  27. private def_head: SpriteFrame;
  28. start() {
  29. }
  30. getNickName: Function = () => " "
  31. showInfo(index: number, type: number, data: any): void {
  32. index++;
  33. this.star1.active = index == 1;
  34. this.star2.active = index == 2;
  35. this.star3.active = index == 3;
  36. this.star4.active = index > 3;
  37. this.my.active = false
  38. if (index <= 3) {
  39. this.rank_txt.node.active = false; // 前三名隐藏文本
  40. } else {
  41. this.rank_txt.node.active = true; // 其他名次显示
  42. this.rank_txt.string = index.toString();
  43. }
  44. //this.rank_txt.string = index.toString();
  45. this.name_txt.string = this.getNickName(data);
  46. this.type1_txt.string = data.score;
  47. if (data.head && data.head != "image") {
  48. this.head.getComponent(UITransform).setContentSize(tSize)
  49. aa.Util.headIconMgr.showIcon(data.userId, data.head, this.head);
  50. } else {
  51. this.adaptationIcon(this.head, this.def_head, tSize)
  52. }
  53. }
  54. showMe(index: number, data: any) {
  55. let rankTxt = "未上榜"
  56. this.star1.active = false;
  57. this.star2.active = false;
  58. this.star3.active = false;
  59. this.star4.active = false;
  60. this.my.active = true
  61. if (index > 0) {
  62. rankTxt = index.toString()
  63. }
  64. this.rank_txt.string = rankTxt;
  65. this.name_txt.string = this.getNickName(data);
  66. this.type1_txt.string = data.score;
  67. //
  68. if (data.head && data.head != "image") {
  69. this.head.getComponent(UITransform).setContentSize(tSize)
  70. aa.Util.headIconMgr.showIcon(data.userId, data.head, this.head);
  71. } else {
  72. this.adaptationIcon(this.head, this.def_head, tSize)
  73. }
  74. }
  75. adaptationIcon(icon: Sprite, spriteFrameIcon: SpriteFrame, tSize: Size) {
  76. if (icon.spriteFrame != spriteFrameIcon) {
  77. if (spriteFrameIcon) {
  78. let size = spriteFrameIcon.originalSize
  79. //适配图片
  80. let iconSize = new Size()
  81. let raito = size.width / size.height
  82. if (raito < 1) {
  83. iconSize.height = tSize.height
  84. iconSize.width = tSize.height * raito
  85. } else {
  86. iconSize.width = tSize.width
  87. iconSize.height = tSize.width / raito
  88. }
  89. icon.spriteFrame = spriteFrameIcon
  90. icon.getComponent(UITransform).setContentSize(iconSize)
  91. }
  92. }
  93. }
  94. protected onDestroy(): void {
  95. this.getNickName = (data: any) => ""
  96. }
  97. }