diff --git a/src/audio/sfx_manager.cpp b/src/audio/sfx_manager.cpp index ceef50d62..c6036d293 100644 --- a/src/audio/sfx_manager.cpp +++ b/src/audio/sfx_manager.cpp @@ -482,25 +482,29 @@ void SFXManager::positionListener(const Vec3 &position, const Vec3 &front) /** Positional sound is cool, but creating a new object just to play a simple * menu sound is not. This function allows for 'quick sounds' in a single call. * \param sound_type Internal name of the sfx to play. + * \return a pointer to the sound, for instance to check when the sound finished. + * don't delete the returned pointer. */ - -void SFXManager::quickSound(const std::string &sound_type) +SFXBase* SFXManager::quickSound(const std::string &sound_type) { - if(!sfxAllowed()) return; + if (!sfxAllowed()) return NULL; std::map::iterator sound = m_quick_sounds.find(sound_type); if (sound == m_quick_sounds.end()) { // sound not yet in our local list of quick sounds SFXBase* newSound = sfx_manager->createSoundSource(sound_type, false); + if (newSound == NULL) return NULL; newSound->play(); m_quick_sounds[sound_type] = newSound; + return newSound; } else { (*sound).second->play(); + return (*sound).second; } - + // m_locked_sound = sfx_manager->newSFX(SFXManager::SOUND_LOCKED); // m_locked_sound->play(); } diff --git a/src/audio/sfx_manager.hpp b/src/audio/sfx_manager.hpp index e96a1a1cc..adf5a7318 100644 --- a/src/audio/sfx_manager.hpp +++ b/src/audio/sfx_manager.hpp @@ -125,7 +125,7 @@ public: static const std::string getErrorString(int err); void positionListener(const Vec3 &position, const Vec3 &front); - void quickSound(const std::string &soundName); + SFXBase* quickSound(const std::string &soundName); /** Called when sound was muted/unmuted */ void soundToggled(const bool newValue); diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 1a36cbf77..292f6e20c 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -19,6 +19,8 @@ #include "states_screens/race_result_gui.hpp" +#include "audio/music_manager.hpp" +#include "audio/sfx_base.hpp" #include "challenges/unlock_manager.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" @@ -55,6 +57,9 @@ void RaceResultGUI::init() getWidget("top")->setVisible(false); getWidget("middle")->setVisible(false); getWidget("bottom")->setVisible(false); + + music_manager->stopMusic(); + m_finish_sound = sfx_manager->quickSound("race_finish"); } // init //----------------------------------------------------------------------------- @@ -374,6 +379,11 @@ GUIEngine::EventPropagation RaceResultGUI::filterActions(PlayerAction action, void RaceResultGUI::onUpdate(float dt, irr::video::IVideoDriver*) { renderGlobal(dt); + + if (m_finish_sound != NULL && m_finish_sound->getStatus() != SFXManager::SFX_PLAYING) + { + music_manager->startMusic( music_manager->getMusicInformation("race_summary.music") ); + } } // onUpdate //----------------------------------------------------------------------------- diff --git a/src/states_screens/race_result_gui.hpp b/src/states_screens/race_result_gui.hpp index 1c86b7f2b..c3e1c06ec 100644 --- a/src/states_screens/race_result_gui.hpp +++ b/src/states_screens/race_result_gui.hpp @@ -160,6 +160,8 @@ private: /** The previous monospace state of the font. */ bool m_was_monospace; + SFXBase* m_finish_sound; + void displayOneEntry(unsigned int x, unsigned int y, unsigned int n, bool display_points); void determineTableLayout();