af918a421bbf8d65fc298cc8d8cc4aae5f37ce8e.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4", "__unresolved_5", "__unresolved_6"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Camera, Layers, Node, ResolutionPolicy, SafeArea, Widget, screen, view, warn, oops, DelegateComponent, LayerDialog, LayerNotify, LayerPopUp, LayerUI, LayerManager, _crd, ScreenAdapterType, LayerType;
  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 _reportPossibleCrUseOfDelegateComponent(extras) {
  11. _reporterNs.report("DelegateComponent", "./DelegateComponent", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfLayerDialog(extras) {
  14. _reporterNs.report("LayerDialog", "./LayerDialog", _context.meta, extras);
  15. }
  16. function _reportPossibleCrUseOfLayerNotify(extras) {
  17. _reporterNs.report("LayerNotify", "./LayerNotify", _context.meta, extras);
  18. }
  19. function _reportPossibleCrUseOfLayerPopUp(extras) {
  20. _reporterNs.report("LayerPopUp", "./LayerPopup", _context.meta, extras);
  21. }
  22. function _reportPossibleCrUseOfLayerUI(extras) {
  23. _reporterNs.report("LayerUI", "./LayerUI", _context.meta, extras);
  24. }
  25. _export("LayerManager", void 0);
  26. return {
  27. setters: [function (_unresolved_) {
  28. _reporterNs = _unresolved_;
  29. }, function (_cc) {
  30. _cclegacy = _cc.cclegacy;
  31. __checkObsolete__ = _cc.__checkObsolete__;
  32. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  33. Camera = _cc.Camera;
  34. Layers = _cc.Layers;
  35. Node = _cc.Node;
  36. ResolutionPolicy = _cc.ResolutionPolicy;
  37. SafeArea = _cc.SafeArea;
  38. Widget = _cc.Widget;
  39. screen = _cc.screen;
  40. view = _cc.view;
  41. warn = _cc.warn;
  42. }, function (_unresolved_2) {
  43. oops = _unresolved_2.oops;
  44. }, function (_unresolved_3) {
  45. DelegateComponent = _unresolved_3.DelegateComponent;
  46. }, function (_unresolved_4) {
  47. LayerDialog = _unresolved_4.LayerDialog;
  48. }, function (_unresolved_5) {
  49. LayerNotify = _unresolved_5.LayerNotify;
  50. }, function (_unresolved_6) {
  51. LayerPopUp = _unresolved_6.LayerPopUp;
  52. }, function (_unresolved_7) {
  53. LayerUI = _unresolved_7.LayerUI;
  54. }],
  55. execute: function () {
  56. _crd = true;
  57. _cclegacy._RF.push({}, "7ba675xFGdHqIOykTysNzEu", "LayerManager", undefined);
  58. __checkObsolete__(['Camera', 'Layers', 'Node', 'ResolutionPolicy', 'SafeArea', 'Widget', 'screen', 'view', 'warn']);
  59. /** 屏幕适配类型 */
  60. _export("ScreenAdapterType", ScreenAdapterType = /*#__PURE__*/function (ScreenAdapterType) {
  61. ScreenAdapterType[ScreenAdapterType["Auto"] = 0] = "Auto";
  62. ScreenAdapterType[ScreenAdapterType["Landscape"] = 1] = "Landscape";
  63. ScreenAdapterType[ScreenAdapterType["Portrait"] = 2] = "Portrait";
  64. return ScreenAdapterType;
  65. }({}));
  66. /** 界面层类型 */
  67. _export("LayerType", LayerType = /*#__PURE__*/function (LayerType) {
  68. LayerType["Game"] = "LayerGame";
  69. LayerType["UI"] = "LayerUI";
  70. LayerType["PopUp"] = "LayerPopUp";
  71. LayerType["Dialog"] = "LayerDialog";
  72. LayerType["System"] = "LayerSystem";
  73. LayerType["Notify"] = "LayerNotify";
  74. LayerType["Guide"] = "LayerGuide";
  75. return LayerType;
  76. }({}));
  77. /**
  78. * 界面配置结构体
  79. * @help https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12037986&doc_id=2873565
  80. * @example
  81. // 界面唯一标识
  82. export enum UIID {
  83. Loading = 1,
  84. Window,
  85. Netinstable
  86. }
  87. // 打开界面方式的配置数据
  88. export var UIConfigData: { [key: number]: UIConfig } = {
  89. [UIID.Loading]: { layer: LayerType.UI, prefab: "loading/prefab/loading", bundle: "resources" },
  90. [UIID.Netinstable]: { layer: LayerType.PopUp, prefab: "common/prefab/netinstable" },
  91. [UIID.Window]: { layer: LayerType.Dialog, prefab: "common/prefab/window" }
  92. }
  93. */
  94. /** 界面层级管理器 */
  95. _export("LayerManager", LayerManager = class LayerManager {
  96. constructor() {
  97. /** 界面根节点 */
  98. this.root = void 0;
  99. /** 界面摄像机 */
  100. this.camera = void 0;
  101. /** 游戏界面特效层 */
  102. this.game = void 0;
  103. /** 新手引导层 */
  104. this.guide = void 0;
  105. /** 窗口宽高比例 */
  106. this.windowAspectRatio = 0;
  107. /** 设计宽高比例 */
  108. this.designAspectRatio = 0;
  109. /** 是否开启移动设备安全区域适配 */
  110. this.mobileSafeArea = false;
  111. /** 界面层 */
  112. this.ui = void 0;
  113. /** 弹窗层 */
  114. this.popup = void 0;
  115. /** 只能弹出一个的弹窗 */
  116. this.dialog = void 0;
  117. /** 游戏系统提示弹窗 */
  118. this.system = void 0;
  119. /** 消息提示控制器,请使用show方法来显示 */
  120. this.notify = void 0;
  121. /** UI配置 */
  122. this.configs = {};
  123. }
  124. /**
  125. * 初始化界面层
  126. * @param root 界面根节点
  127. */
  128. initLayer(root) {
  129. this.root = root;
  130. this.initScreenAdapter();
  131. this.camera = this.root.getComponentInChildren(Camera);
  132. this.game = this.create_node(LayerType.Game);
  133. this.ui = new (_crd && LayerUI === void 0 ? (_reportPossibleCrUseOfLayerUI({
  134. error: Error()
  135. }), LayerUI) : LayerUI)(LayerType.UI);
  136. this.popup = new (_crd && LayerPopUp === void 0 ? (_reportPossibleCrUseOfLayerPopUp({
  137. error: Error()
  138. }), LayerPopUp) : LayerPopUp)(LayerType.PopUp);
  139. this.dialog = new (_crd && LayerDialog === void 0 ? (_reportPossibleCrUseOfLayerDialog({
  140. error: Error()
  141. }), LayerDialog) : LayerDialog)(LayerType.Dialog);
  142. this.system = new (_crd && LayerDialog === void 0 ? (_reportPossibleCrUseOfLayerDialog({
  143. error: Error()
  144. }), LayerDialog) : LayerDialog)(LayerType.System);
  145. this.notify = new (_crd && LayerNotify === void 0 ? (_reportPossibleCrUseOfLayerNotify({
  146. error: Error()
  147. }), LayerNotify) : LayerNotify)(LayerType.Notify);
  148. this.guide = this.create_node(LayerType.Guide);
  149. root.addChild(this.game);
  150. root.addChild(this.ui);
  151. root.addChild(this.popup);
  152. root.addChild(this.dialog);
  153. root.addChild(this.system);
  154. root.addChild(this.notify);
  155. root.addChild(this.guide);
  156. }
  157. /** 初始化屏幕适配 */
  158. initScreenAdapter() {
  159. const drs = view.getDesignResolutionSize();
  160. const ws = screen.windowSize;
  161. this.windowAspectRatio = ws.width / ws.height;
  162. this.designAspectRatio = drs.width / drs.height;
  163. let finalW = 0;
  164. let finalH = 0;
  165. if (this.windowAspectRatio > this.designAspectRatio) {
  166. finalH = drs.height;
  167. finalW = finalH * ws.width / ws.height;
  168. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  169. error: Error()
  170. }), oops) : oops).log.logView("适配屏幕高度", "【横屏】");
  171. } else {
  172. finalW = drs.width;
  173. finalH = finalW * ws.height / ws.width;
  174. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  175. error: Error()
  176. }), oops) : oops).log.logView("适配屏幕宽度", "【竖屏】");
  177. }
  178. view.setDesignResolutionSize(finalW, finalH, ResolutionPolicy.UNKNOWN);
  179. if (this.mobileSafeArea) {
  180. this.root.addComponent(SafeArea);
  181. (_crd && oops === void 0 ? (_reportPossibleCrUseOfoops({
  182. error: Error()
  183. }), oops) : oops).log.logView("开启移动设备安全区域适配");
  184. }
  185. }
  186. /**
  187. * 初始化所有UI的配置对象
  188. * @param configs 配置对象
  189. */
  190. init(configs) {
  191. this.configs = configs;
  192. }
  193. /**
  194. * 设置窗口打开失败回调
  195. * @param callback 回调方法
  196. */
  197. setOpenFailure(callback) {
  198. this.ui.onOpenFailure = this.popup.onOpenFailure = this.dialog.onOpenFailure = this.system.onOpenFailure = callback;
  199. }
  200. /**
  201. * 渐隐飘过提示
  202. * @param content 文本表示
  203. * @param useI18n 是否使用多语言
  204. * @example
  205. * oops.gui.toast("提示内容");
  206. */
  207. toast(content, useI18n = false) {
  208. this.notify.toast(content, useI18n);
  209. }
  210. /** 打开等待提示 */
  211. waitOpen() {
  212. this.notify.waitOpen();
  213. }
  214. /** 关闭等待提示 */
  215. waitClose() {
  216. this.notify.waitClose();
  217. }
  218. /**
  219. * 设置界面配置
  220. * @param uiId 要设置的界面id
  221. * @param config 要设置的配置
  222. */
  223. setConfig(uiId, config) {
  224. this.configs[uiId] = config;
  225. }
  226. /**
  227. * 同步打开一个窗口
  228. * @param uiId 窗口唯一编号
  229. * @param uiArgs 窗口参数
  230. * @param callbacks 回调对象
  231. * @example
  232. var uic: UICallbacks = {
  233. onAdded: (node: Node, params: any) => {
  234. var comp = node.getComponent(LoadingViewComp) as ecs.Comp;
  235. }
  236. onRemoved:(node: Node | null, params: any) => {
  237. }
  238. };
  239. oops.gui.open(UIID.Loading, null, uic);
  240. */
  241. open(uiId, uiArgs = null, callbacks) {
  242. const config = this.configs[uiId];
  243. if (config == null) {
  244. warn(`打开编号为【${uiId}】的界面失败,配置信息不存在`);
  245. return;
  246. }
  247. switch (config.layer) {
  248. case LayerType.UI:
  249. this.ui.add(config, uiArgs, callbacks);
  250. break;
  251. case LayerType.PopUp:
  252. this.popup.add(config, uiArgs, callbacks);
  253. break;
  254. case LayerType.Dialog:
  255. this.dialog.add(config, uiArgs, callbacks);
  256. break;
  257. case LayerType.System:
  258. this.system.add(config, uiArgs, callbacks);
  259. break;
  260. }
  261. }
  262. /**
  263. * 异步打开一个窗口
  264. * @param uiId 窗口唯一编号
  265. * @param uiArgs 窗口参数
  266. * @example
  267. * var node = await oops.gui.openAsync(UIID.Loading);
  268. */
  269. async openAsync(uiId, uiArgs = null) {
  270. return new Promise((resolve, reject) => {
  271. const callbacks = {
  272. onAdded: (node, params) => {
  273. resolve(node);
  274. },
  275. onLoadFailure: () => {
  276. resolve(null);
  277. }
  278. };
  279. this.open(uiId, uiArgs, callbacks);
  280. });
  281. }
  282. /**
  283. * 场景替换
  284. * @param removeUiId 移除场景编号
  285. * @param openUiId 新打开场景编号
  286. * @param uiArgs 新打开场景参数
  287. */
  288. replace(removeUiId, openUiId, uiArgs = null) {
  289. const callbacks = {
  290. onAdded: (node, params) => {
  291. this.remove(removeUiId);
  292. }
  293. };
  294. this.open(openUiId, uiArgs, callbacks);
  295. }
  296. /**
  297. * 异步场景替换
  298. * @param removeUiId 移除场景编号
  299. * @param openUiId 新打开场景编号
  300. * @param uiArgs 新打开场景参数
  301. */
  302. replaceAsync(removeUiId, openUiId, uiArgs = null) {
  303. return new Promise(async (resolve, reject) => {
  304. const node = await this.openAsync(openUiId, uiArgs);
  305. if (node) {
  306. this.remove(removeUiId);
  307. resolve(node);
  308. } else {
  309. resolve(null);
  310. }
  311. });
  312. }
  313. /**
  314. * 缓存中是否存在指定标识的窗口
  315. * @param uiId 窗口唯一标识
  316. * @example
  317. * oops.gui.has(UIID.Loading);
  318. */
  319. has(uiId) {
  320. const config = this.configs[uiId];
  321. if (config == null) {
  322. warn(`编号为【${uiId}】的界面配置不存在,配置信息不存在`);
  323. return false;
  324. }
  325. var result = false;
  326. switch (config.layer) {
  327. case LayerType.UI:
  328. result = this.ui.has(config.prefab);
  329. break;
  330. case LayerType.PopUp:
  331. result = this.popup.has(config.prefab);
  332. break;
  333. case LayerType.Dialog:
  334. result = this.dialog.has(config.prefab);
  335. break;
  336. case LayerType.System:
  337. result = this.system.has(config.prefab);
  338. break;
  339. }
  340. return result;
  341. }
  342. /**
  343. * 缓存中是否存在指定标识的窗口
  344. * @param uiId 窗口唯一标识
  345. * @example
  346. * oops.gui.has(UIID.Loading);
  347. */
  348. get(uiId) {
  349. const config = this.configs[uiId];
  350. if (config == null) {
  351. warn(`编号为【${uiId}】的界面配置不存在,配置信息不存在`);
  352. return null;
  353. }
  354. let result = null;
  355. switch (config.layer) {
  356. case LayerType.UI:
  357. result = this.ui.get(config.prefab);
  358. break;
  359. case LayerType.PopUp:
  360. result = this.popup.get(config.prefab);
  361. break;
  362. case LayerType.Dialog:
  363. result = this.dialog.get(config.prefab);
  364. break;
  365. case LayerType.System:
  366. result = this.system.get(config.prefab);
  367. break;
  368. }
  369. return result;
  370. }
  371. /**
  372. * 移除指定标识的窗口
  373. * @param uiId 窗口唯一标识
  374. * @param isDestroy 移除后是否释放
  375. * @example
  376. * oops.gui.remove(UIID.Loading);
  377. */
  378. remove(uiId, isDestroy) {
  379. const config = this.configs[uiId];
  380. if (config == null) {
  381. warn(`删除编号为【${uiId}】的界面失败,配置信息不存在`);
  382. return;
  383. }
  384. switch (config.layer) {
  385. case LayerType.UI:
  386. this.ui.remove(config.prefab, isDestroy);
  387. break;
  388. case LayerType.PopUp:
  389. this.popup.remove(config.prefab, isDestroy);
  390. break;
  391. case LayerType.Dialog:
  392. this.dialog.remove(config.prefab, isDestroy);
  393. break;
  394. case LayerType.System:
  395. this.system.remove(config.prefab, isDestroy);
  396. break;
  397. }
  398. }
  399. /**
  400. * 删除一个通过this框架添加进来的节点
  401. * @param node 窗口节点
  402. * @param isDestroy 移除后是否释放资源
  403. * @example
  404. * oops.gui.removeByNode(cc.Node);
  405. */
  406. removeByNode(node, isDestroy) {
  407. if (node instanceof Node) {
  408. let comp = node.getComponent(_crd && DelegateComponent === void 0 ? (_reportPossibleCrUseOfDelegateComponent({
  409. error: Error()
  410. }), DelegateComponent) : DelegateComponent);
  411. if (comp && comp.vp) {
  412. // 释放显示的界面
  413. if (node.parent) {
  414. node.parent.remove(comp.vp.config.prefab, isDestroy);
  415. } // 释放缓存中的界面
  416. else if (isDestroy) {
  417. switch (comp.vp.config.layer) {
  418. case LayerType.UI:
  419. // @ts-ignore 注:不对外使用
  420. this.ui.removeCache(comp.vp.config.prefab);
  421. break;
  422. case LayerType.PopUp:
  423. // @ts-ignore 注:不对外使用
  424. this.popup.removeCache(comp.vp.config.prefab);
  425. break;
  426. case LayerType.Dialog:
  427. // @ts-ignore 注:不对外使用
  428. this.dialog.removeCache(comp.vp.config.prefab);
  429. break;
  430. case LayerType.System:
  431. // @ts-ignore 注:不对外使用
  432. this.system.removeCache(comp.vp.config.prefab);
  433. break;
  434. }
  435. }
  436. } else {
  437. warn(`当前删除的node不是通过界面管理器添加到舞台上`);
  438. node.destroy();
  439. }
  440. }
  441. }
  442. /**
  443. * 清除所有窗口
  444. * @param isDestroy 移除后是否释放
  445. * @example
  446. * oops.gui.clear();
  447. */
  448. clear(isDestroy = false) {
  449. this.ui.clear(isDestroy);
  450. this.popup.clear(isDestroy);
  451. this.dialog.clear(isDestroy);
  452. this.system.clear(isDestroy);
  453. }
  454. create_node(name) {
  455. const node = new Node(name);
  456. node.layer = Layers.Enum.UI_2D;
  457. const w = node.addComponent(Widget);
  458. w.isAlignLeft = w.isAlignRight = w.isAlignTop = w.isAlignBottom = true;
  459. w.left = w.right = w.top = w.bottom = 0;
  460. w.alignMode = 2;
  461. w.enabled = true;
  462. return node;
  463. }
  464. });
  465. _cclegacy._RF.pop();
  466. _crd = false;
  467. }
  468. };
  469. });
  470. //# sourceMappingURL=af918a421bbf8d65fc298cc8d8cc4aae5f37ce8e.js.map