overlays: add optional sound to trophy popup

This commit is contained in:
Megamouse 2021-10-29 22:04:49 +02:00
parent f262e77fbd
commit 0e20acdf55
5 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -80,6 +80,7 @@ struct EmuCallbacks
std::function<std::unique_ptr<class TrophyNotificationBase>()> get_trophy_notification_dialog;
std::function<std::string(localized_string_id, const char*)> get_localized_string;
std::function<std::u32string(localized_string_id, const char*)> get_localized_u32string;
std::function<void(const std::string&)> play_sound;
std::string(*resolve_path)(std::string_view) = nullptr; // Resolve path using Qt
};

View File

@ -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<int>(sv.size()))).canonicalFilePath().toStdString();

View File

@ -39,6 +39,7 @@
#include <QLibraryInfo>
#include <QDirIterator>
#include <QFileInfo>
#include <QSound>
#include <clocale>
@ -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<int>(sv.size()))).canonicalFilePath().toStdString();

View File

@ -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<uchar>& trophy_icon_buffer)
{
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
@ -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;