diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 213a33ce..6e483d35 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -97,11 +97,9 @@ export class HeroViewComp extends CCComp { this.top_node.setScale(this.scale*this.top_node.scale.x,1*this.top_node.scale.y); /* 显示角色血*/ this.top_node.getChildByName("hp").active = true; - this.top_node.getChildByName("cd").active = true + this.top_node.getChildByName("cd").active = false; this.top_node.getChildByName("shield").active = false; - this.top_node.getChildByName("lv").active = this.model.fac==FacSet.HERO; - this.top_node.getChildByName("lv").getChildByName("lv2").active=this.model.lv >= 2 - this.top_node.getChildByName("lv").getChildByName("lv3").active=this.model.lv >= 3 + this.top_node.getChildByName("lv").active = false; this.top_node.active = true; this.setTopBarOpacity(false); @@ -162,7 +160,7 @@ export class HeroViewComp extends CCComp { } public cd_show(){ - this.top_node.getChildByName("cd").getComponent(ProgressBar).progress = this.model.getDisplaySkillCdProgress(); + return; } /** 显示护盾 */ diff --git a/assets/script/game/map/HInfoComp.ts b/assets/script/game/map/HInfoComp.ts index c766185a..caf7728c 100644 --- a/assets/script/game/map/HInfoComp.ts +++ b/assets/script/game/map/HInfoComp.ts @@ -1,6 +1,7 @@ -import { _decorator, Label, Node } from "cc"; +import { _decorator, Animation, AnimationClip, Label, Node, 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"; const {property, ccclass } = _decorator; @@ -15,6 +16,8 @@ export class HInfoComp extends CCComp { private model: HeroAttrsComp | null = null; private apLabel: Label | null = null; private hpLabel: Label | null = null; + private iconVisualToken: number = 0; + private iconHeroUuid: number = 0; onLoad() { this.cacheLabels(); @@ -29,6 +32,13 @@ export class HInfoComp extends CCComp { refresh() { if (!this.model) return; + this.updateLevelUI(); + 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))}`; } @@ -59,8 +69,58 @@ export class HInfoComp extends CCComp { return current.getComponent(Label) || current.getComponentInChildren(Label); } + private updateLevelUI() { + if (!this.model) return; + const lvNode = this.node.getChildByName("lv"); + if (!lvNode) return; + lvNode.active = true + const lv2 = lvNode.getChildByName("lv2"); + if (lv2) lv2.active = this.model.lv >= 2; + const lv3 = lvNode.getChildByName("lv3"); + if (lv3) lv3.active = this.model.lv >= 3; + } + + 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)); + } + /** 视图对象通过 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();