From 32192939fff4a66d2ccd8455e0656aeaf275f4ed Mon Sep 17 00:00:00 2001 From: Sendou Date: Thu, 9 Jan 2020 05:01:58 +0200 Subject: [PATCH] weaponselector component --- .../src/components/common/WpnImage.js | 10 +++- .../src/components/plans/MapPlanner.js | 48 +-------------- .../src/components/plans/WeaponSelector.js | 58 +++++++++++++++++++ 3 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 frontend-react/src/components/plans/WeaponSelector.js diff --git a/frontend-react/src/components/common/WpnImage.js b/frontend-react/src/components/common/WpnImage.js index 11ca084d8..24cc47b3f 100644 --- a/frontend-react/src/components/common/WpnImage.js +++ b/frontend-react/src/components/common/WpnImage.js @@ -4,9 +4,15 @@ import english_internal from "../../utils/english_internal.json" import { wpnSmall, wpnMedium } from "../../assets/imageImports" import { Image } from "semantic-ui-react" -const WpnImage = ({ weapon, size = "MEDIUM", style = {} }) => { +const WpnImage = ({ weapon, size = "MEDIUM", onClick = null, style = {} }) => { const dictToUse = size === "MEDIUM" ? wpnMedium : wpnSmall - return + return ( + + ) } export default WpnImage diff --git a/frontend-react/src/components/plans/MapPlanner.js b/frontend-react/src/components/plans/MapPlanner.js index 1ea3c53b5..45660d269 100644 --- a/frontend-react/src/components/plans/MapPlanner.js +++ b/frontend-react/src/components/plans/MapPlanner.js @@ -40,6 +40,7 @@ import warehouse from "../../assets/plannerMaps/warehouse-sz.png" import world from "../../assets/plannerMaps/world-sz.png" import { wpnMedium } from "../../assets/imageImports" import ToolsSelector from "./ToolsSelector" +import WeaponSelector from "./WeaponSelector" const MapPlanner = () => { let sketch = null @@ -72,7 +73,6 @@ const MapPlanner = () => { const fileInput = useRef(null) const [tool, setTool] = useState(Tools.Pencil) const [color, setColor] = useState("#f44336") - const [weapon, setWeapon] = useState("") const [canUndo, setCanUndo] = useState(false) const [canRedo, setCanRedo] = useState(false) const [text, setText] = useState("") @@ -93,39 +93,6 @@ const MapPlanner = () => { sketch.setBackgroundFromDataUrl(reef) }, [sketch]) - const tools = [ - { - key: 1, - text: "Pencil", - value: Tools.Pencil, - icon: "pencil", - }, - { - key: 2, - text: "Line", - value: Tools.Line, - icon: "window minimize outline", - }, - { - key: 3, - text: "Rectangle", - value: Tools.Rectangle, - icon: "square outline", - }, - { - key: 4, - text: "Circle", - value: Tools.Circle, - icon: "circle outline", - }, - { - key: 5, - text: "Select", - value: Tools.Select, - icon: "object group outline", - }, - ] - const maps = [ { key: "The Reef", text: "The Reef", value: reef }, { @@ -201,7 +168,7 @@ const MapPlanner = () => { }, ] - const addImageToSketch = () => { + const addImageToSketch = weapon => { sketch.addImg(wpnMedium[weaponDict[weapon]]) setTool(Tools.Select) } @@ -288,6 +255,7 @@ const MapPlanner = () => { return ( <> + addImageToSketch(weapon)} /> {containerWidth < 1127 && ( Unfortunately this tool isn't designed for narrow screens but you can @@ -382,16 +350,6 @@ const MapPlanner = () => { Please note that changing the map also clears all the drawings - -

Choose a weapon to add

- setWeapon(value)} - /> -
-
-
diff --git a/frontend-react/src/components/plans/WeaponSelector.js b/frontend-react/src/components/plans/WeaponSelector.js new file mode 100644 index 000000000..6cc264c20 --- /dev/null +++ b/frontend-react/src/components/plans/WeaponSelector.js @@ -0,0 +1,58 @@ +import React, { useState } from "react" +import Draggable from "react-draggable" +import { weapons } from "../../utils/lists" +import WpnImage from "../common/WpnImage" + +const WeaponSelector = ({ addWeaponImage }) => { + const [activeDrags, setActiveDrags] = useState(0) + + const onStart = () => { + setActiveDrags(activeDrags + 1) + } + + const onStop = () => { + setActiveDrags(activeDrags - 1) + } + + return ( + +
+ +
+ Weapons +
+
+
+ {weapons.map(wpn => ( + addWeaponImage(wpn)} + /> + ))} +
+
+
+ ) +} + +export default WeaponSelector