Skip to content

Commit 6da18ba

Browse files
committed
Achievement: Fix default custom sound effect behavior
Achievements: Preview custom sounds directly instead of using/opening the system's default audio player.
1 parent 06616ec commit 6da18ba

File tree

7 files changed

+60
-53
lines changed

7 files changed

+60
-53
lines changed

pcsx2-qt/SettingWidgetBinder.h

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QtWidgets/QSpinBox>
2424

2525
#include "common/FileSystem.h"
26+
#include "common/HostSys.h"
2627
#include "common/Path.h"
2728

2829
#include "pcsx2/Config.h"
@@ -1261,8 +1262,8 @@ namespace SettingWidgetBinder
12611262
widget->connect(widget, &QLineEdit::editingFinished, widget, std::move(value_changed));
12621263
}
12631264

1264-
static inline void BindWidgetToFileSetting(SettingsInterface* sif, QLineEdit* widget, QAbstractButton* browse_button,
1265-
QAbstractButton* open_button, QAbstractButton* reset_button, std::string section, std::string key, std::string default_value,
1265+
static inline void BindWidgetToAudioFileSetting(SettingsInterface* sif, QLineEdit* widget, QAbstractButton* browse_button,
1266+
QAbstractButton* preview_button, QAbstractButton* reset_button, std::string section, std::string key, std::string default_value,
12661267
const QString& filter, bool allow_pergame = false, bool use_relative = true)
12671268
{
12681269
using Accessor = SettingAccessor<QLineEdit>;
@@ -1296,60 +1297,48 @@ namespace SettingWidgetBinder
12961297
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str());
12971298
}
12981299
else
1299-
{
13001300
Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.c_str());
1301-
}
13021301

13031302
if (!FileSystem::FileExists(new_value.c_str()))
1304-
{
13051303
QMessageBox::critical(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Error"),
13061304
qApp->translate("SettingWidgetBinder", "File cannot be found."));
1307-
}
13081305

13091306
Host::CommitBaseSettingChanges();
13101307
return;
13111308
}
13121309
else
1313-
{
1314-
QMessageBox::critical(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Error"),
1315-
qApp->translate("SettingWidgetBinder", "File path cannot be empty."));
1316-
}
1310+
Host::RemoveBaseSettingValue(section.c_str(), key.c_str());
13171311

1318-
// reset to old value
1319-
std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str()));
1320-
if (current_path.empty())
1321-
current_path = default_value;
1322-
else if (use_relative && !Path::IsAbsolute(current_path))
1323-
current_path = Path::Canonicalize(Path::Combine(EmuFolders::DataRoot, current_path));
1324-
1325-
widget->setText(QString::fromStdString(current_path));
13261312
};
13271313

13281314
if (browse_button)
13291315
{
13301316
QObject::connect(browse_button, &QAbstractButton::clicked, browse_button, [widget, key, value_changed, filter]() {
13311317
const QString path(QDir::toNativeSeparators(QFileDialog::getOpenFileName(QtUtils::GetRootWidget(widget),
1332-
qApp->translate("SettingWidgetBinder", "Select File"), QString(), filter)));
1318+
qApp->translate("SettingWidgetBinder", "Select Audio File"), QString(), filter)));
13331319
if (path.isEmpty())
13341320
return;
13351321

13361322
widget->setText(path);
13371323
value_changed();
13381324
});
13391325
}
1340-
if (open_button)
1326+
if (preview_button)
13411327
{
1342-
QObject::connect(open_button, &QAbstractButton::clicked, open_button, [widget]() {
1343-
QString path(Accessor::getStringValue(widget));
1344-
if (!path.isEmpty())
1345-
QtUtils::OpenURL(QtUtils::GetRootWidget(widget), QUrl::fromLocalFile(path));
1328+
QObject::connect(preview_button, &QAbstractButton::clicked, preview_button, [widget, default_value = std::move(default_value)]() {
1329+
const QByteArray path = widget->text().toUtf8();
1330+
Common::PlaySoundAsync(
1331+
(path.isEmpty()
1332+
? default_value
1333+
: path.constData()).c_str()
1334+
);
13461335
});
13471336
}
13481337
if (reset_button)
13491338
{
13501339
QObject::connect(
1351-
reset_button, &QAbstractButton::clicked, reset_button, [widget, default_value = std::move(default_value), value_changed]() {
1352-
widget->setText(QString::fromStdString(default_value));
1340+
reset_button, &QAbstractButton::clicked, reset_button, [widget, value_changed]() {
1341+
widget->clear();
13531342
value_changed();
13541343
});
13551344
}

pcsx2-qt/Settings/AchievementSettingsWidget.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
#include <QtCore/QDateTime>
1818
#include <QtWidgets/QMessageBox>
1919

20-
const char* AchievementSettingsWidget::AUDIO_FILE_FILTER = QT_TRANSLATE_NOOP("AchievementSettingsWidget", "WAV Audio Files (*.wav)");
20+
static constexpr const char* AUDIO_FILE_FILTER = QT_TRANSLATE_NOOP("AchievementSettingsWidget", "WAV Audio Files (*.wav)");
21+
static constexpr const char* DEFAULT_INFO_SOUND_NAME = "sounds/achievements/message.wav";
22+
static constexpr const char* DEFAULT_UNLOCK_SOUND_NAME = "sounds/achievements/unlock.wav";
23+
static constexpr const char* DEFAULT_LBSUBMIT_SOUND_NAME = "sounds/achievements/lbsubmit.wav";
2124

2225
AchievementSettingsWidget::AchievementSettingsWidget(SettingsWindow* settings_dialog, QWidget* parent)
2326
: SettingsWidget(settings_dialog, parent)
@@ -44,9 +47,9 @@ AchievementSettingsWidget::AchievementSettingsWidget(SettingsWindow* settings_di
4447
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.achievementNotificationsDuration, "Achievements", "NotificationsDuration", Pcsx2Config::AchievementsOptions::DEFAULT_NOTIFICATION_DURATION);
4548
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.leaderboardNotificationsDuration, "Achievements", "LeaderboardsDuration", Pcsx2Config::AchievementsOptions::DEFAULT_LEADERBOARD_DURATION);
4649

47-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.notificationSoundPath, m_ui.notificationSoundBrowse, m_ui.notificationSoundOpen, m_ui.notificationSoundReset, "Achievements", "InfoSoundName", Path::Combine(EmuFolders::Resources, EmuConfig.Achievements.DEFAULT_INFO_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
48-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.unlockSoundPath, m_ui.unlockSoundBrowse, m_ui.unlockSoundOpen, m_ui.unlockSoundReset, "Achievements", "UnlockSoundName", Path::Combine(EmuFolders::Resources, EmuConfig.Achievements.DEFAULT_UNLOCK_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
49-
SettingWidgetBinder::BindWidgetToFileSetting(sif, m_ui.lbSoundPath, m_ui.lbSoundBrowse, m_ui.lbSoundOpen, m_ui.lbSoundReset, "Achievements", "LBSubmitSoundName", Path::Combine(EmuFolders::Resources, EmuConfig.Achievements.DEFAULT_LBSUBMIT_SOUND_NAME), qApp->translate("AchievementSettingsWidget", AUDIO_FILE_FILTER), true, false);
50+
SettingWidgetBinder::BindWidgetToAudioFileSetting(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::BindWidgetToAudioFileSetting(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::BindWidgetToAudioFileSetting(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);
5053

5154
dialog()->registerWidgetHelp(m_ui.enable, tr("Enable Achievements"), tr("Unchecked"), tr("When enabled and logged in, PCSX2 will scan for achievements on startup."));
5255
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."));

pcsx2-qt/Settings/AchievementSettingsWidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ private Q_SLOTS:
2626

2727
private:
2828
void updateLoginState();
29-
static const char* AUDIO_FILE_FILTER;
3029

3130
Ui::AchievementSettingsWidget m_ui;
3231
};

pcsx2-qt/Settings/AchievementSettingsWidget.ui

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,18 @@
316316
</property>
317317
<layout class="QGridLayout" name="gridLayout_6">
318318
<item row="5" column="0">
319-
<widget class="QLineEdit" name="lbSoundPath"/>
319+
<widget class="QLineEdit" name="lbSoundPath">
320+
<property name="placeholderText">
321+
<string>Default Sound Effect</string>
322+
</property>
323+
</widget>
320324
</item>
321325
<item row="1" column="0">
322-
<widget class="QLineEdit" name="notificationSoundPath"/>
326+
<widget class="QLineEdit" name="notificationSoundPath">
327+
<property name="placeholderText">
328+
<string>Default Sound Effect</string>
329+
</property>
330+
</widget>
323331
</item>
324332
<item row="3" column="1">
325333
<widget class="QPushButton" name="unlockSoundBrowse">
@@ -350,7 +358,11 @@
350358
</widget>
351359
</item>
352360
<item row="3" column="0">
353-
<widget class="QLineEdit" name="unlockSoundPath"/>
361+
<widget class="QLineEdit" name="unlockSoundPath">
362+
<property name="placeholderText">
363+
<string>Default Sound Effect</string>
364+
</property>
365+
</widget>
354366
</item>
355367
<item row="5" column="1">
356368
<widget class="QPushButton" name="lbSoundBrowse">
@@ -426,12 +438,12 @@ Login token generated at:</string>
426438
<property name="alignment">
427439
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
428440
</property>
441+
<property name="textInteractionFlags">
442+
<set>Qt::TextInteractionFlag::TextBrowserInteraction</set>
443+
</property>
429444
<property name="buddy">
430445
<cstring>viewProfile</cstring>
431446
</property>
432-
<property name="textInteractionFlags">
433-
<set>Qt::TextBrowserInteraction</set>
434-
</property>
435447
</widget>
436448
</item>
437449
<item>
@@ -473,7 +485,7 @@ Login token generated at:</string>
473485
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
474486
</property>
475487
<property name="textInteractionFlags">
476-
<set>Qt::TextBrowserInteraction</set>
488+
<set>Qt::TextInteractionFlag::TextBrowserInteraction</set>
477489
</property>
478490
</widget>
479491
</item>

pcsx2/Achievements.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ namespace Achievements
6363
static constexpr float LEADERBOARD_STARTED_NOTIFICATION_TIME = 3.0f;
6464
static constexpr float LEADERBOARD_FAILED_NOTIFICATION_TIME = 3.0f;
6565

66+
static constexpr const char* DEFAULT_INFO_SOUND_NAME = "sounds/achievements/message.wav";
67+
static constexpr const char* DEFAULT_UNLOCK_SOUND_NAME = "sounds/achievements/unlock.wav";
68+
static constexpr const char* DEFAULT_LBSUBMIT_SOUND_NAME = "sounds/achievements/lbsubmit.wav";
69+
6670
static constexpr float INDICATOR_FADE_IN_TIME = 0.1f;
6771
static constexpr float INDICATOR_FADE_OUT_TIME = 0.5f;
6872

@@ -1142,7 +1146,11 @@ void Achievements::DisplayAchievementSummary()
11421146
}
11431147

11441148
if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.InfoSound)
1145-
Common::PlaySoundAsync(EmuConfig.Achievements.InfoSoundName.c_str());
1149+
Common::PlaySoundAsync(
1150+
(EmuConfig.Achievements.InfoSoundName.empty()
1151+
? Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME)
1152+
: EmuConfig.Achievements.InfoSoundName).c_str()
1153+
);
11461154
}
11471155

11481156
void Achievements::DisplayHardcoreDeferredMessage()
@@ -1194,7 +1202,11 @@ void Achievements::HandleUnlockEvent(const rc_client_event_t* event)
11941202
}
11951203

11961204
if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.UnlockSound)
1197-
Common::PlaySoundAsync(EmuConfig.Achievements.UnlockSoundName.c_str());
1205+
Common::PlaySoundAsync(
1206+
(EmuConfig.Achievements.UnlockSoundName.empty()
1207+
? Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME)
1208+
: EmuConfig.Achievements.UnlockSoundName).c_str()
1209+
);
11981210
}
11991211

12001212
void Achievements::HandleGameCompleteEvent(const rc_client_event_t* event)
@@ -1315,7 +1327,11 @@ void Achievements::HandleLeaderboardSubmittedEvent(const rc_client_event_t* even
13151327
}
13161328

13171329
if (EmuConfig.Achievements.SoundEffects && EmuConfig.Achievements.LBSubmitSound)
1318-
Common::PlaySoundAsync(EmuConfig.Achievements.LBSubmitSoundName.c_str());
1330+
Common::PlaySoundAsync(
1331+
(EmuConfig.Achievements.LBSubmitSoundName.empty()
1332+
? Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME)
1333+
: EmuConfig.Achievements.LBSubmitSoundName).c_str()
1334+
);
13191335
}
13201336

13211337
void Achievements::HandleLeaderboardScoreboardEvent(const rc_client_event_t* event)

pcsx2/Config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,6 @@ struct Pcsx2Config
12851285
static constexpr u32 MAXIMUM_NOTIFICATION_DURATION = 30;
12861286
static constexpr u32 DEFAULT_NOTIFICATION_DURATION = 5;
12871287
static constexpr u32 DEFAULT_LEADERBOARD_DURATION = 10;
1288-
static constexpr const char* DEFAULT_INFO_SOUND_NAME = "sounds/achievements/message.wav";
1289-
static constexpr const char* DEFAULT_UNLOCK_SOUND_NAME = "sounds/achievements/unlock.wav";
1290-
static constexpr const char* DEFAULT_LBSUBMIT_SOUND_NAME = "sounds/achievements/lbsubmit.wav";
12911288

12921289
static const char* OverlayPositionNames[(size_t)AchievementOverlayPosition::MaxCount + 1];
12931290

pcsx2/Pcsx2Config.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,15 +1884,6 @@ void Pcsx2Config::AchievementsOptions::LoadSave(SettingsWrapper& wrap)
18841884
{
18851885
SettingsWrapSection("Achievements");
18861886

1887-
if (InfoSoundName.empty())
1888-
InfoSoundName = Path::Combine(EmuFolders::Resources, DEFAULT_INFO_SOUND_NAME);
1889-
1890-
if (UnlockSoundName.empty())
1891-
UnlockSoundName = Path::Combine(EmuFolders::Resources, DEFAULT_UNLOCK_SOUND_NAME);
1892-
1893-
if (LBSubmitSoundName.empty())
1894-
LBSubmitSoundName = Path::Combine(EmuFolders::Resources, DEFAULT_LBSUBMIT_SOUND_NAME);
1895-
18961887
SettingsWrapBitBool(Enabled);
18971888
SettingsWrapBitBoolEx(HardcoreMode, "ChallengeMode");
18981889
SettingsWrapBitBool(EncoreMode);

0 commit comments

Comments
 (0)