Achievements: Add sound effects

This commit is contained in:
Connor McLaughlin 2022-09-21 22:54:37 +10:00
parent a4eb5f1d5d
commit 5568de1e03
9 changed files with 44 additions and 13 deletions

View file

@ -0,0 +1,2 @@
lbsubmit.wav: https://freesound.org/people/Eponn/sounds/636656/
unlock.wav and message.wav are from https://github.com/RetroAchievements/RAInterface

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -344,6 +344,7 @@ void Settings::Load(SettingsInterface& si)
achievements_use_first_disc_from_playlist = si.GetBoolValue("Cheevos", "UseFirstDiscFromPlaylist", true);
achievements_rich_presence = si.GetBoolValue("Cheevos", "RichPresence", true);
achievements_challenge_mode = si.GetBoolValue("Cheevos", "ChallengeMode", false);
achievements_sound_effects = si.GetBoolValue("Cheevos", "SoundEffects", true);
log_level = ParseLogLevelName(si.GetStringValue("Logging", "LogLevel", GetLogLevelName(DEFAULT_LOG_LEVEL)).c_str())
.value_or(DEFAULT_LOG_LEVEL);
@ -528,6 +529,7 @@ void Settings::Save(SettingsInterface& si) const
si.SetBoolValue("Cheevos", "UseFirstDiscFromPlaylist", achievements_use_first_disc_from_playlist);
si.SetBoolValue("Cheevos", "RichPresence", achievements_rich_presence);
si.SetBoolValue("Cheevos", "ChallengeMode", achievements_challenge_mode);
si.SetBoolValue("Cheevos", "SoundEffects", achievements_sound_effects);
si.SetStringValue("Logging", "LogLevel", GetLogLevelName(log_level));
si.SetStringValue("Logging", "LogFilter", log_filter.c_str());

View file

@ -173,6 +173,7 @@ struct Settings
bool achievements_use_first_disc_from_playlist : 1;
bool achievements_rich_presence : 1;
bool achievements_challenge_mode : 1;
bool achievements_sound_effects : 1;
#endif
struct DebugSettings

View file

@ -24,6 +24,7 @@ AchievementSettingsWidget::AchievementSettingsWidget(SettingsDialog* dialog, QWi
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.unofficialTestMode, "Cheevos", "UnofficialTestMode", false);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.useFirstDiscFromPlaylist, "Cheevos",
"UseFirstDiscFromPlaylist", true);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.soundEffects, "Cheevos", "SoundEffects", true);
dialog->registerWidgetHelp(m_ui.enable, tr("Enable Achievements"), tr("Unchecked"),
tr("When enabled and logged in, DuckStation will scan for achievements on startup."));
@ -44,6 +45,9 @@ AchievementSettingsWidget::AchievementSettingsWidget(SettingsDialog* dialog, QWi
dialog->registerWidgetHelp(m_ui.challengeMode, tr("Enable Hardcore Mode"), tr("Unchecked"),
tr("\"Challenge\" mode for achievements. Disables save state, cheats, and slowdown "
"functions, but you receive double the achievement points."));
dialog->registerWidgetHelp(
m_ui.challengeMode, tr("Enable Sound Effects"), tr("Checked"),
tr("Plays sound effects for events such as achievement unlocks and leaderboard submissions."));
connect(m_ui.enable, &QCheckBox::stateChanged, this, &AchievementSettingsWidget::updateEnableState);

View file

@ -39,17 +39,10 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="richPresence">
<item row="2" column="0">
<widget class="QCheckBox" name="challengeMode">
<property name="text">
<string>Enable Rich Presence</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="testMode">
<property name="text">
<string>Enable Test Mode</string>
<string>Enable Hardcore Mode</string>
</property>
</widget>
</item>
@ -60,10 +53,10 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="challengeMode">
<item row="1" column="0">
<widget class="QCheckBox" name="testMode">
<property name="text">
<string>Enable Hardcore Mode</string>
<string>Enable Test Mode</string>
</property>
</widget>
</item>
@ -74,6 +67,20 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="richPresence">
<property name="text">
<string>Enable Rich Presence</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="soundEffects">
<property name="text">
<string>Enable Sound Effects</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View file

@ -16,6 +16,7 @@
#include "core/system.h"
#include "fullscreen_ui.h"
#include "imgui_fullscreen.h"
#include "platform_misc.h"
#include "rapidjson/document.h"
#include "rc_api_info.h"
#include "rc_api_request.h"
@ -53,6 +54,10 @@ enum : s32
NO_RICH_PRESENCE_PING_FREQUENCY = RICH_PRESENCE_PING_FREQUENCY * 2,
};
static constexpr const char* INFO_SOUND_NAME = "sounds/achievements/message.wav";
static constexpr const char* UNLOCK_SOUND_NAME = "sounds/achievements/unlock.wav";
static constexpr const char* LBSUBMIT_SOUND_NAME = "sounds/achievements/lbsubmit.wav";
static void FormattedError(const char* format, ...);
static void LogFailedResponseJSON(const Common::HTTPDownloader::Request::Data& data);
static void EnsureCacheDirectoriesExist();
@ -1021,6 +1026,10 @@ void Achievements::DisplayAchievementSummary()
Host::RunOnCPUThread([title = std::move(title), summary = std::move(summary), icon = s_game_icon]() {
if (FullscreenUI::IsInitialized())
ImGuiFullscreen::AddNotification(10.0f, std::move(title), std::move(summary), std::move(icon));
// Technically not going through the resource API, but since we're passing this to something else, we can't.
if (g_settings.achievements_sound_effects)
FrontendCommon::PlaySoundAsync(Path::Combine(EmuFolders::Resources, INFO_SOUND_NAME).c_str());
});
}
@ -1729,6 +1738,10 @@ void Achievements::SubmitLeaderboardCallback(s32 status_code, std::string conten
submitted_score, best_score, response.new_rank, response.num_entries);
ImGuiFullscreen::AddNotification(10.0f, lb->title, std::move(summary), s_game_icon);
// Technically not going through the resource API, but since we're passing this to something else, we can't.
if (g_settings.achievements_sound_effects)
FrontendCommon::PlaySoundAsync(Path::Combine(EmuFolders::Resources, LBSUBMIT_SOUND_NAME).c_str());
}
void Achievements::UnlockAchievement(u32 achievement_id, bool add_notification /* = true*/)
@ -1769,6 +1782,8 @@ void Achievements::UnlockAchievement(u32 achievement_id, bool add_notification /
ImGuiFullscreen::AddNotification(15.0f, std::move(title), achievement->description,
GetAchievementBadgePath(*achievement));
if (g_settings.achievements_sound_effects)
FrontendCommon::PlaySoundAsync(Path::Combine(EmuFolders::Resources, UNLOCK_SOUND_NAME).c_str());
if (IsTestModeActive())
{