Skip to content

Commit

Permalink
XEEN: Added logic for music/sound toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jan 28, 2018
1 parent 9dffe62 commit 319b2c2
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
6 changes: 3 additions & 3 deletions engines/xeen/dialogs_control_panel.cpp
Expand Up @@ -132,11 +132,11 @@ int ControlPanel::execute() {
break;

case Common::KEYCODE_e:
// TODO: Toggle sound effects
sound.setEffectsOn(!sound._soundOn);
break;

case Common::KEYCODE_m:
// TODO: Toggle music
sound.setMusicOn(!sound._musicOn);
break;

case Common::KEYCODE_ESCAPE:
Expand Down Expand Up @@ -180,7 +180,7 @@ int ControlPanel::execute() {
void ControlPanel::loadButtons() {
_iconSprites.load("cpanel.icn");

addButton(Common::Rect(214, 56, 244, 69), Common::KEYCODE_f, 0, &_iconSprites);
addButton(Common::Rect(214, 56, 244, 69), Common::KEYCODE_e, 0, &_iconSprites);
addButton(Common::Rect(214, 75, 244, 88), Common::KEYCODE_m, 0, &_iconSprites);
addButton(Common::Rect(135, 56, 165, 69), Common::KEYCODE_l, 0, &_iconSprites);
addButton(Common::Rect(135, 75, 165, 88), Common::KEYCODE_s, 0, &_iconSprites);
Expand Down
17 changes: 17 additions & 0 deletions engines/xeen/music.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "common/md5.h"
#include "common/config-manager.h"
#include "xeen/music.h"
#include "xeen/xeen.h"
#include "xeen/files.h"
Expand Down Expand Up @@ -725,6 +726,8 @@ int Music::songCommand(uint commandId, byte volume) {

void Music::playSong(Common::SeekableReadStream &stream) {
stopSong();
if (!_musicOn)
return;

byte *songData = new byte[stream.size()];
stream.seek(0);
Expand All @@ -742,4 +745,18 @@ void Music::playSong(const Common::String &name, int param) {
playSong(f);
}

void Music::setMusicOn(bool isOn) {
ConfMan.setBool("music_mute", !isOn);
if (isOn)
ConfMan.setBool("mute", false);

g_vm->syncSoundSettings();
}

void Music::updateSoundSettings() {
_musicOn = !ConfMan.getBool("music_mute");
if (!_musicOn)
stopSong();
}

} // End of namespace Xeen
10 changes: 10 additions & 0 deletions engines/xeen/music.h
Expand Up @@ -369,6 +369,16 @@ class Music {
void playSong(const byte *data) {
_musicDriver->playSong(data);
}

/**
* Sets whether music is on
*/
void setMusicOn(bool isOn);

/**
* Called to reload sound settings
*/
virtual void updateSoundSettings();
};

} // End of namespace Xeen
Expand Down
19 changes: 19 additions & 0 deletions engines/xeen/sound.cpp
Expand Up @@ -22,6 +22,7 @@

#include "audio/decoders/raw.h"
#include "audio/decoders/voc.h"
#include "common/config-manager.h"
#include "xeen/sound.h"
#include "xeen/xeen.h"

Expand All @@ -39,6 +40,8 @@ Sound::~Sound() {

void Sound::playSound(Common::SeekableReadStream &s, int unused) {
stopSound();
if (!_soundOn)
return;

s.seek(0);
Common::SeekableReadStream *srcStream = s.readStream(s.size());
Expand Down Expand Up @@ -69,4 +72,20 @@ void Sound::stopAllAudio() {
stopSound();
}

void Sound::setEffectsOn(bool isOn) {
ConfMan.setBool("sfx_mute", !isOn);
if (isOn)
ConfMan.setBool("mute", false);

g_vm->syncSoundSettings();
}

void Sound::updateSoundSettings() {
_soundOn = !ConfMan.getBool("sfx_mute");
if (!_soundOn)
stopFX();

Music::updateSoundSettings();
}

} // End of namespace Xeen
11 changes: 11 additions & 0 deletions engines/xeen/sound.h
Expand Up @@ -68,6 +68,17 @@ class Sound : public Music {
* Stops all playing music, FX, and sound samples
*/
void stopAllAudio();

/**
* Sets whether sound effects is on
*/
void setEffectsOn(bool isOn);

/**
* Called to reload sound settings
*/
virtual void updateSoundSettings();

};

} // End of namespace Xeen
Expand Down
5 changes: 5 additions & 0 deletions engines/xeen/xeen.cpp
Expand Up @@ -246,4 +246,9 @@ Common::String XeenEngine::printK2(uint value) {
Common::String::format("%u", value);
}

void XeenEngine::syncSoundSettings() {
if (_sound)
_sound->updateSoundSettings();
}

} // End of namespace Xeen
5 changes: 5 additions & 0 deletions engines/xeen/xeen.h
Expand Up @@ -185,6 +185,11 @@ class XeenEngine : public Engine {
*/
virtual Common::Error saveGameState(int slot, const Common::String &desc);

/**
* Updates sound settings
*/
virtual void syncSoundSettings();

/**
* Returns true if a savegame can currently be loaded
*/
Expand Down

0 comments on commit 319b2c2

Please sign in to comment.