ee79355c865a79ad49b2094aa0c29c3e51f20176.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, instantiate, Node, Prefab, SafeArea, Widget, oops, ViewParams, DelegateComponent, LayerUI, _crd;
  4. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  5. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  6. function _reportPossibleCrUseOfoops(extras) {
  7. _reporterNs.report("oops", "../../Oops", _context.meta, extras);
  8. }
  9. function _reportPossibleCrUseOfUICallbacks(extras) {
  10. _reporterNs.report("UICallbacks", "./Defines", _context.meta, extras);
  11. }
  12. function _reportPossibleCrUseOfViewParams(extras) {
  13. _reporterNs.report("ViewParams", "./Defines", _context.meta, extras);
  14. }
  15. function _reportPossibleCrUseOfDelegateComponent(extras) {
  16. _reporterNs.report("DelegateComponent", "./DelegateComponent", _context.meta, extras);
  17. }
  18. function _reportPossibleCrUseOfUIConfig(extras) {
  19. _reporterNs.report("UIConfig", "./LayerManager", _context.meta, extras);
  20. }
  21. _export("LayerUI", void 0);
  22. return {
  23. setters: [function (_unresolved_) {
  24. _reporterNs = _unresolved_;
  25. }, function (_cc) {
  26. _cclegacy = _cc.cclegacy;
  27. __checkObsolete__ = _cc.__checkObsolete__;
  28. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  29. instantiate = _cc.instantiate;
  30. Node = _cc.Node;
  31. Prefab = _cc.Prefab;
  32. SafeArea = _cc.SafeArea;
  33. Widget = _cc.Widget;
  34. }, function (_unresolved_2) {
  35. oops = _unresolved_2.oops;
  36. }, function (_unresolved_3) {
  37. ViewParams = _unresolved_3.ViewParams;
  38. }, function (_unresolved_4) {
  39. DelegateComponent = _unresolved_4.DelegateComponent;
  40. }],
  41. execute: function () {
  42. _crd = true;
  43. _cclegacy._RF.push({}, "bc8b86Br9dGeKxeLijkyJKE", "LayerUI", undefined);
  44. __checkObsolete__(['instantiate', 'Node', 'Prefab', 'SafeArea', 'Widget']);
  45. /** 界面层对象 */
  46. _export("LayerUI", LayerUI = class LayerUI extends Node {
  47. /**
  48. * UI基础层,允许添加多个预制件节点
  49. * @param name 该层名
  50. */
  51. constructor(name) {
  52. super(name);
  53. /** 全局窗口打开失败 */
  54. this.onOpenFailure = null;
  55. /** 显示界面节点集合 */
  56. this.ui_nodes = new Map();
  57. /** 被移除的界面缓存数据 */
  58. this.ui_cache = new Map();
  59. var widget = this.addComponent(Widget);
  60. widget.isAlignLeft = widget.isAlignRight = widget.isAlignTop = widget.isAlignBottom = true;
  61. widget.left = widget.right = widget.top = widget.bottom = 0;
  62. widget.alignMode = 2;
  63. widget.enabled = true;
  64. }
  65. /**
  66. * 添加一个预制件节点到层容器中,该方法将返回一个唯一`uuid`来标识该操作节点
  67. * @param config 界面配置数据
  68. * @param params 自定义参数
  69. * @param callbacks 回调函数对象,可选
  70. * @returns ture为成功,false为失败
  71. */
  72. add(config, params, callbacks) {
  73. if (this.ui_nodes.has(config.prefab)) {
  74. console.warn("\u8DEF\u5F84\u4E3A\u3010" + config.prefab + "\u3011\u7684\u9884\u5236\u91CD\u590D\u52A0\u8F7D");
  75. return;
  76. } // 检查缓存中是否存界面
  77. var vp = this.ui_cache.get(config.prefab);
  78. if (vp == null) {
  79. vp = new (_crd && ViewParams === void 0 ? (_reportPossibleCrUseOfViewParams({
  80. error: Error()
  81. }), ViewParams) : ViewParams)();
  82. vp.config = config;
  83. }
  84. this.ui_nodes.set(config.prefab, vp);
  85. vp.params = params != null ? params : {};
  86. vp.callbacks = callbacks != null ? callbacks : {};
  87. vp.valid = true;
  88. this.load(vp, config.bundle);
  89. }
  90. /**
  91. * 加载界面资源
  92. * @param vp 显示参数
  93. * @param bundle 远程资源包名,如果为空就是默认本地资源包
  94. */
  95. load(vp, bundle) {
  96. var _this = this;
  97. return _asyncToGenerator(function* () {
  98. // 加载界面资源超时提示
  99. var timerId = setTimeout(_this.onLoadingTimeoutGui, (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  100. error: Error()
  101. }), oops) : oops).config.game.loadingTimeoutGui);
  102. if (vp && vp.node) {
  103. yield _this.showUi(vp);
  104. } else {
  105. // 优先加载配置的指定资源包中资源,如果没配置则加载默认资源包资源
  106. bundle = bundle || (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  107. error: Error()
  108. }), oops) : oops).res.defaultBundleName;
  109. var res = yield (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  110. error: Error()
  111. }), oops) : oops).res.loadAsync(bundle, vp.config.prefab, Prefab);
  112. if (res) {
  113. vp.node = instantiate(res); // 是否启动真机安全区域显示
  114. if (vp.config.safeArea) vp.node.addComponent(SafeArea); // 窗口事件委托
  115. var dc = vp.node.addComponent(_crd && DelegateComponent === void 0 ? (_reportPossibleCrUseOfDelegateComponent({
  116. error: Error()
  117. }), DelegateComponent) : DelegateComponent);
  118. dc.vp = vp;
  119. dc.onCloseWindow = _this.onCloseWindow.bind(_this); // 显示界面
  120. yield _this.showUi(vp);
  121. } else {
  122. console.warn("\u8DEF\u5F84\u4E3A\u3010" + vp.config.prefab + "\u3011\u7684\u9884\u5236\u52A0\u8F7D\u5931\u8D25");
  123. _this.failure(vp);
  124. }
  125. } // 关闭界面资源超时提示
  126. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  127. error: Error()
  128. }), oops) : oops).gui.waitClose();
  129. clearTimeout(timerId);
  130. })();
  131. }
  132. /** 加载超时事件*/
  133. onLoadingTimeoutGui() {
  134. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  135. error: Error()
  136. }), oops) : oops).gui.waitOpen();
  137. }
  138. /** 窗口关闭事件 */
  139. onCloseWindow(vp) {
  140. this.ui_nodes.delete(vp.config.prefab);
  141. }
  142. /**
  143. * 创建界面节点
  144. * @param vp 视图参数
  145. */
  146. showUi(vp) {
  147. var _this2 = this;
  148. return _asyncToGenerator(function* () {
  149. // 触发窗口添加事件
  150. var comp = vp.node.getComponent(_crd && DelegateComponent === void 0 ? (_reportPossibleCrUseOfDelegateComponent({
  151. error: Error()
  152. }), DelegateComponent) : DelegateComponent);
  153. var r = yield comp.add();
  154. if (r) {
  155. vp.node.parent = _this2; // 标记界面为使用状态
  156. vp.valid = true;
  157. } else {
  158. console.warn("\u8DEF\u5F84\u4E3A\u3010" + vp.config.prefab + "\u3011\u7684\u81EA\u5B9A\u4E49\u9884\u5904\u7406\u903B\u8F91\u5F02\u5E38.\u68C0\u67E5\u9884\u5236\u4E0A\u7ED1\u5B9A\u7684\u7EC4\u4EF6\u4E2D onAdded \u65B9\u6CD5,\u8FD4\u56DEtrue\u624D\u80FD\u6B63\u786E\u5B8C\u6210\u7A97\u53E3\u663E\u793A\u6D41\u7A0B");
  159. _this2.failure(vp);
  160. }
  161. return r;
  162. })();
  163. }
  164. /** 打开窗口失败逻辑 */
  165. failure(vp) {
  166. this.onCloseWindow(vp);
  167. vp.callbacks && vp.callbacks.onLoadFailure && vp.callbacks.onLoadFailure();
  168. this.onOpenFailure && this.onOpenFailure();
  169. }
  170. /**
  171. * 根据预制件路径删除,预制件如在队列中也会被删除,如果该预制件存在多个也会一起删除
  172. * @param prefabPath 预制路径
  173. * @param isDestroy 移除后是否释放
  174. */
  175. remove(prefabPath, isDestroy) {
  176. var release = undefined;
  177. if (isDestroy !== undefined) release = isDestroy; // 界面移出舞台
  178. var vp = this.ui_nodes.get(prefabPath);
  179. if (vp) {
  180. // 优先使用参数中控制的释放条件,如果未传递参数则用配置中的释放条件,默认不缓存关闭的界面
  181. if (release === undefined) {
  182. release = vp.config.destroy !== undefined ? vp.config.destroy : true;
  183. } // 不释放界面,缓存起来待下次使用
  184. if (release === false) {
  185. this.ui_cache.set(vp.config.prefab, vp);
  186. }
  187. var childNode = vp.node;
  188. var comp = childNode.getComponent(_crd && DelegateComponent === void 0 ? (_reportPossibleCrUseOfDelegateComponent({
  189. error: Error()
  190. }), DelegateComponent) : DelegateComponent);
  191. comp.remove(release);
  192. } // 验证是否删除后台缓存界面
  193. if (release === true) this.removeCache(prefabPath);
  194. }
  195. /** 删除缓存的界面,当缓存界面被移除舞台时,可通过此方法删除缓存界面 */
  196. removeCache(prefabPath) {
  197. var vp = this.ui_cache.get(prefabPath);
  198. if (vp) {
  199. this.onCloseWindow(vp);
  200. this.ui_cache.delete(prefabPath);
  201. var childNode = vp.node;
  202. childNode.destroy();
  203. }
  204. }
  205. /**
  206. * 根据预制路径获取已打开界面的节点对象
  207. * @param prefabPath 预制路径
  208. */
  209. get(prefabPath) {
  210. var vp = this.ui_nodes.get(prefabPath);
  211. if (vp) return vp.node;
  212. return null;
  213. }
  214. /**
  215. * 判断当前层是否包含 uuid或预制件路径对应的Node节点
  216. * @param prefabPath 预制件路径或者UUID
  217. */
  218. has(prefabPath) {
  219. return this.ui_nodes.has(prefabPath);
  220. }
  221. /**
  222. * 清除所有节点,队列当中的也删除
  223. * @param isDestroy 移除后是否释放
  224. */
  225. clear(isDestroy) {
  226. // 清除所有显示的界面
  227. this.ui_nodes.forEach((value, key) => {
  228. this.remove(value.config.prefab, isDestroy);
  229. value.valid = false;
  230. });
  231. this.ui_nodes.clear(); // 清除缓存中的界面
  232. if (isDestroy) {
  233. this.ui_cache.forEach((value, prefabPath) => {
  234. this.removeCache(prefabPath);
  235. });
  236. }
  237. }
  238. });
  239. _cclegacy._RF.pop();
  240. _crd = false;
  241. }
  242. };
  243. });
  244. //# sourceMappingURL=ee79355c865a79ad49b2094aa0c29c3e51f20176.js.map