feat: 新增关卡进度同步系统并优化UI显示
1. 新增GameEvent.STAGE_PROGRESS_UPDATE事件与关卡进度镜像逻辑 2. 在SingletonModuleComp中添加关卡进度VM层字段与同步方法 3. 重构MissionComp的UI显示逻辑,拆分计时与阶段显示 4. 更新mission.prefab的UI节点结构与数据绑定 5. 统一关卡进度更新的调用方式,替换直接赋值为专用方法
This commit is contained in:
@@ -234,6 +234,12 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
silver: 0, // 银币数据(MVVM绑定字段,镜像 data.silver,刷新卡牌消耗)
|
||||
switch_effect: true, // 音效开关(MVVM绑定字段)
|
||||
switch_music: true, // 音乐开关(MVVM绑定字段)
|
||||
/** 关卡进度(MVVM绑定字段,镜像 data.stage_progress,供 HUD 实时显示) */
|
||||
stage_progress: {
|
||||
chapter: 1,
|
||||
stage: 1,
|
||||
section: 1,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -325,7 +331,9 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
|
||||
// 触发UI更新(同步镜像层 + 事件)
|
||||
this.syncCurrencyToView();
|
||||
this.syncStageProgressToView();
|
||||
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE);
|
||||
oops.message.dispatchEvent(GameEvent.STAGE_PROGRESS_UPDATE);
|
||||
|
||||
} catch (error) {
|
||||
mLogger.error(this.debugMode, 'SMC', `[SMC]: 数据覆盖失败:`, error);
|
||||
@@ -342,6 +350,35 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
this.vmdata.diamond = this.data.diamond ?? 0;
|
||||
this.vmdata.silver = this.data.silver ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 data 层的关卡进度镜像到 vmdata 视图层(MVVM 绑定字段)。
|
||||
* Why: data.stage_progress 为云端持久权威源,vmdata.stage_progress 仅供 HUD 绑定展示;
|
||||
* 登录覆盖、关卡推进后都必须调用本方法保持镜像一致。
|
||||
*/
|
||||
public syncStageProgressToView(): void {
|
||||
const p = this.data.stage_progress;
|
||||
this.vmdata.stage_progress = {
|
||||
chapter: p?.chapter ?? 1,
|
||||
stage: p?.stage ?? 1,
|
||||
section: p?.section ?? 1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关卡进度(权威源 data + 视图镜像 vmdata),并派发事件刷新 UI。
|
||||
* Why: 替代直接赋值 smc.data.stage_progress,保证视图层实时同步。
|
||||
* @param progress 新的关卡进度(章节/大关/小节均从 1 开始)
|
||||
* @param is_sync 是否标记脏并触发云端/本地同步
|
||||
*/
|
||||
public updateStageProgress(progress: { chapter: number; stage: number; section: number }, is_sync: boolean = true): void {
|
||||
this.data.stage_progress = { ...progress };
|
||||
this.syncStageProgressToView();
|
||||
if (is_sync) {
|
||||
gameDataSync.markDataDirty();
|
||||
}
|
||||
oops.message.dispatchEvent(GameEvent.STAGE_PROGRESS_UPDATE);
|
||||
}
|
||||
getGameDate() {
|
||||
let data: GameDate = {
|
||||
...this.data,
|
||||
|
||||
Reference in New Issue
Block a user