c50a7db4c939f8edf21e7a09e61946cd2cb05d33.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, director, error, instantiate, Node, UITransform, Widget, assetManager, tween, v3, UIOpacity, Vec3, Tween, ui_base, ResolutionAutoFit, ui, _dec, _class, _crd, ccclass, property, ui_updater, GameUILayers, gui;
  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 _reportPossibleCrUseOfui_base(extras) {
  7. _reporterNs.report("ui_base", "./ui_base", _context.meta, extras);
  8. }
  9. function _reportPossibleCrUseOfResolutionAutoFit(extras) {
  10. _reporterNs.report("ResolutionAutoFit", "./ui_ResolutionAutoFit", _context.meta, extras);
  11. }
  12. return {
  13. setters: [function (_unresolved_) {
  14. _reporterNs = _unresolved_;
  15. }, function (_cc) {
  16. _cclegacy = _cc.cclegacy;
  17. __checkObsolete__ = _cc.__checkObsolete__;
  18. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  19. _decorator = _cc._decorator;
  20. Component = _cc.Component;
  21. director = _cc.director;
  22. error = _cc.error;
  23. instantiate = _cc.instantiate;
  24. Node = _cc.Node;
  25. UITransform = _cc.UITransform;
  26. Widget = _cc.Widget;
  27. assetManager = _cc.assetManager;
  28. tween = _cc.tween;
  29. v3 = _cc.v3;
  30. UIOpacity = _cc.UIOpacity;
  31. Vec3 = _cc.Vec3;
  32. Tween = _cc.Tween;
  33. }, function (_unresolved_2) {
  34. ui_base = _unresolved_2.default;
  35. }, function (_unresolved_3) {
  36. ResolutionAutoFit = _unresolved_3.ResolutionAutoFit;
  37. }],
  38. execute: function () {
  39. _crd = true;
  40. _cclegacy._RF.push({}, "81e48wxjGBMPp2rQOJDljTG", "ui", undefined);
  41. __checkObsolete__(['_decorator', 'Component', 'director', 'error', 'instantiate', 'Node', 'Prefab', 'UITransform', 'Widget', 'assetManager', 'AssetManager', 'tween', 'v3', 'UIOpacity', 'Vec3', 'ProgressBar', 'Sprite', 'Tween']);
  42. ({
  43. ccclass,
  44. property
  45. } = _decorator);
  46. ui_updater = (_dec = ccclass('ui_updater'), _dec(_class = class ui_updater extends Component {
  47. update(dt) {
  48. (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
  49. error: Error()
  50. }), ui_base) : ui_base).updateAll(dt);
  51. }
  52. }) || _class);
  53. _export("GameUILayers", GameUILayers = /*#__PURE__*/function (GameUILayers) {
  54. GameUILayers[GameUILayers["GAME"] = 0] = "GAME";
  55. GameUILayers[GameUILayers["JOY_STICK"] = 1] = "JOY_STICK";
  56. GameUILayers[GameUILayers["HUD"] = 2] = "HUD";
  57. GameUILayers[GameUILayers["POPUP"] = 3] = "POPUP";
  58. GameUILayers[GameUILayers["ALERT"] = 4] = "ALERT";
  59. GameUILayers[GameUILayers["NOTICE"] = 5] = "NOTICE";
  60. GameUILayers[GameUILayers["LOADING"] = 6] = "LOADING";
  61. GameUILayers[GameUILayers["OVERLAY"] = 7] = "OVERLAY";
  62. return GameUILayers;
  63. }({}));
  64. /**ui管理模块*/
  65. ui = class ui {
  66. constructor() {
  67. this._uiCanvas = void 0;
  68. this._uiRoot = void 0;
  69. this._clss_loading = new Set();
  70. }
  71. static getInstance() {
  72. if (!this._instance) this._instance = new ui();
  73. return this._instance;
  74. }
  75. delay(ms) {
  76. return new Promise(resolve => setTimeout(resolve, ms));
  77. }
  78. delay_second(s) {
  79. return new Promise(resolve => setTimeout(resolve, s * 1000));
  80. }
  81. progressBar_anim(bar, progress, duration) {
  82. if (duration === void 0) {
  83. duration = 0.2;
  84. }
  85. if (bar.progress >= progress) {
  86. bar.progress = progress;
  87. return;
  88. } else {
  89. return new Promise(resolve => tween(bar).to(duration, {
  90. progress: progress
  91. }).call(() => {
  92. resolve();
  93. }).start());
  94. }
  95. }
  96. fillRange_anim(sp, progress, duration, limt) {
  97. if (duration === void 0) {
  98. duration = 0.2;
  99. }
  100. if (limt === void 0) {
  101. limt = 0;
  102. }
  103. if (limt > 0 && sp.fillRange >= progress && limt < 0 && sp.fillRange <= progress) {
  104. sp.fillRange = progress;
  105. return;
  106. } else {
  107. return new Promise(resolve => tween(sp).to(duration, {
  108. fillRange: progress
  109. }).call(() => {
  110. resolve();
  111. }).start());
  112. }
  113. }
  114. scale_anim(node, duration, start, end) {
  115. if (duration === void 0) {
  116. duration = 0.2;
  117. }
  118. if (start === void 0) {
  119. start = 0.5;
  120. }
  121. if (end === void 0) {
  122. end = 1;
  123. }
  124. node.setScale(start, start, 1);
  125. return new Promise(resolve => tween(node).to(duration, {
  126. scale: v3(end, end, 1)
  127. }).call(() => {
  128. resolve();
  129. }).start());
  130. }
  131. scale_elasticOut_anim(node, duration, start, end) {
  132. if (duration === void 0) {
  133. duration = 0.2;
  134. }
  135. if (start === void 0) {
  136. start = 0.5;
  137. }
  138. if (end === void 0) {
  139. end = 1;
  140. }
  141. node.setScale(start, start, 1);
  142. return new Promise(resolve => tween(node).to(duration, {
  143. scale: v3(end, end, 1)
  144. }, {
  145. easing: 'elasticOut'
  146. }).call(() => {
  147. resolve();
  148. }).start());
  149. }
  150. fade_anim(node, duration, startOpacity, targetOpacity) {
  151. var _node$getComponent;
  152. if (duration === void 0) {
  153. duration = 0.2;
  154. }
  155. if (startOpacity === void 0) {
  156. startOpacity = 0;
  157. }
  158. if (targetOpacity === void 0) {
  159. targetOpacity = 255;
  160. }
  161. var opacity = (_node$getComponent = node.getComponent(UIOpacity)) != null ? _node$getComponent : node.addComponent(UIOpacity);
  162. opacity.opacity = startOpacity;
  163. return new Promise(resolve => {
  164. tween(opacity).to(duration, {
  165. opacity: targetOpacity
  166. }).call(() => {
  167. resolve();
  168. }).start();
  169. });
  170. }
  171. shake_anim(node, duration, intensity, shakeCount) {
  172. if (duration === void 0) {
  173. duration = 0.2;
  174. }
  175. if (intensity === void 0) {
  176. intensity = 5;
  177. }
  178. if (shakeCount === void 0) {
  179. shakeCount = 7;
  180. }
  181. return new Promise(resolve => {
  182. var originalPosition = node.position.clone(); // 保存原始位置
  183. var shakeDuration = duration / (shakeCount * 2); // 每次抖动的持续时间
  184. var shakeTween = tween(node);
  185. for (var i = 0; i < shakeCount; i++) {
  186. var offsetX = i % 2 === 0 ? intensity : -intensity; // 交替偏移
  187. shakeTween.to(shakeDuration, {
  188. position: v3(originalPosition.x + offsetX, originalPosition.y, originalPosition.z)
  189. }).to(shakeDuration, {
  190. position: originalPosition
  191. }); // 回到原位
  192. }
  193. shakeTween.call(() => {
  194. resolve();
  195. }).start(); // 开始抖动动画
  196. });
  197. }
  198. rotate_shake_anim(node, duration, intensity, shakeCount) {
  199. if (duration === void 0) {
  200. duration = 0.3;
  201. }
  202. if (intensity === void 0) {
  203. intensity = 5;
  204. }
  205. if (shakeCount === void 0) {
  206. shakeCount = 5;
  207. }
  208. return new Promise(resolve => {
  209. var originalAngle = node.angle; // 保存原始角度
  210. var shakeDuration = duration / (shakeCount * 2); // 每次晃动的持续时间
  211. var shakeTween = tween(node);
  212. for (var i = 0; i < shakeCount; i++) {
  213. var offsetAngle = i % 2 === 0 ? intensity : -intensity; // 交替旋转
  214. shakeTween.to(shakeDuration, {
  215. angle: originalAngle + offsetAngle
  216. }).to(shakeDuration, {
  217. angle: originalAngle
  218. }); // 回到原位
  219. }
  220. shakeTween.call(() => {
  221. resolve();
  222. }).start(); // 开始角度晃动动画
  223. });
  224. }
  225. scale_shake_anim(node, duration, intensity, shakeCount, reset) {
  226. if (duration === void 0) {
  227. duration = 0.3;
  228. }
  229. if (intensity === void 0) {
  230. intensity = 0.1;
  231. }
  232. if (shakeCount === void 0) {
  233. shakeCount = 10;
  234. }
  235. if (reset === void 0) {
  236. reset = null;
  237. }
  238. if (reset) {
  239. Tween.stopAllByTarget(node);
  240. node.setScale(reset, reset, reset);
  241. }
  242. return new Promise(resolve => {
  243. var originalScale = node.scale.clone(); // 保存原始缩放
  244. var shakeDuration = duration / (shakeCount * 2); // 每次震动的持续时间
  245. var shakeTween = tween(node);
  246. for (var i = 0; i < shakeCount; i++) {
  247. var offsetScale = i % 2 === 0 ? intensity : -intensity; // 交替缩放
  248. shakeTween.to(shakeDuration, {
  249. scale: v3(originalScale.x + offsetScale, originalScale.y + offsetScale, originalScale.z)
  250. }).to(shakeDuration, {
  251. scale: originalScale
  252. }); // 回到原位
  253. }
  254. shakeTween.call(() => {
  255. resolve();
  256. }).start(); // 开始缩放震动动画
  257. });
  258. }
  259. opacity_shake_anim(node, duration, intensity, shakeCount) {
  260. var _node$getComponent2;
  261. if (duration === void 0) {
  262. duration = 0.8;
  263. }
  264. if (intensity === void 0) {
  265. intensity = 80;
  266. }
  267. if (shakeCount === void 0) {
  268. shakeCount = 5;
  269. }
  270. var opacity = (_node$getComponent2 = node.getComponent(UIOpacity)) != null ? _node$getComponent2 : node.addComponent(UIOpacity);
  271. var originalOpacity = opacity.opacity;
  272. var shakeDuration = duration / (shakeCount * 2);
  273. return new Promise(resolve => {
  274. var shakeTween = tween(opacity);
  275. for (var i = 0; i < shakeCount; i++) {
  276. var offsetOpacity = i % 2 === 0 ? intensity : -intensity;
  277. shakeTween.to(shakeDuration, {
  278. opacity: Math.min(Math.max(originalOpacity + offsetOpacity, 0), 255)
  279. }).to(shakeDuration, {
  280. opacity: originalOpacity
  281. });
  282. }
  283. shakeTween.call(() => {
  284. resolve();
  285. }).start(); // 开始透明度震动动画
  286. });
  287. }
  288. /**处理弹跳动画*/
  289. bounce_anim(node, height, duration) {
  290. if (height === void 0) {
  291. height = 100;
  292. }
  293. if (duration === void 0) {
  294. duration = 0.5;
  295. }
  296. return new Promise(resolve => {
  297. tween(node).to(duration, {
  298. position: node.position.clone().add(new Vec3(0, height, 0))
  299. }, {
  300. easing: 'bounceOut'
  301. }) // 向上弹跳
  302. .to(duration, {
  303. position: node.position
  304. }, {
  305. easing: 'bounceIn'
  306. }) // 回到原位
  307. .call(() => {
  308. resolve();
  309. }) //完成动画
  310. .start(); //开始动画
  311. });
  312. }
  313. /**
  314. * 奖励物飞行动画
  315. * @param node 奖励物节点
  316. * @param startPos 起始爆开点
  317. * @param targetPos 最终目标点
  318. * @param explosionDistance 爆开距离
  319. * @param explosionDuration 爆开时间
  320. * @param stayDuration 停留时间
  321. * @param moveDuration 移动到目标的时间
  322. * @returns
  323. */
  324. reward_fly_anim(node, startPos, targetPos, explosionDistance, explosionDuration, stayDuration, moveDuration) {
  325. if (explosionDistance === void 0) {
  326. explosionDistance = 100;
  327. }
  328. if (explosionDuration === void 0) {
  329. explosionDuration = 0.3;
  330. }
  331. if (stayDuration === void 0) {
  332. stayDuration = 0.5;
  333. }
  334. if (moveDuration === void 0) {
  335. moveDuration = 0.3;
  336. }
  337. node.setPosition(startPos);
  338. return new Promise(resolve => {
  339. //随机方向
  340. var randomDirection = new Vec3(Math.random() * 2 - 1, Math.random() * 2 - 1, 0).normalize();
  341. var explosionEndPos = startPos.add(randomDirection.multiplyScalar(explosionDistance)); // 爆炸效果的位置
  342. tween(node).to(explosionDuration, {
  343. worldPosition: explosionEndPos
  344. }) // 爆炸动画
  345. .delay(stayDuration) //停留时间
  346. .to(moveDuration, {
  347. worldPosition: targetPos
  348. }, {
  349. easing: 'cubicIn'
  350. }).call(() => {
  351. resolve();
  352. }).start();
  353. });
  354. }
  355. createFullScreenNode() {
  356. var canvas = this._uiCanvas.getComponent(UITransform);
  357. var node = new Node();
  358. node.layer = this._uiCanvas.layer;
  359. var uiTransform = node.addComponent(UITransform);
  360. uiTransform.width = canvas.width;
  361. uiTransform.height = canvas.height;
  362. var widget = node.addComponent(Widget);
  363. widget.isAlignBottom = true;
  364. widget.isAlignTop = true;
  365. widget.isAlignLeft = true;
  366. widget.isAlignRight = true;
  367. widget.left = 0;
  368. widget.right = 0;
  369. widget.top = 0;
  370. widget.bottom = 0;
  371. return node;
  372. }
  373. getLayers() {
  374. return Object.values(GameUILayers).filter(value => typeof value === 'number');
  375. }
  376. /**
  377. * @en init,`don't call more than once`.
  378. * @zh 初始化UIMgr,`不要多次调用`
  379. * */
  380. init(uiCanvas) {
  381. if (this._uiCanvas) return;
  382. if (!uiCanvas) throw error('uiCanvas must be a Node or Prefab');
  383. if (uiCanvas instanceof Node) {
  384. this._uiCanvas = uiCanvas;
  385. } else {
  386. this._uiCanvas = instantiate(uiCanvas);
  387. director.getScene().addChild(this._uiCanvas);
  388. }
  389. this._uiCanvas.name = '__ui_canvas__';
  390. director.addPersistRootNode(this._uiCanvas);
  391. if (!this._uiCanvas.getComponent(ui_updater)) {
  392. this._uiCanvas.addComponent(ui_updater);
  393. }
  394. var canvas = this._uiCanvas.getComponent(UITransform);
  395. this._uiCanvas.addComponent(_crd && ResolutionAutoFit === void 0 ? (_reportPossibleCrUseOfResolutionAutoFit({
  396. error: Error()
  397. }), ResolutionAutoFit) : ResolutionAutoFit);
  398. this._uiRoot = this.createFullScreenNode();
  399. this._uiRoot.name = 'root';
  400. canvas.node.addChild(this._uiRoot);
  401. var layers = this.getLayers(); //create layers
  402. for (var i = 0; i < layers.length; ++i) {
  403. var layerNode = this.createFullScreenNode();
  404. layerNode.name = 'layer_' + GameUILayers[layers[i]];
  405. this._uiRoot.addChild(layerNode);
  406. }
  407. }
  408. /**获取层级节点*/
  409. getLayerNode(layerIndex) {
  410. return this._uiRoot.children[layerIndex] || this._uiRoot;
  411. }
  412. /**关闭所有界面*/
  413. closeAll() {
  414. (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
  415. error: Error()
  416. }), ui_base) : ui_base).closeAll();
  417. }
  418. /**关闭和释放所有界面 */
  419. closeAndReleaseAll() {
  420. (_crd && ui_base === void 0 ? (_reportPossibleCrUseOfui_base({
  421. error: Error()
  422. }), ui_base) : ui_base).closeAndReleaseAll();
  423. }
  424. /**关闭某个界面*/
  425. close(uiCls) {
  426. var _this$get;
  427. (_this$get = this.get(uiCls)) == null || _this$get.close();
  428. }
  429. /**获取界面*/
  430. get(uiCls) {
  431. var all = ui_base._uis;
  432. for (var i = 0; i < all.length; ++i) {
  433. var c = all[i];
  434. if (c instanceof uiCls) {
  435. return c;
  436. }
  437. }
  438. return null;
  439. }
  440. /**某个界面是否显示中*/
  441. isShowing(uiCls) {
  442. return ui_base._hasCls(uiCls);
  443. }
  444. /**是否有正在加载中的界面*/
  445. isLoading(uiCls) {
  446. if (!uiCls) return this._clss_loading.size > 0;
  447. return this._clss_loading.has(uiCls);
  448. }
  449. /***
  450. * @en show ui by the given parameters.
  451. * @zh 显示UI
  452. * @param uiCls the class, must inherits from the class `UIController`.
  453. * @returns the instance of `uiCls`
  454. * */
  455. show(uiCls) {
  456. var _arguments = arguments,
  457. _this = this;
  458. return _asyncToGenerator(function* () {
  459. if (_this.isLoading(uiCls)) return null;
  460. if (_this.isShowing(uiCls)) return null;
  461. var ui = new uiCls();
  462. _this._clss_loading.add(uiCls);
  463. var bundleName = ui.bundle;
  464. if (bundleName) {
  465. var bundle = assetManager.getBundle(bundleName);
  466. for (var _len = _arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  467. data[_key - 1] = _arguments[_key];
  468. }
  469. if (!bundle) {
  470. try {
  471. var loadedBundle = yield _this.loadBundleAsync(bundleName);
  472. return yield _this._create(loadedBundle, ui, uiCls, ...data);
  473. } catch (err) {
  474. console.error(err);
  475. _this._clss_loading.delete(uiCls);
  476. }
  477. } else {
  478. return yield _this._create(bundle, ui, uiCls, ...data);
  479. }
  480. } else {
  481. _this._clss_loading.delete(uiCls);
  482. console.error("ui no bundle name");
  483. return null;
  484. }
  485. })();
  486. }
  487. _create(bundle, ui, uiCls) {
  488. var _arguments2 = arguments,
  489. _this2 = this;
  490. return _asyncToGenerator(function* () {
  491. try {
  492. var data = yield _this2.loadPrefabAsync(bundle, ui.prefab);
  493. var node = instantiate(data);
  494. var parent = _this2.getLayerNode(ui.layer);
  495. parent.addChild(node);
  496. for (var _len2 = _arguments2.length, p = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
  497. p[_key2 - 3] = _arguments2[_key2];
  498. }
  499. ui._setup(uiCls, node, ...p);
  500. _this2._clss_loading.delete(uiCls);
  501. return ui;
  502. } catch (err) {
  503. console.error(err);
  504. _this2._clss_loading.delete(uiCls);
  505. return;
  506. }
  507. })();
  508. }
  509. loadBundleAsync(bundleName) {
  510. return new Promise((resolve, reject) => {
  511. assetManager.loadBundle(bundleName, null, (err, loadedBundle) => {
  512. if (err) {
  513. reject(err);
  514. } else {
  515. resolve(loadedBundle);
  516. }
  517. });
  518. });
  519. }
  520. loadPrefabAsync(bundle, prefabName) {
  521. return new Promise((resolve, reject) => {
  522. bundle.load(prefabName, (err, data) => {
  523. if (err) {
  524. reject(err);
  525. } else {
  526. resolve(data);
  527. }
  528. });
  529. });
  530. }
  531. };
  532. ui._instance = void 0;
  533. _export("gui", gui = ui.getInstance());
  534. _export("ui_base", ui_base);
  535. _cclegacy._RF.pop();
  536. _crd = false;
  537. }
  538. };
  539. });
  540. //# sourceMappingURL=c50a7db4c939f8edf21e7a09e61946cd2cb05d33.js.map