GunAttrItem.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Sprite, Label, ProgressBar } from 'cc';
  2. import ListItem from '../../third/ListItem';
  3. import { ResUtil } from '../../utils/ResUtil';
  4. const { ccclass, property } = _decorator;
  5. //枪的属性数据
  6. /*attr_name attr_value attr_icon max_value attribute_lang*/
  7. @ccclass('GunAttrItem')
  8. export class GunAttrItem extends ListItem {
  9. @property({ type: Sprite, tooltip: "枪的属性图片" })
  10. public attr_sp: Sprite;
  11. @property({ type: ProgressBar, tooltip: "属性值的最大进度" })
  12. public progressBar: ProgressBar;
  13. @property({ type: Label, tooltip: "属性值的数据文本" })
  14. public atts_label: Label;
  15. @property({ type: Label, tooltip: "枪的属性多语言名字" })
  16. public attribute_lang_lable: Label;
  17. public data: any = null;
  18. public start() {
  19. }
  20. /**
  21. * 数据填充
  22. * @param data 数据
  23. * @param cb 回调
  24. */
  25. public init(data: any,cb?: Function){
  26. if(!data)return;
  27. this.data = data;
  28. //设置属性图标
  29. ResUtil.setSpriteFrame(data.attr_icon, this.attr_sp);
  30. // 设置进度条 当前值/最大值
  31. this.progressBar.progress = data.attr_value / data.totalValue;
  32. //设置属性数值文本
  33. this.atts_label.string = `${data.attr_value}/${data.totalValue}`;
  34. //设置多语言属性名称
  35. this.attribute_lang_lable.string = data.attribute_lang;
  36. }
  37. }