import { useContext } from 'react'; import useActiveControl, { GamepadButtonEvent } from '../scripts/gamepads'; import { GamePadButtonCode, Shortcut, useShortcutContext } from '../scripts/shortcuts'; import ShortcutPrompt from './ShortcutPrompt'; import { IconType } from './SvgIcon'; import { ShortcutsContext } from '../scripts/contexts'; export function FloatingShortcuts () { return
; } export default function Shortcuts (data: { centerElement?: any; }) { const iconMap: Record = { [GamePadButtonCode.A]: 'steamdeck_button_a', [GamePadButtonCode.B]: 'steamdeck_button_b', [GamePadButtonCode.X]: 'steamdeck_button_x', [GamePadButtonCode.Y]: 'steamdeck_button_y', [GamePadButtonCode.L1]: 'steamdeck_button_l1', [GamePadButtonCode.R1]: 'steamdeck_button_r1', [GamePadButtonCode.L2]: 'steamdeck_button_l2', [GamePadButtonCode.R2]: 'steamdeck_button_r2', [GamePadButtonCode.Select]: 'steamdeck_button_guide', [GamePadButtonCode.Start]: 'steamdeck_button_options', [GamePadButtonCode.LJoy]: 'steamdeck_stick_l_press', [GamePadButtonCode.RJoy]: 'steamdeck_stick_r_press', [GamePadButtonCode.Up]: 'steamdeck_dpad_up', [GamePadButtonCode.Down]: 'steamdeck_dpad_down', [GamePadButtonCode.Left]: 'steamdeck_dpad_left', [GamePadButtonCode.Right]: 'steamdeck_dpad_right', [GamePadButtonCode.Steam]: 'steamdeck_button_quickaccess' }; const keyboardMap: Record = { [GamePadButtonCode.A]: 'ENTER', [GamePadButtonCode.B]: 'ESC', [GamePadButtonCode.X]: 'BACKSPACE', [GamePadButtonCode.Y]: 'SPACE', [GamePadButtonCode.L1]: 'Q', [GamePadButtonCode.R1]: 'E', [GamePadButtonCode.L2]: '', [GamePadButtonCode.R2]: '', [GamePadButtonCode.Select]: '', [GamePadButtonCode.Start]: '', [GamePadButtonCode.LJoy]: '', [GamePadButtonCode.RJoy]: '', [GamePadButtonCode.Up]: '', [GamePadButtonCode.Down]: '', [GamePadButtonCode.Left]: '', [GamePadButtonCode.Right]: '', [GamePadButtonCode.Steam]: '' }; const { control } = useActiveControl(); const showKeyboard = control === 'keyboard' || control === 'mouse'; const { shortcuts } = useShortcutContext(); return ( <>
{shortcuts?.filter(s => !!s.label && s.side === 'left').map((s, i) => s.action?.(new GamepadButtonEvent('gamepadbuttondown', { button: s.button, isClick: true }))} icon={showKeyboard ? undefined : iconMap[s.button]} label={showKeyboard ? `${keyboardMap[s.button]} | ${s.label}` : s.label} /> )}
{data.centerElement}
{shortcuts?.filter(s => !!s.label && s.side !== 'left').map((s, i) => s.action?.(new GamepadButtonEvent('gamepadbuttondown', { button: s.button, isClick: true }))} icon={showKeyboard ? undefined : iconMap[s.button]} label={showKeyboard ? `${keyboardMap[s.button]} | ${s.label}` : s.label} /> )}
); }