Files
mp-xieyingeng/assets/PageLoading.ts
richarjiang c54a404c12 feat: 接入关卡配置 API 并支持降级到本地配置
- 新增 LevelDataManager 单例管理关卡数据
- 新增 HttpUtil 封装 XMLHttpRequest 请求
- 新增 LevelTypes 类型定义
- PageLoading 集成 API 数据预加载(0-80% 进度)
- PageLevel 支持优先使用 API 数据,失败时降级到本地配置
- 字段映射: hint1/2/3 → clue1/2/3, imageUrl → SpriteFrame
2026-03-15 16:07:00 +08:00

83 lines
2.1 KiB
TypeScript

import { _decorator, Component, ProgressBar, Label } from 'cc';
import { ViewManager } from './scripts/core/ViewManager';
import { LevelDataManager } from './scripts/utils/LevelDataManager';
const { ccclass, property } = _decorator;
/**
* 页面加载组件
* 负责预加载资源并显示加载进度
*/
@ccclass('PageLoading')
export class PageLoading extends Component {
@property(ProgressBar)
progressBar: ProgressBar | null = null;
@property(Label)
statusLabel: Label | null = null;
start() {
this._startPreload();
}
/**
* 开始预加载
*/
private async _startPreload(): Promise<void> {
// 初始化进度条
if (this.progressBar) {
this.progressBar.progress = 0;
}
// 阶段1: 初始化 LevelDataManager (0-80%)
await LevelDataManager.instance.initialize((progress, message) => {
this._updateProgress(progress);
this._updateStatusLabel(message);
});
// 阶段2: 预加载 PageHome (80-100%)
ViewManager.instance.preload('PageHome',
(progress) => {
this._updateProgress(0.8 + progress * 0.2);
},
() => {
this._onPreloadComplete();
}
);
}
/**
* 更新进度条
*/
private _updateProgress(progress: number): void {
if (this.progressBar) {
this.progressBar.progress = progress;
}
}
/**
* 更新状态标签
*/
private _updateStatusLabel(message: string): void {
if (this.statusLabel) {
this.statusLabel.string = message;
}
}
/**
* 预加载完成回调
*/
private _onPreloadComplete(): void {
// 确保进度条显示完成
this._updateProgress(1);
this._updateStatusLabel('加载完成');
// 打开 PageHome
ViewManager.instance.open('PageHome', {
onComplete: () => {
// PageHome 打开成功后,销毁自身
this.node.destroy();
}
});
}
}