Toggle sound and music from everywhere
This commit is contained in:
parent
a53c8fe525
commit
9b4de91e13
37
src/main.c
37
src/main.c
|
@ -355,30 +355,31 @@ static bool
|
|||
handle_main_events(SDL_Event *event)
|
||||
{
|
||||
if (gGameState == PLAYING
|
||||
|| gGameState == IN_GAME_MENU
|
||||
|| gGameState == GAME_OVER)
|
||||
|| gGameState == IN_GAME_MENU
|
||||
|| gGameState == GAME_OVER)
|
||||
{
|
||||
if (keyboard_press(SDLK_ESCAPE, event)) {
|
||||
toggleInGameMenu(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keyboard_mod_press(SDLK_m, KMOD_CTRL, event)) {
|
||||
if (mixer_toggle_music())
|
||||
gui_log("Music enabled");
|
||||
else
|
||||
gui_log("Music disabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keyboard_mod_press(SDLK_s, KMOD_CTRL, event)) {
|
||||
if (mixer_toggle_sound())
|
||||
gui_log("Sound enabled");
|
||||
else
|
||||
gui_log("Sound disabled");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyboard_mod_press(SDLK_m, KMOD_CTRL, event)) {
|
||||
if (mixer_toggle_music(&gGameState))
|
||||
gui_log("Music enabled");
|
||||
else
|
||||
gui_log("Music disabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keyboard_mod_press(SDLK_s, KMOD_CTRL, event)) {
|
||||
if (mixer_toggle_sound())
|
||||
gui_log("Sound enabled");
|
||||
else
|
||||
gui_log("Sound disabled");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
10
src/mixer.c
10
src/mixer.c
|
@ -100,7 +100,7 @@ mixer_toggle_sound(void)
|
|||
}
|
||||
|
||||
bool
|
||||
mixer_toggle_music(void)
|
||||
mixer_toggle_music(GameState *state)
|
||||
{
|
||||
Settings *settings = settings_get();
|
||||
settings->music_enabled = !settings->music_enabled;
|
||||
|
@ -109,8 +109,12 @@ mixer_toggle_music(void)
|
|||
Mix_PauseMusic();
|
||||
else if (Mix_PausedMusic())
|
||||
Mix_ResumeMusic();
|
||||
else
|
||||
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
||||
else {
|
||||
if (*state == MENU)
|
||||
mixer_play_music(MENU_MUSIC);
|
||||
else
|
||||
mixer_play_music(GAME_MUSIC0 + get_random(2));
|
||||
}
|
||||
|
||||
return settings->music_enabled;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define MIXER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "gamestate.h"
|
||||
|
||||
typedef enum Music_t {
|
||||
MENU_MUSIC,
|
||||
|
@ -64,7 +65,7 @@ bool
|
|||
mixer_toggle_sound(void);
|
||||
|
||||
bool
|
||||
mixer_toggle_music(void);
|
||||
mixer_toggle_music(GameState*);
|
||||
|
||||
void
|
||||
mixer_play_effect(Fx fx);
|
||||
|
|
Loading…
Reference in New Issue