UI_Rank_Item.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { UI_Head_Icon } from '../UI/UI_Head_Icon';
  3. import { ch } from '../../../ch/ch';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('UI_Rank_Item')
  6. export class UI_Rank_Item extends Component {
  7. @property(Sprite)
  8. Bg: Sprite = null;
  9. @property([SpriteFrame])
  10. Bgs: SpriteFrame[] = [];
  11. @property(Sprite)
  12. Medal:Sprite = null;
  13. @property([SpriteFrame])
  14. Medals: SpriteFrame[] = [];
  15. @property(Label)
  16. Num: Label = null;
  17. @property(UI_Head_Icon)
  18. Head_Icon: UI_Head_Icon = null;
  19. @property(Label)
  20. Name: Label = null;
  21. @property(Label)
  22. Level: Label = null;
  23. showInfo(index: number, type: number, data: { head: string, nickName: string, score: number, userId: number, [key: string]: any }, me: boolean): void {
  24. if (!data) {
  25. this.node.active = false;
  26. return;
  27. }
  28. this.node.active = true;
  29. if (me) {
  30. this.Bg.spriteFrame=this.Bgs[3];
  31. index<=3?this.Medal.spriteFrame=this.Medals[index-1]:this.Medal.spriteFrame=this.Medals[3];
  32. } else {
  33. index<=3?this.Bg.spriteFrame=this.Bgs[index-1]:this.Bg.spriteFrame=this.Bgs[2];
  34. index<=3?this.Medal.spriteFrame=this.Medals[index-1]:this.Medal.spriteFrame=this.Medals[3];
  35. }
  36. if(index>3)
  37. {
  38. this.Medal.node.active=false;
  39. }else
  40. {
  41. this.Medal.node.active=true;
  42. }
  43. this.Num.string = index==101? "未上榜": index<=3? '':index.toString();
  44. this.Name.string = ch.sdk.getDefNickName(data);
  45. this.Level.string = `${data.score ?? 0}关`;
  46. console.log(data);
  47. this.Head_Icon.show(data.userId.toString(), data.head);
  48. }
  49. }