refactor(HeroBoxComp): 封装更多按钮状态切换逻辑

将英雄盒子的更多按钮显隐状态切换逻辑抽离为独立私有方法,提升代码可读性和维护性。
This commit is contained in:
pan
2026-07-28 16:35:54 +08:00
parent d0346b4e8c
commit 15a98f985b
2 changed files with 810 additions and 252 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -206,6 +206,24 @@ export class HeroBoxComp extends CCComp {
const height = visible ? this.attrBoxHeightExpanded : this.attrBoxHeightCollapsed;
transform.setContentSize(transform.width, height);
}
// 切换更多按钮状态子节点:收起=n_* 激活,展开=a_* 激活
this.setMoreBtnState(visible);
}
/**
* 切换更多按钮的状态子节点。
* 收起态激活 n_Bg / n_Arrow展开态激活 a_Bg / a_Arrow。
*/
private setMoreBtnState(expanded: boolean) {
if (!this.more_btn || !this.more_btn.isValid) return;
const nBg = this.more_btn.getChildByName("n_Bg");
const nArrow = this.more_btn.getChildByName("n_Arrow");
const aBg = this.more_btn.getChildByName("a_Bg");
const aArrow = this.more_btn.getChildByName("a_Arrow");
if (nBg) nBg.active = !expanded;
if (nArrow) nArrow.active = !expanded;
if (aBg) aBg.active = expanded;
if (aArrow) aArrow.active = expanded;
}
/** ECS 组件移除时销毁节点 */