Commit abe0f0b9 authored by Unicorn369's avatar Unicorn369 Committed by fallenstardust

fix

parent f3973192
...@@ -52,9 +52,18 @@ void SoundManager::RefreshBGMDir(path_string path, BGM scene) { ...@@ -52,9 +52,18 @@ void SoundManager::RefreshBGMDir(path_string path, BGM scene) {
void SoundManager::RefreshChantsList() { void SoundManager::RefreshChantsList() {
for(auto& file : Utils::FindfolderFiles(TEXT("./sound/chants"), { TEXT("mp3"), TEXT("ogg"), TEXT("wav") })) { for(auto& file : Utils::FindfolderFiles(TEXT("./sound/chants"), { TEXT("mp3"), TEXT("ogg"), TEXT("wav") })) {
auto scode = Utils::GetFileName(TEXT("./sound/chants/") + file); auto scode = Utils::GetFileName(TEXT("./sound/chants/") + file);
unsigned int code = std::stoi(scode); try {
if(code && !ChantsList.count(code)) unsigned int code = std::stoi(scode);
ChantsList[code] = Utils::ToUTF8IfNeeded(file); if (code && !ChantsList.count(code))
ChantsList[code] = Utils::ToUTF8IfNeeded(file);
}
catch (std::exception& e) {
char buf[1040];
auto fileName = Utils::ToUTF8IfNeeded(TEXT("./sound/chants/") + file);
sprintf(buf, "[文件名只能为卡片ID]: %s", fileName.c_str());
Utils::Deletefile(fileName);
mainGame->ErrorLog(buf);
}
} }
} }
void SoundManager::PlaySoundEffect(SFX sound) { void SoundManager::PlaySoundEffect(SFX sound) {
...@@ -132,16 +141,29 @@ void SoundManager::PlayBGM(BGM scene) { ...@@ -132,16 +141,29 @@ void SoundManager::PlayBGM(BGM scene) {
PlayMusic(BGMName, false); PlayMusic(BGMName, false);
} }
} }
void SoundManager::StopSound() {
sfx->stopAll();
}
void SoundManager::StopBGM() { void SoundManager::StopBGM() {
bgm->stopAll(); bgm->stopAll();
} }
bool SoundManager::PlayChant(unsigned int code) { bool SoundManager::PlayChant(unsigned int code) {
if(ChantsList.count(code)) { if(ChantsList.count(code)) {
if (bgm) bgm->play("./sound/chants/" + ChantsList[code], false); if (bgm) PlayMusic("./sound/chants/" + ChantsList[code], false);
return true; return true;
} }
return false; return false;
} }
void SoundManager::PlayCustomSound(char* SoundName) {
if (!soundsEnabled) return;
if (access(SoundName, 0) != 0) return;
if (sfx) sfx->play(SoundName, false);
}
void SoundManager::PlayCustomBGM(char* BGMName) {
if (!musicEnabled || !mainGame->chkMusicMode->isChecked()) return;
if (access(BGMName, 0) != 0) return;
if (bgm) PlayMusic(BGMName, false);
}
void SoundManager::SetSoundVolume(double volume) { void SoundManager::SetSoundVolume(double volume) {
if (sfx) sfx->setVolume(volume); if (sfx) sfx->setVolume(volume);
} }
...@@ -150,6 +172,9 @@ void SoundManager::SetMusicVolume(double volume) { ...@@ -150,6 +172,9 @@ void SoundManager::SetMusicVolume(double volume) {
} }
void SoundManager::EnableSounds(bool enable) { void SoundManager::EnableSounds(bool enable) {
soundsEnabled = enable; soundsEnabled = enable;
if(!soundsEnabled) {
StopSound();
}
} }
void SoundManager::EnableMusic(bool enable) { void SoundManager::EnableMusic(bool enable) {
musicEnabled = enable; musicEnabled = enable;
......
...@@ -56,8 +56,11 @@ public: ...@@ -56,8 +56,11 @@ public:
void PlayDialogSound(irr::gui::IGUIElement * element); void PlayDialogSound(irr::gui::IGUIElement * element);
void PlayMusic(const std::string& song, bool loop); void PlayMusic(const std::string& song, bool loop);
void PlayBGM(BGM scene); void PlayBGM(BGM scene);
void StopSound();
void StopBGM(); void StopBGM();
bool PlayChant(unsigned int code); bool PlayChant(unsigned int code);
void PlayCustomSound(char* SoundName);
void PlayCustomBGM(char* BGMName);
void SetSoundVolume(double volume); void SetSoundVolume(double volume);
void SetMusicVolume(double volume); void SetMusicVolume(double volume);
void EnableSounds(bool enable); void EnableSounds(bool enable);
......
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