MatchMaster/assets/Script/GiveUpConfirmation.ts
2026-09-21 15:30:27 +08:00

50 lines
2.1 KiB
TypeScript

export interface GiveUpLosses {
hp: boolean;
day: boolean;
winStreak: boolean;
}
export function getGiveUpLosses(infiniteHealth: boolean): GiveUpLosses {
const config = cc.fx.GameConfig;
const mainline = !(config.GM_INFO.otherLevel > 0);
return {
hp: !infiniteHealth,
day: mainline && config.GM_INFO.level >= config.getFeatureUnlockLevel("daily"),
winStreak: mainline && config.isWinStreakUnlocked() && config.GM_INFO.winStreak >= 10,
};
}
/** 暂停与失败共用展示规则;按钮行为由各自的面板保留。 */
export function renderGiveUpConfirmation(panel: cc.Node, frames: cc.SpriteFrame[], losses: GiveUpLosses): boolean {
const { hp, day, winStreak } = losses;
const visible = ["hp", "day", "winStreak"].filter((name, index) => {
const icon = panel.getChildByName(name);
icon.active = [hp, day, winStreak][index];
return icon.active;
});
if (!visible.length) return false;
const positions = visible.length === 1
? [cc.v2(0, 100)]
: visible.length === 2
? [cc.v2(-140, 150), cc.v2(170, -20)]
: [cc.v2(-200, 180), cc.v2(220, 180), cc.v2(0, -100)];
// 以 Lose 的按钮位置为基准,兼容暂停面板 Health 容器的偏移。
const offsetY = panel.getChildByName("timeBtn").y + 348.229;
visible.forEach((name, index) => {
const icon = panel.getChildByName(name);
icon.setPosition(positions[index].x, positions[index].y + offsetY);
icon.setScale((visible.length === 1 ? 320 : 280) / Math.max(icon.width, icon.height, 1));
});
// “仅体力”和兜底的“体力+连胜”均按约定使用 giveup1。
const titleIndex = hp ? (day ? (winStreak ? 3 : 2) : 1) : (day ? (winStreak ? 5 : 4) : 6);
const title = panel.getChildByName("result_title");
const sprite = title.getComponent(cc.Sprite);
sprite.sizeMode = cc.Sprite.SizeMode.RAW;
sprite.trim = false;
sprite.spriteFrame = frames[titleIndex - 1];
title.setContentSize(sprite.spriteFrame.getOriginalSize());
return true;
}