diff --git a/CMakeLists.txt b/CMakeLists.txt index 24a81243f..ce05f13a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,7 +260,6 @@ endif() add_subdirectory(externals) include_directories(src) -include_directories(Resources) if(ENABLE_QT_GUI) find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent LinguistTools Network Multimedia) @@ -1242,6 +1241,7 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeRC.cmake") cmrc_add_resource_library(embedded-resources ALIAS res::embedded NAMESPACE res + src/images/trophy.wav src/images/bronze.png src/images/gold.png src/images/platinum.png diff --git a/REUSE.toml b/REUSE.toml index 4b1c94d21..c58fd0944 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -73,6 +73,7 @@ path = [ "src/images/shadps4.svg", "src/images/website.svg", "src/images/youtube.svg", + "src/images/trophy.wav", "src/shadps4.qrc", "src/shadps4.rc", "src/qt_gui/translations/update_translation.sh", diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index 3c9f883b3..57090be90 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -5,8 +5,8 @@ #include #include #include +#include #include -#include #include #ifdef ENABLE_QT_GUI @@ -15,6 +15,7 @@ #include "common/assert.h" #include "common/config.h" +#include "common/path_util.h" #include "common/singleton.h" #include "imgui/imgui_std.h" #include "trophy_ui.h" @@ -73,6 +74,7 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin } std::vector imgdata; + auto resource = cmrc::res::get_filesystem(); if (!customPath.empty()) { std::ifstream file(customPath, std::ios::binary); if (file) { @@ -82,7 +84,6 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin LOG_ERROR(Lib_NpTrophy, "Could not open custom file for trophy in {}", customPath); } } else { - auto resource = cmrc::res::get_filesystem(); auto file = resource.open(pathString); imgdata = std::vector(file.begin(), file.end()); } @@ -91,17 +92,56 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin AddLayer(this); + bool customsoundplayed = false; #ifdef ENABLE_QT_GUI QString musicPathWav = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.wav"); QString musicPathMp3 = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.mp3"); if (fs::exists(musicPathWav.toStdString())) { BackgroundMusicPlayer::getInstance().setVolume(100); BackgroundMusicPlayer::getInstance().playMusic(musicPathWav, false); + customsoundplayed = true; } else if (fs::exists(musicPathMp3.toStdString())) { BackgroundMusicPlayer::getInstance().setVolume(100); BackgroundMusicPlayer::getInstance().playMusic(musicPathMp3, false); + customsoundplayed = true; } #endif + + if (!customsoundplayed) { + auto soundFile = resource.open("src/images/trophy.wav"); + std::vector soundData = std::vector(soundFile.begin(), soundFile.end()); + + SDL_AudioSpec spec; + Uint8* audioBuf; + Uint32 audioLen; + + if (!SDL_LoadWAV_IO(SDL_IOFromMem(soundData.data(), soundData.size()), true, &spec, + &audioBuf, &audioLen)) { + LOG_ERROR(Lib_NpTrophy, "Cannot load trophy sound: {}", SDL_GetError()); + SDL_free(audioBuf); + return; + } + + SDL_AudioStream* stream = + SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, nullptr, nullptr); + if (!stream) { + LOG_ERROR(Lib_NpTrophy, "Cannot create audio stream for trophy sound: {}", + SDL_GetError()); + SDL_free(audioBuf); + return; + } + + if (!SDL_PutAudioStreamData(stream, audioBuf, audioLen)) { + LOG_ERROR(Lib_NpTrophy, "Cannot add trophy sound data to stream: {}", SDL_GetError()); + SDL_free(audioBuf); + return; + } + + // Set audio gain 20% higher since audio file itself is soft + SDL_SetAudioStreamGain(stream, Config::getVolumeSlider() / 100.0f * 1.2f); + SDL_ResumeAudioStreamDevice(stream); + SDL_free(audioBuf); + } } TrophyUI::~TrophyUI() { diff --git a/src/images/trophy.wav b/src/images/trophy.wav new file mode 100644 index 000000000..ad9811476 Binary files /dev/null and b/src/images/trophy.wav differ