diff options
author | uruk | 2014-07-25 22:23:28 +0200 |
---|---|---|
committer | uruk | 2014-07-25 22:24:36 +0200 |
commit | 668b133dabdf642ee08b53bab75a273c90cc9529 (patch) | |
tree | 170b93655553e0f146179e3736a03878b76a7f42 | |
parent | 9524f1d128df9588d0934ab3afa64f22d0df4fd0 (diff) | |
download | scummvm-rg350-668b133dabdf642ee08b53bab75a273c90cc9529.tar.gz scummvm-rg350-668b133dabdf642ee08b53bab75a273c90cc9529.tar.bz2 scummvm-rg350-668b133dabdf642ee08b53bab75a273c90cc9529.zip |
CGE2: Implement the music volume button on the toolbar.
-rw-r--r-- | engines/cge2/cge2.h | 5 | ||||
-rw-r--r-- | engines/cge2/cge2_main.cpp | 1 | ||||
-rw-r--r-- | engines/cge2/toolbar.cpp | 57 |
3 files changed, 56 insertions, 7 deletions
diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index c23a101de8..caf39227c6 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -113,10 +113,6 @@ struct SavegameHeader; #define kSavegameStrSize 12 #define kSavegameStr "SCUMMVM_CGE2" -#define kVolumeSwitchRate 25.7 -// == 257 / 10; where 10 equals to the volume switches' number of states -// and ScummVM has a scale of 257 different values for setting sounds. - enum CallbackType { kNullCB = 0, kQGame, kXScene, kSoundSetVolume }; @@ -199,6 +195,7 @@ public: void busyStep(); void checkSounds(); void checkMusicSwitch(); + void checkVolumeSwitches(); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 87ab2dea8f..65f856d815 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -556,6 +556,7 @@ void CGE2Engine::mainLoop() { void CGE2Engine::checkSounds() { _sound->checkSoundHandles(); checkSaySwitch(); + checkVolumeSwitches(); checkMusicSwitch(); _midiPlayer->syncVolume(); } diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 529f0b5125..edabd123b0 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -35,6 +35,17 @@ namespace CGE2 { +#define kSoundNumtoStateRate 25.7 +// == 257 / 10; where 10 equals to the volume switches' number of states [0..9] +// and ScummVM has a scale of 257 different values for setting sounds. + +#define kSoundStatetoNumRate 28.45 +// == 256 / 9 + 0.1; where 256 is the positive range of numbers we can set the volume to +// and the 10 states of a switch cut this range up to 9 equally big parts. +// We don't take into account 0 regarding the 256 different values (it would be the 257th), +// since 0 * x == 0. +// 0.1 is only for correct rounding at the 10th state. + void CGE2Engine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1: @@ -52,6 +63,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { break; case true: ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); break; } } @@ -142,7 +154,46 @@ void CGE2Engine::quit() { } void CGE2Engine::setVolume(int idx, int cnt) { - warning("STUB: CGE2Engine::setVolume()"); + if (cnt && _vol[idx]) { + int p = _vol[idx]->_seqPtr + cnt; + if (p >= 0 && p < _vol[idx]->_seqCnt) { + _vol[idx]->step(p); + int newVolume = p * kSoundStatetoNumRate; + switch (idx) { + case 0: + ConfMan.setInt("sfx_volume", newVolume); + break; + case 1: + if (newVolume == 0) + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", newVolume); + break; + default: + break; + } + } + } +} + +void CGE2Engine::checkVolumeSwitches() { + bool mute = false; + if (ConfMan.hasKey("mute")) + mute = ConfMan.getBool("mute"); + bool musicMuted = mute; + int musicVolume = ConfMan.getInt("music_volume"); + if (!musicMuted) + musicMuted = musicVolume == 0; + bool sfxMuted = mute; + int sfxVolume = ConfMan.getInt("sfx_volume"); + if (!sfxMuted) + sfxMuted = sfxVolume == 0; + + if ((!musicMuted && !_music) || (musicVolume != _oldMusicVolume)) { + _vol[1]->step(musicVolume / kSoundNumtoStateRate); + } + if (musicMuted && _music) { + _vol[1]->step(0); + } } void CGE2Engine::switchCap() { @@ -215,9 +266,9 @@ void CGE2Engine::initToolbar() { _vol[1] = _vga->_showQ->locate(kMvolRef); if (_vol[0]) - _vol[0]->step(_sfxVolume / kVolumeSwitchRate); + _vol[0]->step(_sfxVolume / kSoundNumtoStateRate); if (_vol[1]) - _vol[1]->step(_musicVolume / kVolumeSwitchRate); + _vol[1]->step(_musicVolume / kSoundNumtoStateRate); } } // End of namespace CGE2 |