import { Grid } from "@styled-icons/boxicons-regular/Grid"; import { Pause } from "@styled-icons/fa-solid"; import { ArrowsAlt } from "@styled-icons/fa-solid/ArrowsAlt"; import { ArrowsAltV } from "@styled-icons/fa-solid/ArrowsAltV"; import { Bars } from "@styled-icons/fa-solid/Bars"; import { Bullseye } from "@styled-icons/fa-solid/Bullseye"; import { Globe } from "@styled-icons/fa-solid/Globe"; import { Magnet } from "@styled-icons/fa-solid/Magnet"; import { Play } from "@styled-icons/fa-solid/Play"; import { SyncAlt } from "@styled-icons/fa-solid/SyncAlt"; import PropTypes from "prop-types"; import React, { Component } from "react"; import styled from "styled-components"; import { TransformSpace } from "@xr3ngine/engine/src/editor/constants/TransformSpace"; import { SnapMode, TransformMode, TransformPivot } from "@xr3ngine/engine/src/editor/controls/EditorControls"; import { Button } from "../inputs/Button"; import NumericStepperInput from "../inputs/NumericStepperInput"; import SelectInput from "../inputs/SelectInput"; import { ContextMenu, MenuItem, showMenu, SubMenu } from "../layout/ContextMenu"; import { InfoTooltip } from "../layout/Tooltip"; import styledTheme from "../theme"; import ToolButton from "./ToolButton"; import LocationModal from '../../../../admin/components/LocationModal'; /** * * @author Robert Long */ const StyledToolbar = (styled as any).div` display: flex; flex-direction: row; height: 40px; background-color: ${props => props.theme.toolbar}; user-select: none; `; /** * * @author Robert Long */ const ToolButtons = (styled as any).div` width: auto; height: inherit; display: flex; flex-direction: row; `; /** * * @author Robert Long */ const ToolToggles = (styled as any).div` width: auto; height: inherit; display: flex; flex-direction: row; background-color: ${props => props.theme.toolbar2}; align-items: center; padding: 0 16px; `; /** * * @author Robert Long */ const Spacer = (styled as any).div` flex: 1; `; /** * * @author Robert Long */ const PublishButton = (styled as any)(Button)` align-self: center; margin: 1em; padding: 0 2em; `; /** * * @author Robert Long */ const snapInputStyles = { container: base => ({ ...base, width: "80px" }), control: base => ({ ...base, backgroundColor: styledTheme.inputBackground, minHeight: "24px", borderRadius: "0px", borderWidth: "0px", cursor: "pointer", outline: "none", boxShadow: "none" }) }; /** * * @author Robert Long */ const rightSnapInputStyles = { container: base => ({ ...base, width: "80px" }), control: base => ({ ...base, backgroundColor: styledTheme.inputBackground, minHeight: "24px", borderTopLeftRadius: "0px", borderBottomLeftRadius: "0px", borderWidth: "0px 0px 0px 1px", borderColor: styledTheme.border, cursor: "pointer", outline: "none", boxShadow: "none", ":hover": { borderColor: styledTheme.border } }) }; /** * * @author Robert Long */ const selectInputStyles = { container: base => ({ ...base, width: "100px" }), control: base => ({ ...base, backgroundColor: styledTheme.inputBackground, minHeight: "24px", borderTopLeftRadius: "0px", borderBottomLeftRadius: "0px", borderWidth: "0px", cursor: "pointer", outline: "none", boxShadow: "none" }) }; /** * * @author Robert Long */ const StyledToggleButton = (styled as any).div` display: flex; justify-content: center; align-items: center; width: 24px; height: 24px; background-color: ${props => (props.value ? props.theme.blue : props.theme.toolbar)}; border-top-left-radius: 4px; border-bottom-left-radius: 4px; :hover { background-color: ${props => props.theme.blueHover}; } :active { background-color: ${props => props.theme.blue}; } `; /** * * @author Robert Long * @param {any} tooltip * @param {any} children * @param {any} rest * @returns */ function ToggleButton({ tooltip, children, ...rest }) { return ( {children} ); } ToggleButton.propTypes = { tooltip: PropTypes.string, children: PropTypes.node }; /** * * @author Robert Long */ const ToolbarInputGroup = (styled as any).div` display: flex; align-items: center; border: 1px solid ${props => props.theme.border}; border-radius: 4px; margin: 0 4px; `; /** * * @author Robert Long */ const ToolbarNumericStepperInput = (styled as any)(NumericStepperInput)` width: 100px; input { border-width: 0; } button { border-width: 0px 1px 0px 1px; &:first-child { border-radius: 0; } &:last-child { border-right-width: 0; } } `; /** * * @author Robert Long */ const translationSnapOptions = [ { label: "0.1m", value: 0.1 }, { label: "0.125m", value: 0.125 }, { label: "0.25m", value: 0.25 }, { label: "0.5m", value: 0.5 }, { label: "1m", value: 1 }, { label: "2m", value: 2 }, { label: "4m", value: 4 } ]; /** * * @author Robert Long */ const rotationSnapOptions = [ { label: "1°", value: 1 }, { label: "5°", value: 5 }, { label: "10°", value: 10 }, { label: "15°", value: 15 }, { label: "30°", value: 30 }, { label: "45°", value: 45 }, { label: "90°", value: 90 } ]; /** * * @author Robert Long */ const transformPivotOptions = [ { label: "Selection", value: TransformPivot.Selection }, { label: "Center", value: TransformPivot.Center }, { label: "Bottom", value: TransformPivot.Bottom } ]; /** * * @author Robert Long */ const transformSpaceOptions = [ { label: "Selection", value: TransformSpace.LocalSelection }, { label: "World", value: TransformSpace.World } ]; /** * * @author Robert Long */ const initialLocation = { id: null, name: "", maxUsersPerInstance: 10, sceneId: null, locationSettingsId: null, location_setting: { instanceMediaChatEnabled: false, videoEnabled: false, locationType: 'private' } }; type ToolBarProps = { } /** * * @author Robert Long */ type ToolBarState = { locationModalOpen: any; selectedLocation: any; editorInitialized: boolean; menuOpen: boolean; locationEditing: boolean } /** * * @author Robert Long */ export class ToolBar extends Component { static propTypes = { menu: PropTypes.array, editor: PropTypes.object, onPublish: PropTypes.func, onOpenScene: PropTypes.func, isPublishedScene: PropTypes.bool, queryParams: PropTypes.object, }; constructor(props) { super(props); this.state = { editorInitialized: false, menuOpen: false, locationModalOpen: false, selectedLocation: initialLocation, locationEditing: false }; } componentDidMount() { const editor = (this.props as any).editor; editor.addListener("initialized", this.onEditorInitialized); editor.addListener("playModeChanged", this.onForceUpdate); editor.addListener("settingsChanged", this.onForceUpdate); } componentWillUnmount() { const editor = (this.props as any).editor; editor.removeListener("initialized", this.onEditorInitialized); if (editor.editorControls) { editor.editorControls.removeListener("transformModeChanged", this.onForceUpdate); editor.editorControls.removeListener("transformSpaceChanged", this.onForceUpdate); editor.editorControls.removeListener("transformPivotChanged", this.onForceUpdate); editor.editorControls.removeListener("snapSettingsChanged", this.onForceUpdate); editor.removeListener("gridHeightChanged", this.onForceUpdate); editor.removeListener("gridVisibilityChanged", this.onForceUpdate); editor.removeListener("playModeChanged", this.onForceUpdate); editor.removeListener("settingsChanged", this.onForceUpdate); } } openModalCreate = () => { this.setState({ locationModalOpen: true }); } handleLocationClose = (e: any): void => { this.setState({ locationModalOpen: false }); } onEditorInitialized = () => { const editor = (this.props as any).editor; editor.editorControls.addListener("transformModeChanged", this.onForceUpdate); editor.editorControls.addListener("transformSpaceChanged", this.onForceUpdate); editor.editorControls.addListener("transformPivotChanged", this.onForceUpdate); editor.editorControls.addListener("snapSettingsChanged", this.onForceUpdate); editor.addListener("gridHeightChanged", this.onForceUpdate); editor.addListener("gridVisibilityChanged", this.onForceUpdate); this.setState({ editorInitialized: true }); }; onForceUpdate = () => { this.forceUpdate(); }; onMenuSelected = e => { if (!(this.state as any).menuOpen) { const x = 0; const y = e.currentTarget.offsetHeight; showMenu({ position: { x, y }, target: e.currentTarget, id: "menu" }); this.setState({ menuOpen: true }); window.addEventListener("mousedown", this.onWindowClick); } }; onWindowClick = () => { window.removeEventListener("mousedown", this.onWindowClick); this.setState({ menuOpen: false }); }; renderMenu = menu => { if (!menu.items || menu.items.length === 0) { return ( {menu.name} {menu.hotkey &&
{menu.hotkey}
}
); } else { return ( {menu.items.map(item => { return this.renderMenu(item); })} ); } }; onSelectTranslate = () => { (this.props as any).editor.editorControls.setTransformMode(TransformMode.Translate); }; onSelectRotate = () => { (this.props as any).editor.editorControls.setTransformMode(TransformMode.Rotate); }; onSelectScale = () => { (this.props as any).editor.editorControls.setTransformMode(TransformMode.Scale); }; onToggleTransformSpace = () => { (this.props as any).editor.editorControls.toggleTransformSpace(); }; onChangeTransformPivot = transformPivot => { (this.props as any).editor.editorControls.setTransformPivot(transformPivot); }; onToggleTransformPivot = () => { (this.props as any).editor.editorControls.changeTransformPivot(); }; onToggleSnapMode = () => { (this.props as any).editor.editorControls.toggleSnapMode(); }; onChangeTranslationSnap = translationSnap => { (this.props as any).editor.editorControls.setTranslationSnap(parseFloat(translationSnap)); (this.props as any).editor.editorControls.setSnapMode(SnapMode.Grid); }; onChangeScaleSnap = scaleSnap => { (this.props as any).editor.editorControls.setScaleSnap(scaleSnap); }; onChangeRotationSnap = rotationSnap => { (this.props as any).editor.editorControls.setRotationSnap(parseFloat(rotationSnap)); (this.props as any).editor.editorControls.setSnapMode(SnapMode.Grid); }; onChangeGridHeight = value => { (this.props as any).editor.setGridHeight(value); }; onToggleGridVisible = () => { (this.props as any).editor.toggleGridVisible(); }; onTogglePlayMode = () => { if ((this.props as any).editor.playing) { (this.props as any).editor.leavePlayMode(); } else { (this.props as any).editor.enterPlayMode(); } }; render() { const { editorInitialized, menuOpen } = this.state as any; if (!editorInitialized) { return ; } const { transformMode, transformSpace, transformPivot, snapMode, translationSnap, rotationSnap } = (this.props as any).editor.editorControls; const queryParams = (this.props as any).queryParams; //@ts-ignore const button = ; return ( { /* @ts-ignore */} { /* @ts-ignore */} { /* @ts-ignore */} { /* @ts-ignore */} "Custom: " + value + "m"} isValidNewOption={value => value.trim() !== "" && !isNaN(value)} creatable /> { /* @ts-ignore */} "Custom: " + value + "°"} isValidNewOption={value => value.trim() !== "" && !isNaN(value)} creatable /> {(this.props as any).editor.playing ? : } { !queryParams ? button : } {(this.props as any).menu.map(menu => { return this.renderMenu(menu); })} ); } } export default ToolBar;