StoreItem.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Sprite, Label} from 'cc';
  2. import ListItem from '../../third/ListItem';
  3. import { ResUtil } from '../../utils/ResUtil';
  4. import i18n from '../../core/i18n/runtime-scripts/LanguageData';
  5. const { ccclass, property } = _decorator;
  6. //商店数据
  7. @ccclass('StoreItem')
  8. export class StoreItem extends ListItem {
  9. @property({ type: Sprite, tooltip: "道具图标" })
  10. public s_icon: Sprite;
  11. @property({ type: Label, tooltip: "道具描述" })
  12. public s_des_lable: Label;
  13. @property({ type: Label, tooltip: "看广告的次数" })
  14. public video_label: Label;
  15. public data: any = null;
  16. public cb?: Function = null;
  17. /**
  18. * 看视频
  19. */
  20. private clikItemVideo(){
  21. if(!this.data)return;
  22. this.cb?.(this.data,this.s_icon.node);
  23. }
  24. /**
  25. * 数据填充
  26. * @param data 数据
  27. * @param cb 回调
  28. */
  29. public init(data: any,cb?: Function){
  30. if(!data)return;
  31. this.data = data;
  32. this.cb = cb;
  33. //敌人投降
  34. ResUtil.setSpriteFrame(data.icon,this.s_icon);
  35. //道具描述
  36. this.s_des_lable.string = i18n.isZh ? data.des : data.des_lang;
  37. //看广告的次数
  38. this.video_label.string = `${data.price_2}/${data.alreadyVideo}`;
  39. }
  40. }