BoomerangItem.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Sprite, Label, EventTouch } from 'cc';
  2. import ListItem from '../../third/ListItem';
  3. import { ResUtil } from '../../utils/ResUtil';
  4. import { userIns } from '../../data/UserData';
  5. const { ccclass, property } = _decorator;
  6. //飞镖商店的数据
  7. @ccclass('BoomerangItem')
  8. export class BoomerangItem extends ListItem {
  9. @property({ type: Sprite, tooltip: "道具图片" })
  10. public prop_icon: Sprite;
  11. @property({ type: Label, tooltip: "价格文本" })
  12. public price_lable: Label;
  13. @property({ type: Label, tooltip: "购买数量文本" })
  14. public buy_num_label: Label;
  15. public data: any = null;
  16. public cb: Function = null;
  17. public start() {
  18. }
  19. /**
  20. * 点击了按钮
  21. */
  22. public onBtnClicked(event:EventTouch, param:any){
  23. if(!this.data)return;
  24. this.cb?.(this.data,this.prop_icon.node);
  25. }
  26. /**
  27. * 数据填充
  28. * @param data 数据
  29. * @param cb 回调
  30. */
  31. public init(data: any,cb?: Function){
  32. if(!data)return;
  33. this.data = data;
  34. this.cb = cb;
  35. //购买的数量
  36. this.buy_num_label.string = `x${data.quantity}`;
  37. //升级需要消耗的材料
  38. const [id,num] = data.price_1.split("_");
  39. const sData:any = userIns.itemTable.find(e=>e.id == id);
  40. if(sData){
  41. //设置材料图标
  42. ResUtil.setSpriteFrame(sData.icon, this.prop_icon);
  43. //设置材料数量文本
  44. this.price_lable.string = `x${num}`;
  45. }
  46. }
  47. }