Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | 2x 31x 31x 31x 31x 31x 31x 31x 18x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 31x 17x 17x 31x 31x 155x 250x 5x 15x | /**
* PauseMenu Component - Main pause menu overlay
*
* Features:
* - Resume combat
* - Restart match
* - View controls
* - Adjust settings
* - Return to menu (with confirmation)
* - Korean/English bilingual text
* - Cyberpunk Korean theming
* - Backdrop blur effect
* - WCAG 2.1 Level AA compliant
* - Keyboard navigation (Arrow keys, Enter, Escape)
* - Focus indicators with high contrast
* - ARIA labels for screen readers
*
* Refactored to use useKoreanTheme for consistent theming
*/
import React, { useCallback, useState, useEffect, useRef } from "react";
import { useAudio } from "../../../../../audio/AudioProvider";
import { useKoreanTheme } from "../../../../shared/base/useKoreanTheme";
import { hexToRgbaString } from "../../../../../utils/colorUtils";
import ConfirmDialog from "../../../../shared/ui/shared/ConfirmDialog";
import ControlsGuide from "./ControlsGuide";
import QuickSettings from "./QuickSettings";
import { handleKeyboardNav } from "../../../../../utils/accessibility";
import { createBilingualLabel } from "../../../../../types/AccessibilityTypes";
import { PauseMenuButton } from "./PauseMenuButton";
export interface PauseMenuProps {
readonly onResume: () => void;
readonly onRestart: () => void;
readonly onReturnToMenu: () => void;
readonly isMobile: boolean;
}
interface MenuItem {
readonly key: string;
readonly labelKorean: string;
readonly labelEnglish: string;
readonly testId: string;
readonly onClick: () => void;
readonly icon?: string;
}
/**
* PauseMenu - Main pause menu with options and submenus
*/
export const PauseMenu: React.FC<PauseMenuProps> = ({
onResume,
onRestart,
onReturnToMenu,
isMobile,
}) => {
const audio = useAudio();
const theme = useKoreanTheme({ variant: "primary", size: "lg", isMobile });
const [activeSubmenu, setActiveSubmenu] = useState<
"controls" | "settings" | null
>(null);
const [showConfirm, setShowConfirm] = useState<
"restart" | "menu" | null
>(null);
const [focusedIndex, setFocusedIndex] = useState<number>(0);
const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);
// Memoize menuItems to prevent recreation on every render
const menuItems: MenuItem[] = React.useMemo(
() => [
{
key: "resume",
labelKorean: "계속",
labelEnglish: "Resume",
testId: "pause-resume-button",
onClick: () => {
audio.playSFX("menu_select");
onResume();
},
icon: "▶️",
},
{
key: "restart",
labelKorean: "재시작",
labelEnglish: "Restart Match",
testId: "pause-restart-button",
onClick: () => {
audio.playSFX("menu_select");
setShowConfirm("restart");
},
icon: "🔄",
},
{
key: "controls",
labelKorean: "조작법",
labelEnglish: "Controls",
testId: "pause-controls-button",
onClick: () => {
audio.playSFX("menu_select");
setActiveSubmenu("controls");
},
icon: "🎮",
},
{
key: "settings",
labelKorean: "설정",
labelEnglish: "Settings",
testId: "pause-settings-button",
onClick: () => {
audio.playSFX("menu_select");
setActiveSubmenu("settings");
},
icon: "⚙️",
},
{
key: "menu",
labelKorean: "메인 메뉴",
labelEnglish: "Return to Menu",
testId: "pause-menu-button",
onClick: () => {
audio.playSFX("menu_select");
setShowConfirm("menu");
},
icon: "🏠",
},
],
[audio, onResume]
);
// Focus first button on mount
useEffect(() => {
Eif (buttonRefs.current[0]) {
buttonRefs.current[0].focus();
}
}, [menuItems]);
// Keyboard navigation handler
const handleKeyDown = useCallback(
(e: React.KeyboardEvent, index: number) => {
handleKeyboardNav(e.nativeEvent, {
onActivate: () => {
menuItems[index].onClick();
},
onCancel: () => {
onResume();
},
onNavigate: (direction) => {
if (direction === 'up') {
const newIndex = (index - 1 + menuItems.length) % menuItems.length;
setFocusedIndex(newIndex);
buttonRefs.current[newIndex]?.focus();
} else if (direction === 'down') {
const newIndex = (index + 1) % menuItems.length;
setFocusedIndex(newIndex);
buttonRefs.current[newIndex]?.focus();
}
},
});
},
[menuItems, onResume]
);
// ESC key handling is now managed by the parent (CombatScreen3D) to avoid conflicts
return (
<>
{/* Main Pause Menu */}
<div
data-testid="pause-menu"
role="dialog"
aria-modal="true"
aria-labelledby="pause-title"
aria-describedby="pause-hint"
style={{
position: "fixed",
top: 0,
left: 0,
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
backgroundColor: hexToRgbaString(theme.colors.BLACK_SOLID, 0.85),
backdropFilter: "blur(8px)",
zIndex: 1000,
pointerEvents: "auto",
}}
>
{/* Pause Title */}
<h1
id="pause-title"
data-testid="pause-title"
style={{
fontSize: isMobile ? "48px" : "72px",
color: hexToRgbaString(theme.colors.ACCENT_GOLD, 1),
fontFamily: theme.fontFamily.KOREAN,
fontWeight: "bold",
margin: `0 0 ${isMobile ? "40px" : "60px"} 0`,
textShadow: `0 0 30px ${hexToRgbaString(
theme.colors.ACCENT_GOLD,
0.6
)}`,
textAlign: "center",
}}
>
일시정지 | Paused
</h1>
{/* Menu Buttons */}
<div
role="menu"
aria-label={createBilingualLabel('일시정지 메뉴', 'Pause Menu').label}
style={{
display: "flex",
flexDirection: "column",
gap: isMobile ? "12px" : "16px",
minWidth: isMobile ? "280px" : "360px",
}}
>
{menuItems.map((item, index) => (
<PauseMenuButton
key={item.key}
ref={(el) => { buttonRefs.current[index] = el; }}
labelKorean={item.labelKorean}
labelEnglish={item.labelEnglish}
icon={item.icon}
onClick={item.onClick}
onMouseEnter={() => audio.playSFX("menu_hover")}
onKeyDown={(e) => handleKeyDown(e, index)}
onFocus={() => setFocusedIndex(index)}
isFocused={focusedIndex === index}
isMobile={isMobile}
testId={item.testId}
/>
))}
</div>
{/* ESC hint */}
<div
id="pause-hint"
data-testid="pause-hint"
style={{
marginTop: isMobile ? "40px" : "60px",
fontSize: isMobile ? "12px" : "14px",
color: hexToRgbaString(theme.colors.TEXT_SECONDARY, 0.8),
fontFamily: theme.fontFamily.KOREAN,
textAlign: "center",
}}
>
ESC 키를 눌러 계속 | Press ESC to resume
<br />
↑↓ 키로 이동 | Use ↑↓ to navigate
</div>
</div>
{/* Controls Guide Submenu */}
{activeSubmenu === "controls" && (
<ControlsGuide
onClose={() => {
setActiveSubmenu(null);
}}
isMobile={isMobile}
/>
)}
{/* Settings Submenu */}
{activeSubmenu === "settings" && (
<QuickSettings
onClose={() => {
setActiveSubmenu(null);
}}
isMobile={isMobile}
/>
)}
{/* Restart Confirmation Dialog */}
{showConfirm === "restart" && (
<ConfirmDialog
isOpen={true}
title="Restart Match?"
titleKorean="경기를 재시작하시겠습니까?"
message="All progress in the current match will be lost."
messageKorean="현재 경기의 모든 진행 상황이 초기화됩니다."
onConfirm={() => {
setShowConfirm(null);
onRestart();
}}
onCancel={() => {
setShowConfirm(null);
}}
isMobile={isMobile}
/>
)}
{/* Return to Menu Confirmation Dialog */}
{showConfirm === "menu" && (
<ConfirmDialog
isOpen={true}
title="Return to Menu?"
titleKorean="메인 메뉴로 돌아가시겠습니까?"
message="All progress in the current match will be lost."
messageKorean="현재 경기의 모든 진행 상황이 손실됩니다."
onConfirm={() => {
setShowConfirm(null);
onReturnToMenu();
}}
onCancel={() => {
setShowConfirm(null);
}}
isMobile={isMobile}
/>
)}
</>
);
};
export default PauseMenu;
|