/** * @file contains the navigation bars of the app. */ import * as React from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faDownload, faUpload, faEraser, faBook, faBookOpen, faGlobe, faHome, faArrowRight, faArrowLeft, faXmark, faBars, faCode, faCircleInfo, faTerminal, faMobileScreenButton, faDesktop, faGear } from '@fortawesome/free-solid-svg-icons' import { GameIdContext } from "../app" import { InputModeContext, PreferencesContext, WorldLevelIdContext } from "./infoview/context" import { GameInfo, useGetGameInfoQuery } from '../state/api' import { changedOpenedIntro, selectCompleted, selectDifficulty, selectProgress } from '../state/progress' import { useAppDispatch, useAppSelector } from '../hooks' import { Button } from './button' import { downloadProgress } from './popup/erase' /** navigation buttons for mobile welcome page to switch between intro/tree/inventory. */ function MobileNavButtons({pageNumber, setPageNumber}: { pageNumber: number, setPageNumber: any}) { const gameId = React.useContext(GameIdContext) const dispatch = useAppDispatch() // if `prevText` or `prevIcon` is set, show a button to go back let prevText = {0: null, 1: "Intro", 2: null}[pageNumber] let prevIcon = {0: null, 1: null, 2: faBookOpen}[pageNumber] let prevTitle = {0: null, 1: "Game Introduction", 2: "World selection"}[pageNumber] // if `nextText` or `nextIcon` is set, show a button to go forward let nextText = {0: "Start", 1: null, 2: null}[pageNumber] let nextIcon = {0: null, 1: faBook, 2: null}[pageNumber] let nextTitle = {0: "World selection", 1: "Inventory", 2: null}[pageNumber] return <> {(prevText || prevIcon) && } {(nextText || nextIcon) && } } /** button to toggle dropdown menu. */ function MenuButton({navOpen, setNavOpen}) { return } /** button to go one level futher. * for the last level, this button turns into a button going back to the welcome page. */ function NextButton({worldSize, difficulty, completed, setNavOpen}) { const gameId = React.useContext(GameIdContext) const {worldId, levelId} = React.useContext(WorldLevelIdContext) return (levelId < worldSize ? : ) } /** button to go one level back. * only renders if the current level id is > 0. */ function PreviousButton({setNavOpen}) { const gameId = React.useContext(GameIdContext) const {worldId, levelId} = React.useContext(WorldLevelIdContext) return (levelId > 0 && <> ) } /** button to toggle between editor and typewriter */ function InputModeButton({setNavOpen, isDropdown}) { const {levelId} = React.useContext(WorldLevelIdContext) const {typewriterMode, setTypewriterMode, lockInputMode} = React.useContext(InputModeContext) /** toggle input mode if allowed */ function toggleInputMode(ev: React.MouseEvent) { if (!lockInputMode){ setTypewriterMode(!typewriterMode) setNavOpen(false) } } return } /** button to toggle iimpressum popup */ function ImpressumButton({setNavOpen, toggleImpressum, isDropdown}) { return } /** button to go back to welcome page */ function HomeButton({isDropdown}) { const gameId = React.useContext(GameIdContext) return } /** button in mobile level to toggle inventory. * only displays a button if `setPageNumber` is set. */ function InventoryButton({pageNumber, setPageNumber}) { return (setPageNumber && ) } /** the navigation bar on the welcome page */ export function WelcomeAppBar({pageNumber, setPageNumber, gameInfo, toggleImpressum, toggleEraseMenu, toggleUploadMenu, toggleInfo, togglePreferencesPopup} : { pageNumber: number, setPageNumber: any, gameInfo: GameInfo, toggleImpressum: any, toggleEraseMenu: any, toggleUploadMenu: any, toggleInfo: any, togglePreferencesPopup: () => void; }) { const gameId = React.useContext(GameIdContext) const gameProgress = useAppSelector(selectProgress(gameId)) const {mobile} = React.useContext(PreferencesContext) const [navOpen, setNavOpen] = React.useState(false) return
{!mobile && {gameInfo?.title}}
{mobile && }
} /** the navigation bar in a level */ export function LevelAppBar({isLoading, levelTitle, toggleImpressum, pageNumber=undefined, setPageNumber=undefined} : { isLoading: boolean, levelTitle: string, toggleImpressum: any, pageNumber?: number, setPageNumber?: any, }) { const gameId = React.useContext(GameIdContext) const {worldId, levelId} = React.useContext(WorldLevelIdContext) const {mobile} = React.useContext(PreferencesContext) const [navOpen, setNavOpen] = React.useState(false) const gameInfo = useGetGameInfoQuery({game: gameId}) const completed = useAppSelector(selectCompleted(gameId, worldId, levelId)) const difficulty = useAppSelector(selectDifficulty(gameId)) let worldTitle = gameInfo.data?.worlds.nodes[worldId].title return
{mobile ? <> {/* MOBILE VERSION */}
{levelTitle}
: <> {/* DESKTOP VERSION */}
{worldTitle && `World: ${worldTitle}`}
{levelTitle}
}
}