aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptitSeb2017-12-16 14:38:00 +0100
committerptitSeb2017-12-16 14:38:00 +0100
commitddd76d59cc4958abb5c42090046bf6781cf75096 (patch)
tree796082296283a5aaec052469bc7d4360184c50ce
parent3638a171bda48dc9a8d264f68dd04a187a433aa6 (diff)
downloadhydracastlelabyrinth-ddd76d59cc4958abb5c42090046bf6781cf75096.tar.gz
hydracastlelabyrinth-ddd76d59cc4958abb5c42090046bf6781cf75096.tar.bz2
hydracastlelabyrinth-ddd76d59cc4958abb5c42090046bf6781cf75096.zip
Added Music Volume option
-rw-r--r--src/ini.c24
-rw-r--r--src/options.c18
-rw-r--r--src/sdl/audio.c8
-rw-r--r--src/sdl/audio.h4
4 files changed, 52 insertions, 2 deletions
diff --git a/src/ini.c b/src/ini.c
index 99b2f62..d2d3f57 100644
--- a/src/ini.c
+++ b/src/ini.c
@@ -13,6 +13,7 @@ void sizeLoad(char* first, char* second);
void blurLoad(char* first, char* second);
void languageLoad(char* first, char* second);
void autosaveLoad(char* first, char* second);
+void musicvolumeLoad(char* first, char* second);
void iniInit()
{
@@ -117,6 +118,12 @@ void saveSettings()
}else{
fprintf(f, "off");
}
+
+ #ifdef _SDL
+ fprintf(f, "\r\n[audio]");
+ fprintf(f, "\r\nmusic=%d", music_volume);
+ // Audio
+ #endif
fclose(f);
}
@@ -153,7 +160,7 @@ void loadSettings()
lineptr = trimString(lineptr);
if (lineptr != NULL) {
- //Ignore catigory lines
+ //Ignore category lines
if (lineptr[0] != '[')
{
//Check if it has a = delimiter first
@@ -178,6 +185,7 @@ void loadSettings()
blurLoad(fhalf, shalf);
languageLoad(fhalf, shalf);
autosaveLoad(fhalf, shalf);
+ musicvolumeLoad(fhalf, shalf);
}
}
@@ -301,4 +309,16 @@ void autosaveLoad(char* first, char* second)
setAutoSave(0);
}
}
-} \ No newline at end of file
+}
+
+void musicvolumeLoad(char* first, char* second)
+{
+ #ifdef _SDL
+ if (strcmp(first, "music") == 0) {
+ if (second[0] >= '0' && second[0] <= '4') {
+ music_volume = second[0]-'0';
+ PHL_MusicVolume(0.25f * music_volume);
+ }
+ }
+ #endif
+}
diff --git a/src/options.c b/src/options.c
index 4c31314..377bb48 100644
--- a/src/options.c
+++ b/src/options.c
@@ -146,6 +146,14 @@ int optionsStep()
}
}
#endif
+
+ #ifdef _SDL
+ // Music volume
+ if(optCursor == 2) {
+ music_volume = (music_volume+1)%5;
+ PHL_MusicVolume(0.25f * music_volume);
+ }
+ #endif
//Back
if (optCursor == lastOption) {
@@ -252,6 +260,16 @@ void optionsDraw()
ydraw += ystep;
optioncount++;
#endif
+
+ #ifdef _SDL
+ // Music volume
+ PHL_DrawTextBold("MUSIC", xleft, ydraw, YELLOW);
+ char buff[50];
+ sprintf(buff, "%d%", music_volume*25);
+ PHL_DrawTextBold(buff, xright, ydraw, YELLOW);
+ ydraw += ystep;
+ optioncount++;
+ #endif
PHL_DrawTextBold("BACK", xleft, ydraw, YELLOW);
diff --git a/src/sdl/audio.c b/src/sdl/audio.c
index 8e19bf9..b66ce1e 100644
--- a/src/sdl/audio.c
+++ b/src/sdl/audio.c
@@ -1,11 +1,15 @@
#include "audio.h"
#include <SDL/SDL.h>
+int music_volume = 4;
+
void PHL_AudioInit()
{
SDL_InitSubSystem(SDL_INIT_AUDIO);
Mix_Init(0);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096);
+
+ PHL_MusicVolume(0.25f * music_volume);
}
void PHL_AudioClose()
@@ -35,6 +39,10 @@ PHL_Sound PHL_LoadSound(char* fname)
return Mix_LoadWAV(buff);
}
+void PHL_MusicVolume(float vol)
+{
+ Mix_VolumeMusic(SDL_MIX_MAXVOLUME*vol);
+}
void PHL_PlayMusic(PHL_Music snd)
{
diff --git a/src/sdl/audio.h b/src/sdl/audio.h
index 2cf30d3..b21cad1 100644
--- a/src/sdl/audio.h
+++ b/src/sdl/audio.h
@@ -12,9 +12,13 @@ typedef struct
} PHL_Music;
+extern int music_volume;
+
void PHL_AudioInit();
void PHL_AudioClose();
+void PHL_MusicVolume(float vol);
+
PHL_Music PHL_LoadMusic(char* fname, int loop); //Same as PHL_LoadSound, but expects a file name without extension
PHL_Sound PHL_LoadSound(char* fname);