feat: 完善新版 UI
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { _decorator, Component, ProgressBar, Label } from 'cc';
|
||||
import { _decorator, Component, ProgressBar, Label, assetManager } from 'cc';
|
||||
import type { AssetManager } from 'cc';
|
||||
import { ViewManager } from './scripts/core/ViewManager';
|
||||
import { LevelDataManager } from './scripts/utils/LevelDataManager';
|
||||
import { AuthManager } from './scripts/utils/AuthManager';
|
||||
@@ -14,6 +15,8 @@ const { ccclass, property } = _decorator;
|
||||
*/
|
||||
@ccclass('PageLoading')
|
||||
export class PageLoading extends Component {
|
||||
private static readonly FONT_BUNDLE_NAME = 'fonts';
|
||||
|
||||
@property(ProgressBar)
|
||||
progressBar: ProgressBar | null = null;
|
||||
|
||||
@@ -52,6 +55,12 @@ export class PageLoading extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
const fontSuccess = await this._loadFontBundle();
|
||||
if (!fontSuccess) {
|
||||
this._updateStatusLabel('字体资源加载失败,请重新打开游戏');
|
||||
return;
|
||||
}
|
||||
|
||||
// 登录 + 关卡数据都就绪后,用服务端进度覆盖本地进度
|
||||
if (loginSuccess) {
|
||||
this._syncProgressFromServer();
|
||||
@@ -77,10 +86,10 @@ export class PageLoading extends Component {
|
||||
console.warn('[PageLoading] 加入分享失败,进入正常模式');
|
||||
}
|
||||
|
||||
// 正常流程:预加载 PageHome (80-100%)
|
||||
// 正常流程:预加载 PageHome (82-100%)
|
||||
ViewManager.instance.preload('PageHome',
|
||||
(progress) => {
|
||||
this._updateProgress(0.8 + progress * 0.2);
|
||||
this._updateProgress(0.82 + progress * 0.18);
|
||||
this._updateStatusLabel('正在加载界面资源...');
|
||||
},
|
||||
() => {
|
||||
@@ -112,6 +121,36 @@ export class PageLoading extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载字体分包,避免字体资源进入小游戏主包
|
||||
*/
|
||||
private _loadFontBundle(): Promise<boolean> {
|
||||
const bundleName = PageLoading.FONT_BUNDLE_NAME;
|
||||
const cachedBundle = assetManager.getBundle(bundleName);
|
||||
if (cachedBundle) {
|
||||
console.log(`[PageLoading] 字体分包已加载: ${bundleName}`);
|
||||
this._updateProgress(0.82);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
this._updateStatusLabel('正在加载字体资源...');
|
||||
this._updateProgress(0.8);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
assetManager.loadBundle(bundleName, (err: Error | null, bundle: AssetManager.Bundle | null) => {
|
||||
if (err || !bundle) {
|
||||
console.error(`[PageLoading] 字体分包加载失败: ${bundleName}`, err);
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[PageLoading] 字体分包加载完成: ${bundleName}`);
|
||||
this._updateProgress(0.82);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 用服务端通关进度同步本地进度
|
||||
* 1. 根据 completedLevelIds 标记已通关关卡
|
||||
|
||||
Reference in New Issue
Block a user