rework the [music_volume] tag to a more generic [volume]...

...to be able to adjust sound effect through WML, patch by lfernando
This commit is contained in:
Jérémy Rosen 2010-05-09 10:10:41 +00:00
parent bd05419633
commit 58b319c6bc
4 changed files with 22 additions and 19 deletions

View file

@ -86,7 +86,7 @@ Version 1.9.0-svn:
* Add [replace_schedule] tag, which replaces the time of day schedule
* Trying to include a missing macro/file is now a fatal error
* Extended #ifdef so that it also tests for files and directories
* Add [music_volume] tag, which permits modifications to music volume during scenario
* Added [volume] tag, which allows game volume to be changed during scenarios
* Added ON_DIFFICULTY, a macro that makes using different values based on difficulty simpler
* Prototype support for [set_global_variable]
* Prototype support for [get_global_variable]

View file

@ -712,25 +712,34 @@ WML_HANDLER_FUNCTION(music, /*event_info*/, cfg)
sound::play_music_config(cfg.get_parsed_config());
}
WML_HANDLER_FUNCTION(music_volume, /*event_info*/, cfg)
WML_HANDLER_FUNCTION(volume, /*event_info*/, cfg)
{
std::string absolute = cfg["value"];
std::string relative = cfg["relative"];
int vol = sound::get_music_volume();
if(!absolute.empty()) {
vol = atoi(absolute.c_str());
int vol;
float rel;
std::string music = cfg["music"];
std::string sound = cfg["sound"];
if(!music.empty()) {
vol = preferences::music_volume();
rel = atof(music.c_str());
if (rel < 100.0) {
vol = static_cast<int>(rel*vol/100.0);
}
sound::set_music_volume(vol);
}
if(!relative.empty()) {
const float rel = atof(relative.c_str());
vol = static_cast<int>(rel*vol/100.0);
if(!sound.empty()) {
vol = preferences::sound_volume();
rel = atof(sound.c_str());
if (rel < 100.0) {
vol = static_cast<int>(rel*vol/100.0);
}
sound::set_sound_volume(vol);
}
sound::set_music_volume(vol);
}
WML_HANDLER_FUNCTION(sound, /*event_info*/, cfg)
{
play_controller *controller = resources::controller;

View file

@ -808,11 +808,6 @@ void play_UI_sound(const std::string& files)
}
}
int get_music_volume()
{
return Mix_VolumeMusic(-1);
}
void set_music_volume(int vol)
{
if(mix_ok && vol >= 0) {

View file

@ -87,7 +87,6 @@ class music_thinker : public events::pump_monitor {
// Save music playlist for snapshot
void write_music_play_list(config& snapshot);
int get_music_volume();
void set_music_volume(int vol);
void set_sound_volume(int vol);
void set_bell_volume(int vol);