Commit 4c8c139b authored by Unicorn369's avatar Unicorn369 Committed by fallenstardust

同曲不重放

parent accd65f4
......@@ -130,6 +130,7 @@ void SoundManager::PlayMusic(const std::string& song, bool loop) {
if(!musicEnabled) return;
StopBGM();
if (bgm) bgmCurrent = bgm->play(song, loop);
bgm_process = true;
}
void SoundManager::PlayBGM(BGM scene) {
if(!mainGame->chkMusicMode->isChecked())
......@@ -139,6 +140,7 @@ void SoundManager::PlayBGM(BGM scene) {
if (musicEnabled && (scene != bgm_scene || !bgm->exists(bgmCurrent)) && bgm_process && count > 0) {
bgm_scene = scene;
int bgm = (std::uniform_int_distribution<>(0, count - 1))(rnd);
bgm_PlayingName = list[bgm];
std::string BGMName = "./sound/BGM/" + list[bgm];
PlayMusic(BGMName, false);
}
......@@ -154,11 +156,11 @@ bool SoundManager::PlayChant(unsigned int code) {
if(dataManager.GetData(code, &cd) && (cd.alias != 0))
code = cd.alias;
if(ChantsList.count(code)) {
if(ChantsList.count(code) && bgm_PlayingName != ChantsList[code]) {
if (bgm) {
bgm_process = false;
bgm_PlayingName = ChantsList[code];
PlayMusic("./sound/chants/" + ChantsList[code], false);
bgm_process = true;
}
return true;
}
......@@ -172,10 +174,12 @@ void SoundManager::PlayCustomSound(char* SoundName) {
void SoundManager::PlayCustomBGM(char* BGMName) {
if (!musicEnabled || !mainGame->chkMusicMode->isChecked()) return;
if (access(BGMName, 0) != 0) return;
if (bgm) {
std::string CustomBGM = Utils::GetFileName(TEXT(BGMName));
if (bgm && bgm_PlayingName != CustomBGM) {
bgm_process = false;
bgm_PlayingName = CustomBGM;
PlayMusic(BGMName, false);
bgm_process = true;
}
}
void SoundManager::SetSoundVolume(double volume) {
......
......@@ -69,6 +69,7 @@ public:
private:
std::vector<std::string> BGMList[9];
std::map<unsigned int, std::string> ChantsList;
std::string bgm_PlayingName;
int bgm_scene = -1;
bool bgm_process;
std::mt19937 rnd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment