All files / blacktrigram/src/components/screens ControlsScreen.tsx

0% Statements 0/148
0% Branches 0/1
0% Functions 0/1
0% Lines 0/148

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                                                                                                                                                                                                                                                                                                                                                         
import "@pixi/layout";
import { extend } from "@pixi/react";
import { Container, FillGradient } from "pixi.js";
import React, { useEffect, useMemo } from "react";
import { KOREAN_COLORS } from "../../types/constants";
import { ControlsSection } from "./ControlsSection";
 
extend({ Container });
 
export interface ControlsScreenProps {
  readonly onReturnToMenu: () => void;
  readonly width?: number;
  readonly height?: number;
}
 
export const ControlsScreen: React.FC<ControlsScreenProps> = ({
  onReturnToMenu,
  width = 1200,
  height = 800,
}) => {
  const isMobile = useMemo(() => width < 768, [width]);
  const layoutConstants = useMemo(
    () => ({
      padding: isMobile ? 10 : 20,
      headerHeight: isMobile ? 50 : 60,
      footerHeight: isMobile ? 40 : 50,
    }),
    [isMobile]
  );
 
  // Enhanced keyboard handling for screen-level navigation
  useEffect(() => {
    const handleKeyDown = (event: KeyboardEvent) => {
      if (event.key === "Escape" || event.key.toLowerCase() === "m") {
        event.preventDefault();
        onReturnToMenu();
      }
    };
 
    window.addEventListener("keydown", handleKeyDown, { passive: false });
    return () => window.removeEventListener("keydown", handleKeyDown);
  }, [onReturnToMenu]);
 
  return (
    <pixiContainer
      width={width}
      height={height}
      data-testid="controls-screen"
      layout={{
        width,
        height,
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "flex-start",
        padding: 0,
      }}
    >
      <pixiGraphics
        draw={(g) => {
          g.clear();
          const gradient = new FillGradient(0, 0, width, height);
          gradient.addColorStop(0, 0x0a0a0f);
          gradient.addColorStop(0.5, 0x1a1a2e);
          gradient.addColorStop(1, 0x0f0f23);
          g.fill(gradient);
          g.rect(0, 0, width, height);
          g.fill();
 
          // Cyberpunk grid overlay
          g.stroke({
            width: 1,
            color: KOREAN_COLORS.PRIMARY_CYAN,
            alpha: 0.15,
          });
          const gridSize = isMobile ? 40 : 60;
          for (let i = 0; i < width; i += gridSize) {
            g.moveTo(i, 0);
            g.lineTo(i, height);
          }
          for (let i = 0; i < height; i += gridSize) {
            g.moveTo(0, i);
            g.lineTo(width, i);
          }
          g.stroke();
        }}
        layout={{
          position: "absolute",
          top: 0,
          left: 0,
          width: "100%",
          height: "100%",
        }}
        data-testid="controls-background"
      />
 
      <pixiContainer
        layout={{
          width: "100%",
          height: layoutConstants.headerHeight,
          alignItems: "center",
          justifyContent: "center",
          flexShrink: 0,
        }}
        data-testid="controls-header"
      >
        <pixiText
          text="조작법 안내 - Controls Guide"
          style={{
            fontSize: isMobile ? 16 : 20,
            fill: KOREAN_COLORS.ACCENT_GOLD,
            fontWeight: "bold",
            fontFamily: "Noto Sans KR",
            align: "center",
          }}
          anchor={0.5}
          x={width / 2}
          y={layoutConstants.headerHeight / 2}
        />
      </pixiContainer>
 
      <pixiContainer
        layout={{
          width: "100%",
          flexGrow: 1,
          flexDirection: "column",
          alignItems: "center",
          justifyContent: "center",
          padding: layoutConstants.padding,
        }}
      >
        <ControlsSection
          onBack={onReturnToMenu}
          x={0}
          y={0}
          width={width - layoutConstants.padding * 2}
          height={
            height -
            layoutConstants.headerHeight -
            layoutConstants.footerHeight -
            layoutConstants.padding * 2
          }
        />
      </pixiContainer>
 
      <pixiContainer
        layout={{
          width: "100%",
          height: layoutConstants.footerHeight,
          alignItems: "center",
          justifyContent: "center",
          flexShrink: 0,
        }}
        data-testid="controls-footer"
      >
        <pixiText
          text="ESC 또는 M 키로 메뉴로 돌아가기 - Press ESC or M to return to menu"
          style={{
            fontSize: isMobile ? 10 : 12,
            fill: KOREAN_COLORS.TEXT_SECONDARY,
            fontStyle: "italic",
            align: "center",
          }}
          anchor={0.5}
          x={width / 2}
          y={layoutConstants.footerHeight / 2}
        />
      </pixiContainer>
    </pixiContainer>
  );
};
 
export default ControlsScreen;