From 52bd28a83051697348bf7fe4792ad69f9b38087d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Wed, 9 Jun 2021 15:54:28 +0200 Subject: [PATCH] sound callback ok --- sources/Component/Sound/SoundComponent.cpp | 21 +++++++++++++++------ sources/Component/Sound/SoundComponent.hpp | 10 ++++++++-- sources/Runner/Runner.cpp | 16 ++++++++++++++-- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/sources/Component/Sound/SoundComponent.cpp b/sources/Component/Sound/SoundComponent.cpp index 752efe9f..6396ff54 100644 --- a/sources/Component/Sound/SoundComponent.cpp +++ b/sources/Component/Sound/SoundComponent.cpp @@ -54,17 +54,16 @@ namespace BBM this->_soundList[this->_soundIndex].get()->pause(); } - void SoundComponent::setVolume(float &volumeUpdate) + void SoundComponent::setVolume(float volumeUpdate) { - if (!this->_isSoundLoad.at(this->_soundIndex)) - return; - if (volumeUpdate >= 0) { + if (volumeUpdate >= 0 && volumeUpdate <= 1) { this->volume = volumeUpdate; - this->_soundList[this->_soundIndex].get()->setVolume(this->volume); + for (auto &sound : _soundList) + sound.second->setVolume(volume); } } - void SoundComponent::setPitch(float &pitch) + void SoundComponent::setPitch(float pitch) { if (!this->_isSoundLoad.at(this->_soundIndex)) return; @@ -88,4 +87,14 @@ namespace BBM return (this->_soundIndex); } + void SoundComponent::turnDownVolume() + { + this->setVolume(SoundComponent::volume - 0.1); + } + + void SoundComponent::turnUpVolume() + { + this->setVolume(SoundComponent::volume + 0.1); + } + } // namespace WAL diff --git a/sources/Component/Sound/SoundComponent.hpp b/sources/Component/Sound/SoundComponent.hpp index f5278114..64a217d5 100644 --- a/sources/Component/Sound/SoundComponent.hpp +++ b/sources/Component/Sound/SoundComponent.hpp @@ -42,10 +42,16 @@ namespace BBM void pauseSound(); //! @brief set Sound volume - void setVolume(float &); + void setVolume(float); + + //! @brief volume -= 0.1 + void turnDownVolume(); + + //! @brief volume += 0.1 + void turnUpVolume(); //! @brief set pitch volume - void setPitch(float &); + void setPitch(float); //! @brief is Sound playing bool isPlaying(); diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 3aa7386d..e4cde34b 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -409,7 +409,13 @@ namespace BBM auto &soundUp = scene->addEntity("sound up button") .addComponent(1920 / 1.5, 1080 - 360, 0) .addComponent("assets/buttons/button_plus.png") - .addComponent() + .addComponent(sounds) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnUpVolume(); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); @@ -426,13 +432,19 @@ namespace BBM auto &soundDown = scene->addEntity("sound down button") .addComponent(1920 / 3, 1080 - 360, 0) .addComponent("assets/buttons/button_minus.png") - .addComponent() + .addComponent(sounds) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_minus.png"); }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + auto &component = entity.getComponent(); + + component.turnDownVolume(); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get());