import * as Phaser from "phaser"; // import { DOWNLOAD_BUTTON_URL } from '../../DebugConfig'; /** 游戏结束面板的配置选项 */ export interface GameOverPanelConfig { type: "win" | "lose"; // 'win' 使用 win_panel, 'lose' 使用 lose_panel onClose?: () => void; } /** * 游戏结束面板组件。 * 显示胜利或失败的全屏面板,包含半透明遮罩和结果图片。 */ export class GameOverPanel extends Phaser.GameObjects.Container { private readonly config: GameOverPanelConfig; constructor(scene: Phaser.Scene, config: GameOverPanelConfig) { super(scene); this.config = config; scene.add.existing(this); // Ensure the game-over panel renders above ALL other UI (GameTopUI=500, nomoveHint=1600, back=1702) this.setDepth(2000); this.setScrollFactor(0); // 半透明黑色背景遮罩 const { width: gameWidth, height: gameHeight } = scene.scale; const overlay = scene.add.rectangle( 0, 0, gameWidth, gameHeight, 0x000000, 0.7, ); overlay.setOrigin(0, 0); this.add(overlay); // 根据类型选择图片 const imageKey = config.type === "win" ? "win_panel" : "lose_panel"; const gameOverImage = scene.add.image( gameWidth / 2, gameHeight / 2, imageKey, ); // 根据屏幕大小自适应缩放图片 const maxWidth = gameWidth * 0.8; const maxHeight = gameHeight * 0.6; const scaleX = maxWidth / gameOverImage.width; const scaleY = maxHeight / gameOverImage.height; const scale = Math.min(scaleX, scaleY, 1); // 不放大,只缩小 gameOverImage.setScale(scale); this.add(gameOverImage); // 点击任意位置跳转到下载链接 overlay.setInteractive({ useHandCursor: true }); overlay.on("pointerup", () => { this.handleClick(); }); // 也可以点击图片跳转 gameOverImage.setInteractive({ useHandCursor: true }); gameOverImage.on("pointerup", () => { this.handleClick(); }); } /** 处理点击事件,触发关闭回调。 */ private handleClick() { this.config.onClose?.(); } }