Properly change volume
This commit is contained in:
@@ -202,6 +202,9 @@ bool init(void *userData) {
|
||||
ECS_COMPONENT_DEFINE(ECS, SoundState);
|
||||
ecs_singleton_set(ECS, SoundState, {});
|
||||
SoundState *sounds = ecs_singleton_get_mut(ECS, SoundState);
|
||||
sounds->masterVolume = 0.5f;
|
||||
sounds->musicVolume = 0.5f;
|
||||
sounds->soundVolume = 0.5f;
|
||||
soundsLoad(sounds, SOUND_WOOD_PUNCH, 0.1f, "assets/sounds/wood hit 17.wav");
|
||||
}
|
||||
setScreen(game, SCREEN_MAIN_MENU);
|
||||
@@ -392,6 +395,8 @@ void update(float dt, void *userData) {
|
||||
} else {
|
||||
game->options = getDefaultOptions();
|
||||
}
|
||||
SoundState *sounds = ecs_singleton_get_mut(ECS, SoundState);
|
||||
soundsApplyVolume(sounds, opts.master, opts.music, opts.sound);
|
||||
optsLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
#include "sounds.h"
|
||||
|
||||
void soundsApplyVolume(SoundState *sounds, f32 master, f32 music, f32 sound) {
|
||||
SetMasterVolume(master);
|
||||
if (sounds->musicLoaded)
|
||||
SetMusicVolume(sounds->music, music);
|
||||
if (IsSoundPlaying(sounds->playing))
|
||||
SetSoundVolume(sounds->playing, sound);
|
||||
|
||||
sounds->masterVolume = master;
|
||||
sounds->musicVolume = music;
|
||||
sounds->soundVolume = sound;
|
||||
}
|
||||
|
||||
void soundsLoad(SoundState *sounds, SoundType type, f32 interval, const char *path) {
|
||||
Sound newSound = LoadSound(path);
|
||||
sounds->sounds[type] = newSound;
|
||||
@@ -8,6 +20,7 @@ void soundsLoad(SoundState *sounds, SoundType type, f32 interval, const char *pa
|
||||
}
|
||||
void soundsPlay(SoundState *sounds, SoundType type) {
|
||||
PlaySound(sounds->playing);
|
||||
SetSoundVolume(sounds->playing, sounds->soundVolume);
|
||||
}
|
||||
|
||||
void soundsUnloadAll(SoundState *sounds) {
|
||||
@@ -29,6 +42,7 @@ void soundsLoadMusicStream(SoundState *sounds, const char *path) {
|
||||
void soundsPlayMusicStream(SoundState *sounds) {
|
||||
if (sounds->musicLoaded == false) return;
|
||||
PlayMusicStream(sounds->music);
|
||||
SetMusicVolume(sounds->music, sounds->musicVolume);
|
||||
}
|
||||
void soundsPauseMusicStream(SoundState *sounds) {
|
||||
if (sounds->musicLoaded == false) return;
|
||||
|
||||
@@ -19,8 +19,14 @@ typedef struct SoundState {
|
||||
|
||||
bool musicLoaded;
|
||||
Music music;
|
||||
|
||||
f32 masterVolume;
|
||||
f32 musicVolume;
|
||||
f32 soundVolume;
|
||||
} SoundState;
|
||||
|
||||
void soundsApplyVolume(SoundState *sounds, f32 master, f32 music, f32 sound);
|
||||
|
||||
void soundsLoad(SoundState *sounds, SoundType type, f32 interval, const char *path);
|
||||
void soundsPlay(SoundState *sounds, SoundType type);
|
||||
|
||||
|
||||
@@ -307,6 +307,8 @@ void drawSettingsUI(Game *game, f32 dt) {
|
||||
if (uiSettingsButton("Apply")) {
|
||||
serializeOptions(SETTINGS_PATH, &opts);
|
||||
game->options = opts;
|
||||
SoundState *sounds = ecs_singleton_get_mut(ECS, SoundState);
|
||||
soundsApplyVolume(sounds, opts.master, opts.music, opts.sound);
|
||||
setScreen(game, SCREEN_MAIN_MENU);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,7 +202,9 @@ void uiSettingsCheckbox(const char *txt, bool *check) {
|
||||
uiBaseCheckbox(txt, getFont(), 1.0f, check);
|
||||
}
|
||||
void uiSettingsSlider(const char *txt, f32 *value) {
|
||||
uiBaseSlider(txt, getFont(), 1.0f, value, 0, 10);
|
||||
f32 val = *value * 10.0f;
|
||||
uiBaseSlider(txt, getFont(), 1.0f, &val, 0, 10);
|
||||
*value = val / 10.0f;
|
||||
}
|
||||
|
||||
void uiGameResCount(i32 amount, i32 capacity, Rectangle icon, Texture2D texture) {
|
||||
|
||||
BIN
settings.ini
BIN
settings.ini
Binary file not shown.
Reference in New Issue
Block a user