Files
pixelheros/assets/script/game/map/MissionGetsComp.ts
walkpan 9bf8ad2625 feat(奖励系统): 实现等级奖励分发和收集品显示功能
- 新增GameEvent.UpdateCollection事件用于更新收集品显示
- 将CardType枚举移至GameSet并添加getLevelRewardType函数
- 修改MissionComp根据等级分发不同类型奖励事件
- 实现MissionGetsComp收集品数量显示功能
- 在SingletonModuleComp中添加收集品更新事件触发
2026-01-05 20:06:23 +08:00

84 lines
2.6 KiB
TypeScript

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('MissionGetsCompComp')
@ecs.register('MissionGetsComp', false)
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() {
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
this.updateView();
}
onDestroy() {
oops.message.off(GameEvent.UpdateCollection, this.updateView, this);
}
private updateView() {
if (!smc.vmdata || !smc.vmdata.collection) return;
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) {
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) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}