From 5861b963ed4af0531052c2354159acdd57e661c7 Mon Sep 17 00:00:00 2001 From: uruk Date: Fri, 25 Jul 2014 23:19:11 +0200 Subject: CGE2: Now refactor optionTouch() the right way. --- engines/cge2/cge2.h | 2 ++ engines/cge2/toolbar.cpp | 50 +++++++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 987a77386c..9e85d03e7d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -196,6 +196,8 @@ public: void checkSounds(); void checkMusicSwitch(); void checkVolumeSwitches(); + void updateMusicVolume(); + void updateSpeechVolume(); void optionTouch(int opt, uint16 mask); void switchColorMode(); diff --git a/engines/cge2/toolbar.cpp b/engines/cge2/toolbar.cpp index 3556ec72ca..b6bcfd7806 100644 --- a/engines/cge2/toolbar.cpp +++ b/engines/cge2/toolbar.cpp @@ -56,18 +56,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case 2: if ((mask & kMouseLeftUp) && notMuted) { switchMusic(_music = !_music); - - switch (_music) { - case false: - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - _vol[1]->step(0); - break; - case true: - ConfMan.setInt("music_volume", _oldMusicVolume); - _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); - break; - } + updateMusicVolume(); } break; case 3: @@ -89,16 +78,7 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { case 9: if ((mask & kMouseLeftUp) && notMuted) { switchVox(); - - switch (_sayVox) { - case false: - _oldSpeechVolume = ConfMan.getInt("speech_volume"); - ConfMan.setInt("speech_volume", 0); - break; - case true: - ConfMan.setInt("speech_volume", _oldSpeechVolume); - break; - } + updateSpeechVolume(); } break; default: @@ -118,6 +98,20 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); } +void CGE2Engine::updateMusicVolume() { + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + _vol[1]->step(0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + _vol[1]->step(_oldMusicVolume / kSoundNumtoStateRate); + break; + } +} + void CGE2Engine::checkMusicSwitch() { bool mute = false; if (ConfMan.hasKey("mute")) @@ -229,6 +223,18 @@ void CGE2Engine::switchVox() { } } +void CGE2Engine::updateSpeechVolume() { + switch (_sayVox) { + case false: + _oldSpeechVolume = ConfMan.getInt("speech_volume"); + ConfMan.setInt("speech_volume", 0); + break; + case true: + ConfMan.setInt("speech_volume", _oldSpeechVolume); + break; + } +} + void CGE2Engine::switchSay() { _commandHandlerTurbo->addCommand(kCmdSeq, 129, _sayVox, nullptr); _commandHandlerTurbo->addCommand(kCmdSeq, 128, _sayCap, nullptr); -- cgit v1.2.3