54f65e2869e26841ae28395e203d9703c6ba1fcb.js 19 KB

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