import Main from "../../../main/Main"; import { __MagicBox } from "../../data/sdata/SManage"; const {ccclass, property} = cc._decorator; @ccclass export default class MagicBoxItem extends cc.Component { @property(cc.Sprite) mIcon: cc.Sprite = null; @property(cc.Label) mCount: cc.Label = null; public _magicBox:__MagicBox public main:Main public callback:(item:MagicBoxItem)=>void public init(main:Main,_magicBox:__MagicBox){ this.main = main this._magicBox = _magicBox cc.resources.load('icon/magic_box/'+_magicBox.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{ if(err){ cc.error(err); }else{ this.mIcon.spriteFrame = spriteFrame; } } ); this.flush() } public flush(){ let count = this.main.player.getGoodCount(this._magicBox.goodId) this.mCount.string = count+'/'+this._magicBox.goodCount } public setCallback(callback:(item:MagicBoxItem)=>void){ this.callback = callback } public onclick(){ if(this.callback){ this.callback(this) } } }