Fix: in-game mute button now mutes background music too
HUD mute is a master toggle (sound effects + music) via sound-store.toggleAll; icon reflects fully-muted state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -53,7 +53,9 @@ export function GameTable({ onExit }: { onExit?: () => void } = {}) {
|
||||
const { t } = useI18n();
|
||||
|
||||
const sfx = useSoundStore((s) => s.sfx);
|
||||
const toggleSfx = useSoundStore((s) => s.toggleSfx);
|
||||
const music = useSoundStore((s) => s.music);
|
||||
const toggleAll = useSoundStore((s) => s.toggleAll);
|
||||
const muted = !sfx && !music;
|
||||
|
||||
const exit = onExit ?? reset;
|
||||
const { phase, players, hakem, trump, turn, currentTrick } = game;
|
||||
@@ -72,14 +74,14 @@ export function GameTable({ onExit }: { onExit?: () => void } = {}) {
|
||||
<div className="flex items-center gap-2">
|
||||
{trump && <TrumpBadge trump={trump} />}
|
||||
<button
|
||||
onClick={toggleSfx}
|
||||
onClick={toggleAll}
|
||||
className="glass rounded-full p-2.5 hover:bg-navy-800 transition"
|
||||
title={t("settings.sound")}
|
||||
title={t("settings.audio")}
|
||||
>
|
||||
{sfx ? (
|
||||
<Volume2 className="size-4 text-gold-400" />
|
||||
) : (
|
||||
{muted ? (
|
||||
<VolumeX className="size-4 text-cream/60" />
|
||||
) : (
|
||||
<Volume2 className="size-4 text-gold-400" />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
|
||||
@@ -8,6 +8,8 @@ interface SoundStore {
|
||||
music: boolean;
|
||||
toggleSfx: () => void;
|
||||
toggleMusic: () => void;
|
||||
/** Master mute: turns BOTH sfx and music off (or both back on). */
|
||||
toggleAll: () => void;
|
||||
}
|
||||
|
||||
export const useSoundStore = create<SoundStore>((set, get) => ({
|
||||
@@ -23,4 +25,11 @@ export const useSoundStore = create<SoundStore>((set, get) => ({
|
||||
sound.setMusicEnabled(v);
|
||||
set({ music: v });
|
||||
},
|
||||
toggleAll: () => {
|
||||
// If anything is on, mute everything; otherwise turn everything back on.
|
||||
const v = !(get().sfx || get().music);
|
||||
sound.setSfxEnabled(v);
|
||||
sound.setMusicEnabled(v);
|
||||
set({ sfx: v, music: v });
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user