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.
This commit is contained in:
Conn O'Griofa 2017-09-14 02:18:52 +01:00
parent 99c1ddb260
commit dca648c160

View file

@ -76,13 +76,11 @@ public:
inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; } inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; }
inline void setSelectorColor(unsigned int color) { mSelectorColor = color; } inline void setSelectorColor(unsigned int color) { mSelectorColor = color; }
inline void setSelectedColor(unsigned int color) { mSelectedColor = color; } inline void setSelectedColor(unsigned int color) { mSelectedColor = color; }
inline void setScrollSound(const std::shared_ptr<Sound>& sound) { mScrollSound = sound; }
inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; } inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; }
inline void setSound(const std::shared_ptr<Sound>& sound) { mScrollSound = sound; }
inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; } inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
protected: 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); virtual void onCursorChanged(const CursorState& state);
private: private:
@ -105,7 +103,7 @@ private:
float mSelectorOffsetY; float mSelectorOffsetY;
unsigned int mSelectorColor; unsigned int mSelectorColor;
unsigned int mSelectedColor; unsigned int mSelectedColor;
std::shared_ptr<Sound> mScrollSound; std::string mScrollSound;
static const unsigned int COLOR_ID_COUNT = 2; static const unsigned int COLOR_ID_COUNT = 2;
unsigned int mColors[COLOR_ID_COUNT]; unsigned int mColors[COLOR_ID_COUNT];
@ -354,7 +352,7 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme, c
setSelectorHeight(selectorHeight); setSelectorHeight(selectorHeight);
if(properties & SOUND && elem->has("scrollSound")) if(properties & SOUND && elem->has("scrollSound"))
setSound(Sound::get(elem->get<std::string>("scrollSound"))); mScrollSound = elem->get<std::string>("scrollSound");
if(properties & ALIGNMENT) if(properties & ALIGNMENT)
{ {