From f6f68e547d39957fc4678859a95cbec839cc41e4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 23 Apr 2016 19:03:55 -0400 Subject: TITANIC: Implement changing sound slider percentages --- engines/titanic/pet_control/pet_control.cpp | 8 +++ engines/titanic/pet_control/pet_control.h | 5 ++ engines/titanic/pet_control/pet_slider.cpp | 12 +++++ engines/titanic/pet_control/pet_slider.h | 5 ++ engines/titanic/pet_control/pet_sound.cpp | 77 +++++++++++++++++++++++++++++ engines/titanic/pet_control/pet_sound.h | 11 +++++ 6 files changed, 118 insertions(+) (limited to 'engines/titanic/pet_control') diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 0bba2c2330..145543fb07 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -423,4 +423,12 @@ void CPetControl::moveToHiddenRoom(CTreeItem *item) { } } +void CPetControl::playSound(int soundNum) { + CTreeItem *player = getHiddenObject("PETSoundPlayer"); + if (player) { + CPETPlaySoundMsg playMsg(soundNum); + playMsg.execute(player); + } +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index e7ec993ba9..e4f0710b76 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -240,6 +240,11 @@ public: void moveToHiddenRoom(CTreeItem *item); void setC8(int val) { _fieldC8 = val; } + + /** + * Play a sound + */ + void playSound(int soundNum); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_slider.cpp b/engines/titanic/pet_control/pet_slider.cpp index 3e579a4b33..1bbad969a2 100644 --- a/engines/titanic/pet_control/pet_slider.cpp +++ b/engines/titanic/pet_control/pet_slider.cpp @@ -168,6 +168,18 @@ void CPetSlider::setOrientation(SliderOrientation orientation) { _orientation |= orientation; } +void CPetSlider::stepPosition(int direction) { + double val = getOffsetPixels(); + + if (direction == -1) { + val = MAX(val - 0.1, 0.0); + } else if (direction == 1) { + val = MIN(val + 0.1, 1.0); + } + + setSliderOffset(val); +} + /*------------------------------------------------------------------------*/ void CPetSoundSlider::setupBackground(const CString &name, CPetControl *petControl) { diff --git a/engines/titanic/pet_control/pet_slider.h b/engines/titanic/pet_control/pet_slider.h index 7a61741143..58b2aa68cc 100644 --- a/engines/titanic/pet_control/pet_slider.h +++ b/engines/titanic/pet_control/pet_slider.h @@ -180,6 +180,11 @@ public: _bounds.translate(pt.x, pt.y); _slidingRect.translate(pt.x, pt.y); } + + /** + * Change the current position of a slider by a step amount + */ + void stepPosition(int direction); }; class CPetSoundSlider : public CPetSlider { diff --git a/engines/titanic/pet_control/pet_sound.cpp b/engines/titanic/pet_control/pet_sound.cpp index d4c6fb376c..2305f42a8f 100644 --- a/engines/titanic/pet_control/pet_sound.cpp +++ b/engines/titanic/pet_control/pet_sound.cpp @@ -22,6 +22,7 @@ #include "titanic/pet_control/pet_sound.h" #include "titanic/pet_control/pet_control.h" +#include "titanic/game_manager.h" namespace Titanic { @@ -121,4 +122,80 @@ void CPetSound::draw2(CScreenManager *screenManager) { _textSpeechVolume.draw(screenManager); } +bool CPetSound::checkHighlight(const Point &pt) { + if (_musicVolume.checkThumb(pt) || _masterVolume.checkThumb(pt) || + _speechVolume.checkThumb(pt)) + return true; + + if (_parrotVolume.checkThumb(pt)) { + CPetControl *pet = getPetControl(); + if (pet) + pet->playSound(2); + + return true; + } + + Rect rectLeft(0, 0, 10, 11); + Rect rectRight(0, 0, 10, 11); + rectLeft.translate(415, 379); + rectRight.translate(567, 378); + + CPetSlider *sliders[4] = { &_masterVolume, &_musicVolume, &_parrotVolume, &_speechVolume }; + for (int idx = 0; idx < 4; ++idx) { + CPetSlider *slider = sliders[idx]; + bool isLeft = rectLeft.contains(pt); + bool isRight = rectRight.contains(pt); + int offset; + + if (isLeft) { + slider->stepPosition(-1); + offset = slider->getOffsetPixels(); + } else if (isRight) { + slider->stepPosition(1); + offset = slider->getOffsetPixels(); + } + + if (isLeft || isRight) { + sliderChanged(offset, idx); + return true; + } + + // Move to next slider row + rectLeft.translate(0, 20); + rectRight.translate(0, 20); + } + + return false; +} + +void CPetSound::sliderChanged(double offset, int 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 0: + soundManager.setMasterPercent(percent); + break; + case 1: + soundManager.setMusicPercent(percent); + break; + case 2: + soundManager.setParrotPercent(percent); + break; + case 3: + soundManager.setSpeechPercent(percent); + break; + default: + break; + } +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_sound.h b/engines/titanic/pet_control/pet_sound.h index 55e1f8a45c..36b6a8bb33 100644 --- a/engines/titanic/pet_control/pet_sound.h +++ b/engines/titanic/pet_control/pet_sound.h @@ -43,6 +43,11 @@ private: CPetText _textSpeechVolume; int _field198; int _field19C; +private: + /** + * Called when a slider has changed + */ + void sliderChanged(double offset, int sliderNum); public: CPetSound(); @@ -60,6 +65,12 @@ public: * Handles any secondary drawing of the glyph */ virtual void draw2(CScreenManager *screenManager); + + /** + * Checks and updates any highlight of the glyph or any contextual + * information it displays + */ + virtual bool checkHighlight(const Point &pt); }; } // End of namespace Titanic -- cgit v1.2.3