refactor(HeroBoxComp): 优化属性栏配置与实时刷新逻辑

1. 将静态高度常量改为可编辑器配置的序列化属性
2. 添加帧更新实现属性降频刷新功能,同步实时属性
3. 调整变量声明顺序优化代码可读性
This commit is contained in:
pan
2026-07-28 16:29:52 +08:00
parent 371178fce3
commit d0346b4e8c
4 changed files with 2443 additions and 2890 deletions

View File

@@ -134,12 +134,13 @@ export class HeroBoxComp extends CCComp {
@property(Node)
private wfuny_row: Node = null;
/** 属性栏收起高度 */
private attrBoxHeightCollapsed: number = 100;
/** 属性栏展开高度 */
private attrBoxHeightExpanded: number = 210;
/** 次级属性栏是否展开 */
private moreExpanded: boolean = false;
/** 属性栏收起高度 */
private static readonly ATTR_BOX_HEIGHT_COLLAPSED = 125;
/** 属性栏展开高度 */
private static readonly ATTR_BOX_HEIGHT_EXPANDED = 210;
// ======================== 运行时状态 ========================
@@ -166,6 +167,24 @@ export class HeroBoxComp extends CCComp {
}
}
/** 刷新计时累计(降频刷新实时属性) */
private refreshElapsed: number = 0;
/** 实时刷新间隔(秒) */
private static readonly REFRESH_INTERVAL = 0.25;
/**
* 帧更新:绑定英雄后按固定间隔实时刷新面板信息。
* Why: AP/HP/暴击等属性受 buff/光环影响实时变化,需降频轮询同步;
* 实体失效时 refresh 会自动切换为空状态。
*/
update(dt: number) {
if (!this.model) return;
this.refreshElapsed += dt;
if (this.refreshElapsed < HeroBoxComp.REFRESH_INTERVAL) return;
this.refreshElapsed = 0;
this.refresh();
}
/** 更多按钮点击:切换次级属性栏显示/隐藏 */
private onMoreBtnClick() {
oops.audio.playEffect("music/button");
@@ -181,10 +200,10 @@ export class HeroBoxComp extends CCComp {
row.active = visible;
}
}
// 展开/收起时切换属性栏高度125 ↔ 210
// 展开/收起时切换属性栏高度(默认 125 ↔ 210,可在编辑器自定义
if (this.attr_box && this.attr_box.isValid) {
const transform = this.attr_box.getComponent(UITransform) || this.attr_box.addComponent(UITransform);
const height = visible ? HeroBoxComp.ATTR_BOX_HEIGHT_EXPANDED : HeroBoxComp.ATTR_BOX_HEIGHT_COLLAPSED;
const height = visible ? this.attrBoxHeightExpanded : this.attrBoxHeightCollapsed;
transform.setContentSize(transform.width, height);
}
}