e2a64b1b86682447693e82b91eec4ccebdf4a666.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Label, tween, Logger, _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _crd, ccclass, property, LoadingUI;
  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 _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  7. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  8. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  9. function _reportPossibleCrUseOfLogger(extras) {
  10. _reporterNs.report("Logger", "./Logger", _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. Label = _cc.Label;
  22. tween = _cc.tween;
  23. }, function (_unresolved_2) {
  24. Logger = _unresolved_2.Logger;
  25. }],
  26. execute: function () {
  27. _crd = true;
  28. _cclegacy._RF.push({}, "0b1a611XNpHVLjup75rkN0R", "LoadingUI", undefined);
  29. __checkObsolete__(['_decorator', 'Component', 'Label', 'Tween', 'tween', 'v3']);
  30. ({
  31. ccclass,
  32. property
  33. } = _decorator);
  34. /*初始化加载界面*/
  35. _export("LoadingUI", LoadingUI = (_dec = ccclass("LoadingUI"), _dec2 = property(Label), _dec3 = property(Label), _dec(_class = (_class2 = class LoadingUI extends Component {
  36. constructor() {
  37. super(...arguments);
  38. _initializerDefineProperty(this, "progressLabel", _descriptor, this);
  39. _initializerDefineProperty(this, "tipLabel", _descriptor2, this);
  40. this._currentProgress = 0;
  41. this._isLoading = false;
  42. this._progressTween = null;
  43. this._taskQueue = [];
  44. this._currentTaskIndex = 0;
  45. }
  46. /**
  47. * 开始加载流程
  48. * @param initialProgress 初始进度 (0-100)
  49. * @example 调用事例:
  50. * this.loadingUI.startLoading();
  51. //添加所有加载任务
  52. this.loadingUI.addTask(10, '资源加载中...', () => {
  53. PlayerData.ins().initialize();
  54. PlatformSystem.initialize();
  55. SettingData.ins().initialize();
  56. });
  57. this.loadingUI.addTask(30, '加载音乐资源...', async () => {
  58. await AudioManager.initialize();
  59. });
  60. this.loadingUI.addTask(40, '加载关卡数据...', async () => {
  61. await LevelsResData.ins().initialize();
  62. await LevelsResData.instance.preLoadAllMap();
  63. });
  64. this.loadingUI.addTask(20, '预加载场景...', async () => {
  65. await SceneManager.initialize();
  66. });
  67. //执行所有任务完成后会自动调用finishLoading()
  68. await this.loadingUI.executeTasks();
  69. */
  70. startLoading(initialProgress) {
  71. if (initialProgress === void 0) {
  72. initialProgress = 0;
  73. }
  74. if (this._isLoading) {
  75. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  76. error: Error()
  77. }), Logger) : Logger).warn("Loading is already in progress");
  78. return;
  79. }
  80. this.node.active = true;
  81. this._isLoading = true;
  82. this._currentProgress = initialProgress;
  83. this._updateProgressDisplay(this._currentProgress);
  84. }
  85. /**
  86. * 添加一个加载任务
  87. * @param progress 该任务增加的进度值 (0-100)
  88. * @param tips 提示文本
  89. * @param callback 任务回调函数,可以是异步的
  90. */
  91. addTask(progress, tips, callback) {
  92. this._taskQueue.push({
  93. progress,
  94. tips,
  95. callback
  96. });
  97. }
  98. /**
  99. * 执行所有加载任务
  100. */
  101. executeTasks() {
  102. var _this = this;
  103. return _asyncToGenerator(function* () {
  104. if (!_this._isLoading) {
  105. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  106. error: Error()
  107. }), Logger) : Logger).warn("Loading has not started yet");
  108. return;
  109. }
  110. for (_this._currentTaskIndex = 0; _this._currentTaskIndex < _this._taskQueue.length; _this._currentTaskIndex++) {
  111. var task = _this._taskQueue[_this._currentTaskIndex]; //更新提示文本
  112. if (task.tips) {
  113. _this.tipLabel.string = task.tips;
  114. } //执行任务回调
  115. if (task.callback) {
  116. try {
  117. var result = task.callback();
  118. if (result instanceof Promise) {
  119. yield result;
  120. }
  121. } catch (error) {
  122. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  123. error: Error()
  124. }), Logger) : Logger).error("Loading task failed:", error);
  125. }
  126. } //更新进度
  127. yield _this._updateProgress(_this._currentProgress + task.progress);
  128. } //所有任务完成后自动完成加载
  129. yield _this.finishLoading();
  130. })();
  131. }
  132. /**
  133. * 直接设置进度(带动画)
  134. * @param targetProgress 目标进度 (0-100)
  135. * @param duration 动画持续时间 (秒)
  136. */
  137. setProgress(targetProgress, duration) {
  138. var _this2 = this;
  139. return _asyncToGenerator(function* () {
  140. if (duration === void 0) {
  141. duration = 0.3;
  142. }
  143. if (!_this2._isLoading) {
  144. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  145. error: Error()
  146. }), Logger) : Logger).warn("Loading has not started yet");
  147. return;
  148. }
  149. yield _this2._updateProgress(targetProgress, duration);
  150. })();
  151. }
  152. /**
  153. * 完成加载(自动跳转到100%)
  154. */
  155. finishLoading(isHide) {
  156. var _this3 = this;
  157. return _asyncToGenerator(function* () {
  158. if (isHide === void 0) {
  159. isHide = false;
  160. }
  161. if (!_this3._isLoading) {
  162. (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
  163. error: Error()
  164. }), Logger) : Logger).warn("Loading has not started yet");
  165. return;
  166. }
  167. yield _this3._updateProgress(100, 0.5);
  168. _this3._isLoading = false; //延迟隐藏
  169. yield new Promise(resolve => setTimeout(resolve, 500));
  170. if (isHide) {
  171. _this3.node.active = false;
  172. } //重置状态
  173. _this3._reset();
  174. })();
  175. }
  176. _reset() {
  177. this._currentProgress = 0;
  178. this._taskQueue = [];
  179. this._currentTaskIndex = 0;
  180. if (this._progressTween) {
  181. this._progressTween.stop();
  182. this._progressTween = null;
  183. }
  184. }
  185. _updateProgress(targetProgress, duration) {
  186. var _this4 = this;
  187. return _asyncToGenerator(function* () {
  188. if (duration === void 0) {
  189. duration = 0.3;
  190. }
  191. //确保进度在0-100范围内
  192. targetProgress = Math.min(100, Math.max(0, targetProgress)); // 如果不需要动画,直接设置
  193. if (duration <= 0) {
  194. _this4._currentProgress = targetProgress;
  195. _this4._updateProgressDisplay(_this4._currentProgress);
  196. return;
  197. } //使用Tween实现平滑过渡
  198. return new Promise(resolve => {
  199. if (_this4._progressTween) {
  200. _this4._progressTween.stop();
  201. }
  202. var startProgress = _this4._currentProgress;
  203. _this4._progressTween = tween({
  204. progress: startProgress
  205. }).to(duration, {
  206. progress: targetProgress
  207. }, {
  208. onUpdate: target => {
  209. _this4._currentProgress = Math.floor(target.progress);
  210. _this4._updateProgressDisplay(_this4._currentProgress);
  211. },
  212. onComplete: () => {
  213. _this4._currentProgress = targetProgress;
  214. _this4._updateProgressDisplay(_this4._currentProgress);
  215. _this4._progressTween = null;
  216. resolve();
  217. }
  218. }).start();
  219. });
  220. })();
  221. }
  222. _updateProgressDisplay(progress) {
  223. this.progressLabel.string = progress + "%";
  224. }
  225. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "progressLabel", [_dec2], {
  226. configurable: true,
  227. enumerable: true,
  228. writable: true,
  229. initializer: function initializer() {
  230. return null;
  231. }
  232. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tipLabel", [_dec3], {
  233. configurable: true,
  234. enumerable: true,
  235. writable: true,
  236. initializer: function initializer() {
  237. return null;
  238. }
  239. })), _class2)) || _class));
  240. _cclegacy._RF.pop();
  241. _crd = false;
  242. }
  243. };
  244. });
  245. //# sourceMappingURL=e2a64b1b86682447693e82b91eec4ccebdf4a666.js.map