Add default trophy sound (#3271)

* Add default trophy sound

* delete include to removed folder

* remove redundant conditions

* Change trophy sound - credit to Tlarok
This commit is contained in:
rainmakerv2 2025-07-22 05:52:20 +08:00 committed by GitHub
parent bad9cd097a
commit 1fc9eedbab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 3 deletions

View File

@ -260,7 +260,6 @@ endif()
add_subdirectory(externals) add_subdirectory(externals)
include_directories(src) include_directories(src)
include_directories(Resources)
if(ENABLE_QT_GUI) if(ENABLE_QT_GUI)
find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent LinguistTools Network Multimedia) 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 cmrc_add_resource_library(embedded-resources
ALIAS res::embedded ALIAS res::embedded
NAMESPACE res NAMESPACE res
src/images/trophy.wav
src/images/bronze.png src/images/bronze.png
src/images/gold.png src/images/gold.png
src/images/platinum.png src/images/platinum.png

View File

@ -73,6 +73,7 @@ path = [
"src/images/shadps4.svg", "src/images/shadps4.svg",
"src/images/website.svg", "src/images/website.svg",
"src/images/youtube.svg", "src/images/youtube.svg",
"src/images/trophy.wav",
"src/shadps4.qrc", "src/shadps4.qrc",
"src/shadps4.rc", "src/shadps4.rc",
"src/qt_gui/translations/update_translation.sh", "src/qt_gui/translations/update_translation.sh",

View File

@ -5,8 +5,8 @@
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <mutex> #include <mutex>
#include <SDL3/SDL_audio.h>
#include <cmrc/cmrc.hpp> #include <cmrc/cmrc.hpp>
#include <common/path_util.h>
#include <imgui.h> #include <imgui.h>
#ifdef ENABLE_QT_GUI #ifdef ENABLE_QT_GUI
@ -15,6 +15,7 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/config.h" #include "common/config.h"
#include "common/path_util.h"
#include "common/singleton.h" #include "common/singleton.h"
#include "imgui/imgui_std.h" #include "imgui/imgui_std.h"
#include "trophy_ui.h" #include "trophy_ui.h"
@ -73,6 +74,7 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin
} }
std::vector<u8> imgdata; std::vector<u8> imgdata;
auto resource = cmrc::res::get_filesystem();
if (!customPath.empty()) { if (!customPath.empty()) {
std::ifstream file(customPath, std::ios::binary); std::ifstream file(customPath, std::ios::binary);
if (file) { 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); LOG_ERROR(Lib_NpTrophy, "Could not open custom file for trophy in {}", customPath);
} }
} else { } else {
auto resource = cmrc::res::get_filesystem();
auto file = resource.open(pathString); auto file = resource.open(pathString);
imgdata = std::vector<u8>(file.begin(), file.end()); imgdata = std::vector<u8>(file.begin(), file.end());
} }
@ -91,17 +92,56 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin
AddLayer(this); AddLayer(this);
bool customsoundplayed = false;
#ifdef ENABLE_QT_GUI #ifdef ENABLE_QT_GUI
QString musicPathWav = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.wav"); QString musicPathWav = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.wav");
QString musicPathMp3 = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.mp3"); QString musicPathMp3 = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.mp3");
if (fs::exists(musicPathWav.toStdString())) { if (fs::exists(musicPathWav.toStdString())) {
BackgroundMusicPlayer::getInstance().setVolume(100); BackgroundMusicPlayer::getInstance().setVolume(100);
BackgroundMusicPlayer::getInstance().playMusic(musicPathWav, false); BackgroundMusicPlayer::getInstance().playMusic(musicPathWav, false);
customsoundplayed = true;
} else if (fs::exists(musicPathMp3.toStdString())) { } else if (fs::exists(musicPathMp3.toStdString())) {
BackgroundMusicPlayer::getInstance().setVolume(100); BackgroundMusicPlayer::getInstance().setVolume(100);
BackgroundMusicPlayer::getInstance().playMusic(musicPathMp3, false); BackgroundMusicPlayer::getInstance().playMusic(musicPathMp3, false);
customsoundplayed = true;
} }
#endif #endif
if (!customsoundplayed) {
auto soundFile = resource.open("src/images/trophy.wav");
std::vector<u8> soundData = std::vector<u8>(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() { TrophyUI::~TrophyUI() {

BIN
src/images/trophy.wav Normal file

Binary file not shown.