GoodsValue.ts 886 B

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