RankItemBest.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Node, Sprite, Label, ImageAsset, SpriteFrame, Texture2D } from 'cc';
  2. import { JSB } from 'cc/env';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { ConfigData } from '../../Data/ConfigData';
  5. import { RankItemData } from './RankData';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('RankItemBest')
  8. export class RankItemBest extends Component {
  9. @property({ type: Sprite, tooltip: "头像" })
  10. imgHead: Sprite = null;
  11. @property({ type: Label, tooltip: "昵称文本" })
  12. txtNickName: Label = null;
  13. @property({ type: Label, tooltip: "金额文本" })
  14. txtMoney: Label = null;
  15. @property({ type: Label, tooltip: "积分文本" })
  16. txtScore: Label = null;
  17. private data: RankItemData;
  18. private money: number = 0;
  19. public async onDataChange(data: RankItemData, index: number) {
  20. this.data = data;
  21. if (data == null) {
  22. this.txtNickName.string = `暂无玩家`;
  23. this.txtScore.string = `积分:-`;
  24. this.txtMoney.string = `0元`;
  25. return;
  26. }
  27. let rankCfg = ConfigData.configMap.get("rank");
  28. if (index + 1 <= 100) {
  29. if (index + 1 <= 1) {
  30. this.money = rankCfg.reward1;
  31. } else if (index + 1 <= 2) {
  32. this.money = rankCfg.reward2;
  33. } else if (index + 1 <= 3) {
  34. this.money = rankCfg.reward3;
  35. } else if (index + 1 <= 10) {
  36. this.money = rankCfg.reward10;
  37. } else if (index + 1 <= 30) {
  38. this.money = rankCfg.reward30;
  39. } else if (index + 1 <= 100) {
  40. this.money = rankCfg.reward100;
  41. } else {
  42. this.money = 0;
  43. }
  44. }
  45. this.txtNickName.string = `${data.nick.length > 6 ? data.nick.slice(0, 5) + "..." : data.nick}`;
  46. this.txtScore.string = `积分:${data.score}`;
  47. this.txtMoney.string = `${this.money}元`;
  48. if (JSB && data.avator != "") {
  49. let img = await ResourcesUtils.loadRemote<ImageAsset>(data.avator, { ext: ".png" }, this);
  50. const spriteFrame = new SpriteFrame();
  51. const texture = new Texture2D();
  52. texture.image = img;
  53. spriteFrame.texture = texture;
  54. this.imgHead.spriteFrame = spriteFrame;
  55. }
  56. }
  57. }