fix(map): 修复任务奖励图标加载问题并重构组件逻辑

- 移除 MGetsComp 中未使用的属性和方法,简化组件结构
- 在 MissionGetsComp 中实现动态加载奖励图标功能,支持从 gui/uicons 图集获取
- 调整 get.prefab 结构,分离图标和数字显示节点
- 解决资源加载机制限制,确保动态加载资源正常工作
This commit is contained in:
panw
2026-01-27 16:02:33 +08:00
parent ce6b7bce1e
commit b869e1c33c
4 changed files with 204 additions and 47 deletions

View File

@@ -29,25 +29,28 @@
},
{
"__id__": 26
},
{
"__id__": 32
}
],
"_active": true,
"_components": [
{
"__id__": 32
"__id__": 38
},
{
"__id__": 34
"__id__": 40
},
{
"__id__": 36
"__id__": 42
},
{
"__id__": 39
"__id__": 45
}
],
"_prefab": {
"__id__": 41
"__id__": 47
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -605,7 +608,7 @@
},
{
"__type__": "cc.Node",
"_name": "num",
"_name": "icon",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
@@ -626,8 +629,8 @@
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 34.381,
"y": -27.61,
"x": 0,
"y": 3,
"z": 0
},
"_lrot": {
@@ -665,6 +668,142 @@
"__prefab": {
"__id__": 28
},
"_contentSize": {
"__type__": "cc.Size",
"width": 93,
"height": 90
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "bbJGIGV/FBhKHt/1tzLuwE"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 26
},
"_enabled": true,
"__prefab": {
"__id__": 30
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "031877cb-0f3d-4e92-bc5d-e492a0d95a08@5dd64",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 1,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "4al0MLxMlB56FJWnzCZ4F9"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "3fySg1nP5PX4FJgI5Phn2X",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "num",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 33
},
{
"__id__": 35
}
],
"_prefab": {
"__id__": 37
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 34.381,
"y": -27.61,
"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": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 32
},
"_enabled": true,
"__prefab": {
"__id__": 34
},
"_contentSize": {
"__type__": "cc.Size",
"width": 17.90380859375,
@@ -687,11 +826,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 26
"__id__": 32
},
"_enabled": true,
"__prefab": {
"__id__": 30
"__id__": 36
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -772,7 +911,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 33
"__id__": 39
},
"_contentSize": {
"__type__": "cc.Size",
@@ -800,7 +939,7 @@
},
"_enabled": false,
"__prefab": {
"__id__": 35
"__id__": 41
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -845,11 +984,11 @@
},
"_enabled": true,
"__prefab": {
"__id__": 37
"__id__": 43
},
"clickEvents": [
{
"__id__": 38
"__id__": 44
}
],
"_interactable": true,
@@ -913,7 +1052,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 40
"__id__": 46
},
"_id": ""
},

View File

@@ -11,24 +11,17 @@ const { ccclass, property } = _decorator;
@ccclass('MGetsCompComp')
@ecs.register('MGetsComp', false)
export class MGetsCompComp extends CCComp {
get:any = {};
get_uuid:number=0;
get_num:number=0;
start() {
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
this.updateView();
}
onDestroy() {
oops.message.off(GameEvent.UpdateCollection, this.updateView, this);
}
private updateView() {
}
private updateNodeNum(node: Node, num: number) {
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {

View File

@@ -1,4 +1,4 @@
import { _decorator, Node, Label } from "cc";
import { _decorator, Node, Label, PrefabLink, instantiate, Prefab, SpriteAtlas, Sprite, resources } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
@@ -11,7 +11,10 @@ const { ccclass, property } = _decorator;
@ccclass('MissionGetsCompComp')
@ecs.register('MissionGetsComp', false)
export class MissionGetsCompComp extends CCComp {
get_datas:any={};
get_nodes:Node[]=[];
// 图标图集缓存
private uiconsAtlas: SpriteAtlas | null = null;
start() {
}
@@ -19,27 +22,39 @@ export class MissionGetsCompComp extends CCComp {
onDestroy() {
}
load_hui(uuid:string){
var path = "game/gui/get";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
// 将节点添加到父节点下
this.node.addChild(node);
node.getChildByName("num").getComponent(Label).string = "1";
const sprite = node.getChildByName("icon").getComponent(Sprite);
if (!sprite) return;
load_hui(uuid:number, pos_index: number){
var path = "game/gui/get";
}
if (this.uiconsAtlas) {
const frame = this.uiconsAtlas.getSpriteFrame(uuid);
if (frame) {
sprite.spriteFrame = frame;
}
} else {
// 加载图集
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
if (err) {
console.error("[MissionCardComp] Failed to load uicons atlas", err);
return;
}
this.uiconsAtlas = atlas;
const frame = atlas.getSpriteFrame(uuid);
if (frame) {
sprite.spriteFrame = frame;
}
});
}
}
private updateNodeNum(node: Node, num: number) {
if (!node) return;
// Try to find Label on the node itself
let label = node.getComponent(Label);
// If not found, try to find a child named "num" with Label
if (!label) {
const numNode = node.getChildByName("num");
if (numNode) {
label = numNode.getComponent(Label);
}
}
if (label) {
label.string = num > 0 ? num.toString() : "";
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */

View File

@@ -100,6 +100,16 @@
- 现状resetCD 里按 AS/SS 计算了 cd但随后又把 cd 覆盖回 cd_max。
- 风险:攻速/技速体系失效,强化与天赋相关数值无法体现。
14. [问题] 资源加载机制限制gui 目录资源无法直接获取
- 位置assets/script/game/map/HInfoComp.ts 及资源目录
- 现状:`oops.res.get` 仅能获取已预加载的资源。当前初始化流程LoadingViewComp仅预加载了 `game` 目录,导致 `gui` 目录下的资源无法通过代码动态获取。
- 影响:设计师无法随意引用 `gui` 下的资源,限制了界面开发的灵活性。
- 建议方案:
1. 规范:将所有动态加载的资源统一放入 `assets/resources/game` 目录下(推荐)。
2. 扩展:在 LoadingViewComp 中增加 `gui` 目录的预加载(需评估内存和启动时间)。
- 风险:攻速/技速体系失效,强化与天赋相关数值无法体现。
14. [严重问题] 计数型天赋 key 与属性枚举不一致,导致天赋效果读取失败
- 位置assets/script/game/hero/TalComp.ts + assets/script/game/hero/HeroAtkSystem.ts