refactor(HeroBoxComp): 封装更多按钮状态切换逻辑
将英雄盒子的更多按钮显隐状态切换逻辑抽离为独立私有方法,提升代码可读性和维护性。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -206,6 +206,24 @@ export class HeroBoxComp extends CCComp {
|
|||||||
const height = visible ? this.attrBoxHeightExpanded : this.attrBoxHeightCollapsed;
|
const height = visible ? this.attrBoxHeightExpanded : this.attrBoxHeightCollapsed;
|
||||||
transform.setContentSize(transform.width, height);
|
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 组件移除时销毁节点 */
|
/** ECS 组件移除时销毁节点 */
|
||||||
|
|||||||
Reference in New Issue
Block a user