Made navigation sounds unload and reload properly on theme changes.

Also improved the navigation sound handling for SystemView.
This commit is contained in:
Leon Styhre 2020-06-17 22:13:07 +02:00
parent 20001d0cca
commit 3c7d86a578
5 changed files with 17 additions and 6 deletions

View file

@ -12,9 +12,9 @@
#include "views/ViewController.h"
#include "Log.h"
#include "Settings.h"
#include "Sound.h"
#include "SystemData.h"
#include "Window.h"
#include "Sound.h"
// Buffer values for scrolling velocity (left, stopped, right).
const int logoBuffersLeft[] = { -5, -2, -1 };
@ -163,12 +163,10 @@ bool SystemView::input(InputConfig* config, Input input)
case VERTICAL:
case VERTICAL_WHEEL:
if (config->isMappedLike("up", input)) {
NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND);
listInput(-1);
return true;
}
if (config->isMappedLike("down", input)) {
NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND);
listInput(1);
return true;
}
@ -177,12 +175,10 @@ bool SystemView::input(InputConfig* config, Input input)
case HORIZONTAL_WHEEL:
default:
if (config->isMappedLike("left", input)) {
NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND);
listInput(-1);
return true;
}
if (config->isMappedLike("right", input)) {
NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND);
listInput(1);
return true;
}
@ -237,6 +233,8 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
// Update help style.
updateHelpPrompts();
// NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND);
float startPos = mCamOffset;
float posMax = (float)mEntries.size();

View file

@ -12,6 +12,7 @@
#include "components/TextComponent.h"
#include "resources/Font.h"
#include "GuiComponent.h"
#include "Sound.h"
#include <memory>
class AnimatedImageComponent;
@ -67,6 +68,8 @@ public:
protected:
void onCursorChanged(const CursorState& state) override;
virtual void onScroll() {
NavigationSounds::getInstance()->playThemeNavigationSound(SYSTEMBROWSESOUND); }
private:
void populate();

View file

@ -548,6 +548,7 @@ void ViewController::reloadAll()
}
// Load navigation sounds.
NavigationSounds::getInstance()->deinit();
NavigationSounds::getInstance()->loadThemeNavigationSounds(
SystemData::sSystemVector.front()->getTheme());

View file

@ -38,12 +38,20 @@ std::shared_ptr<Sound> Sound::getFromTheme(const std::shared_ptr<ThemeData>& the
NavigationSounds* NavigationSounds::getInstance()
{
if (sInstance == NULL)
if (sInstance == nullptr)
sInstance = new NavigationSounds();
return sInstance;
}
void NavigationSounds::deinit()
{
if (sInstance)
delete sInstance;
sInstance = nullptr;
}
void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme)
{
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowseSound"));

View file

@ -60,6 +60,7 @@ class NavigationSounds
public:
static NavigationSounds* getInstance();
void deinit();
void loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme);
void playThemeNavigationSound(NavigationSoundsID soundID);
bool isPlayingThemeNavigationSound(NavigationSoundsID soundID);