123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Label, tween, Logger, _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _crd, ccclass, property, LoadingUI;
- 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); } }
- 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); }); }; }
- 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 }); }
- 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; }
- 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.'); }
- function _reportPossibleCrUseOfLogger(extras) {
- _reporterNs.report("Logger", "./Logger", _context.meta, extras);
- }
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Component = _cc.Component;
- Label = _cc.Label;
- tween = _cc.tween;
- }, function (_unresolved_2) {
- Logger = _unresolved_2.Logger;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "0b1a611XNpHVLjup75rkN0R", "LoadingUI", undefined);
- __checkObsolete__(['_decorator', 'Component', 'Label', 'Tween', 'tween', 'v3']);
- ({
- ccclass,
- property
- } = _decorator);
- /*初始化加载界面*/
- _export("LoadingUI", LoadingUI = (_dec = ccclass("LoadingUI"), _dec2 = property(Label), _dec3 = property(Label), _dec(_class = (_class2 = class LoadingUI extends Component {
- constructor() {
- super(...arguments);
- _initializerDefineProperty(this, "progressLabel", _descriptor, this);
- _initializerDefineProperty(this, "tipLabel", _descriptor2, this);
- this._currentProgress = 0;
- this._isLoading = false;
- this._progressTween = null;
- this._taskQueue = [];
- this._currentTaskIndex = 0;
- }
- /**
- * 开始加载流程
- * @param initialProgress 初始进度 (0-100)
- * @example 调用事例:
- * this.loadingUI.startLoading();
- //添加所有加载任务
- this.loadingUI.addTask(10, '资源加载中...', () => {
- PlayerData.ins().initialize();
- PlatformSystem.initialize();
- SettingData.ins().initialize();
- });
- this.loadingUI.addTask(30, '加载音乐资源...', async () => {
- await AudioManager.initialize();
- });
- this.loadingUI.addTask(40, '加载关卡数据...', async () => {
- await LevelsResData.ins().initialize();
- await LevelsResData.instance.preLoadAllMap();
- });
- this.loadingUI.addTask(20, '预加载场景...', async () => {
- await SceneManager.initialize();
- });
- //执行所有任务完成后会自动调用finishLoading()
- await this.loadingUI.executeTasks();
- */
- startLoading(initialProgress) {
- if (initialProgress === void 0) {
- initialProgress = 0;
- }
- if (this._isLoading) {
- (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
- error: Error()
- }), Logger) : Logger).warn("Loading is already in progress");
- return;
- }
- this.node.active = true;
- this._isLoading = true;
- this._currentProgress = initialProgress;
- this._updateProgressDisplay(this._currentProgress);
- }
- /**
- * 添加一个加载任务
- * @param progress 该任务增加的进度值 (0-100)
- * @param tips 提示文本
- * @param callback 任务回调函数,可以是异步的
- */
- addTask(progress, tips, callback) {
- this._taskQueue.push({
- progress,
- tips,
- callback
- });
- }
- /**
- * 执行所有加载任务
- */
- executeTasks() {
- var _this = this;
- return _asyncToGenerator(function* () {
- if (!_this._isLoading) {
- (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
- error: Error()
- }), Logger) : Logger).warn("Loading has not started yet");
- return;
- }
- for (_this._currentTaskIndex = 0; _this._currentTaskIndex < _this._taskQueue.length; _this._currentTaskIndex++) {
- var task = _this._taskQueue[_this._currentTaskIndex]; //更新提示文本
- if (task.tips) {
- _this.tipLabel.string = task.tips;
- } //执行任务回调
- if (task.callback) {
- try {
- var result = task.callback();
- if (result instanceof Promise) {
- yield result;
- }
- } catch (error) {
- (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
- error: Error()
- }), Logger) : Logger).error("Loading task failed:", error);
- }
- } //更新进度
- yield _this._updateProgress(_this._currentProgress + task.progress);
- } //所有任务完成后自动完成加载
- yield _this.finishLoading();
- })();
- }
- /**
- * 直接设置进度(带动画)
- * @param targetProgress 目标进度 (0-100)
- * @param duration 动画持续时间 (秒)
- */
- setProgress(targetProgress, duration) {
- var _this2 = this;
- return _asyncToGenerator(function* () {
- if (duration === void 0) {
- duration = 0.3;
- }
- if (!_this2._isLoading) {
- (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
- error: Error()
- }), Logger) : Logger).warn("Loading has not started yet");
- return;
- }
- yield _this2._updateProgress(targetProgress, duration);
- })();
- }
- /**
- * 完成加载(自动跳转到100%)
- */
- finishLoading(isHide) {
- var _this3 = this;
- return _asyncToGenerator(function* () {
- if (isHide === void 0) {
- isHide = false;
- }
- if (!_this3._isLoading) {
- (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
- error: Error()
- }), Logger) : Logger).warn("Loading has not started yet");
- return;
- }
- yield _this3._updateProgress(100, 0.5);
- _this3._isLoading = false; //延迟隐藏
- yield new Promise(resolve => setTimeout(resolve, 500));
- if (isHide) {
- _this3.node.active = false;
- } //重置状态
- _this3._reset();
- })();
- }
- _reset() {
- this._currentProgress = 0;
- this._taskQueue = [];
- this._currentTaskIndex = 0;
- if (this._progressTween) {
- this._progressTween.stop();
- this._progressTween = null;
- }
- }
- _updateProgress(targetProgress, duration) {
- var _this4 = this;
- return _asyncToGenerator(function* () {
- if (duration === void 0) {
- duration = 0.3;
- }
- //确保进度在0-100范围内
- targetProgress = Math.min(100, Math.max(0, targetProgress)); // 如果不需要动画,直接设置
- if (duration <= 0) {
- _this4._currentProgress = targetProgress;
- _this4._updateProgressDisplay(_this4._currentProgress);
- return;
- } //使用Tween实现平滑过渡
- return new Promise(resolve => {
- if (_this4._progressTween) {
- _this4._progressTween.stop();
- }
- var startProgress = _this4._currentProgress;
- _this4._progressTween = tween({
- progress: startProgress
- }).to(duration, {
- progress: targetProgress
- }, {
- onUpdate: target => {
- _this4._currentProgress = Math.floor(target.progress);
- _this4._updateProgressDisplay(_this4._currentProgress);
- },
- onComplete: () => {
- _this4._currentProgress = targetProgress;
- _this4._updateProgressDisplay(_this4._currentProgress);
- _this4._progressTween = null;
- resolve();
- }
- }).start();
- });
- })();
- }
- _updateProgressDisplay(progress) {
- this.progressLabel.string = progress + "%";
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "progressLabel", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tipLabel", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- })), _class2)) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=e2a64b1b86682447693e82b91eec4ccebdf4a666.js.map
|