5 Commits

Author SHA1 Message Date
panw
38f4a1f47d fix(ECS): 延迟初始化查询匹配器并添加空值检查
避免在组件重置后访问未初始化的匹配器,将匹配器的初始化移至 onLoad 方法,并在清理和重置逻辑中添加空值保护,防止运行时错误。
2026-05-08 16:02:50 +08:00
panw
cc60ebf332 fix(任务组件): 修复PhaseTime可能未初始化的空指针异常
在切换任务阶段时,如果PhaseTime尚未初始化,调用reset方法会导致空指针异常。同样在组件销毁时也需要安全地清理PhaseTime。

- 在data_init中确保PhaseTime被正确初始化
- 在setPhase方法中添加空值检查
- 在reset方法中安全销毁节点并清理PhaseTime引用
2026-05-08 15:51:04 +08:00
panw
64168e576f fix(mission): 修复组件生命周期与节点安全访问问题
- 移除 MissionCardComp.onLoad 中自动触发的 onMissionStart,改为由 MissionComp 通过 scheduleOnce 事件驱动,确保组件初始化顺序
- 在设置节点 active 属性前增加节点有效性检查,避免节点已销毁时访问导致的错误
- 在更新计时器 UI 时增加节点和组件存在性检查,防止空引用异常
2026-05-08 15:09:06 +08:00
panw
07aec09283 fix: 修复组件销毁时事件解绑和空引用问题并添加任务界面
- 在多个组件的onDestroy方法中添加节点有效性检查,防止无效节点上解绑事件
- 修复MissionComp中任务启动逻辑,改为通过UI打开方式触发MissionStart事件
- 添加新的任务界面(UIID.Mission)及相关配置
- 修复MissionCardComp中Map未初始化导致的空引用问题
- 优化按钮事件绑定和解绑逻辑,增加空值检查
2026-05-08 14:14:38 +08:00
panw
c70e3bbb4d feat(ui): 优化任务界面显示逻辑与天赋物品样式
移除 MissionMonComp 中多余的 resetSlotSpawnData 调用
在 MissionHomeComp 中添加地图主节点的显示/隐藏控制
重构 map_rpg 预制体结构,将 maps 节点重命名为 fight 并添加 main 节点
调整 prefab_talent_item 的布局和样式,优化显示效果
2026-05-08 10:28:27 +08:00
19 changed files with 20612 additions and 20196 deletions

View File

@@ -28,17 +28,17 @@
"_active": true,
"_components": [
{
"__id__": 120
"__id__": 130
},
{
"__id__": 122
"__id__": 132
},
{
"__id__": 124
"__id__": 134
}
],
"_prefab": {
"__id__": 126
"__id__": 136
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -197,17 +197,17 @@
"_active": true,
"_components": [
{
"__id__": 113
"__id__": 123
},
{
"__id__": 115
"__id__": 125
},
{
"__id__": 117
"__id__": 127
}
],
"_prefab": {
"__id__": 119
"__id__": 129
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -251,23 +251,23 @@
"__id__": 8
},
{
"__id__": 66
"__id__": 76
},
{
"__id__": 70
"__id__": 80
},
{
"__id__": 104
"__id__": 114
}
],
"_active": true,
"_components": [
{
"__id__": 110
"__id__": 120
}
],
"_prefab": {
"__id__": 112
"__id__": 122
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -312,19 +312,22 @@
},
{
"__id__": 57
},
{
"__id__": 67
}
],
"_active": true,
"_components": [
{
"__id__": 61
"__id__": 71
},
{
"__id__": 63
"__id__": 73
}
],
"_prefab": {
"__id__": 65
"__id__": 75
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -357,7 +360,7 @@
},
{
"__type__": "cc.Node",
"_name": "maps",
"_name": "fight",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
@@ -991,7 +994,7 @@
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"x": -9.387,
"y": -43.92,
"z": 0
},
@@ -1456,6 +1459,234 @@
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "main",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 8
},
"_children": [
{
"__id__": 58
}
],
"_active": false,
"_components": [
{
"__id__": 64
}
],
"_prefab": {
"__id__": 66
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "1_Lobby",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 57
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 59
},
{
"__id__": 61
}
],
"_prefab": {
"__id__": 63
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 2,
"y": 2,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 58
},
"_enabled": true,
"__prefab": {
"__id__": 60
},
"_contentSize": {
"__type__": "cc.Size",
"width": 432,
"height": 936
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "0e18K7RrtFlJdnHk0ZPrmZ"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 58
},
"_enabled": true,
"__prefab": {
"__id__": 62
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "d7d869bc-06aa-4876-806f-487e68b96780@fe1eb",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 1,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "2ehPuc5IRMr7wJTRutqDQe"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "71XEQ7teRJxLirxzocu773",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 57
},
"_enabled": true,
"__prefab": {
"__id__": 65
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "e1MvAbrRhD5aP+s7KLy8Pt"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "1do9aUUb1AVJtdvOEYrrX8",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "loading",
@@ -1468,11 +1699,11 @@
"_active": false,
"_components": [
{
"__id__": 58
"__id__": 68
}
],
"_prefab": {
"__id__": 60
"__id__": 70
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1509,11 +1740,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 57
"__id__": 67
},
"_enabled": true,
"__prefab": {
"__id__": 59
"__id__": 69
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1554,7 +1785,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 62
"__id__": 72
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1582,7 +1813,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 64
"__id__": 74
},
"bgImg": null,
"_id": ""
@@ -1616,11 +1847,11 @@
"_active": true,
"_components": [
{
"__id__": 67
"__id__": 77
}
],
"_prefab": {
"__id__": 69
"__id__": 79
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1657,11 +1888,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 66
"__id__": 76
},
"_enabled": true,
"__prefab": {
"__id__": 68
"__id__": 78
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1702,38 +1933,38 @@
},
"_children": [
{
"__id__": 71
"__id__": 81
},
{
"__id__": 75
"__id__": 85
},
{
"__id__": 79
"__id__": 89
},
{
"__id__": 83
"__id__": 93
},
{
"__id__": 87
"__id__": 97
},
{
"__id__": 91
"__id__": 101
},
{
"__id__": 95
"__id__": 105
}
],
"_active": true,
"_components": [
{
"__id__": 99
"__id__": 109
},
{
"__id__": 101
"__id__": 111
}
],
"_prefab": {
"__id__": 103
"__id__": 113
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1770,17 +2001,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 72
"__id__": 82
}
],
"_prefab": {
"__id__": 74
"__id__": 84
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1817,11 +2048,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 71
"__id__": 81
},
"_enabled": true,
"__prefab": {
"__id__": 73
"__id__": 83
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1858,17 +2089,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 76
"__id__": 86
}
],
"_prefab": {
"__id__": 78
"__id__": 88
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1905,11 +2136,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 75
"__id__": 85
},
"_enabled": true,
"__prefab": {
"__id__": 77
"__id__": 87
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1946,17 +2177,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 80
"__id__": 90
}
],
"_prefab": {
"__id__": 82
"__id__": 92
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1993,11 +2224,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 79
"__id__": 89
},
"_enabled": true,
"__prefab": {
"__id__": 81
"__id__": 91
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2034,17 +2265,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 84
"__id__": 94
}
],
"_prefab": {
"__id__": 86
"__id__": 96
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -2081,11 +2312,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 83
"__id__": 93
},
"_enabled": true,
"__prefab": {
"__id__": 85
"__id__": 95
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2122,17 +2353,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 88
"__id__": 98
}
],
"_prefab": {
"__id__": 90
"__id__": 100
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -2169,11 +2400,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 87
"__id__": 97
},
"_enabled": true,
"__prefab": {
"__id__": 89
"__id__": 99
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2210,17 +2441,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 92
"__id__": 102
}
],
"_prefab": {
"__id__": 94
"__id__": 104
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -2257,11 +2488,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 91
"__id__": 101
},
"_enabled": true,
"__prefab": {
"__id__": 93
"__id__": 103
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2298,17 +2529,17 @@
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 70
"__id__": 80
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 96
"__id__": 106
}
],
"_prefab": {
"__id__": 98
"__id__": 108
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -2345,11 +2576,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 95
"__id__": 105
},
"_enabled": true,
"__prefab": {
"__id__": 97
"__id__": 107
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2386,11 +2617,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 70
"__id__": 80
},
"_enabled": true,
"__prefab": {
"__id__": 100
"__id__": 110
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2414,11 +2645,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 70
"__id__": 80
},
"_enabled": true,
"__prefab": {
"__id__": 102
"__id__": 112
},
"_id": ""
},
@@ -2451,14 +2682,14 @@
"_active": true,
"_components": [
{
"__id__": 105
"__id__": 115
},
{
"__id__": 107
"__id__": 117
}
],
"_prefab": {
"__id__": 109
"__id__": 119
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -2495,11 +2726,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 104
"__id__": 114
},
"_enabled": true,
"__prefab": {
"__id__": 106
"__id__": 116
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2523,11 +2754,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 104
"__id__": 114
},
"_enabled": true,
"__prefab": {
"__id__": 108
"__id__": 118
},
"light": null,
"_id": ""
@@ -2559,7 +2790,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 111
"__id__": 121
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2600,7 +2831,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 114
"__id__": 124
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2628,7 +2859,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 116
"__id__": 126
},
"camera": {
"__id__": 3
@@ -2637,16 +2868,16 @@
"__id__": 7
},
"mapLayer": {
"__id__": 63
"__id__": 73
},
"floorLayer": {
"__id__": 66
"__id__": 76
},
"entityLayer": {
"__id__": 101
"__id__": 111
},
"SkillLayer": {
"__id__": 107
"__id__": 117
},
"isFollowPlayer": true,
"_id": ""
@@ -2665,7 +2896,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 118
"__id__": 128
},
"_id": ""
},
@@ -2696,7 +2927,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 121
"__id__": 131
},
"_contentSize": {
"__type__": "cc.Size",
@@ -2724,7 +2955,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 123
"__id__": 133
},
"_cameraComponent": {
"__id__": 3
@@ -2746,7 +2977,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 125
"__id__": 135
},
"_alignFlags": 45,
"_target": null,

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "60491d56-aa9b-4121-b9a7-4b146b58ec2e",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "mission"
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,7 @@ export enum UIID {
Ranks,
Heros,
Talents,
Mission,
}
/** 打开界面方式的配置数据 */
@@ -33,4 +34,5 @@ export var UIConfigData: { [key: number]: UIConfig } = {
[UIID.Ranks]: { layer: LayerType.UI, prefab: "gui/element/ranks" },
[UIID.Heros]: { layer: LayerType.UI, prefab: "gui/element/heros" },
[UIID.Talents]: { layer: LayerType.UI, prefab: "gui/element/talents" },
[UIID.Mission]: { layer: LayerType.UI, prefab: "gui/element/mission" },
}

View File

@@ -513,12 +513,18 @@ export class CardComp extends CCComp {
/** 解绑触控,防止节点销毁后残留回调 */
private unbindEvents() {
if (this.node && this.node.isValid) {
this.node.off(NodeEventType.TOUCH_START, this.onCardTouchStart, this);
this.node.off(NodeEventType.TOUCH_MOVE, this.onCardTouchMove, this);
this.node.off(NodeEventType.TOUCH_END, this.onCardTouchEnd, this);
this.node.off(NodeEventType.TOUCH_CANCEL, this.onCardTouchCancel, this);
this.Lock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
this.unLock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
}
if (this.Lock && this.Lock.isValid) {
this.Lock.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
}
if (this.unLock && this.unLock.isValid) {
this.unLock.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
}
}
// ======================== 触摸交互 ========================

View File

@@ -87,7 +87,10 @@ export class CardControllerComp extends CCComp {
*/
page_init(){
this.node.getChildByName("mission_home").active=true;
this.node.getChildByName("mission").active=false;
let missionNode = this.node.getChildByName("mission");
if (missionNode) {
missionNode.active = false;
}
}
/** ECS 组件移除时销毁节点 */

View File

@@ -79,8 +79,10 @@ export class IBoxComp extends CCComp {
/** 解绑点击事件 */
onDestroy() {
if (this.node && this.node.isValid) {
this.node.off(NodeEventType.TOUCH_END, this.onTapClose, this);
}
}
/** ECS 组件移除时销毁节点 */
reset() {

View File

@@ -167,7 +167,7 @@ export class MissionCardComp extends CCComp {
this.cacheCardComps();
this.layoutCardSlots();
this.initCardsPanelPos();
this.onMissionStart();
// this.onMissionStart(); // 移除 onLoad 自动触发,改为事件驱动
mLogger.log(this.debugMode, "MissionCardComp", "onLoad init", {
slots: this.cardComps.length,
poolLv: this.poolLv
@@ -176,6 +176,11 @@ export class MissionCardComp extends CCComp {
/** 组件销毁时解绑所有事件并清理英雄信息面板 */
onDestroy() {
if (this.cards_chou && this.cards_chou.isValid) {
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
this.cards_chou.off(NodeEventType.TOUCH_CANCEL, this.onDrawTouchCancel, this);
}
this.unbindEvents();
this.clearHeroInfoPanels();
}
@@ -205,6 +210,17 @@ export class MissionCardComp extends CCComp {
missionData.hero_max_num = FightSet.HERO_MAX_NUM;
missionData.hero_extend_max_num = FightSet.HERO_MAX_NUM + 1;
}
// 确保 Map 被正确初始化
if (!this.heroInfoItems) {
this.heroInfoItems = new Map();
}
// 确保卡牌组件列表已被正确缓存
if (!this.cardComps || this.cardComps.length === 0) {
this.cacheCardComps();
}
this.clearHeroInfoPanels();
this.layoutCardSlots();
this.clearAllCards();
@@ -215,7 +231,9 @@ export class MissionCardComp extends CCComp {
// this.resetButtonScale(this.cards_up);
this.updateCoinAndCostUI();
this.updateHeroNumUI(false, false);
if (this.node && this.node.isValid) {
this.node.active = true;
}
const cards = this.buildDrawCards();
this.dispatchCardsToSlots(cards);
mLogger.log(this.debugMode, "MissionCardComp", "mission start", {
@@ -227,8 +245,10 @@ export class MissionCardComp extends CCComp {
onMissionEnd() {
this.clearAllCards();
this.clearHeroInfoPanels();
if (this.node && this.node.isValid) {
this.node.active = false;
}
}
start() {
}
@@ -248,8 +268,10 @@ export class MissionCardComp extends CCComp {
/** 关闭面板(不销毁数据模型,仅隐藏) */
close() {
if (this.node && this.node.isValid) {
this.node.active = false;
}
}
// ======================== 事件绑定 ========================
@@ -362,9 +384,11 @@ export class MissionCardComp extends CCComp {
oops.message.off(GameEvent.UseHeroCard, this.onUseHeroCard, this);
oops.message.off(GameEvent.UseSpecialCard, this.onUseSpecialCard, this);
oops.message.off(GameEvent.CardPoolUpgrade, this.onCardPoolUpgrade, this);
this.cards_chou?.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
this.cards_chou?.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
this.cards_chou?.off(NodeEventType.TOUCH_CANCEL, this.onDrawTouchCancel, this);
if (this.cards_chou && this.cards_chou.isValid) {
this.cards_chou.off(NodeEventType.TOUCH_START, this.onDrawTouchStart, this);
this.cards_chou.off(NodeEventType.TOUCH_END, this.onDrawTouchEnd, this);
this.cards_chou.off(NodeEventType.TOUCH_CANCEL, this.onDrawTouchCancel, this);
}
// this.cards_up?.off(NodeEventType.TOUCH_START, this.onUpgradeTouchStart, this);
// this.cards_up?.off(NodeEventType.TOUCH_END, this.onUpgradeTouchEnd, this);
// this.cards_up?.off(NodeEventType.TOUCH_CANCEL, this.onUpgradeTouchCancel, this);
@@ -700,7 +724,9 @@ export class MissionCardComp extends CCComp {
/** 全量分发给4槽每个槽位是否接收由 CardComp 自己判断(锁定可跳过) */
private dispatchCardsToSlots(cards: CardConfig[]) {
if (!this.cardComps) return;
for (let i = 0; i < this.cardComps.length; i++) {
if (this.cardComps[i]) {
const accepted = this.cardComps[i].applyDrawCard(cards[i] ?? null);
mLogger.log(this.debugMode, "MissionCardComp", "dispatch card", {
index: i,
@@ -709,18 +735,25 @@ export class MissionCardComp extends CCComp {
});
}
}
}
/** 系统清空4槽用于任务切换 */
private clearAllCards() {
this.cardComps.forEach(comp => comp.clearBySystem());
if (!this.cardComps) return;
this.cardComps.forEach(comp => {
if (comp) comp.clearBySystem();
});
}
private layoutCardSlots() {
if (!this.cardComps) return;
const count = this.cardComps.length;
if (count === 0) return;
for (let i = 0; i < count; i++) {
if (this.cardComps[i]) {
this.cardComps[i].setSlotPosition(this.cardsPos[i]);
}
}
mLogger.log(this.debugMode, "MissionCardComp", "layout card slots", {
count,
cardWidth: this.cardWidth
@@ -956,12 +989,14 @@ export class MissionCardComp extends CCComp {
}
private clearHeroInfoPanels() {
if (this.heroInfoItems) {
this.heroInfoItems.forEach(item => {
if (item.node && item.node.isValid) {
if (item && item.node && item.node.isValid) {
item.node.destroy();
}
});
this.heroInfoItems.clear();
}
if (this.hero_info_node && this.hero_info_node.isValid) {
for (let i = this.hero_info_node.children.length - 1; i >= 0; i--) {
const child = this.hero_info_node.children[i];
@@ -1149,6 +1184,13 @@ export class MissionCardComp extends CCComp {
this.clearHeroInfoPanels();
this.resetButtonScale(this.cards_chou);
// this.resetButtonScale(this.cards_up);
// 关键:在 reset/销毁 时将 Map 置空,彻底切断引用
this.heroInfoItems = null as any;
this.cardComps = [] as any;
if (this.node && this.node.isValid) {
this.node.destroy();
}
}
}

View File

@@ -170,18 +170,20 @@ export class MissionComp extends CCComp {
// ======================== ECS 查询匹配器(预缓存) ========================
/** 匹配拥有 HeroViewComp 的实体(英雄/怪物视图) */
private readonly heroViewMatcher = ecs.allOf(HeroViewComp);
private heroViewMatcher: any = null;
/** 匹配拥有 SkillView 的实体(技能视图) */
private readonly skillViewMatcher = ecs.allOf(SkillView);
private skillViewMatcher: any = null;
/** 匹配拥有 HeroAttrsComp 的实体(英雄/怪物属性) */
private readonly heroAttrsMatcher = ecs.allOf(HeroAttrsComp);
private heroAttrsMatcher: any = null;
// ======================== 生命周期 ========================
onLoad(){
this.heroViewMatcher = ecs.allOf(HeroViewComp);
this.skillViewMatcher = ecs.allOf(SkillView);
this.heroAttrsMatcher = ecs.allOf(HeroAttrsComp);
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 +191,19 @@ export class MissionComp extends CCComp {
this.removeMemoryPanel()
}
onAdded(args: any) {
// 使用 scheduleOnce 将事件推迟到下一帧执行,
// 确保所有关联组件(如 MissionCardComp 等)都已经完成其 onLoad 生命周期。
this.scheduleOnce(() => {
oops.message.dispatchEvent(GameEvent.MissionStart, {});
this.mission_start();
}, 0);
}
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);
}
}
/**
@@ -237,7 +250,13 @@ export class MissionComp extends CCComp {
if (this.isBossWave) {
const str = "∞";
if (str != this.lastTimeStr) {
this.time_node.getChildByName("time").getComponent(Label).string = str;
if (this.time_node && this.time_node.isValid) {
const timeChild = this.time_node.getChildByName("time");
if (timeChild) {
const label = timeChild.getComponent(Label);
if (label) label.string = str;
}
}
this.lastTimeStr = str;
this.lastTimeSecond = -1;
}
@@ -253,7 +272,13 @@ export class MissionComp extends CCComp {
const wave = Math.max(1, this.currentWave || smc.vmdata.mission_data.level || 1);
let str = `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`;
if(str != this.lastTimeStr){
this.time_node.getChildByName("time").getComponent(Label).string = str;
if (this.time_node && this.time_node.isValid) {
const timeChild = this.time_node.getChildByName("time");
if (timeChild) {
const label = timeChild.getComponent(Label);
if (label) label.string = str;
}
}
this.lastTimeStr = str;
}
}
@@ -295,16 +320,17 @@ 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")
let loading=this.node.getChildByName("loading")
if (loading) {
loading.active=true
this.scheduleOnce(()=>{
loading.active=false
},0.5)
}
}
/** 更新开始按钮的状态显示 */
private updateStartBtnState() {
@@ -409,7 +435,9 @@ export class MissionComp extends CCComp {
}
// 重置状态机的计时器
if (this.PhaseTime) {
this.PhaseTime.reset();
}
switch (targetPhase) {
case MissionPhase.PrepareStart:
@@ -670,7 +698,7 @@ export class MissionComp extends CCComp {
this.changePhase(MissionPhase.None);
this.cleanComponents()
this.clearBattlePools()
this.node.active=false
oops.gui.remove(UIID.Mission);
}
/**
@@ -681,6 +709,9 @@ export class MissionComp extends CCComp {
* - 性能监控基准值
*/
data_init(){
if (!this.PhaseTime) {
this.PhaseTime = new Timer(1);
}
smc.mission.play = true;
smc.mission.pause = false;
smc.mission.stop_mon_action = false;
@@ -876,6 +907,7 @@ export class MissionComp extends CCComp {
/** 清理所有英雄和技能 ECS 实体 */
private cleanComponents() {
if (!this.heroViewMatcher || !this.skillViewMatcher) return;
const heroEntities: ecs.Entity[] = [];
ecs.query(this.heroViewMatcher).forEach(entity => {
heroEntities.push(entity);
@@ -1030,6 +1062,12 @@ export class MissionComp extends CCComp {
/** ECS 组件移除时销毁节点 */
reset() {
this.PhaseTime = null as any;
this.heroViewMatcher = null;
this.skillViewMatcher = null;
this.heroAttrsMatcher = null;
if (this.node && this.node.isValid) {
this.node.destroy();
}
}
}

View File

@@ -98,9 +98,6 @@ export class MissionHeroCompComp extends CCComp {
// 清理全部监听
oops.message.off(GameEvent.CallHero,this.call_hero,this)
oops.message.off("PhasePrepareStart",this.fight_ready,this)
oops.message.off(GameEvent.FightReady,this.fight_ready,this)
oops.message.off(GameEvent.Zhaohuan,this.zhao_huan,this)
oops.message.off(GameEvent.MissionEnd,this.clear_heros,this)
}
start() {

View File

@@ -72,11 +72,18 @@ export class MissionHomeComp extends CCComp {
* 1. 打印日志。
* 2. 分发 MissionStart 事件,驱动 MissionComp / MissionCardComp 初始化战斗。
* 3. 隐藏主页节点。
* 4. 隐藏 mapLayer 下的 main 节点。
*/
start_mission() {
mLogger.log(this.debugMode, 'MissionHomeComp', "start_mission")
oops.message.dispatchEvent(GameEvent.MissionStart, {})
oops.gui.open(UIID.Mission)
this.node.active=false;
// 隐藏 mapLayer 下的 main 节点
let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main");
if (mainNode) {
mainNode.active = false;
}
}
/** 打开排行榜弹窗 */
@@ -99,6 +106,12 @@ export class MissionHomeComp extends CCComp {
home_active(){
this.uodate_data()
this.node.active=true
// 重新显示 mapLayer 下的 main 节点
let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main");
if (mainNode) {
mainNode.active = true;
}
}
/** 更新主页显示数据(预留) */

View File

@@ -105,7 +105,6 @@ export class MissionMonCompComp extends CCComp {
this.on("SpawnSpecialMonster", this.onSpawnSpecialMonster, this);
this.on("PhasePrepareEnd", this.onPhasePrepareEnd, this);
this.on("TimeUpAdvanceWave", this.onTimeUpAdvanceWave, this);
this.resetSlotSpawnData(1)
}
/**

View File

@@ -94,7 +94,9 @@ export class SkillBoxComp extends CCComp {
onDestroy() {
oops.message.off(GameEvent.FightStart, this.onFightStart, this);
oops.message.off(GameEvent.MissionEnd, this.onMissionEnd, this);
if (this.node && this.node.isValid) {
this.node.off(GameEvent.NewWave, this.onNewWave, this);
}
oops.message.off(GameEvent.NewWave, this.onNewWaveGlobal, this);
// 通知 MissSkillsComp 回收该节点占用的槽位
oops.message.dispatchEvent(GameEvent.RemoveSkillBox, this.node);

View File

@@ -78,10 +78,10 @@ export class TalentsComp extends CCComp {
protected onLoad(): void {
// 绑定按钮事件
if (this.btn_reset) {
if (this.btn_reset && this.btn_reset.node) {
this.btn_reset.node.on(Button.EventType.CLICK, this.onResetClicked, this);
}
if (this.btn_close) {
if (this.btn_close && this.btn_close.node) {
this.btn_close.node.on(Button.EventType.CLICK, this.onCloseClicked, this);
}
}
@@ -343,6 +343,12 @@ export class TalentsComp extends CCComp {
protected onDestroy(): void {
mLogger.log(this.debugMode, 'TalentsComp', "释放界面");
if (this.btn_reset && this.btn_reset.node && this.btn_reset.node.isValid) {
this.btn_reset.node.off(Button.EventType.CLICK, this.onResetClicked, this);
}
if (this.btn_close && this.btn_close.node && this.btn_close.node.isValid) {
this.btn_close.node.off(Button.EventType.CLICK, this.onCloseClicked, this);
}
}
/** ECS 组件移除时销毁节点 */

View File

@@ -34,6 +34,7 @@ import { CKind } from "../common/config/CardSet";
import { ScoreWeights } from "../common/config/ScoreSet";
import { HighlightSet, HighlightType, HighlightLevel } from "../common/config/HighlightSet";
import { mLogger } from "../common/Logger";
import { UIID } from "../common/config/GameUIConfig";
const { ccclass, property } = _decorator;
@@ -585,7 +586,7 @@ export class VictoryComp extends CCComp {
oops.message.dispatchEvent(GameEvent.MissionEnd)
this.node.getChildByName("loading").active=true
this.scheduleOnce(()=>{
oops.message.dispatchEvent(GameEvent.MissionStart)
oops.gui.open(UIID.Mission)
this.node.getChildByName("loading").active=false
oops.gui.removeByNode(this.node)
},0.5)

View File

@@ -182,13 +182,13 @@ export class SkillView extends CCComp {
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
// 清理碰撞体事件监听
if (this.collider) {
if (this.collider && this.collider.isValid) {
this.collider.off(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.collider.enabled = false;
}
this.pendingDisableCollider = false;
this.isDisposing = false;
if (this.anim) {
if (this.anim && this.anim.isValid) {
this.anim.off(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
// 取消所有定时器

View File

@@ -16,8 +16,9 @@ export class oneCom extends Component {
}
onDestroy() {
if (!this.anim) return;
if (this.anim && this.anim.isValid) {
this.anim.off(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
this.anim = null;
}