feat(map): 新增可动态加载的收集物UI组件
- 添加 MGetComp 组件用于管理单个收集物的显示逻辑 - 创建 get.prefab 预制体作为收集物UI模板 - 重构 MissionGetsComp,移除硬编码节点引用,改为动态加载 - 支持通过 load_hui 方法按需加载收集物UI实例
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"__type__": "cc.Prefab",
|
"__type__": "cc.Prefab",
|
||||||
"_name": "icon",
|
"_name": "get",
|
||||||
"_objFlags": 0,
|
"_objFlags": 0,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_native": "",
|
"_native": "",
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.Node",
|
"__type__": "cc.Node",
|
||||||
"_name": "icon",
|
"_name": "get",
|
||||||
"_objFlags": 0,
|
"_objFlags": 0,
|
||||||
"__editorExtras__": {},
|
"__editorExtras__": {},
|
||||||
"_parent": null,
|
"_parent": null,
|
||||||
@@ -41,10 +41,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__id__": 36
|
"__id__": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__id__": 39
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_prefab": {
|
"_prefab": {
|
||||||
"__id__": 39
|
"__id__": 41
|
||||||
},
|
},
|
||||||
"_lpos": {
|
"_lpos": {
|
||||||
"__type__": "cc.Vec3",
|
"__type__": "cc.Vec3",
|
||||||
@@ -900,6 +903,24 @@
|
|||||||
"handler": "",
|
"handler": "",
|
||||||
"customEventData": ""
|
"customEventData": ""
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"__type__": "7ddd1IfGRhO7a2b66ov5bYG",
|
||||||
|
"_name": "",
|
||||||
|
"_objFlags": 0,
|
||||||
|
"__editorExtras__": {},
|
||||||
|
"node": {
|
||||||
|
"__id__": 1
|
||||||
|
},
|
||||||
|
"_enabled": true,
|
||||||
|
"__prefab": {
|
||||||
|
"__id__": 40
|
||||||
|
},
|
||||||
|
"_id": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"__type__": "cc.CompPrefabInfo",
|
||||||
|
"fileId": "c89eW5WlxFUokvJRFAfrSA"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"__type__": "cc.PrefabInfo",
|
"__type__": "cc.PrefabInfo",
|
||||||
"root": {
|
"root": {
|
||||||
@@ -8,6 +8,6 @@
|
|||||||
],
|
],
|
||||||
"subMetas": {},
|
"subMetas": {},
|
||||||
"userData": {
|
"userData": {
|
||||||
"syncNodeName": "icon"
|
"syncNodeName": "get"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
37
assets/script/game/map/MGetComp.ts
Normal file
37
assets/script/game/map/MGetComp.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { _decorator, Node, Label } 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";
|
||||||
|
import { GameEvent } from "../common/config/GameEvent";
|
||||||
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
|
|
||||||
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
|
/** 视图层对象 */
|
||||||
|
@ccclass('MGetsCompComp')
|
||||||
|
@ecs.register('MGetsComp', false)
|
||||||
|
export class MGetsCompComp extends CCComp {
|
||||||
|
get:any = {};
|
||||||
|
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() {
|
||||||
|
this.node.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
9
assets/script/game/map/MGetComp.ts.meta
Normal file
9
assets/script/game/map/MGetComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"ver": "4.0.24",
|
||||||
|
"importer": "typescript",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "7ddd121f-1918-4eed-ad9b-ebaa2fe5b606",
|
||||||
|
"files": [],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {}
|
||||||
|
}
|
||||||
@@ -11,53 +11,19 @@ const { ccclass, property } = _decorator;
|
|||||||
@ccclass('MissionGetsCompComp')
|
@ccclass('MissionGetsCompComp')
|
||||||
@ecs.register('MissionGetsComp', false)
|
@ecs.register('MissionGetsComp', false)
|
||||||
export class MissionGetsCompComp extends CCComp {
|
export class MissionGetsCompComp extends CCComp {
|
||||||
@property(Node)
|
|
||||||
get0:Node = null!
|
|
||||||
@property(Node)
|
|
||||||
get1:Node = null!
|
|
||||||
@property(Node)
|
|
||||||
get2:Node = null!
|
|
||||||
@property(Node)
|
|
||||||
get3:Node = null!
|
|
||||||
@property(Node)
|
|
||||||
get4:Node = null!
|
|
||||||
@property(Node)
|
|
||||||
get5:Node = null!
|
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
|
|
||||||
this.updateView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {
|
onDestroy() {
|
||||||
oops.message.off(GameEvent.UpdateCollection, this.updateView, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateView() {
|
load_hui(uuid:number, pos_index: number){
|
||||||
if (!smc.vmdata || !smc.vmdata.collection) return;
|
var path = "game/gui/get";
|
||||||
const data = smc.vmdata.collection;
|
|
||||||
|
}
|
||||||
// Talents (get0 - get3)
|
|
||||||
const talentIds = Object.keys(data.talents);
|
|
||||||
const talentNodes = [this.get0, this.get1, this.get2, this.get3];
|
|
||||||
|
|
||||||
for (let i = 0; i < talentNodes.length; i++) {
|
|
||||||
const node = talentNodes[i];
|
|
||||||
if (i < talentIds.length) {
|
|
||||||
const id = Number(talentIds[i]); // Object.keys returns strings
|
|
||||||
const count = data.talents[id];
|
|
||||||
this.updateNodeNum(node, count);
|
|
||||||
} else {
|
|
||||||
this.updateNodeNum(node, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skill (get4)
|
|
||||||
this.updateNodeNum(this.get4, data.skill.count);
|
|
||||||
|
|
||||||
// Friend (get5)
|
|
||||||
this.updateNodeNum(this.get5, data.friend.count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateNodeNum(node: Node, num: number) {
|
private updateNodeNum(node: Node, num: number) {
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user