From 0e20acdf55f79493f392d77839d3a774faaaadeb Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 29 Oct 2021 22:04:49 +0200 Subject: [PATCH] overlays: add optional sound to trophy popup --- .../Emu/RSX/Overlays/overlay_trophy_notification.cpp | 3 +++ rpcs3/Emu/System.h | 1 + rpcs3/headless_application.cpp | 2 ++ rpcs3/rpcs3qt/gui_application.cpp | 12 ++++++++++++ rpcs3/rpcs3qt/trophy_notification_helper.cpp | 4 ++++ 5 files changed, 22 insertions(+) diff --git a/rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.cpp b/rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.cpp index 1c01edb40f..a1b4d5b186 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.cpp @@ -175,6 +175,9 @@ namespace rsx fade_animation.active = true; visible = true; + + Emu.GetCallbacks().play_sound(fs::get_config_dir() + "sounds/trophy.wav"); + return CELL_OK; } } // namespace overlays diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 2ebfff999a..f1fffd8155 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -80,6 +80,7 @@ struct EmuCallbacks std::function()> get_trophy_notification_dialog; std::function get_localized_string; std::function get_localized_u32string; + std::function play_sound; std::string(*resolve_path)(std::string_view) = nullptr; // Resolve path using Qt }; diff --git a/rpcs3/headless_application.cpp b/rpcs3/headless_application.cpp index 591f6ee270..41c2e35e02 100644 --- a/rpcs3/headless_application.cpp +++ b/rpcs3/headless_application.cpp @@ -110,6 +110,8 @@ void headless_application::InitializeCallbacks() callbacks.get_localized_string = [](localized_string_id, const char*) -> std::string { return {}; }; callbacks.get_localized_u32string = [](localized_string_id, const char*) -> std::u32string { return {}; }; + callbacks.play_sound = [](const std::string&){}; + callbacks.resolve_path = [](std::string_view sv) { return QFileInfo(QString::fromUtf8(sv.data(), static_cast(sv.size()))).canonicalFilePath().toStdString(); diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 0b0bb54ef9..5e65b09e7d 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -412,6 +413,17 @@ void gui_application::InitializeCallbacks() return localized_emu::get_u32string(id, args); }; + callbacks.play_sound = [](const std::string& path) + { + Emu.CallAfter([path]() + { + if (fs::is_file(path)) + { + QSound::play(qstr(path)); + } + }); + }; + callbacks.resolve_path = [](std::string_view sv) { return QFileInfo(QString::fromUtf8(sv.data(), static_cast(sv.size()))).canonicalFilePath().toStdString(); diff --git a/rpcs3/rpcs3qt/trophy_notification_helper.cpp b/rpcs3/rpcs3qt/trophy_notification_helper.cpp index 7eaa431e80..c81ee8d9c4 100644 --- a/rpcs3/rpcs3qt/trophy_notification_helper.cpp +++ b/rpcs3/rpcs3qt/trophy_notification_helper.cpp @@ -5,6 +5,8 @@ #include "../Emu/System.h" #include "../Emu/RSX/Overlays/overlay_trophy_notification.h" +#include "Utilities/File.h" + s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails& trophy, const std::vector& trophy_icon_buffer) { if (auto manager = g_fxo->try_get()) @@ -26,6 +28,8 @@ s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails& // Move notification to upper lefthand corner trophy_notification->move(m_game_window->mapToGlobal(QPoint(0, 0))); trophy_notification->show(); + + Emu.GetCallbacks().play_sound(fs::get_config_dir() + "sounds/trophy.wav"); }); return 0;