ShopItem.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. icon: cc.Sprite
  14. },
  15. reloadData (data) {
  16. this._data = data;
  17. this.initUI();
  18. },
  19. enabelClick (enable) {
  20. this.selfButton.interactable = enable;
  21. },
  22. initUI () {
  23. if (!this._data) return;
  24. let config = this._data.itemConfig;
  25. let iconPath = cc.js.formatStr("res_image/itemicon/%d", config.id);
  26. cc.loader.loadRes(iconPath, cc.SpriteFrame, (error, spriteFrame) => {
  27. if (!error && cc.isValid(this.node, true)) {
  28. this.icon.spriteFrame = spriteFrame;
  29. }
  30. });
  31. let quality = this._data.quality;
  32. let path = cc.js.formatStr("res_image/itemicon/box-djk0%d", quality);
  33. cc.loader.loadRes(path, cc.SpriteFrame, (error, spriteFrame) => {
  34. if (!error && cc.isValid(this.node, true)) {
  35. this.bg.spriteFrame = spriteFrame;
  36. }
  37. });
  38. let surface = this._data.surface;
  39. let surfacepath = cc.js.formatStr("res_image/itemicon/other-tag0%d", surface);
  40. cc.loader.loadRes(surfacepath, cc.SpriteFrame, (error, spriteFrame) => {
  41. if (!error && cc.isValid(this.node, true)) {
  42. this.surfaceBg.spriteFrame = spriteFrame;
  43. }
  44. });
  45. this.surface.string = this._data.surfaceStr;
  46. this.cost.string = this._data.cost;
  47. this.itemName.string = this._data.name;
  48. },
  49. onClicked () {
  50. if (!this._data || !this._data.cb) return;
  51. this._data.cb(this._data);
  52. }
  53. });