UIImage.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s,
  5. e =
  6. (this && this.__decorate) ||
  7. function(t, e, i, s) {
  8. var o,
  9. a = arguments.length,
  10. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  11. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  12. else
  13. for (var r = t.length - 1; 0 <= r; r--)
  14. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  15. return 3 < a && n && Object.defineProperty(e, i, n), n;
  16. };
  17. Object.defineProperty(i, "__esModule", { value: !0 }), (i.UIImage = void 0);
  18. const { ccclass: o, property: a, menu: n } = cc._decorator;
  19. let r = /(\.jpg)$/,
  20. l = (s = class extends cc.Sprite {
  21. constructor() {
  22. super(...arguments), (this._source = null), (this.sourceChanged = !1);
  23. }
  24. set source(t) {
  25. if ("" === t) return (this._source = t), void(this.spriteFrame = null);
  26. t != this._source &&
  27. ((this._source = t),
  28. this.node && this.node.activeInHierarchy ? this.parseSource() : (this.sourceChanged = !0));
  29. }
  30. onLoad() {
  31. this.sourceChanged && this.parseSource();
  32. }
  33. onEnable() {
  34. super.onEnable(), this.sourceChanged && this.parseSource();
  35. }
  36. get source() {
  37. return this._source;
  38. }
  39. $setTexture(t) {
  40. if (t == this.spriteFrame) return !1;
  41. (this.spriteFrame = t), (this.sourceChanged = !1);
  42. }
  43. parseSource() {
  44. this.sourceChanged = !1;
  45. let i = this._source;
  46. if (i && "string" == typeof i) {
  47. var t = s.cacheList[i] || cc.resources.get(i, cc.SpriteFrame);
  48. if (t) this.$setTexture(t);
  49. else if (-1 == i.indexOf("http"))
  50. cc.resources.load(i, cc.SpriteFrame, (t, e) => {
  51. i === this._source &&
  52. (t ? Log.error(`\u56fe\u7247\u4e0d\u5b58\u5728:${i}`, t) : this.$setTexture(e));
  53. });
  54. else {
  55. let t = ".png";
  56. r.test(i) && (t = ".jpg"),
  57. cc.assetManager.loadRemote(i, { ext: t }, (t, e) => {
  58. i === this._source &&
  59. (t ?
  60. Log.error(`\u56fe\u7247\u4e0d\u5b58\u5728:${i}`, t) :
  61. ((s.cacheList[i] = new cc.SpriteFrame(e)), this.$setTexture(s.cacheList[i])));
  62. });
  63. }
  64. } else this.$setTexture(i);
  65. }
  66. });
  67. (l.cacheList = {}),
  68. e([a({ type: cc.SpriteFrame })], l.prototype, "_source", void 0),
  69. e([a({ type: cc.SpriteFrame })], l.prototype, "source", null),
  70. (s = e([o], l)),
  71. (i.UIImage = s);