- 删除多个文件中的 console.log/console.warn/console.error 调试输出 - 将日志输出统一替换为 mLogger 工具,支持调试模式控制 - 清理注释掉的调试代码和空方法体
158 lines
5.6 KiB
TypeScript
158 lines
5.6 KiB
TypeScript
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";
|
|
import { GameEvent } from "../common/config/GameEvent";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { CardKind } from "../common/config/GameSet";
|
|
import { mLogger } from "../common/Logger";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionGetsCompComp')
|
|
@ecs.register('MissionGetsComp', false)
|
|
export class MissionGetsCompComp extends CCComp {
|
|
debugMode = false;
|
|
get_datas: { [key: number]: { num: number, node: Node, kind?: number } } = {};
|
|
get_nodes: Node[] = [];
|
|
// 图标图集缓存
|
|
private uiconsAtlas: SpriteAtlas | null = null;
|
|
|
|
onLoad() {
|
|
oops.message.on(GameEvent.UpdateMissionGet, this.onUpdateMissionGet, this);
|
|
oops.message.on(GameEvent.MissionStart, this.onMissionStart, this);
|
|
}
|
|
|
|
start() {
|
|
|
|
}
|
|
|
|
onDestroy() {
|
|
oops.message.off(GameEvent.UpdateMissionGet, this.onUpdateMissionGet, this);
|
|
oops.message.off(GameEvent.MissionStart, this.onMissionStart, this);
|
|
}
|
|
|
|
onMissionStart(){
|
|
// 清理旧的节点
|
|
this.get_nodes.forEach(node => {
|
|
if (node && node.isValid) {
|
|
node.destroy();
|
|
}
|
|
});
|
|
this.get_nodes = [];
|
|
this.get_datas = {};
|
|
}
|
|
|
|
private onUpdateMissionGet(event: string, args: any) {
|
|
if (!args || !args.uuid) return;
|
|
const { uuid, icon, kind } = args;
|
|
this.addGet(uuid, icon, kind);
|
|
}
|
|
|
|
addGet(uuid: number, iconName?: string, kind?: number) {
|
|
mLogger.log(this.debugMode, 'MissionGetsComp', "[MissionGetsComp]添加获取到的物品:", uuid, iconName, kind);
|
|
if (this.get_datas[uuid]) {
|
|
this.get_datas[uuid].num++;
|
|
this.updateNodeNum(this.get_datas[uuid].node, this.get_datas[uuid].num);
|
|
} else {
|
|
this.load_hui(uuid, iconName || uuid.toString(), kind);
|
|
}
|
|
}
|
|
|
|
load_hui(uuid: number, iconName: string, kind?: number){
|
|
var path = "game/gui/get";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
if (!prefab) {
|
|
mLogger.log(this.debugMode, 'MissionGetsComp', "Prefab not found:", path);
|
|
return;
|
|
}
|
|
var node = instantiate(prefab);
|
|
// 将节点添加到父节点下
|
|
this.node.addChild(node);
|
|
|
|
// 记录数据
|
|
this.get_datas[uuid] = { num: 1, node: node, kind: kind };
|
|
this.get_nodes.push(node);
|
|
|
|
node.getChildByName("num").getComponent(Label).string = "1";
|
|
|
|
// 先隐藏所有类型标识
|
|
const typeNodes = ["Atk", "Atked", "Buff", "Attr", "Skill", "Hp", "Dead", "Partner"];
|
|
// 1. 处理 bg 节点
|
|
typeNodes.forEach(nodeName => {
|
|
const node_bg = node.getChildByName(nodeName);
|
|
if (node_bg) node_bg.active = false;
|
|
});
|
|
// 根据 kind 激活bg
|
|
let activeNodeName = "";
|
|
switch (kind) {
|
|
case CardKind.Atk:
|
|
activeNodeName = "Atk";
|
|
break;
|
|
case CardKind.Atted:
|
|
activeNodeName = "Atked";
|
|
break;
|
|
case CardKind.Buff:
|
|
activeNodeName = "Buff";
|
|
break;
|
|
case CardKind.Attr:
|
|
activeNodeName = "Attr";
|
|
break;
|
|
case CardKind.Skill:
|
|
activeNodeName = "Skill";
|
|
break;
|
|
case CardKind.Hp:
|
|
activeNodeName = "Hp";
|
|
break;
|
|
case CardKind.Dead:
|
|
activeNodeName = "Dead";
|
|
break;
|
|
case CardKind.Partner:
|
|
activeNodeName = "Partner";
|
|
break;
|
|
}
|
|
|
|
if (activeNodeName) {
|
|
// 激活bg
|
|
const activeNode = node.getChildByName(activeNodeName);
|
|
if (activeNode) activeNode.active = true;
|
|
}
|
|
|
|
const sprite = node.getChildByName("icon").getComponent(Sprite);
|
|
if (!sprite) return;
|
|
|
|
if (this.uiconsAtlas) {
|
|
const frame = this.uiconsAtlas.getSpriteFrame(iconName);
|
|
if (frame) {
|
|
sprite.spriteFrame = frame;
|
|
}
|
|
} else {
|
|
// 加载图集
|
|
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
|
if (err) {
|
|
mLogger.error(this.debugMode, 'MissionGetsComp', "[MissionGetsComp] Failed to load uicons atlas", err);
|
|
return;
|
|
}
|
|
this.uiconsAtlas = atlas;
|
|
const frame = atlas.getSpriteFrame(iconName);
|
|
if (frame) {
|
|
sprite.spriteFrame = frame;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private updateNodeNum(node: Node, num: number) {
|
|
const label = node.getChildByName("num")?.getComponent(Label);
|
|
if (label) {
|
|
label.string = num.toString();
|
|
}
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
}
|