fix: 修复组件销毁时事件解绑和空引用问题并添加任务界面

- 在多个组件的onDestroy方法中添加节点有效性检查,防止无效节点上解绑事件
- 修复MissionComp中任务启动逻辑,改为通过UI打开方式触发MissionStart事件
- 添加新的任务界面(UIID.Mission)及相关配置
- 修复MissionCardComp中Map未初始化导致的空引用问题
- 优化按钮事件绑定和解绑逻辑,增加空值检查
This commit is contained in:
panw
2026-05-08 14:14:38 +08:00
parent c70e3bbb4d
commit 07aec09283
16 changed files with 19665 additions and 19580 deletions

View File

@@ -181,7 +181,6 @@ export class MissionComp extends CCComp {
onLoad(){
this.showMemoryPanel = false
// 注册生命周期事件
this.on(GameEvent.MissionStart,this.mission_start,this)
this.on(GameEvent.MissionEnd,this.mission_end,this)
this.on(GameEvent.NewWave,this.onNewWave,this)
this.on(GameEvent.DO_AD_BACK,this.do_ad,this)
@@ -189,8 +188,16 @@ export class MissionComp extends CCComp {
this.removeMemoryPanel()
}
onAdded(args: any) {
// UI加载完成后抛出MissionStart事件启动战斗触发自身 mission_start 及其他系统)
oops.message.dispatchEvent(GameEvent.MissionStart, {});
this.mission_start();
}
onDestroy(){
this.start_btn?.off(NodeEventType.TOUCH_END, this.onStartFightBtnClick, this)
if (this.start_btn && this.start_btn.isValid) {
this.start_btn.off(NodeEventType.TOUCH_END, this.onStartFightBtnClick, this);
}
}
/**
@@ -295,15 +302,16 @@ export class MissionComp extends CCComp {
async mission_start(){
this.unscheduleAllCallbacks();
this.cleanComponents();
this.node.active=true
this.data_init()
oops.message.dispatchEvent(GameEvent.FightReady)
this.changePhase(MissionPhase.Prepare)
let loading=this.node.parent.getChildByName("loading")
loading.active=true
this.scheduleOnce(()=>{
loading.active=false
},0.5)
let loading=this.node.getChildByName("loading")
if (loading) {
loading.active=true
this.scheduleOnce(()=>{
loading.active=false
},0.5)
}
}
/** 更新开始按钮的状态显示 */
@@ -670,7 +678,7 @@ export class MissionComp extends CCComp {
this.changePhase(MissionPhase.None);
this.cleanComponents()
this.clearBattlePools()
this.node.active=false
oops.gui.remove(UIID.Mission);
}
/**