SystemComponent.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", { value: !0 }), (i.UI = void 0);
  17. const o = t("NotificationConst"),
  18. s = t("SystemOpenConst"),
  19. a = t("SystemOpenController"),
  20. n = t("App"),
  21. r = t("GameText"),
  22. l = t("EffectUtils"),
  23. h = t("Toast"),
  24. { ccclass: c, property: d, menu: u, executeInEditMode: p } = cc._decorator;
  25. (t = i.UI || (i.UI = {})),
  26. (i = class extends cc.Component {
  27. constructor() {
  28. super(...arguments),
  29. (this._systemIndex = ""),
  30. (this.lock = null),
  31. (this.unlock = null),
  32. (this.graySprites = []),
  33. (this.showType = 0),
  34. (this.isPlay = !0),
  35. (this.isInit = !1);
  36. }
  37. set systemIndex(t) {
  38. this._systemIndex = s.OpenTypeConst[t];
  39. }
  40. get systemIndex() {
  41. return s.OpenTypeConst[this._systemIndex];
  42. }
  43. set state(t) {
  44. (this.isOpen = t), this.updateState(this.systemIndex, t);
  45. }
  46. get state() {
  47. return this.isOpen;
  48. }
  49. start() {
  50. var t;
  51. if (!CC_EDITOR) {
  52. (this.config = a.default.ins.getConfigByType(this._systemIndex)),
  53. this.config &&
  54. ((t = a.default.ins.checkSystemOpen(this.config.index)) ||
  55. (n.default.NotificationCenter.addListener(
  56. o.NotificationConst.SYS_OPEN,
  57. this.updateSys,
  58. this,
  59. 200
  60. ),
  61. this.node.on(cc.Node.EventType.TOUCH_END, this.onTouch, this)),
  62. this.updateSys(this.systemIndex, t, !1));
  63. }
  64. }
  65. onTouch() {
  66. this.isOpen || h.default.launch(r.GameText.getTextByStr("system_con_" + this.config.id));
  67. }
  68. onDestroy() {
  69. n.default.NotificationCenter.removeListener(o.NotificationConst.SYS_OPEN, this.updateSys, this);
  70. }
  71. updateSys(e, i, t) {
  72. if (null == i)
  73. return (
  74. n.default.TimerManager.doTimer(
  75. 500,
  76. 1,
  77. () => {
  78. var t = a.default.ins.checkSystemOpen(this.config.index);
  79. this.updateSys(this.config.index, t, !1);
  80. },
  81. this
  82. ),
  83. void this.updateState(e, i)
  84. );
  85. if (e == this.systemIndex)
  86. if ((this.isOpen = i) && t && this.isPlay) {
  87. if (i && t && this.isPlay) {
  88. n.default.NotificationCenter.removeListener(o.NotificationConst.SYS_OPEN, this.updateSys, this);
  89. let t = this.node.convertToWorldSpaceAR(cc.v2(0, 0));
  90. "" != this.config.pos &&
  91. "none" != this.config.pos &&
  92. ((s = {}),
  93. n.default.CommonUtils.parsePos(s, this.config.pos, "|"),
  94. (t.x = n.default.CommonUtils.getPosX1(s, cc.winSize.width, 0)),
  95. (t.y = n.default.CommonUtils.getPosY1(s, cc.winSize.height, 0)));
  96. var s = {
  97. id: this.config.id,
  98. icon: this.config.iconSource,
  99. desc: this.config.desc,
  100. pos: t,
  101. func: () => {
  102. this.updateState(e, i);
  103. },
  104. obj: this
  105. };
  106. l.default.instance.playLockAni(s);
  107. }
  108. } else this.updateState(e, i);
  109. }
  110. updateState(e, i) {
  111. if (e == this.systemIndex) {
  112. i && n.default.NotificationCenter.removeListener(o.NotificationConst.SYS_OPEN, this.updateSys, this);
  113. let t = this.node.getComponent(cc.Button);
  114. switch ((t && (t.interactable = i), this.showType)) {
  115. case s.ShowTypeConst.LOCK:
  116. if (
  117. (this.lock && (this.lock.active = !i),
  118. this.unlock && (this.unlock.active = i),
  119. this.graySprites.length)
  120. )
  121. for (const e of this.graySprites)
  122. i ?
  123. e.setMaterial(0, cc.Material.getBuiltinMaterial("2d-sprite")) :
  124. e.setMaterial(0, cc.Material.getBuiltinMaterial("2d-gray-sprite"));
  125. break;
  126. case s.ShowTypeConst.HIDE:
  127. this.node.active = i;
  128. }
  129. }
  130. }
  131. }),
  132. e([d], i.prototype, "_systemIndex", void 0),
  133. e([d({ type: cc.Enum(s.OpenTypeConst) })], i.prototype, "systemIndex", null),
  134. e(
  135. [
  136. d({
  137. type: cc.Node,
  138. visible() {
  139. return this.showType == s.ShowTypeConst.LOCK;
  140. }
  141. })
  142. ],
  143. i.prototype,
  144. "lock",
  145. void 0
  146. ),
  147. e([d({ type: cc.Node })], i.prototype, "unlock", void 0),
  148. e(
  149. [
  150. d({
  151. type: cc.Sprite,
  152. visible() {
  153. return this.showType == s.ShowTypeConst.LOCK;
  154. }
  155. })
  156. ],
  157. i.prototype,
  158. "graySprites",
  159. void 0
  160. ),
  161. e([d({ type: cc.Enum(s.ShowTypeConst) })], i.prototype, "showType", void 0),
  162. e([d({})], i.prototype, "isPlay", void 0),
  163. (i = e([c, p], i)),
  164. (t.SystemComponent = i);