diff --git a/src/frontend/components/menu.tsx b/src/frontend/components/menu.tsx index 8c0aba4..653fe9f 100644 --- a/src/frontend/components/menu.tsx +++ b/src/frontend/components/menu.tsx @@ -50,10 +50,14 @@ function mainMenu(
  • - +
  • - +
  • @@ -93,7 +97,7 @@ export function Menu({ onNewGame, client, reloadClient }: Props) { setCurrentMenu(GameMenu.MainMenu)} /> ); } else if (currentMenu === GameMenu.TeamEditor) { @@ -104,11 +108,7 @@ export function Menu({ onNewGame, client, reloadClient }: Props) { /> ); } else if (currentMenu === GameMenu.Settings) { - return ( - setCurrentMenu(GameMenu.MainMenu)} - /> - ); + return setCurrentMenu(GameMenu.MainMenu)} />; } else if (currentMenu === GameMenu.OverlayTest) { return ; } diff --git a/src/frontend/components/menus/account.tsx b/src/frontend/components/menus/account.tsx index e1bc301..e469421 100644 --- a/src/frontend/components/menus/account.tsx +++ b/src/frontend/components/menus/account.tsx @@ -1,12 +1,12 @@ import { useState, useCallback, useEffect } from "preact/hooks"; import { NetClientConfig, NetGameClient } from "../../../net/client"; -import { GameMenu } from "./types"; +import menuStyles from "../menu.module.css"; import config from "../config"; import styles from "./account.module.css"; interface Props { client: NetGameClient | undefined; - setCurrentMenu: (menu: GameMenu) => void; + onGoBack: () => void; reloadClient: () => void; } @@ -63,11 +63,7 @@ function LoggedInView({ client }: { client: NetGameClient }) { ); } -export default function AccountMenu({ - client, - setCurrentMenu, - reloadClient, -}: Props) { +export default function AccountMenu({ client, onGoBack, reloadClient }: Props) { const [loginInProgress, setLoginInProgress] = useState(false); const [error, setError] = useState(); const onSubmit = useCallback( @@ -139,9 +135,9 @@ export default function AccountMenu({ } return ( -
    +

    Wormgine Account

    - + {content}
    ); diff --git a/src/frontend/components/menus/settings.tsx b/src/frontend/components/menus/settings.tsx index be2b087..cf85f89 100644 --- a/src/frontend/components/menus/settings.tsx +++ b/src/frontend/components/menus/settings.tsx @@ -2,7 +2,11 @@ import useLocalStorageState from "use-local-storage-state"; import menuStyles from "../menu.module.css"; import { useCallback } from "preact/hooks"; import { JSX } from "preact/jsx-runtime"; -import { GameSettings, getGameSettings, WORMGINE_STORAGE_KEY_SETTINGS } from "../../../settings"; +import { + GameSettings, + getGameSettings, + WORMGINE_STORAGE_KEY_SETTINGS, +} from "../../../settings"; interface Props { onGoBack: () => void; @@ -16,24 +20,33 @@ export default function SettingsMenu({ onGoBack }: Props) { }, ); - const onVolumeSet: JSX.MouseEventHandler = useCallback((evt) => { - const element = (evt.target as HTMLMeterElement); - const rect = element.getClientRects()[0]; - const value = Math.round(((evt.clientX - rect.x) / rect.width) * 10) / 10; - setSettings((s: GameSettings) => ({...s, soundEffectVolume: value})) - }, []); + const onVolumeSet: JSX.GenericEventHandler = useCallback( + (evt) => { + const element = evt.target as HTMLInputElement; + setSettings((s: GameSettings) => ({ + ...s, + soundEffectVolume: element.valueAsNumber / 100, + })); + }, + [], + ); return (

    Settings

    -

    - General -

    - - 75% +

    General

    + +
    diff --git a/src/settings.ts b/src/settings.ts index c96e0a3..5b6f4d3 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -9,23 +9,23 @@ export interface StoredTeam { } export interface GameSettings { - soundEffectVolume: number; + soundEffectVolume: number; } const DEFAULT_SETTINGS: GameSettings = { - soundEffectVolume: 0.1, + soundEffectVolume: 0.1, }; export function getGameSettings(): GameSettings { - const item = localStorage.getItem(WORMGINE_STORAGE_KEY_SETTINGS); - if (!item) { - return DEFAULT_SETTINGS; - } - // TODO: Sanitize. - return { - ...DEFAULT_SETTINGS, - ...JSON.parse(item), - }; + const item = localStorage.getItem(WORMGINE_STORAGE_KEY_SETTINGS); + if (!item) { + return DEFAULT_SETTINGS; + } + // TODO: Sanitize. + return { + ...DEFAULT_SETTINGS, + ...JSON.parse(item), + }; } export function getLocalTeams(): StoredTeam[] {