feat(奖励系统): 实现等级奖励分发和收集品显示功能

- 新增GameEvent.UpdateCollection事件用于更新收集品显示
- 将CardType枚举移至GameSet并添加getLevelRewardType函数
- 修改MissionComp根据等级分发不同类型奖励事件
- 实现MissionGetsComp收集品数量显示功能
- 在SingletonModuleComp中添加收集品更新事件触发
This commit is contained in:
walkpan
2026-01-05 20:06:23 +08:00
parent 93e0ab083b
commit 9bf8ad2625
7 changed files with 121 additions and 154 deletions

View File

@@ -1,6 +1,9 @@
import { _decorator, Node } from "cc";
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;
@@ -8,34 +11,73 @@ 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!
/** 视图层逻辑代码分离演示 */
@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() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
this.updateView();
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
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();
}
}
}