GoodsValue.ts 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { formatGoodsNum } from '@scripts/utils/Helper';
  2. import { _decorator, Component, Label, Node } from 'cc';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('GoodsValue')
  5. export class GoodsValue extends Component {
  6. @property(Node)
  7. flagNode: Node;
  8. @property(Node)
  9. valueNode: Node;
  10. @property(Node)
  11. bonusNode: Node;
  12. @property(Label)
  13. lblBonus: Label;
  14. @property(Label)
  15. lblPercent: Label;
  16. @property(Label)
  17. lblValue: Label;
  18. initValue(value: number, bonus: number, percent: number, isSc = false) {
  19. this.node.active = value > 0;
  20. if (this.flagNode) this.flagNode.active = isSc;
  21. const total = value + bonus;
  22. this.lblValue.string = formatGoodsNum(total);
  23. this.lblBonus.string = `+${bonus}`;
  24. this.lblPercent.string = `+${percent}%`;
  25. const hasBonus = bonus > 0;
  26. this.bonusNode.active = hasBonus;
  27. this.valueNode.y = hasBonus ? 11.5 : 0;
  28. }
  29. }