[Scummvm-git-logs] scummvm master -> 0c2fc12756311baf3457718fae7e9394aea390b8

dreammaster dreammaster at scummvm.org
Wed Sep 6 03:11:14 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
0c2fc12756 TITANIC: Hook up in-game sound sliders to ScummVM volumes


Commit: 0c2fc12756311baf3457718fae7e9394aea390b8
    https://github.com/scummvm/scummvm/commit/0c2fc12756311baf3457718fae7e9394aea390b8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-09-05T21:11:06-04:00

Commit Message:
TITANIC: Hook up in-game sound sliders to ScummVM volumes

Changed paths:
    engines/titanic/pet_control/pet_control.cpp
    engines/titanic/pet_control/pet_control.h
    engines/titanic/pet_control/pet_real_life.cpp
    engines/titanic/pet_control/pet_real_life.h
    engines/titanic/pet_control/pet_sound.cpp
    engines/titanic/pet_control/pet_sound.h
    engines/titanic/sound/sound_manager.h
    engines/titanic/titanic.cpp
    engines/titanic/titanic.h


diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp
index cfd209f..a86a72f 100644
--- a/engines/titanic/pet_control/pet_control.cpp
+++ b/engines/titanic/pet_control/pet_control.cpp
@@ -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) {
diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h
index 35556e0..6408c8a 100644
--- a/engines/titanic/pet_control/pet_control.h
+++ b/engines/titanic/pet_control/pet_control.h
@@ -297,6 +297,11 @@ public:
 	bool checkNode(const CString &name);
 
 	/**
+	 * Handles updates to the sound levels
+	 */
+	void syncSoundSettings();
+
+	/**
 	 * Play a sound
 	 */
 	void playSound(int soundNum);
diff --git a/engines/titanic/pet_control/pet_real_life.cpp b/engines/titanic/pet_control/pet_real_life.cpp
index 57d81c7..ff87a2f 100644
--- a/engines/titanic/pet_control/pet_real_life.cpp
+++ b/engines/titanic/pet_control/pet_real_life.cpp
@@ -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
diff --git a/engines/titanic/pet_control/pet_real_life.h b/engines/titanic/pet_control/pet_real_life.h
index 294f9a3..965b4ea 100644
--- a/engines/titanic/pet_control/pet_real_life.h
+++ b/engines/titanic/pet_control/pet_real_life.h
@@ -126,6 +126,10 @@ public:
 	 */
 	virtual CTextControl *getText() { return &_text; }
 
+	/**
+	 * Handles updates to the sound levels
+	 */
+	void syncSoundSettings();
 };
 
 } // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_sound.cpp b/engines/titanic/pet_control/pet_sound.cpp
index e4fac34..c2c9110 100644
--- a/engines/titanic/pet_control/pet_sound.cpp
+++ b/engines/titanic/pet_control/pet_sound.cpp
@@ -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 {
 
@@ -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) {
@@ -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; 
@@ -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();
 
@@ -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;
diff --git a/engines/titanic/pet_control/pet_sound.h b/engines/titanic/pet_control/pet_sound.h
index 9365b31..54e2fc1 100644
--- a/engines/titanic/pet_control/pet_sound.h
+++ b/engines/titanic/pet_control/pet_sound.h
@@ -50,11 +50,6 @@ private:
 	SliderType _draggingSliderNum;
 private:
 	/**
-	 * Sets the positions of the volume sliders
-	 */
-	void setSliders();
-
-	/**
 	 * Called when a slider has changed
 	 */
 	void sliderChanged(double offset, SliderType sliderNum);
@@ -112,6 +107,11 @@ public:
 	 * 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
diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h
index 59a514c..e07c62d 100644
--- a/engines/titanic/sound/sound_manager.h
+++ b/engines/titanic/sound/sound_manager.h
@@ -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() {}
diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp
index 67bdf82..9c05a13 100644
--- a/engines/titanic/titanic.cpp
+++ b/engines/titanic/titanic.cpp
@@ -119,6 +119,8 @@ bool TitanicEngine::initialize() {
 	setItemNames();
 	setRoomNames();
 
+	syncSoundSettings();
+
 	_window->applicationStarting();
 	return true;
 }
@@ -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;
diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h
index c49a137..0fea879 100644
--- a/engines/titanic/titanic.h
+++ b/engines/titanic/titanic.h
@@ -156,6 +156,11 @@ public:
 	virtual Common::Error saveGameState(int slot, const Common::String &desc);
 
 	/**
+	 * Handles updates to the sound levels
+	 */
+	virtual void syncSoundSettings();
+
+	/**
 	 * Gets the game features
 	 */
 	uint32 getFeatures() const;





More information about the Scummvm-git-logs mailing list