Skip to content

Commit 1b5dccf

Browse files
committed
Achievements: Preview custom sounds directly
instead of using/opening the system's default audio player.
1 parent 0ed0b1b commit 1b5dccf

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

pcsx2-qt/Settings/AchievementSettingsWidget.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pcsx2/Achievements.h"
1212
#include "pcsx2/Config.h"
1313
#include "pcsx2/Host.h"
14+
#include "common/HostSys.h"
1415

1516
#include "common/StringUtil.h"
1617

@@ -47,9 +48,55 @@ AchievementSettingsWidget::AchievementSettingsWidget(SettingsWindow* settings_di
4748
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.achievementNotificationsDuration, "Achievements", "NotificationsDuration", Pcsx2Config::AchievementsOptions::DEFAULT_NOTIFICATION_DURATION);
4849
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.leaderboardNotificationsDuration, "Achievements", "LeaderboardsDuration", Pcsx2Config::AchievementsOptions::DEFAULT_LEADERBOARD_DURATION);
4950

50-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.notificationSoundPath, m_ui.notificationSoundBrowse, m_ui.notificationSoundOpen, m_ui.notificationSoundReset, "Achievements", "InfoSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
51-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.unlockSoundPath, m_ui.unlockSoundBrowse, m_ui.unlockSoundOpen, m_ui.unlockSoundReset, "Achievements", "UnlockSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
52-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.lbSoundPath, m_ui.lbSoundBrowse, m_ui.lbSoundOpen, m_ui.lbSoundReset, "Achievements", "LBSubmitSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
51+
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.notificationSoundPath, m_ui.notificationSoundBrowse, nullptr, nullptr, "Achievements", "InfoSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
52+
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.unlockSoundPath, m_ui.unlockSoundBrowse, nullptr, nullptr, "Achievements", "UnlockSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
53+
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.lbSoundPath, m_ui.lbSoundBrowse, nullptr, nullptr, "Achievements", "LBSubmitSoundName", Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
54+
55+
// Preview Button
56+
57+
QObject::connect(m_ui.notificationSoundOpen, &QAbstractButton::clicked, m_ui.notificationSoundOpen, [&]() {
58+
const QByteArray path = m_ui.notificationSoundPath->text().toUtf8();
59+
Common::PlaySoundAsync(
60+
(path.isEmpty()
61+
? Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME)
62+
: path.constData()).c_str()
63+
);
64+
});
65+
66+
QObject::connect(m_ui.unlockSoundOpen, &QAbstractButton::clicked, m_ui.unlockSoundOpen, [&]() {
67+
const QByteArray path = m_ui.unlockSoundPath->text().toUtf8();
68+
Common::PlaySoundAsync(
69+
(path.isEmpty()
70+
? Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME)
71+
: path.constData()).c_str()
72+
);
73+
});
74+
75+
QObject::connect(m_ui.lbSoundOpen, &QAbstractButton::clicked, m_ui.lbSoundOpen, [&]() {
76+
const QByteArray path = m_ui.lbSoundPath->text().toUtf8();
77+
Common::PlaySoundAsync(
78+
(path.isEmpty()
79+
? Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME)
80+
: path.constData()).c_str()
81+
);
82+
});
83+
84+
// Reset button
85+
86+
QObject::connect(m_ui.notificationSoundReset, &QAbstractButton::clicked, m_ui.notificationSoundReset, [&]() {
87+
m_ui.notificationSoundPath->clear();
88+
Host::RemoveBaseSettingValue("Achievements", "InfoSoundName");
89+
});
90+
91+
QObject::connect(m_ui.unlockSoundReset, &QAbstractButton::clicked, m_ui.unlockSoundReset, [&]() {
92+
m_ui.unlockSoundPath->clear();
93+
Host::RemoveBaseSettingValue("Achievements", "UnlockSoundName");
94+
});
95+
96+
QObject::connect(m_ui.lbSoundReset, &QAbstractButton::clicked, m_ui.lbSoundReset, [&]() {
97+
m_ui.lbSoundPath->clear();
98+
Host::RemoveBaseSettingValue("Achievements", "LBSubmitSoundName");
99+
});
53100

54101
dialog()->registerWidgetHelp(m_ui.enable, tr("Enable Achievements"), tr("Unchecked"), tr("When enabled and logged in, PCSX2 will scan for achievements on startup."));
55102
dialog()->registerWidgetHelp(m_ui.hardcoreMode, tr("Enable Hardcore Mode"), tr("Unchecked"), tr("\"Challenge\" mode for achievements, including leaderboard tracking. Disables save state, cheats, and slowdown functions."));

0 commit comments

Comments
 (0)