Add exit button to paue menu

This commit is contained in:
Mike Müller 2026-03-08 21:03:43 +01:00
parent ddf68f316e
commit 86ae86febc

View File

@ -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();
}