/** * @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, 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' import { useTranslation } from 'react-i18next' /** 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 { t } = useTranslation() const dispatch = useAppDispatch() // if `prevText` or `prevIcon` is set, show a button to go back let prevText = {0: null, 1: t("Intro"), 2: null}[pageNumber] let prevIcon = {0: null, 1: null, 2: faBookOpen}[pageNumber] let prevTitle = {0: null, 1: t("Game Introduction"), 2: t("World selection")}[pageNumber] // if `nextText` or `nextIcon` is set, show a button to go forward let nextText = {0: t("Start"), 1: null, 2: null}[pageNumber] let nextIcon = {0: null, 1: faBook, 2: null}[pageNumber] let nextTitle = {0: t("World selection"), 1: t("Inventory"), 2: null}[pageNumber] return <> {(prevText || prevIcon) && } {(nextText || nextIcon) && } } /** button to toggle dropdown menu. */ export 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 { t } = useTranslation() 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 { t } = useTranslation() 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 { t } = useTranslation() const {levelId} = React.useContext(WorldLevelIdContext) const {typewriterMode, setTypewriterMode, lockEditorMode} = React.useContext(InputModeContext) /** toggle input mode if allowed */ function toggleInputMode(ev: React.MouseEvent) { if (!lockEditorMode){ setTypewriterMode(!typewriterMode) setNavOpen(false) } } return } /** button to toggle iimpressum popup * * Note: Do not translate the word "Impressum"! German GDPR needs this. */ export function ImpressumButton({setNavOpen, toggleImpressum, isDropdown}) { const { t } = useTranslation() return } export function PreferencesButton({setNavOpen, togglePreferencesPopup}) { const { t } = useTranslation() return } function GameInfoButton({setNavOpen, toggleInfo}) { const { t } = useTranslation() return } function EraseButton ({setNavOpen, toggleEraseMenu}) { const { t } = useTranslation() return } function DownloadButton ({setNavOpen, gameId, gameProgress}) { const { t } = useTranslation() return } function UploadButton ({setNavOpen, toggleUploadMenu}) { const { t } = useTranslation() return } /** button to go back to welcome page */ function HomeButton({isDropdown}) { const { t } = useTranslation() const gameId = React.useContext(GameIdContext) return } function LandingPageButton() { const { t } = useTranslation() return } /** button in mobile level to toggle inventory. * only displays a button if `setPageNumber` is set. */ function InventoryButton({pageNumber, setPageNumber}) { const { t } = useTranslation() 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 { t } = useTranslation() const gameId = React.useContext(GameIdContext) const gameProgress = useAppSelector(selectProgress(gameId)) const {mobile} = React.useContext(PreferencesContext) const [navOpen, setNavOpen] = React.useState(false) return
{!mobile && {t(gameInfo?.title, {ns: gameId})}}
{mobile && }
} /** the navigation bar in a level */ export function LevelAppBar({isLoading, levelTitle, toggleImpressum, toggleInfo, togglePreferencesPopup, pageNumber=undefined, setPageNumber=undefined} : { isLoading: boolean, levelTitle: string, toggleImpressum: any, toggleInfo: any, togglePreferencesPopup: any, pageNumber?: number, setPageNumber?: any, }) { const { t } = useTranslation() 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 && `${t("World")}: ${t(worldTitle, {ns: gameId})}`}
{levelTitle}
}
}