MagicBoxItem.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import Main from "../../../main/Main";
  2. import { __MagicBox } from "../../data/sdata/SManage";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class MagicBoxItem extends cc.Component {
  6. @property(cc.Sprite)
  7. mIcon: cc.Sprite = null;
  8. @property(cc.Label)
  9. mCount: cc.Label = null;
  10. public _magicBox:__MagicBox
  11. public main:Main
  12. public callback:(item:MagicBoxItem)=>void
  13. public init(main:Main,_magicBox:__MagicBox){
  14. this.main = main
  15. this._magicBox = _magicBox
  16. cc.resources.load('icon/magic_box/'+_magicBox.icon,
  17. cc.SpriteFrame,
  18. (err, spriteFrame:cc.SpriteFrame) =>{
  19. if(err){
  20. cc.error(err);
  21. }else{
  22. this.mIcon.spriteFrame = spriteFrame;
  23. }
  24. } );
  25. this.flush()
  26. }
  27. public flush(){
  28. let count = this.main.player.getGoodCount(this._magicBox.goodId)
  29. this.mCount.string = count+'/'+this._magicBox.goodCount
  30. }
  31. public setCallback(callback:(item:MagicBoxItem)=>void){
  32. this.callback = callback
  33. }
  34. public onclick(){
  35. if(this.callback){
  36. this.callback(this)
  37. }
  38. }
  39. }