45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
const LEFT_ENTRY_NAMES = [
|
|
"shop",
|
|
"sevenDayDoor",
|
|
"yicon",
|
|
"redeemBtn",
|
|
"passBtn",
|
|
"jungle",
|
|
"xinshou",
|
|
];
|
|
|
|
const RIGHT_ENTRY_NAMES = [
|
|
"rank",
|
|
"gacha",
|
|
"day",
|
|
"posBtn",
|
|
"topBtn",
|
|
"hammer",
|
|
];
|
|
|
|
const FIRST_ENTRY_Y = -143.83;
|
|
const ENTRY_GAP_Y = 220;
|
|
|
|
/** 只排列主页两侧已显示的活动入口,不修改节点显隐、父节点或层级顺序。 */
|
|
export default class SevenDayHomeEntryLayout {
|
|
constructor(private top: cc.Node) { }
|
|
|
|
public refresh() {
|
|
if (!this.top || !cc.isValid(this.top)) return;
|
|
this.layoutColumn(LEFT_ENTRY_NAMES);
|
|
this.layoutColumn(RIGHT_ENTRY_NAMES);
|
|
}
|
|
|
|
private layoutColumn(entryNames: string[]) {
|
|
let visibleIndex = 0;
|
|
entryNames.forEach((name: string) => {
|
|
const entry = this.top.getChildByName(name);
|
|
if (!entry || !entry.active) return;
|
|
|
|
const targetY = FIRST_ENTRY_Y - ENTRY_GAP_Y * visibleIndex;
|
|
if (Math.abs(entry.y - targetY) > 0.1) entry.y = targetY;
|
|
visibleIndex++;
|
|
});
|
|
}
|
|
}
|