ShopItem.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. cc.Class({
  2. extends: cc.Component,
  3. editor: {
  4. menu: 'Shop/ShopItem'
  5. },
  6. properties: {
  7. bg: cc.Sprite,
  8. surfaceBg: cc.Sprite,
  9. surface: cc.Label,
  10. itemName: cc.Label,
  11. cost: cc.Label,
  12. selfButton: cc.Button
  13. },
  14. reloadData (data) {
  15. this._data = data;
  16. this.initUI();
  17. },
  18. enabelClick (enable) {
  19. this.selfButton.interactable = enable;
  20. },
  21. initUI () {
  22. if (!this._data) return;
  23. let quality = this._data.quality;
  24. let path = cc.js.formatStr("res_image/itemicon/box-djk0%d", quality);
  25. cc.loader.loadRes(path, cc.SpriteFrame, (error, spriteFrame) => {
  26. if (!error && cc.isValid(this.node, true)) {
  27. this.bg.spriteFrame = spriteFrame;
  28. }
  29. });
  30. let surface = this._data.surface;
  31. let surfacepath = cc.js.formatStr("res_image/itemicon/other-tag0%d", surface);
  32. cc.loader.loadRes(surfacepath, cc.SpriteFrame, (error, spriteFrame) => {
  33. if (!error && cc.isValid(this.node, true)) {
  34. this.surfaceBg.spriteFrame = spriteFrame;
  35. }
  36. });
  37. this.surface.string = this._data.surfaceStr;
  38. this.cost.string = this._data.cost;
  39. this.itemName.string = this._data.name;
  40. },
  41. onClicked () {
  42. if (!this._data || !this._data.cb) return;
  43. this._data.cb(this._data);
  44. }
  45. });