PlayHisItem.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { CURRENCY_TYPE, CurrencyType } from '@scripts/define/Define';
  2. import { IGameHistory } from '@scripts/store/gameStore/data';
  3. import { formatCurrency, formatGCNum, formatGoodsNum, formatSCNum } from '@scripts/utils/Helper';
  4. import { setSpriteFrame } from '@scripts/utils/ResHelper';
  5. import { _decorator, Component, isValid, Label, Node, Sprite } from 'cc';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('PlayHisItem')
  8. export class PlayHisItem extends Component {
  9. @property(Sprite)
  10. sptIcon: Sprite = null;
  11. @property(Label)
  12. lblName: Label = null;
  13. @property(Label)
  14. lblTimes: Label = null;
  15. @property(Node)
  16. scNode: Node;
  17. @property(Node)
  18. gcNode: Node;
  19. @property(Label)
  20. scEntryText: Label;
  21. @property(Label)
  22. scWinText: Label;
  23. @property(Label)
  24. gcEntryText: Label;
  25. @property(Label)
  26. gcWinText: Label;
  27. private m_data: IGameHistory;
  28. updateView(data: IGameHistory) {
  29. this.m_data = data;
  30. const isGC = data.currency === CURRENCY_TYPE.GC;
  31. this.scNode.active = !isGC;
  32. this.gcNode.active = isGC;
  33. const entryValue = data.entry
  34. const winValue = data.win;
  35. const lblEntry = isGC ? this.gcEntryText : this.scEntryText;
  36. const lblWin = isGC ? this.gcWinText : this.scWinText;
  37. lblEntry.string = isGC ? formatGoodsNum(entryValue) : formatSCNum(entryValue);
  38. lblWin.string = isGC ? formatGoodsNum(winValue) : formatSCNum(winValue);
  39. const roundId = data.roundId;
  40. setSpriteFrame(this.sptIcon, data.coverUrl, {
  41. onCheck: () => {
  42. return this.m_data.roundId === roundId && isValid(this.node);
  43. },
  44. });
  45. }
  46. }