f714a6c34d01c870d1a023bdacf5c55af433d72e.js 9.9 KB

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