将HeroAttrsComp中的card_lv字段重命名为pool_lv,以更准确地反映其表示英雄池等级的含义。同时更新所有相关引用点,包括HInfoComp的显示逻辑、Hero的加载方法以及MissionHeroCompComp的召唤队列和合成逻辑,确保数据一致性。
186 lines
6.0 KiB
TypeScript
186 lines
6.0 KiB
TypeScript
import { _decorator, Animation, AnimationClip, Button, Event, Label, Node, NodeEventType, 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 { HeroInfo } from "../common/config/heroSet";
|
|
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
|
|
import { Hero } from "../hero/Hero";
|
|
import { oops } from "db://oops-framework/core/Oops";
|
|
import { UIID } from "../common/config/GameUIConfig";
|
|
import { mLogger } from "../common/Logger";
|
|
|
|
const {property, ccclass } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('HInfoComp')
|
|
@ecs.register('HInfoComp', false)
|
|
export class HInfoComp extends CCComp {
|
|
@property(Node)
|
|
icon_node=null!
|
|
@property(Node)
|
|
sell_node=null!
|
|
|
|
@property(Node)
|
|
NF_node=null!
|
|
@property(Node)
|
|
HF_node=null!
|
|
|
|
|
|
private eid: number = 0;
|
|
private model: HeroAttrsComp | null = null;
|
|
private apLabel: Label | null = null;
|
|
private hpLabel: Label | null = null;
|
|
private iconVisualToken: number = 0;
|
|
private iconHeroUuid: number = 0;
|
|
private debugMode: boolean = true;
|
|
onLoad() {
|
|
this.cacheLabels();
|
|
// this.bindEvents();
|
|
}
|
|
|
|
onDestroy() {
|
|
// this.unbindEvents();
|
|
}
|
|
|
|
bindData(eid: number, model: HeroAttrsComp) {
|
|
this.eid = eid;
|
|
this.model = model;
|
|
this.cacheLabels();
|
|
this.refresh();
|
|
}
|
|
|
|
refresh() {
|
|
if (!this.model) return;
|
|
|
|
const isHighLevel = (this.model.lv ?? 0) > 1;
|
|
if (this.HF_node) this.HF_node.active = isHighLevel;
|
|
if (this.NF_node) this.NF_node.active = !isHighLevel;
|
|
|
|
const activeFrameNode = isHighLevel ? this.HF_node : this.NF_node;
|
|
if (activeFrameNode) {
|
|
const cardLvStr = `lv${this.model.pool_lv ?? 1}`;
|
|
activeFrameNode.children.forEach(child => {
|
|
child.active = (child.name === cardLvStr);
|
|
});
|
|
}
|
|
|
|
const heroUuid = this.model.hero_uuid ?? 0;
|
|
if (heroUuid !== this.iconHeroUuid) {
|
|
this.iconHeroUuid = heroUuid;
|
|
this.iconVisualToken += 1;
|
|
this.updateHeroAnimation(this.icon_node, heroUuid, this.iconVisualToken);
|
|
}
|
|
if (this.apLabel) {
|
|
this.apLabel.string = `${Math.max(0, Math.floor(this.model.ap ?? 0))}`;
|
|
}
|
|
if (this.hpLabel) {
|
|
this.hpLabel.string = `${Math.max(0, Math.floor(this.model.hp_max ?? 0))}`;
|
|
}
|
|
}
|
|
|
|
isModelAlive(): boolean {
|
|
return !!(this.model as any)?.ent;
|
|
}
|
|
|
|
private cacheLabels() {
|
|
if (!this.apLabel) {
|
|
this.apLabel = this.findLabelByPath(["ap", "val"]);
|
|
}
|
|
if (!this.hpLabel) {
|
|
this.hpLabel = this.findLabelByPath(["hp", "val"]);
|
|
}
|
|
}
|
|
|
|
private findLabelByPath(path: string[]): Label | null {
|
|
let current: Node | null = this.node;
|
|
for (let i = 0; i < path.length; i++) {
|
|
current = current?.getChildByName(path[i]) ?? null;
|
|
if (!current) return null;
|
|
}
|
|
return current.getComponent(Label) || current.getComponentInChildren(Label);
|
|
}
|
|
|
|
|
|
|
|
private updateHeroAnimation(node: Node, uuid: number, token: number) {
|
|
if (!node) return;
|
|
const sprite = node.getComponent(Sprite) || node.getComponentInChildren(Sprite);
|
|
if (sprite) sprite.spriteFrame = null;
|
|
const hero = HeroInfo[uuid];
|
|
if (!hero) {
|
|
this.clearIconAnimation(node);
|
|
return;
|
|
}
|
|
const anim = node.getComponent(Animation) || node.addComponent(Animation);
|
|
this.clearAnimationClips(anim);
|
|
const path = `game/heros/hero/${hero.path}/idle`;
|
|
resources.load(path, AnimationClip, (err, clip) => {
|
|
if (err || !clip) return;
|
|
if (token !== this.iconVisualToken || !this.model || this.model.hero_uuid !== uuid) {
|
|
return;
|
|
}
|
|
this.clearAnimationClips(anim);
|
|
anim.addClip(clip);
|
|
anim.play("idle");
|
|
});
|
|
}
|
|
|
|
private clearIconAnimation(node: Node) {
|
|
const anim = node?.getComponent(Animation);
|
|
if (!anim) return;
|
|
anim.stop();
|
|
this.clearAnimationClips(anim);
|
|
}
|
|
|
|
private clearAnimationClips(anim: Animation) {
|
|
const clips = (anim as any).clips as AnimationClip[] | undefined;
|
|
if (!clips || clips.length === 0) return;
|
|
[...clips].forEach(clip => anim.removeClip(clip, true));
|
|
}
|
|
|
|
// private bindEvents() {
|
|
// this.sell_node?.on(Button.EventType.CLICK, this.onSellHero, this);
|
|
// this.node.on(NodeEventType.TOUCH_END, this.onOpenIBox, this);
|
|
// }
|
|
|
|
// private unbindEvents() {
|
|
// this.sell_node?.off(Button.EventType.CLICK, this.onSellHero, this);
|
|
// this.node.off(NodeEventType.TOUCH_END, this.onOpenIBox, this);
|
|
// }
|
|
|
|
private onOpenIBox() {
|
|
if (!this.model) return;
|
|
if (!this.isModelAlive()) return;
|
|
const heroUuid = this.model.hero_uuid ?? 0;
|
|
if (!heroUuid || !HeroInfo[heroUuid]) return;
|
|
const heroLv = Math.max(1, Math.floor(this.model.lv ?? 1));
|
|
oops.gui.remove(UIID.IBox);
|
|
oops.gui.open(UIID.IBox, {
|
|
heroUuid,
|
|
heroLv,
|
|
skills: this.model.skills
|
|
});
|
|
}
|
|
|
|
private onSellHero(event?: Event) {
|
|
if (!this.eid) return;
|
|
const removed = Hero.removeByEid(this.eid);
|
|
mLogger.log(this.debugMode, "HInfoComp", "onSellHero", {
|
|
eid: this.eid,
|
|
isAlive: this.isModelAlive(),
|
|
removed
|
|
});
|
|
if (!removed) return;
|
|
oops.gui.remove(UIID.IBox);
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.clearIconAnimation(this.icon_node);
|
|
this.iconVisualToken = 0;
|
|
this.iconHeroUuid = 0;
|
|
this.model = null;
|
|
this.eid = 0;
|
|
this.node.destroy();
|
|
}
|
|
}
|