FTmpTaskGood.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { __GoodData } from "../data/sdata/SManage";
  2. import FTmpTaskPanel from "./FTmpTaskPanel";
  3. /**
  4. * 临时道具
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class FTmpTaskGood extends cc.Component {
  9. @property(cc.Label)
  10. mCount: cc.Label = null;
  11. @property(cc.Sprite)
  12. mIcon: cc.Sprite = null;
  13. public _good:__GoodData;
  14. public count:number;
  15. private callback:(goodItem:FTmpTaskGood,isActive:boolean)=>void
  16. onLoad(){
  17. this.node.on(cc.Node.EventType.TOUCH_START, this._touchStartEvent, this);
  18. this.node.on(cc.Node.EventType.TOUCH_END, this._touchEndEvent, this);
  19. this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._touchEndEvent, this);
  20. }
  21. public init(good:__GoodData,count){
  22. this._good = good;
  23. this.count = count;
  24. this.mCount.string = 'x'+count
  25. cc.resources.load('icon/good/'+good.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  26. if(err){
  27. cc.error(err);
  28. }else{
  29. this.mIcon.spriteFrame = spriteFrame;
  30. }
  31. });
  32. }
  33. public setCallback(callback:(goodItem:FTmpTaskGood,isActive:boolean)=>void){
  34. this.callback = callback
  35. }
  36. private _touchStartEvent(event) {
  37. this.callback(this,true)
  38. }
  39. private _touchEndEvent() {
  40. this.callback(this,false)
  41. }
  42. }