From f1148e1d0734b4ad0ba53ebe65c2b96c7cffa76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20=C4=8Carapi=C4=87?= Date: Mon, 10 Feb 2025 16:50:26 +0100 Subject: [PATCH] Pause menu --- src/classes/gui/GamePausedDialog.ts | 57 +++++++++++++++++++++++++++++ src/scenes/Game.ts | 4 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/classes/gui/GamePausedDialog.ts diff --git a/src/classes/gui/GamePausedDialog.ts b/src/classes/gui/GamePausedDialog.ts new file mode 100644 index 0000000..76c0e19 --- /dev/null +++ b/src/classes/gui/GamePausedDialog.ts @@ -0,0 +1,57 @@ +import * as PIXI from 'pixi.js'; +import ModalDialogBase from './ModalDialog'; +import Button, { ButtonTexture } from './Button'; +import { Engine } from '../Bastion'; +import { MissionPickerScene } from '../../scenes/MissionPicker'; +import { GameScene } from '../../scenes/Game'; +import KeyboardManager from '../game/KeyboardManager'; + +export default class GamePausedDialog extends ModalDialogBase { + private btnMainMenu: Button; + private btnRetry: Button; + private btnContinue: Button; + private _unsubKeypress: () => void; + + constructor() { + super([]); + this._unsubKeypress = KeyboardManager.onKeyPressed(this.onContinueClick.bind(this)); + } + + protected override createContent(): PIXI.Container { + const container = new PIXI.Container(); + this.btnMainMenu = new Button(new PIXI.Rectangle(0, 0, 300, 60), 'Main Menu', ButtonTexture.Button01); + this.btnMainMenu.onClick = this.onMainMenuClick.bind(this); + container.addChild(this.btnMainMenu.container); + this.btnRetry = new Button(new PIXI.Rectangle(0, 70, 300, 60), 'Retry', ButtonTexture.Button01); + this.btnRetry.onClick = this.onRetryClick.bind(this); + container.addChild(this.btnRetry.container); + + this.btnContinue = new Button(new PIXI.Rectangle(0, 140, 300, 60), 'Continue', ButtonTexture.Button01); + this.btnContinue.onClick = this.onContinueClick.bind(this); + container.addChild(this.btnContinue.container); + + return container; + } + + private onMainMenuClick(): void { + this.close(); + this._unsubKeypress(); + Engine.GameScene.destroy(); + Engine.GameMaster.changeScene(new MissionPickerScene()); + } + + private onRetryClick(): void { + const missionName = Engine.GameScene.mission.name; + this.close(); + this._unsubKeypress(); + Engine.GameScene.destroy(); + Engine.GameMaster.changeScene(new MissionPickerScene()); + Engine.GameMaster.changeScene(new GameScene(missionName)); + Engine.NotificationManager.Notify('Retrying mission.', 'green'); + } + + private onContinueClick(): void { + this.close(); + Engine.GameScene.UnpauseGame(); + } +} diff --git a/src/scenes/Game.ts b/src/scenes/Game.ts index a1997a8..9207865 100644 --- a/src/scenes/Game.ts +++ b/src/scenes/Game.ts @@ -18,6 +18,7 @@ import TowerPanel, { VisualGemSlot } from '../classes/gui/TowerPanel'; import Gem from '../classes/game/Gem'; import EndGameDialog from '../classes/gui/EndGameDialog'; import HighScoreDialog, { HighScoreDialogButtons } from '../classes/gui/HighScoreDialog'; +import GamePausedDialog from '../classes/gui/GamePausedDialog'; enum RoundMode { Purchase = 0, @@ -289,7 +290,8 @@ export class GameScene extends Scene { this.ticker.start(); } public ShowPauseDialog() { - console.warn("Pause dialog doesn't exist."); + const gamePausedDialog = new GamePausedDialog(); + gamePausedDialog.show(); } private async ShowEndgameDialog(lost) {