UI_rank_item.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, Label, log, Node, Sprite, SpriteFrame } from 'cc';
  2. import { ch } from 'db://assets/ch/ch';
  3. import { UI_Head_Icon } from './UI_Head_Icon';
  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. pm_Bg: Sprite = null;
  13. @property([SpriteFrame])
  14. pm_Skin: SpriteFrame[] = [];
  15. @property(UI_Head_Icon)//头像
  16. Headicon: UI_Head_Icon
  17. @property(Label)
  18. private rank_txt: Label;//排名
  19. @property(Label)
  20. private name_txt: Label;//昵称
  21. @property(Label)
  22. private score_txt: Label;//通关数
  23. //index:排名 type:类型参数 data:用户数据 头像 昵称 通关数 用户id 是否是当前用户
  24. showInfo(index: number, type: number, data: { head: string, nickName: string, score: number, userId: number, [key: string]: any }, me: boolean): void {
  25. log('UI_rank_item+++++++++',data)
  26. if (!data) {
  27. this.node.active = false;
  28. return;
  29. }
  30. this.node.active = true;
  31. if (me) {
  32. this.Bg.spriteFrame = this.Bgs[2]
  33. index <= 3
  34. ? this.pm_Bg.spriteFrame = this.pm_Skin[index - 1]
  35. : this.pm_Bg.spriteFrame = this.pm_Skin[3];
  36. } else {
  37. index <= 3
  38. ? this.Bg.spriteFrame = this.Bgs[0]
  39. : this.Bg.spriteFrame = this.Bgs[1];
  40. index <= 3
  41. ? this.pm_Bg.spriteFrame = this.pm_Skin[index - 1]
  42. : this.pm_Bg.spriteFrame = this.pm_Skin[3];
  43. }
  44. if (index > 3) {
  45. this.pm_Bg.node.active = false;
  46. } else {
  47. this.pm_Bg.node.active = true;
  48. }
  49. this.rank_txt.string = index==101? "未上榜": index<=3? '':index.toString();
  50. this.name_txt.string = ch.sdk.getDefNickName(data);
  51. this.score_txt.string = `${data.score ?? 0}关`;
  52. console.log('UI_rank_item-------------------');
  53. console.log(data)
  54. this.Headicon.show(data.userId.toString(), data.head);
  55. }
  56. }