12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { _decorator, Sprite, Label, EventTouch } from 'cc';
- import ListItem from '../../third/ListItem';
- import { ResUtil } from '../../utils/ResUtil';
- import { userIns } from '../../data/UserData';
- const { ccclass, property } = _decorator;
- //飞镖商店的数据
- @ccclass('BoomerangItem')
- export class BoomerangItem extends ListItem {
- @property({ type: Sprite, tooltip: "道具图片" })
- public prop_icon: Sprite;
- @property({ type: Label, tooltip: "价格文本" })
- public price_lable: Label;
- @property({ type: Label, tooltip: "购买数量文本" })
- public buy_num_label: Label;
- public data: any = null;
- public cb: Function = null;
- public start() {
- }
- /**
- * 点击了按钮
- */
- public onBtnClicked(event:EventTouch, param:any){
- if(!this.data)return;
- this.cb?.(this.data,this.prop_icon.node);
- }
- /**
- * 数据填充
- * @param data 数据
- * @param cb 回调
- */
- public init(data: any,cb?: Function){
- if(!data)return;
- this.data = data;
- this.cb = cb;
- //购买的数量
- this.buy_num_label.string = `x${data.quantity}`;
- //升级需要消耗的材料
- const [id,num] = data.price_1.split("_");
- const sData:any = userIns.itemTable.find(e=>e.id == id);
- if(sData){
- //设置材料图标
- ResUtil.setSpriteFrame(sData.icon, this.prop_icon);
- //设置材料数量文本
- this.price_lable.string = `x${num}`;
- }
- }
- }
|