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

View file

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

View file

@ -548,6 +548,7 @@ void ViewController::reloadAll()
} }
// Load navigation sounds. // Load navigation sounds.
NavigationSounds::getInstance()->deinit();
NavigationSounds::getInstance()->loadThemeNavigationSounds( NavigationSounds::getInstance()->loadThemeNavigationSounds(
SystemData::sSystemVector.front()->getTheme()); 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() NavigationSounds* NavigationSounds::getInstance()
{ {
if (sInstance == NULL) if (sInstance == nullptr)
sInstance = new NavigationSounds(); sInstance = new NavigationSounds();
return sInstance; return sInstance;
} }
void NavigationSounds::deinit()
{
if (sInstance)
delete sInstance;
sInstance = nullptr;
}
void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme) void NavigationSounds::loadThemeNavigationSounds(const std::shared_ptr<ThemeData>& theme)
{ {
navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowseSound")); navigationSounds.push_back(Sound::getFromTheme(theme, "all", "systembrowseSound"));

View file

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