fix(ui): 动态调整信息框时同步更新名称位置

修复当信息框内容行数变化时,名称标签位置未同步调整的问题。新增 updateNamePosition 方法,根据显示行数动态计算名称的垂直位置,确保视觉布局的一致性。
This commit is contained in:
walkpan
2026-03-27 20:14:04 +08:00
parent 804577bef1
commit 25cd0b419e
2 changed files with 286 additions and 313 deletions

View File

@@ -21,6 +21,8 @@ export class IBoxComp extends CCComp {
Line5: Node = null!
private readonly baseHeight: number = 100;
private readonly extraLineHeight: number = 50;
private readonly nameBaseY: number = 50;
private readonly nameExtraLineOffsetY: number = 25;
onAdded(args: {
heroUuid?: number;
@@ -91,6 +93,7 @@ export class IBoxComp extends CCComp {
}
const targetHeight = this.baseHeight + Math.max(0, showCount - 1) * this.extraLineHeight;
this.updateIBoxHeight(targetHeight);
this.updateNamePosition(showCount);
}
private updateIBoxHeight(height: number) {
@@ -111,6 +114,15 @@ export class IBoxComp extends CCComp {
}
}
private updateNamePosition(showCount: number) {
const bgNode = this.node.getChildByName("Bg");
const nameNode = bgNode?.getChildByName("name");
if (!nameNode) return;
const targetY = this.nameBaseY + Math.max(0, showCount - 1) * this.nameExtraLineOffsetY;
const current = nameNode.position;
nameNode.setPosition(current.x, targetY, current.z);
}
private updateLineTypeIcon(line: Node, iType?: IType) {
const meleeNode = line.getChildByName("Melee");
const remoteNode = line.getChildByName("remote");