The main menu music would not start again when you returned to the main menu.
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "../Engine/Core/EPause.h"
|
#include "../Engine/Core/EPause.h"
|
||||||
#include "../Engine/Core/EComponentAttached.h"
|
#include "../Engine/Core/EComponentAttached.h"
|
||||||
#include "../Core/EPlayerSpawned.h"
|
#include "../Core/EPlayerSpawned.h"
|
||||||
|
#include "../Engine/Network/EPlayerDisconnected.h"
|
||||||
|
|
||||||
|
|
||||||
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
||||||
@@ -139,6 +140,8 @@ private:
|
|||||||
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
|
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
|
||||||
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
|
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
|
||||||
bool OnChangeBGM(const Events::ChangeBGM &e);
|
bool OnChangeBGM(const Events::ChangeBGM &e);
|
||||||
|
EventRelay<SoundManager, Events::PlayerDisconnected> m_EplayerDisconnected;
|
||||||
|
bool OnPlayerDisconnected(const Events::PlayerDisconnected& e);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
|
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EplayerDisconnected, &SoundManager::OnPlayerDisconnected);
|
||||||
|
|
||||||
Events::ChangeBGM e;
|
Events::ChangeBGM e;
|
||||||
e.FilePath = "Audio/bgm/MenuMusic.wav";
|
e.FilePath = "Audio/bgm/MenuMusic.wav";
|
||||||
@@ -394,7 +395,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
|||||||
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
||||||
{
|
{
|
||||||
if (m_CurrentBGM != nullptr) {
|
if (m_CurrentBGM != nullptr) {
|
||||||
stopSound(m_CurrentBGM);
|
if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
|
||||||
|
stopSound(m_CurrentBGM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_CurrentBGM = createSource(e.FilePath);
|
m_CurrentBGM = createSource(e.FilePath);
|
||||||
m_CurrentBGM->Type = SoundType::BGM;
|
m_CurrentBGM->Type = SoundType::BGM;
|
||||||
@@ -403,6 +406,22 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SoundManager::OnPlayerDisconnected(const Events::PlayerDisconnected& e)
|
||||||
|
{
|
||||||
|
// A player returned to the main menu. Easiest solution when we don't have states in the game. Not "PC".
|
||||||
|
if (m_CurrentBGMCombo != nullptr) {
|
||||||
|
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
|
||||||
|
stopSound(m_CurrentBGMCombo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stopSound(m_CurrentBGMCombo);
|
||||||
|
Events::ChangeBGM changeBGM;
|
||||||
|
changeBGM.FilePath = "Audio/BGM/MenuMusic.wav";
|
||||||
|
m_EventBroker->Publish(changeBGM);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
ALenum SoundManager::getSourceState(ALuint source)
|
ALenum SoundManager::getSourceState(ALuint source)
|
||||||
{
|
{
|
||||||
ALenum state;
|
ALenum state;
|
||||||
|
|||||||
Reference in New Issue
Block a user