feat(英雄列表): 添加前后英雄预览并改进动画管理

- 新增 phero_icon 和 nhero_icon 节点用于显示前后英雄
- 将 iconVisualToken 改为 Map 结构以分别管理多个节点的动画令牌
- 在更新显示时加载并播放当前、前一个及后一个英雄的动画
- 优化动画加载的取消逻辑,避免令牌不匹配导致的动画错误
This commit is contained in:
panw
2026-04-01 16:54:16 +08:00
parent 64536e926f
commit 197e913c53
2 changed files with 980 additions and 603 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,10 @@ export class HListComp extends CCComp {
@property(Node)
hero_icon=null!
@property(Node)
phero_icon=null!
@property(Node)
nhero_icon=null!
@property(Node)
ap_node=null!
@property(Node)
hp_node=null!
@@ -30,7 +34,7 @@ export class HListComp extends CCComp {
huuid:number=null!
private currentIndex: number = 0;
private iconVisualToken: number = 0;
private iconVisualTokens: Map<Node, number> = new Map();
debugMode: boolean = false;
onLoad() {
@@ -62,6 +66,12 @@ export class HListComp extends CCComp {
const hero = HeroInfo[this.huuid];
if (!hero) return;
// 获取前后英雄的 uuid
const preIndex = (this.currentIndex - 1 + HeroList.length) % HeroList.length;
const nextIndex = (this.currentIndex + 1) % HeroList.length;
const pUuid = HeroList[preIndex];
const nUuid = HeroList[nextIndex];
// 更新基础属性标签
this.setLabelText(this.name_node, hero.name);
this.setLabelText(this.ap_node, `攻击力: ${hero.ap}`);
@@ -69,6 +79,8 @@ export class HListComp extends CCComp {
// 更新动画
this.updateHeroAnimation(this.hero_icon, this.huuid);
this.updateHeroAnimation(this.phero_icon, pUuid);
this.updateHeroAnimation(this.nhero_icon, nUuid);
// 更新技能列表
this.updateSkillInfo(hero);
@@ -93,8 +105,8 @@ export class HListComp extends CCComp {
const anim = node.getComponent(Animation) || node.addComponent(Animation);
this.clearAnimationClips(anim);
this.iconVisualToken++;
const token = this.iconVisualToken;
let token = (this.iconVisualTokens.get(node) || 0) + 1;
this.iconVisualTokens.set(node, token);
const path = `game/heros/hero/${hero.path}/idle`;
resources.load(path, AnimationClip, (err, clip) => {
@@ -102,7 +114,7 @@ export class HListComp extends CCComp {
mLogger.log(this.debugMode, "HListComp", `load hero animation failed ${uuid}`, err);
return;
}
if (token !== this.iconVisualToken || this.huuid !== uuid) {
if (token !== this.iconVisualTokens.get(node)) {
return;
}
this.clearAnimationClips(anim);