diff --git a/assets/script/game/map/HlistComp.ts b/assets/script/game/map/HlistComp.ts index dc5235df..92050b9e 100644 --- a/assets/script/game/map/HlistComp.ts +++ b/assets/script/game/map/HlistComp.ts @@ -46,17 +46,15 @@ export class HListComp extends CCComp { } private onPreClick() { - if (this.currentIndex > 0) { - this.currentIndex--; - this.updateHeroView(); - } + if (!HeroList || HeroList.length === 0) return; + this.currentIndex = (this.currentIndex - 1 + HeroList.length) % HeroList.length; + this.updateHeroView(); } private onNextClick() { - if (this.currentIndex < HeroList.length - 1) { - this.currentIndex++; - this.updateHeroView(); - } + if (!HeroList || HeroList.length === 0) return; + this.currentIndex = (this.currentIndex + 1) % HeroList.length; + this.updateHeroView(); } private updateHeroView() { @@ -123,13 +121,23 @@ export class HListComp extends CCComp { } } + private findNodeByName(root: Node, name: string): Node | null { + if (!root) return null; + if (root.name === name) return root; + for (let i = 0; i < root.children.length; i++) { + const res = this.findNodeByName(root.children[i], name); + if (res) return res; + } + return null; + } + private updateSkillInfo(hero: any) { if (!this.info_node) return; const skills = Object.values(hero.skills || {}); for (let i = 1; i <= 5; i++) { - const line = this.info_node.getChildByName(`Line${i}`); + let line = this.findNodeByName(this.info_node, `Line${i}`) || this.findNodeByName(this.info_node, `line${i}`); if (!line) continue; const skill: any = skills[i - 1]; @@ -140,7 +148,7 @@ export class HListComp extends CCComp { const text = config ? `${config.name} Lv.${skill.lv} CD:${skill.cd}s ${config.info}` : `未知技能 CD:${skill.cd}s`; - const noteNode = line.getChildByName("note"); + const noteNode = this.findNodeByName(line, "note"); const label = noteNode?.getComponent(Label) || noteNode?.getComponentInChildren(Label) || line.getComponentInChildren(Label); if (label) { label.string = text; @@ -154,9 +162,9 @@ export class HListComp extends CCComp { } private updateLineTypeIcon(line: Node, iType?: IType) { - const meleeNode = line.getChildByName("Melee"); - const remoteNode = line.getChildByName("remote"); - const supportNode = line.getChildByName("support"); + const meleeNode = this.findNodeByName(line, "Melee"); + const remoteNode = this.findNodeByName(line, "remote"); + const supportNode = this.findNodeByName(line, "support"); if (meleeNode) meleeNode.active = iType === IType.Melee; if (remoteNode) remoteNode.active = iType === IType.remote; if (supportNode) supportNode.active = iType === IType.support;