From 86ae86febcd3371775121ec376962fc2efd3ad57 Mon Sep 17 00:00:00 2001 From: Mike Mueller Date: Sun, 8 Mar 2026 21:03:43 +0100 Subject: [PATCH] Add exit button to paue menu --- src/game.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/game.js b/src/game.js index e986036..be13e21 100644 --- a/src/game.js +++ b/src/game.js @@ -435,6 +435,7 @@ function getMenuItems() { { id: "resume", label: "Resume Match" }, { id: "music", label: `Music: ${audio && audio.isMusicEnabled() ? "On" : "Off"}` }, { id: "restart", label: "Restart Round" }, + { id: "exitSingle", label: "Exit To Main Menu" }, ]; } @@ -507,6 +508,11 @@ function activateMenuSelection() { return; } + if (item.id === "exitSingle") { + leaveSinglePlayerToMainMenu(); + return; + } + if (item.id === "leaveMatch") { closeMenu(); leaveMultiplayerToMainMenu(); @@ -877,6 +883,16 @@ function leaveMultiplayerToMainMenu() { state.message = "Select mode"; } +function leaveSinglePlayerToMainMenu() { + closeMenu(); + inputState.bombQueued = false; + inputState.bombHeld = false; + state.mode = "single"; + state.screen = "mainMenu"; + state.status = "idle"; + state.message = "Select mode"; +} + function hostStartMatchFromLobby() { if (!network.isHost || network.lobbyPhase !== "lobby" || network.lobbyPlayers.length < 2) { return; @@ -2087,8 +2103,12 @@ function drawMenu() { } const items = getMenuItems(); + const hasOutcome = state.status === "ended"; const panelWidth = 340; - const panelHeight = 220; + const itemsStartOffset = hasOutcome ? 102 : 90; + const itemStep = 34; + const footerOffset = itemsStartOffset + items.length * itemStep + 14; + const panelHeight = Math.max(220, footerOffset + 24); const panelX = (canvas.width - panelWidth) / 2; const panelY = (canvas.height - panelHeight) / 2; @@ -2117,22 +2137,22 @@ function drawMenu() { ctx.fillText(state.message, canvas.width / 2, panelY + 70); } - const baseY = state.status === "ended" ? panelY + 102 : panelY + 92; + const baseY = panelY + itemsStartOffset; items.forEach((item, index) => { - const y = baseY + index * 36; + const y = baseY + index * itemStep; const selected = index === state.menu.selectedIndex; if (selected) { ctx.fillStyle = "#ffd166"; - ctx.fillRect(panelX + 36, y - 20, panelWidth - 72, 28); + ctx.fillRect(panelX + 36, y - 18, panelWidth - 72, 26); } ctx.fillStyle = selected ? "#1a2a3f" : "#e7f4ff"; - ctx.font = "bold 19px Trebuchet MS"; + ctx.font = "bold 18px Trebuchet MS"; ctx.fillText(item.label, canvas.width / 2, y); }); ctx.fillStyle = "#9ecdf0"; ctx.font = "bold 13px Trebuchet MS"; - ctx.fillText("Up/Down + Enter | D-pad Up/Down + A", canvas.width / 2, panelY + panelHeight - 26); + ctx.fillText("Up/Down + Enter | D-pad Up/Down + A", canvas.width / 2, panelY + footerOffset); ctx.restore(); }