Allow preview of UI sound volume while changing the slider.

This commit is contained in:
Henrik Rydgård
2025-02-11 18:03:42 -06:00
parent 25817c3bdb
commit d200d80633
4 changed files with 22 additions and 5 deletions
+8 -1
View File
@@ -202,7 +202,7 @@ void PopupSliderChoiceFloat::SetFormat(std::string_view fmt) {
EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
restoreFocus_ = HasFocus();
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, defaultValue_, ChopTitle(text_), step_, units_);
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, defaultValue_, ChopTitle(text_), step_, units_, liveUpdate_);
if (!negativeLabel_.empty())
popupScreen->SetNegativeDisable(negativeLabel_);
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
@@ -346,6 +346,13 @@ void SliderPopupScreen::UpdateTextBox() {
char temp[128];
snprintf(temp, sizeof(temp), "%d", sliderValue_);
edit_->SetText(temp);
if (liveUpdate_ && *value_ != sliderValue_) {
*value_ = sliderValue_;
EventParams e{};
e.v = nullptr;
e.a = *value_;
OnChange.Trigger(e);
}
}
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
+7 -2
View File
@@ -80,8 +80,8 @@ private:
class SliderPopupScreen : public PopupScreen {
public:
SliderPopupScreen(int *value, int minValue, int maxValue, int defaultValue, std::string_view title, int step = 1, std::string_view units = "")
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), defaultValue_(defaultValue), step_(step) {}
SliderPopupScreen(int *value, int minValue, int maxValue, int defaultValue, std::string_view title, int step, std::string_view units, bool liveUpdate)
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), defaultValue_(defaultValue), step_(step), liveUpdate_(liveUpdate) {}
void CreatePopupContents(ViewGroup *parent) override;
void SetNegativeDisable(const std::string &str) {
@@ -110,6 +110,7 @@ private:
int maxValue_;
int defaultValue_;
int step_;
bool liveUpdate_;
bool changing_ = false;
bool disabled_ = false;
};
@@ -303,6 +304,9 @@ public:
void SetZeroLabel(std::string_view str) {
zeroLabel_ = str;
}
void SetLiveUpdate(bool update) {
liveUpdate_ = update;
}
void SetNegativeDisable(std::string_view str) {
negativeLabel_ = str;
}
@@ -327,6 +331,7 @@ private:
std::string units_;
ScreenManager *screenManager_;
bool restoreFocus_ = false;
bool liveUpdate_ = false;
};
class PopupSliderChoiceFloat : public AbstractChoiceWithValueDisplay {
+6 -1
View File
@@ -679,7 +679,12 @@ void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) {
PopupSliderChoice *uiVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iUIVolume, 0, VOLUMEHI_FULL, VOLUMEHI_FULL, ac->T("UI volume"), screenManager()));
uiVolume->SetFormat("%d%%");
uiVolume->SetZeroLabel(a->T("Mute"));
uiVolume->SetLiveUpdate(true);
uiVolume->OnChange.Add([](UI::EventParams &e) {
// Audio preview
PlayUISound(UI::UISound::CONFIRM);
return UI::EVENT_DONE;
});
audioSettings->Add(new ItemHeader(a->T("Audio backend")));
// Hide the backend selector in UWP builds (we only support XAudio2 there).
+1 -1
View File
@@ -340,7 +340,7 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
return UI::EVENT_DONE;
});
viewGroup->Add(new CheckBox(&g_Config.bAchievementsHardcoreMode, ac->T("Hardcore Mode (no savestates)")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new CheckBox(&g_Config.bAchievementsSoundEffects, ac->T("Sound Effects")))->SetEnabledPtr(&g_Config.bAchievementsEnable); // not yet implemented
viewGroup->Add(new CheckBox(&g_Config.bAchievementsSoundEffects, ac->T("Sound Effects")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new ItemHeader(di->T("Links")));
viewGroup->Add(new Choice(ac->T("RetroAchievements website")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {