From 11d2cf66b60799c12bec5279f801c402d90f1476 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 3 Aug 2014 22:23:55 +0200 Subject: CGE2: Rework the handling of the sound buttons on the toolbar. Also keep in sync the volume settings and the audio mode of the game and the settings in the Launcher. --- engines/cge2/cge2.cpp | 20 +++---- engines/cge2/cge2.h | 10 +--- engines/cge2/cge2_main.cpp | 2 - engines/cge2/saveload.cpp | 2 - engines/cge2/toolbar.cpp | 126 +++++++++------------------------------------ 5 files changed, 31 insertions(+), 129 deletions(-) (limited to 'engines') diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 9c16bd4e0c..f3bc1de44c 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -96,15 +96,12 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _midiNotify = nullptr; _spriteNotify = nullptr; - _enaCap = true; - _enaVox = true; - _sayCap = true; - _sayVox = true; + _sayCap = ConfMan.getBool("subtitles"); + _sayVox = !ConfMan.getBool("speech_mute"); if (ConfMan.getBool("mute")) { - _oldSpeechVolume = _oldMusicVolume = _oldSfxVolume = 0; + _oldMusicVolume = _oldSfxVolume = 0; _music = _sfx = false; } else { - _oldSpeechVolume = ConfMan.getInt("speech_volume"); _oldMusicVolume = ConfMan.getInt("music_volume"); _oldSfxVolume = ConfMan.getInt("sfx_volume"); _music = _oldMusicVolume != 0; @@ -192,20 +189,17 @@ bool CGE2Engine::hasFeature(EngineFeature f) const { Common::Error CGE2Engine::run() { syncSoundSettings(); - syncSpeechSettings(); initGraphics(kScrWidth, kScrHeight, false); init(); cge2_main(); deinit(); - return Common::kNoError; -} + ConfMan.setBool("subtitles", _sayCap); + ConfMan.setBool("speech_mute", !_sayVox); + ConfMan.flushToDisk(); -void CGE2Engine::syncSpeechSettings() { - _enaCap = _sayCap = ConfMan.getBool("subtitles"); - _enaVox = _sayVox = !ConfMan.getBool("speech_mute"); + return Common::kNoError; } - } // End of namespace CGE2 diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 630be47421..8b2a2382e6 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -144,7 +144,6 @@ private: bool loadGame(int slotNumber); void syncHeader(Common::Serializer &s); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); - void syncSpeechSettings(); void resetGame(); public: CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription); @@ -209,17 +208,13 @@ public: void optionTouch(int opt, uint16 mask); void switchColorMode(); - void switchMusic(bool on); - void updateMusicVolume(); - void checkMusicSwitch(); + void switchMusic(); void quit(); void setVolume(int idx, int cnt); void checkVolumeSwitches(); void switchCap(); void switchVox(); - void updateSpeechVolume(); void switchSay(); - void checkSaySwitch(); void initToolbar(); void initVolumeSwitch(Sprite *volSwitch); @@ -298,11 +293,8 @@ public: NotifyFunctionType _spriteNotify; int _startGameSlot; - bool _enaCap; - bool _enaVox; bool _sayCap; bool _sayVox; - int _oldSpeechVolume; int _oldMusicVolume; int _oldSfxVolume; bool _music; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index cdf2aa648a..9b4b1afd75 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -541,9 +541,7 @@ void CGE2Engine::mainLoop() { void CGE2Engine::checkSounds() { _sound->checkSoundHandles(); - checkSaySwitch(); checkVolumeSwitches(); - checkMusicSwitch(); _midiPlayer->syncVolume(); } diff --git a/engines/cge2/saveload.cpp b/engines/cge2/saveload.cpp index b5355966c3..a7d04bbc09 100644 --- a/engines/cge2/saveload.cpp +++ b/engines/cge2/saveload.cpp @@ -239,8 +239,6 @@ bool CGE2Engine::loadGame(int slotNumber) { syncGame(readStream, nullptr); delete readStream; - syncSpeechSettings(); - loadHeroes(); return true; diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 4b328df6b0..3972df9c67 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -54,10 +54,8 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && notMuted) { - switchMusic(_music = !_music); - updateMusicVolume(); - } + if ((mask & kMouseLeftUp) && notMuted) + switchMusic(); break; case 3: if (mask & kMouseLeftUp) @@ -72,14 +70,12 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { setVolume(opt - 4, (mask & kMouseLeftUp) ? 1 : -1); break; case 8: - if (mask & kMouseLeftUp) + if ((mask & kMouseLeftUp) && notMuted) switchCap(); break; case 9: - if ((mask & kMouseLeftUp) && notMuted) { + if ((mask & kMouseLeftUp) && notMuted) switchVox(); - updateSpeechVolume(); - } break; default: break; @@ -94,38 +90,12 @@ void CGE2Engine::switchColorMode() { _vga->setColors(_vga->_sysPal, 64); } -void CGE2Engine::switchMusic(bool on) { - _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); +void CGE2Engine::switchMusic() { + _music = !_music; + _mixer->muteSoundType(Audio::Mixer::kMusicSoundType, !_music); + _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, _music, nullptr); keyClick(); - _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); -} - -void CGE2Engine::updateMusicVolume() { - if (_music) { - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - } else { - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - } -} - -void CGE2Engine::checkMusicSwitch() { - 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; - - if (!musicMuted && !_music) - switchMusic(_music = true); - - if (musicMuted && _music) - switchMusic(_music = false); + _commandHandlerTurbo->addCommand(kCmdMidi, -1, _music ? (_now << 8) : -1, nullptr); } void CGE2Engine::quit() { @@ -168,65 +138,33 @@ void CGE2Engine::setVolume(int idx, int cnt) { } 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 && !musicMuted)) + if (musicVolume != _oldMusicVolume) _vol[1]->step(musicVolume / kSoundNumtoStateRate); - if (musicMuted && _music) - _vol[1]->step(0); - - if ((!sfxMuted && !_sfx) || (sfxVolume != _oldSfxVolume)) { + int sfxVolume = ConfMan.getInt("sfx_volume"); + if (sfxVolume != _oldSfxVolume) { _vol[0]->step(sfxVolume / kSoundNumtoStateRate); _oldSfxVolume = sfxVolume; _sfx = true; } - - if (sfxMuted && _sfx) { - _vol[0]->step(0); - _sfx = false; - } } void CGE2Engine::switchCap() { - if (_enaCap && _enaVox) { - _sayCap = !_sayCap; - if (!_sayCap && _enaVox) - _sayVox = true; - keyClick(); - switchSay(); - } + _sayCap = !_sayCap; + if (!_sayCap) + _sayVox = true; + keyClick(); + switchSay(); } void CGE2Engine::switchVox() { - if (_enaVox && _enaCap) { - _sayVox = !_sayVox; - if (!_sayVox && _enaCap) - _sayCap = true; - keyClick(); - switchSay(); - } -} - -void CGE2Engine::updateSpeechVolume() { - if (_sayVox) - ConfMan.setInt("speech_volume", _oldSpeechVolume); - else { - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - } + _mixer->muteSoundType(Audio::Mixer::kSpeechSoundType, _sayVox); + _sayVox = !_sayVox; + if (!_sayVox) + _sayCap = true; + keyClick(); + switchSay(); } void CGE2Engine::switchSay() { @@ -234,24 +172,6 @@ void CGE2Engine::switchSay() { _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); } -void CGE2Engine::checkSaySwitch() { - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - bool speechMuted = mute; - if (!speechMuted) { - int speechVolume = ConfMan.getInt("speech_volume"); - speechMuted = speechVolume == 0; - } - - if (!speechMuted && !_sayVox) - switchVox(); - - if (speechMuted && _sayVox) - switchVox(); -} - void CGE2Engine::initToolbar() { selectPocket(-1); -- cgit v1.2.3