fix(地图): 反转英雄卡牌排序逻辑以匹配渲染顺序
由于 cc.Layout 的节点渲染顺序与之前手动排序逻辑相反,导致英雄卡牌位置错乱。现在将排序规则改为 x 坐标越小(越靠后排)的 index 越小,并移除手动位置计算,完全依赖 Layout 自动排版。
This commit is contained in:
@@ -841,12 +841,11 @@ export class MissionCardComp extends CCComp {
|
|||||||
const bView = bEnt?.get(HeroViewComp);
|
const bView = bEnt?.get(HeroViewComp);
|
||||||
const aMove = aEnt?.get(MoveComp);
|
const aMove = aEnt?.get(MoveComp);
|
||||||
const bMove = bEnt?.get(MoveComp);
|
const bMove = bEnt?.get(MoveComp);
|
||||||
// 排序逻辑:
|
// 排序逻辑反转:适应 cc.Layout 的节点渲染顺序(先渲染/index小的在左边)
|
||||||
// 1. 如果有 x 坐标,按照 x 坐标从大到小(在前面)排序
|
// 1. x 坐标越小(越靠后排)的,index 应该越小
|
||||||
// 2. 如果没有 x 坐标,默认退化到按照生成顺序或 eid 排序
|
|
||||||
const aFrontScore = aView?.node?.position?.x ?? -999999;
|
const aFrontScore = aView?.node?.position?.x ?? -999999;
|
||||||
const bFrontScore = bView?.node?.position?.x ?? -999999;
|
const bFrontScore = bView?.node?.position?.x ?? -999999;
|
||||||
if (aFrontScore !== bFrontScore) return bFrontScore - aFrontScore;
|
if (aFrontScore !== bFrontScore) return aFrontScore - bFrontScore;
|
||||||
|
|
||||||
const aSpawnOrder = aMove?.spawnOrder ?? 0;
|
const aSpawnOrder = aMove?.spawnOrder ?? 0;
|
||||||
const bSpawnOrder = bMove?.spawnOrder ?? 0;
|
const bSpawnOrder = bMove?.spawnOrder ?? 0;
|
||||||
@@ -861,11 +860,8 @@ export class MissionCardComp extends CCComp {
|
|||||||
const item = sortedItems[index];
|
const item = sortedItems[index];
|
||||||
if (!item.node || !item.node.isValid) continue;
|
if (!item.node || !item.node.isValid) continue;
|
||||||
|
|
||||||
// 使用 Widget 布局的话需要禁用它或者单纯调整位置
|
// 既然使用了 cc.Layout 进行自动排版,我们只需设置渲染顺序
|
||||||
// 这里我们使用绝对坐标进行排列,假设是从左到右
|
// Layout 会自动根据 siblingIndex 对所有子节点重新排位
|
||||||
const targetX = index * (this.heroInfoItemGap + this.heroInfoItemSpacing);
|
|
||||||
const pos = item.node.position;
|
|
||||||
item.node.setPosition(targetX, pos.y, pos.z);
|
|
||||||
item.node.setSiblingIndex(index);
|
item.node.setSiblingIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user