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 | import React, { useCallback, useEffect, useMemo } from "react"; import { SelectIcon, BrickIcon, EraserIcon, PlusIcon, PaintIcon, ListIcon, } from "ui/icons/Icons"; import { MenuItem } from "ui/menu/Menu"; import l10n from "shared/lib/lang/l10n"; import { Tool } from "store/features/editor/editorState"; import editorActions from "store/features/editor/editorActions"; import styled from "styled-components"; import { Button } from "ui/buttons/Button"; import { FloatingPanel, FloatingPanelDivider } from "ui/panels/FloatingPanel"; import { DropdownButton } from "ui/buttons/DropdownButton"; import { useAppDispatch, useAppSelector } from "store/hooks"; import settingsActions from "store/features/settings/settingsActions"; import { NAVIGATOR_MIN_WIDTH } from "consts"; interface ToolPickerProps { hasFocusForKeyboardShortcuts: () => boolean; } const Wrapper = styled(FloatingPanel)` position: absolute; left: 10px; top: 10px; `; const ToolPicker = ({ hasFocusForKeyboardShortcuts }: ToolPickerProps) => { const dispatch = useAppDispatch(); const selected = useAppSelector((state) => state.editor.tool); const isAddSelected = useMemo(() => { return ["actors", "triggers", "scene"].indexOf(selected) > -1; }, [selected]); const showNavigator = useAppSelector( (state) => state.project.present.settings.showNavigator ); const setTool = useCallback( (tool: Tool) => { dispatch(editorActions.setTool({ tool })); }, [dispatch] ); const onKeyDown = useCallback( (e: KeyboardEvent) => { Iif (e.ctrlKey || e.shiftKey || e.metaKey) { return; } Iif (!hasFocusForKeyboardShortcuts()) { return; } if (e.code === "KeyT") { setTool("triggers"); } else if (e.code === "KeyA") { setTool("actors"); } else if (e.code === "KeyC") { setTool("collisions"); } else if (e.code === "KeyZ") { setTool("colors"); } else if (e.code === "KeyS") { setTool("scene"); } else if (e.code === "KeyE") { setTool("eraser"); } else if (e.code === "KeyV") { setTool("select"); } else Iif (e.code === "Escape") { setTool("select"); } }, [hasFocusForKeyboardShortcuts, setTool] ); useEffect(() => { window.addEventListener("keydown", onKeyDown); return () => { window.removeEventListener("keydown", onKeyDown); }; }, [onKeyDown]); const setToolActors = useCallback( (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => { e.stopPropagation(); setTool("actors"); }, [setTool] ); const setToolTriggers = useCallback( (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => { e.stopPropagation(); setTool("triggers"); }, [setTool] ); const setToolScene = useCallback( (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => { e.stopPropagation(); setTool("scene"); }, [setTool] ); const setToolSelect = useCallback( (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => { e.preventDefault(); e.stopPropagation(); setTool("select"); }, [setTool] ); const setToolEraser = useCallback(() => setTool("eraser"), [setTool]); const setToolCollisions = useCallback(() => setTool("collisions"), [setTool]); const setToolColors = useCallback(() => setTool("colors"), [setTool]); const enableNavigator = useCallback(() => { dispatch(editorActions.resizeNavigatorSidebar(NAVIGATOR_MIN_WIDTH)); dispatch( settingsActions.editSettings({ showNavigator: true, }) ); }, [dispatch]); return ( <Wrapper vertical> <Button variant="transparent" onClick={setToolSelect} title={`${l10n("TOOL_SELECT_LABEL")} (v)`} active={selected === "select"} > <SelectIcon /> </Button> <DropdownButton size="small" variant="transparent" menuDirection="left" offsetX={23} offsetY={-13} showArrow={false} label={<PlusIcon />} active={isAddSelected} > <MenuItem onClick={setToolActors} title={`${l10n("TOOL_ADD_ACTOR_LABEL")} (a)`} > {l10n("ACTOR")} </MenuItem> <MenuItem onClick={setToolTriggers} title={`${l10n("TOOL_ADD_TRIGGER_LABEL")} (t)`} > {l10n("TRIGGER")} </MenuItem> <MenuItem onClick={setToolScene} title={`${l10n("TOOL_ADD_SCENE_LABEL")} (s)`} > {l10n("SCENE")} </MenuItem> </DropdownButton> <Button variant="transparent" onClick={setToolEraser} title={`${l10n("TOOL_ERASER_LABEL")} (e)`} active={selected === "eraser"} > <EraserIcon /> </Button> <Button variant="transparent" onClick={setToolCollisions} title={`${l10n("TOOL_COLLISIONS_LABEL")} (c)`} active={selected === "collisions"} > <BrickIcon /> </Button> <Button variant="transparent" onClick={setToolColors} title={`${l10n("TOOL_COLORS_LABEL")} (z)`} active={selected === "colors"} > <PaintIcon /> </Button> {!showNavigator && ( <> <FloatingPanelDivider /> <Button variant="transparent" onClick={enableNavigator} title={l10n("MENU_SHOW_NAVIGATOR")} > <ListIcon /> </Button> </> )} </Wrapper> ); }; export default ToolPicker; |