From dca648c160071caa0ad2af196eab8f747d6e9434 Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Thu, 14 Sep 2017 02:18:52 +0100 Subject: [PATCH] TextListComponent: rework onScroll function Modify onScroll so that AudioManager is initialized only when playback is necessary. Before this change, ViewController::preload() was initializing audio during startup for any theme that has the scroll sound, even if navigation sounds are disabled in the settings. --- es-app/src/components/TextListComponent.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/es-app/src/components/TextListComponent.h b/es-app/src/components/TextListComponent.h index 0aa078ac2..336cbac50 100644 --- a/es-app/src/components/TextListComponent.h +++ b/es-app/src/components/TextListComponent.h @@ -76,13 +76,11 @@ public: inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; } inline void setSelectorColor(unsigned int color) { mSelectorColor = color; } inline void setSelectedColor(unsigned int color) { mSelectedColor = color; } - inline void setScrollSound(const std::shared_ptr& sound) { mScrollSound = sound; } inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; } - inline void setSound(const std::shared_ptr& sound) { mScrollSound = sound; } inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; } protected: - virtual void onScroll(int amt) { if(mScrollSound) mScrollSound->play(); } + virtual void onScroll(int amt) { if(!mScrollSound.empty()) Sound::get(mScrollSound)->play(); } virtual void onCursorChanged(const CursorState& state); private: @@ -105,7 +103,7 @@ private: float mSelectorOffsetY; unsigned int mSelectorColor; unsigned int mSelectedColor; - std::shared_ptr mScrollSound; + std::string mScrollSound; static const unsigned int COLOR_ID_COUNT = 2; unsigned int mColors[COLOR_ID_COUNT]; @@ -354,7 +352,7 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, c setSelectorHeight(selectorHeight); if(properties & SOUND && elem->has("scrollSound")) - setSound(Sound::get(elem->get("scrollSound"))); + mScrollSound = elem->get("scrollSound"); if(properties & ALIGNMENT) {