Skip to content

Commit

Permalink
Add a setting. Various tweaks to sound triggering.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 3, 2020
1 parent 434b717 commit 3fd8f3d
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ static ConfigSetting generalSettings[] = {
ConfigSetting("Language", &g_Config.sLanguageIni, &DefaultLangRegion),
ConfigSetting("ForceLagSync2", &g_Config.bForceLagSync, false, true, true),
ConfigSetting("DiscordPresence", &g_Config.bDiscordPresence, true, true, false), // Or maybe it makes sense to have it per-game? Race conditions abound...
ConfigSetting("UISound", &g_Config.bUISound, true, true, false),

ReportedConfigSetting("NumWorkerThreads", &g_Config.iNumWorkerThreads, &DefaultNumWorkers, true, true),
ConfigSetting("AutoLoadSaveState", &g_Config.iAutoLoadSaveState, 0, true, true),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct Config {
int iMaxRecent;
int iCurrentStateSlot;
int iRewindFlipFrequency;
bool bUISound;
bool bEnableStateUndo;
int iAutoLoadSaveState; // 0 = off, 1 = oldest, 2 = newest, >2 = slot number + 3
bool bEnableCheats;
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void GameSettingsScreen::CreateViews() {
}
}
#endif

systemSettings->Add(new CheckBox(&g_Config.bUISound, dev->T("UI Sound")));
systemSettings->Add(new CheckBox(&g_Config.bCheckForNewVersion, sy->T("VersionCheck", "Check for new versions of PPSSPP")));
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg";
Expand Down
2 changes: 2 additions & 0 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,8 @@ void NativeUpdate() {
screenManager->update();

g_Discord.Update();

UI::SetSoundEnabled(g_Config.bUISound);
}

bool NativeIsAtTopLevel() {
Expand Down
8 changes: 7 additions & 1 deletion ext/native/ui/root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <deque>

#include "ppsspp_config.h"

#include "base/timeutil.h"
#include "ui/root.h"
#include "ui/viewgroup.h"
Expand All @@ -18,6 +19,7 @@ bool focusForced;
static std::mutex eventMutex_;

static std::function<void(UISound)> soundCallback;
static bool soundEnabled = true;


struct DispatchQueueItem {
Expand Down Expand Up @@ -141,12 +143,16 @@ void MoveFocus(ViewGroup *root, FocusDirection direction) {
}
}

void SetSoundEnabled(bool enabled) {
soundEnabled = enabled;
}

void SetSoundCallback(std::function<void(UISound)> func) {
soundCallback = func;
}

void PlayUISound(UISound sound) {
if (soundCallback) {
if (soundEnabled && soundCallback) {
soundCallback(sound);
}
}
Expand Down
1 change: 1 addition & 0 deletions ext/native/ui/root.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum class UISound {
COUNT,
};

void SetSoundEnabled(bool enabled);
void SetSoundCallback(std::function<void(UISound)> func);

void PlayUISound(UISound sound);
Expand Down
5 changes: 1 addition & 4 deletions ext/native/ui/ui_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ bool UIScreen::key(const KeyInput &key) {
}

void UIScreen::TriggerFinish(DialogResult result) {
switch (result) {
case DialogResult::DR_BACK: UI::PlayUISound(UI::UISound::BACK); break;
case DialogResult::DR_OK: UI::PlayUISound(UI::UISound::CONFIRM); break;
}
screenManager()->finishDialog(this, result);
}

Expand All @@ -172,6 +168,7 @@ bool UIDialogScreen::key(const KeyInput &key) {
} else {
finished_ = true;
TriggerFinish(DR_BACK);
UI::PlayUISound(UI::UISound::BACK);
}
return true;
}
Expand Down
24 changes: 21 additions & 3 deletions ext/native/ui/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ void Clickable::Click() {
UI::EventParams e{};
e.v = this;
OnClick.Trigger(e);
UI::PlayUISound(UI::UISound::CONFIRM);
};

void Clickable::FocusChanged(int focusFlags) {
Expand Down Expand Up @@ -377,6 +376,7 @@ bool StickyChoice::Key(const KeyInput &key) {
if (key.flags & KEY_DOWN) {
if (IsAcceptKey(key)) {
down_ = true;
UI::PlayUISound(UI::UISound::TOGGLE_ON);
Click();
return true;
}
Expand Down Expand Up @@ -425,6 +425,11 @@ void ClickableItem::Draw(UIContext &dc) {
DrawBG(dc, style);
}

void Choice::Click() {
ClickableItem::Click();
UI::PlayUISound(UI::UISound::CONFIRM);
}

void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const {
if (atlasImage_.isValid()) {
dc.Draw()->GetAtlas()->measureImage(atlasImage_, &w, &h);
Expand Down Expand Up @@ -597,8 +602,10 @@ void PopupHeader::Draw(UIContext &dc) {
}

void CheckBox::Toggle() {
if (toggle_)
if (toggle_) {
*toggle_ = !(*toggle_);
UI::PlayUISound(*toggle_ ? UI::UISound::TOGGLE_ON : UI::UISound::TOGGLE_OFF);
}
}

bool CheckBox::Toggled() const {
Expand Down Expand Up @@ -669,8 +676,14 @@ void CheckBox::GetContentDimensions(const UIContext &dc, float &w, float &h) con
}

void BitCheckBox::Toggle() {
if (bitfield_)
if (bitfield_) {
*bitfield_ = *bitfield_ ^ bit_;
if (*bitfield_ & bit_) {
UI::PlayUISound(UI::UISound::TOGGLE_ON);
} else {
UI::PlayUISound(UI::UISound::TOGGLE_OFF);
}
}
}

bool BitCheckBox::Toggled() const {
Expand All @@ -690,6 +703,11 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
h += paddingH_;
}

void Button::Click() {
Clickable::Click();
UI::PlayUISound(UI::UISound::CONFIRM);
}

void Button::Draw(UIContext &dc) {
Style style = dc.theme->buttonStyle;

Expand Down
2 changes: 2 additions & 0 deletions ext/native/ui/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ class Button : public Clickable {
Button(const std::string &text, ImageID imageID, LayoutParams *layoutParams = 0)
: Clickable(layoutParams), text_(text), imageID_(imageID) {}

void Click() override;
void Draw(UIContext &dc) override;
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
const std::string &GetText() const { return text_; }
Expand Down Expand Up @@ -647,6 +648,7 @@ class Choice : public ClickableItem {
Choice(ImageID image, LayoutParams *layoutParams = nullptr)
: ClickableItem(layoutParams), atlasImage_(image), iconImage_(ImageID::invalid()), centered_(false), highlighted_(false), selected_(false) {}

virtual void Click();
virtual void HighlightChanged(bool highlighted);
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;
void Draw(UIContext &dc) override;
Expand Down
15 changes: 11 additions & 4 deletions ext/native/ui/viewgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "math/curves.h"
#include "ui/ui_context.h"
#include "ui/ui_tween.h"
#include "ui/root.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "gfx_es2/draw_buffer.h"
Expand Down Expand Up @@ -1321,11 +1322,17 @@ void ChoiceStrip::HighlightChoice(unsigned int choice){
bool ChoiceStrip::Key(const KeyInput &input) {
bool ret = false;
if (input.flags & KEY_DOWN) {
if (IsTabLeftKey(input) && selected_ > 0) {
SetSelection(selected_ - 1);
if (IsTabLeftKey(input)) {
if (selected_ > 0) {
SetSelection(selected_ - 1);
UI::PlayUISound(UI::UISound::TOGGLE_OFF); // Maybe make specific sounds for this at some point?
}
ret = true;
} else if (IsTabRightKey(input) && selected_ < (int)views_.size() - 1) {
SetSelection(selected_ + 1);
} else if (IsTabRightKey(input)) {
if (selected_ < (int)views_.size() - 1) {
SetSelection(selected_ + 1);
UI::PlayUISound(UI::UISound::TOGGLE_ON);
}
ret = true;
}
}
Expand Down

0 comments on commit 3fd8f3d

Please sign in to comment.