-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Add settings menu and ability to adjust sound.
- Loading branch information
Showing
6 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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"; | ||
|
||
interface Props { | ||
onGoBack: () => void; | ||
} | ||
|
||
export default function SettingsMenu({ onGoBack }: Props) { | ||
const [settings, setSettings] = useLocalStorageState<GameSettings>( | ||
WORMGINE_STORAGE_KEY_SETTINGS, | ||
{ | ||
defaultValue: getGameSettings(), | ||
}, | ||
); | ||
|
||
const onVolumeSet: JSX.MouseEventHandler<HTMLMeterElement> = 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})) | ||
}, []); | ||
|
||
return ( | ||
<main className={menuStyles.menu}> | ||
<h1>Settings</h1> | ||
<section> | ||
<h2> | ||
General | ||
</h2> | ||
<label for="sound-effect-meter"> | ||
Sound Effect Volume: | ||
</label> | ||
<meter title={`${settings.soundEffectVolume * 100}%`} id="sound-effect-meter" role="slider" onClick={onVolumeSet} style={{width: "200px"}} min="0" max="1" value={settings.soundEffectVolume}>75%</meter> | ||
</section> | ||
<button onClick={onGoBack}>Back</button> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ export enum GameMenu { | |
AccountMenu, | ||
TeamEditor, | ||
OverlayTest, | ||
Settings, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters