Skip to content

Commit

Permalink
TITANIC: Hook up in-game sound sliders to ScummVM volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Sep 6, 2017
1 parent 128edee commit 0c2fc12
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 55 deletions.
4 changes: 4 additions & 0 deletions engines/titanic/pet_control/pet_control.cpp
Expand Up @@ -562,6 +562,10 @@ bool CPetControl::checkNode(const CString &name) {
return nameLower.contains(str);
}

void CPetControl::syncSoundSettings() {
_realLife.syncSoundSettings();
}

void CPetControl::playSound(int soundNum) {
CTreeItem *player = getHiddenObject("PETSoundPlayer");
if (player) {
Expand Down
5 changes: 5 additions & 0 deletions engines/titanic/pet_control/pet_control.h
Expand Up @@ -296,6 +296,11 @@ class CPetControl : public CGameObject {

bool checkNode(const CString &name);

/**
* Handles updates to the sound levels
*/
void syncSoundSettings();

/**
* Play a sound
*/
Expand Down
8 changes: 7 additions & 1 deletion engines/titanic/pet_control/pet_real_life.cpp
Expand Up @@ -123,6 +123,12 @@ void CPetRealLife::addButton(CPetGlyph *glyph) {
}
}


void CPetRealLife::syncSoundSettings() {
for (CPetGlyphs::iterator i = _glyphs.begin(); i != _glyphs.end(); ++i) {
CPetSound *sound = dynamic_cast<CPetSound *>(*i);
if (sound)
sound->setSliders();
}
}

} // End of namespace Titanic
4 changes: 4 additions & 0 deletions engines/titanic/pet_control/pet_real_life.h
Expand Up @@ -126,6 +126,10 @@ class CPetRealLife : public CPetSection {
*/
virtual CTextControl *getText() { return &_text; }

/**
* Handles updates to the sound levels
*/
void syncSoundSettings();
};

} // End of namespace Titanic
Expand Down
109 changes: 61 additions & 48 deletions engines/titanic/pet_control/pet_sound.cpp
Expand Up @@ -24,6 +24,8 @@
#include "titanic/pet_control/pet_control.h"
#include "titanic/pet_control/pet_real_life.h"
#include "titanic/game_manager.h"
#include "titanic/titanic.h"
#include "common/config-manager.h"

namespace Titanic {

Expand Down Expand Up @@ -110,21 +112,59 @@ bool CPetSound::reset() {
}

void CPetSound::setSliders() {
CPetControl *pet = getPetControl();
CGameManager *gameMan = pet ? pet->getGameManager() : nullptr;

if (gameMan) {
CSoundManager &soundMan = gameMan->_sound._soundManager;
uint masterVol = soundMan.getModeVolume(VOL_NORMAL);
uint musicVol = soundMan.getMusicVolume();
uint parrotVol = soundMan.getParrotVolume();
uint speechVol = soundMan.getSpeechVolume();

_masterVolume.setSliderOffset(masterVol * 0.01);
_musicVolume.setSliderOffset(musicVol * 0.01);
_parrotVolume.setSliderOffset(parrotVol * 0.01);
_speechVolume.setSliderOffset(speechVol * 0.01);
// Get the mute settings
bool muteAll = ConfMan.hasKey("mute") ? ConfMan.getBool("mute") : false;
bool musicMute = muteAll || (ConfMan.hasKey("music_mute") && ConfMan.getBool("music_mute"));
bool sfxMute = muteAll || (ConfMan.hasKey("sfx_mute") && ConfMan.getBool("sfx_mute"));
bool speechMute = muteAll || (ConfMan.hasKey("speech_mute") && ConfMan.getBool("speech_mute"));

// Get the volume levels
uint musicVol = musicMute ? 0 : MIN(255, ConfMan.getInt("music_volume"));
uint parrotVol = sfxMute ? 0 : MIN(255, ConfMan.getInt("sfx_volume"));
uint speechVol = speechMute ? 0 : MIN(255, ConfMan.getInt("speech_volume"));
uint masterVol = MAX(musicVol, MAX(parrotVol, speechVol));

const double FACTOR = 1.0 / 255.0;
_masterVolume.setSliderOffset(masterVol * FACTOR);
_musicVolume.setSliderOffset(musicVol * FACTOR);
_parrotVolume.setSliderOffset(parrotVol * FACTOR);
_speechVolume.setSliderOffset(speechVol * FACTOR);
}

void CPetSound::sliderChanged(double offset, SliderType sliderNum) {
uint newVol = (uint)(offset * 255.0);

switch (sliderNum) {
case MASTER_SLIDER:
ConfMan.setBool("music_mute", false);
ConfMan.setBool("sfx_mute", false);
ConfMan.setBool("sfx_mute", false);
ConfMan.setInt("music_volume", newVol);
ConfMan.setInt("sfx_volume", newVol);
ConfMan.setInt("speech_volume", newVol);

_musicVolume.setSliderOffset(newVol * 0.01);
_parrotVolume.setSliderOffset(newVol * 0.01);
_speechVolume.setSliderOffset(newVol * 0.01);
break;
case MUSIC_SLIDER:
ConfMan.setBool("music_mute", false);
ConfMan.setInt("music_volume", newVol);
break;
case PARROT_SLIDER:
ConfMan.setBool("sfx_mute", false);
ConfMan.setInt("sfx_volume", newVol);
break;
case SPEECH_SLIDER:
ConfMan.setBool("speech_mute", false);
ConfMan.setInt("speech_volume", newVol);
break;
default:
return;
}

ConfMan.setBool("mute", false);
g_vm->syncSoundSettings();
}

void CPetSound::draw2(CScreenManager *screenManager) {
Expand Down Expand Up @@ -187,36 +227,6 @@ bool CPetSound::MouseButtonDownMsg(const Point &pt) {
return false;
}

void CPetSound::sliderChanged(double offset, SliderType sliderNum) {
CPetControl *pet = getPetControl();
if (!pet)
return;

CGameManager *gameManager = pet->getGameManager();
if (!gameManager)
return;

QSoundManager &soundManager = gameManager->_sound._soundManager;
double percent = offset * 100.0;

switch (sliderNum) {
case MASTER_SLIDER:
soundManager.setMasterPercent(percent);
break;
case MUSIC_SLIDER:
soundManager.setMusicPercent(percent);
break;
case PARROT_SLIDER:
soundManager.setParrotPercent(percent);
break;
case SPEECH_SLIDER:
soundManager.setSpeechPercent(percent);
break;
default:
break;
}
}

bool CPetSound::MouseDragStartMsg(CMouseDragStartMsg *msg) {
if (_masterVolume.resetThumbFocus()) {
_draggingSlider = &_masterVolume;
Expand Down Expand Up @@ -262,6 +272,9 @@ bool CPetSound::MouseDragEndMsg(CMouseDragEndMsg *msg) {
if (!_draggingSlider)
return false;

// Flush the changed settings
ConfMan.flushToDisk();

bool result = _draggingSlider->MouseDragEndMsg(msg->_mousePos);
getOwner()->endDragging();

Expand All @@ -272,12 +285,12 @@ bool CPetSound::MouseButtonUpMsg(const Point &pt) {
SliderType sliderNum = MASTER_SLIDER;
CPetSlider *slider = nullptr;

if (_musicVolume.MouseButtonUpMsg(pt)) {
if (_masterVolume.MouseButtonUpMsg(pt)) {
sliderNum = MASTER_SLIDER;
slider = &_musicVolume;
} else if (_masterVolume.MouseButtonUpMsg(pt)) {
sliderNum = MUSIC_SLIDER;
slider = &_masterVolume;
} else if (_musicVolume.MouseButtonUpMsg(pt)) {
sliderNum = MUSIC_SLIDER;
slider = &_musicVolume;
} else if (_parrotVolume.MouseButtonUpMsg(pt)) {
sliderNum = PARROT_SLIDER;
slider = &_parrotVolume;
Expand Down
10 changes: 5 additions & 5 deletions engines/titanic/pet_control/pet_sound.h
Expand Up @@ -49,11 +49,6 @@ class CPetSound : public CPetGlyph {
CPetSlider *_draggingSlider;
SliderType _draggingSliderNum;
private:
/**
* Sets the positions of the volume sliders
*/
void setSliders();

/**
* Called when a slider has changed
*/
Expand Down Expand Up @@ -112,6 +107,11 @@ class CPetSound : public CPetGlyph {
* Returns the tooltip text for when the glyph is selected
*/
virtual void getTooltip(CTextControl *text);

/**
* Sets the positions of the volume sliders
*/
void setSliders();
};

} // End of namespace Titanic
Expand Down
4 changes: 3 additions & 1 deletion engines/titanic/sound/sound_manager.h
Expand Up @@ -42,11 +42,13 @@ enum VolumeMode {
*/
class CSoundManager {
protected:
uint _handleCtr;
// Old volume levels, deprecated in favor of setting the volumes
// directly in the ScummVM mixer
double _musicPercent;
double _speechPercent;
double _masterPercent;
double _parrotPercent;
uint _handleCtr;
public:
CSoundManager();
virtual ~CSoundManager() {}
Expand Down
13 changes: 13 additions & 0 deletions engines/titanic/titanic.cpp
Expand Up @@ -119,6 +119,8 @@ bool TitanicEngine::initialize() {
setItemNames();
setRoomNames();

syncSoundSettings();

_window->applicationStarting();
return true;
}
Expand Down Expand Up @@ -258,6 +260,17 @@ CString TitanicEngine::getSavegameName(int slot) {
return CString();
}

void TitanicEngine::syncSoundSettings() {
Engine::syncSoundSettings();

if (_window->_project) {
CPetControl *pet = _window->_project->getPetControl();
if (pet) {
pet->syncSoundSettings();
}
}
}

void TitanicEngine::GUIError(const char *msg, ...) {
char buffer[STRINGBUFLEN];
va_list va;
Expand Down
5 changes: 5 additions & 0 deletions engines/titanic/titanic.h
Expand Up @@ -155,6 +155,11 @@ class TitanicEngine : public Engine {
*/
virtual Common::Error saveGameState(int slot, const Common::String &desc);

/**
* Handles updates to the sound levels
*/
virtual void syncSoundSettings();

/**
* Gets the game features
*/
Expand Down

0 comments on commit 0c2fc12

Please sign in to comment.