fix(ui): 动态调整信息框时同步更新名称位置
修复当信息框内容行数变化时,名称标签位置未同步调整的问题。新增 updateNamePosition 方法,根据显示行数动态计算名称的垂直位置,确保视觉布局的一致性。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,8 @@ export class IBoxComp extends CCComp {
|
|||||||
Line5: Node = null!
|
Line5: Node = null!
|
||||||
private readonly baseHeight: number = 100;
|
private readonly baseHeight: number = 100;
|
||||||
private readonly extraLineHeight: number = 50;
|
private readonly extraLineHeight: number = 50;
|
||||||
|
private readonly nameBaseY: number = 50;
|
||||||
|
private readonly nameExtraLineOffsetY: number = 25;
|
||||||
|
|
||||||
onAdded(args: {
|
onAdded(args: {
|
||||||
heroUuid?: number;
|
heroUuid?: number;
|
||||||
@@ -91,6 +93,7 @@ export class IBoxComp extends CCComp {
|
|||||||
}
|
}
|
||||||
const targetHeight = this.baseHeight + Math.max(0, showCount - 1) * this.extraLineHeight;
|
const targetHeight = this.baseHeight + Math.max(0, showCount - 1) * this.extraLineHeight;
|
||||||
this.updateIBoxHeight(targetHeight);
|
this.updateIBoxHeight(targetHeight);
|
||||||
|
this.updateNamePosition(showCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateIBoxHeight(height: number) {
|
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) {
|
private updateLineTypeIcon(line: Node, iType?: IType) {
|
||||||
const meleeNode = line.getChildByName("Melee");
|
const meleeNode = line.getChildByName("Melee");
|
||||||
const remoteNode = line.getChildByName("remote");
|
const remoteNode = line.getChildByName("remote");
|
||||||
|
|||||||
Reference in New Issue
Block a user