From 9b94edd561d27a69ba137c89f225ed49cbd5bf2f Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 24 May 2012 04:34:53 +0200 Subject: [PATCH] audio tab with volume sliders --- apps/openmw/mwgui/settingswindow.cpp | 44 ++++++++++++++++--- apps/openmw/mwgui/settingswindow.hpp | 9 ++++ apps/openmw/mwsound/soundmanager.cpp | 16 +++++-- apps/openmw/mwsound/soundmanager.hpp | 8 ++++ files/mygui/openmw_settings_window_layout.xml | 43 ++++++++++++++++-- files/settings-default.cfg | 4 +- 6 files changed, 109 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 6eaf31ce9..d8e1072e3 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -24,6 +24,11 @@ namespace MWGui getWidget(mMenuTransparencySlider, "MenuTransparencySlider"); getWidget(mViewDistanceSlider, "ViewDistanceSlider"); getWidget(mFullscreenButton, "FullscreenButton"); + getWidget(mMasterVolumeSlider, "MasterVolume"); + getWidget(mVoiceVolumeSlider, "VoiceVolume"); + getWidget(mEffectsVolumeSlider, "EffectsVolume"); + getWidget(mFootstepsVolumeSlider, "FootstepsVolume"); + getWidget(mMusicVolumeSlider, "MusicVolume"); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked); mFullscreenButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled); @@ -31,6 +36,12 @@ namespace MWGui mViewDistanceSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); mResolutionList->eventListChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onResolutionSelected); + mMasterVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mVoiceVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mEffectsVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mFootstepsVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + mMusicVolumeSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition); + center(); int okSize = mOkButton->getTextSize().width + 24; @@ -54,6 +65,12 @@ namespace MWGui int viewdist = (mViewDistanceSlider->getScrollRange()-1) * val; mViewDistanceSlider->setScrollPosition(viewdist); + mMasterVolumeSlider->setScrollPosition(Settings::Manager::getFloat("master volume", "Sound") * (mMasterVolumeSlider->getScrollRange()-1)); + mMusicVolumeSlider->setScrollPosition(Settings::Manager::getFloat("music volume", "Sound") * (mMusicVolumeSlider->getScrollRange()-1)); + mEffectsVolumeSlider->setScrollPosition(Settings::Manager::getFloat("sfx volume", "Sound") * (mEffectsVolumeSlider->getScrollRange()-1)); + mFootstepsVolumeSlider->setScrollPosition(Settings::Manager::getFloat("footsteps volume", "Sound") * (mFootstepsVolumeSlider->getScrollRange()-1)); + mVoiceVolumeSlider->setScrollPosition(Settings::Manager::getFloat("voice volume", "Sound") * (mVoiceVolumeSlider->getScrollRange()-1)); + std::string on = mWindowManager.getGameSettingString("sOn", "On"); std::string off = mWindowManager.getGameSettingString("sOff", "On"); @@ -90,7 +107,7 @@ namespace MWGui Settings::Manager::setInt("resolution x", "Video", resX); Settings::Manager::setInt("resolution y", "Video", resY); - MWBase::Environment::get().getWorld()->processChangedSettings(Settings::Manager::apply()); + apply(); } void SettingsWindow::onButtonToggled(MyGUI::Widget* _sender) @@ -117,14 +134,27 @@ namespace MWGui { float val = pos / float(scroller->getScrollRange()-1); if (scroller == mMenuTransparencySlider) - { Settings::Manager::setFloat("menu transparency", "GUI", val); - } else if (scroller == mViewDistanceSlider) - { - Settings::Manager::setFloat("max viewing distance", "Viewing distance", (1-val) * 2000 + val * 5600); - } + Settings::Manager::setFloat("max viewing distance", "Viewing distance", (1-val) * 2000 + val * 5600); + else if (scroller == mMasterVolumeSlider) + Settings::Manager::setFloat("master volume", "Sound", val); + else if (scroller == mVoiceVolumeSlider) + Settings::Manager::setFloat("voice volume", "Sound", val); + else if (scroller == mEffectsVolumeSlider) + Settings::Manager::setFloat("sfx volume", "Sound", val); + else if (scroller == mFootstepsVolumeSlider) + Settings::Manager::setFloat("footsteps volume", "Sound", val); + else if (scroller == mMusicVolumeSlider) + Settings::Manager::setFloat("music volume", "Sound", val); + + apply(); + } - MWBase::Environment::get().getWorld()->processChangedSettings(Settings::Manager::apply()); + void SettingsWindow::apply() + { + const Settings::CategorySettingVector changed = Settings::Manager::apply(); + MWBase::Environment::get().getWorld()->processChangedSettings(changed); + MWBase::Environment::get().getWorld()->processChangedSettings(changed); } } diff --git a/apps/openmw/mwgui/settingswindow.hpp b/apps/openmw/mwgui/settingswindow.hpp index 785b0c9b1..62acc5649 100644 --- a/apps/openmw/mwgui/settingswindow.hpp +++ b/apps/openmw/mwgui/settingswindow.hpp @@ -22,11 +22,20 @@ namespace MWGui MyGUI::ScrollBar* mMenuTransparencySlider; MyGUI::ScrollBar* mViewDistanceSlider; + // audio + MyGUI::ScrollBar* mMasterVolumeSlider; + MyGUI::ScrollBar* mVoiceVolumeSlider; + MyGUI::ScrollBar* mEffectsVolumeSlider; + MyGUI::ScrollBar* mFootstepsVolumeSlider; + MyGUI::ScrollBar* mMusicVolumeSlider; + void onOkButtonClicked(MyGUI::Widget* _sender); void onSliderChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onButtonToggled(MyGUI::Widget* _sender); void onResolutionSelected(MyGUI::ListBox* _sender, size_t index); void onResolutionAccept(); + + void apply(); }; } diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 8deab3c04..11576e22a 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -7,7 +7,6 @@ #include #include -#include #include "../mwbase/environment.hpp" @@ -53,6 +52,8 @@ namespace MWSound , mMasterVolume(1.0f) , mSFXVolume(1.0f) , mMusicVolume(1.0f) + , mFootstepsVolume(1.0f) + , mVoiceVolume(1.0f) { if(!useSound) return; @@ -210,7 +211,7 @@ namespace MWSound try { // The range values are not tested - float basevol = mMasterVolume * mSFXVolume; + float basevol = mMasterVolume * mVoiceVolume; std::string filePath = "Sound/"+filename; const ESM::Position &pos = ptr.getCellRef().pos; const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]); @@ -234,7 +235,7 @@ namespace MWSound return; try { - float basevol = mMasterVolume * mSFXVolume; + float basevol = mMasterVolume * mVoiceVolume; std::string filePath = "Sound/"+filename; SoundPtr sound = mOutput->playSound(filePath, basevol, 1.0f, Play_Normal); @@ -527,6 +528,15 @@ namespace MWSound } + void SoundManager::processChangedSettings(const Settings::CategorySettingVector& settings) + { + mMasterVolume = Settings::Manager::getFloat("master volume", "Sound"); + mMusicVolume = Settings::Manager::getFloat("music volume", "Sound"); + mSFXVolume = Settings::Manager::getFloat("sfx volume", "Sound"); + mFootstepsVolume = Settings::Manager::getFloat("footsteps volume", "Sound"); + mVoiceVolume = Settings::Manager::getFloat("voice volume", "Sound"); + } + // Default readAll implementation, for decoders that can't do anything // better void Sound_Decoder::readAll(std::vector &output) diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index e1816cd1f..562b2af00 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -7,6 +7,8 @@ #include +#include + #include "../mwworld/ptr.hpp" @@ -52,6 +54,10 @@ namespace MWSound float mMasterVolume; float mSFXVolume; float mMusicVolume; + float mVoiceVolume; + + // not implemented + float mFootstepsVolume; boost::shared_ptr mMusic; std::string mCurrentPlaylist; @@ -78,6 +84,8 @@ namespace MWSound SoundManager(bool useSound); ~SoundManager(); + void processChangedSettings(const Settings::CategorySettingVector& settings); + void stopMusic(); ///< Stops music if it's playing diff --git a/files/mygui/openmw_settings_window_layout.xml b/files/mygui/openmw_settings_window_layout.xml index 2fa332d9a..dc1cbfa9e 100644 --- a/files/mygui/openmw_settings_window_layout.xml +++ b/files/mygui/openmw_settings_window_layout.xml @@ -9,23 +9,58 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index ab0b75ff2..a6623656c 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -131,7 +131,9 @@ underwater effect = true # Device name. Blank means default device = -# Volumes. Sfx and music volumes are both affected by the master volume +# Volumes. master volume affects all other volumes. master volume = 1.0 sfx volume = 1.0 music volume = 0.4 +footsteps volume = 0.6 +voice volume = 1.0