From 014b734c984c6e7d09ce6924d5e216525cffab5c Mon Sep 17 00:00:00 2001 From: uruk Date: Wed, 23 Jul 2014 14:24:06 +0200 Subject: CGE2: Increase readability of code connected to music switch. --- engines/cge2/cge2.cpp | 1 - engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 36 ++++++++++++++++++++---------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/engines/cge2/cge2.cpp b/engines/cge2/cge2.cpp index 916b12fef9..55ac835637 100644 --- a/engines/cge2/cge2.cpp +++ b/engines/cge2/cge2.cpp @@ -74,7 +74,6 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription) _quitFlag = false; _bitmapPalette = nullptr; _music = true; - _musicMuted = false; _oldMusicVolume = ConfMan.getInt("music_volume");; _startupMode = 1; _now = 1; diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 0c5ab4d29c..b7b2dd3b65 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -266,7 +266,6 @@ public: bool _quitFlag; Dac *_bitmapPalette; bool _music; - bool _musicMuted; int _oldMusicVolume; int _startupMode; int _now; diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index a22df8d896..10e9bb97b5 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -567,16 +567,15 @@ void CGE2Engine::checkMusicSwitch() { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); - _musicMuted = mute; + bool musicMuted = mute; int musicVolume = ConfMan.getInt("music_volume"); - if (!_musicMuted) - _musicMuted = musicVolume == 0; - - if (!_musicMuted && !_music) { - _oldMusicVolume = musicVolume; + if (!musicMuted) + musicMuted = musicVolume == 0; + + if (!musicMuted && !_music) { switchMusic(_music = true); } - if (_musicMuted && _music) { + if (musicMuted && _music) { switchMusic(_music = false); } } @@ -1098,8 +1097,21 @@ void CGE2Engine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) + if ((mask & kMouseLeftUp) && !ConfMan.getBool("mute")) { switchMusic(_music = !_music); + + switch (_music) { + case false: + _oldMusicVolume = ConfMan.getInt("music_volume"); + ConfMan.setInt("music_volume", 0); + break; + case true: + ConfMan.setInt("music_volume", _oldMusicVolume); + break; + default: + break; + } + } break; case 3: if (mask & kMouseLeftUp) @@ -1136,14 +1148,6 @@ void CGE2Engine::switchMusic(bool on) { _commandHandlerTurbo->addCommand(kCmdSeq, kMusicRef, on, nullptr); keyClick(); _commandHandlerTurbo->addCommand(kCmdMidi, -1, on ? (_now << 8) : -1, nullptr); - - if (!on) { - if (!_musicMuted) { - _oldMusicVolume = ConfMan.getInt("music_volume"); - ConfMan.setInt("music_volume", 0); - } - } else - ConfMan.setInt("music_volume", _oldMusicVolume); } void CGE2Engine::quit() { -- cgit v1.2.3