Added navigation sound support (configurable per theme) and implemented proper sound handling at most places in ES

This commit is contained in:
Leon Styhre 2020-05-15 18:08:26 +02:00
parent 5f5d12535d
commit 0aafc1314a
10 changed files with 54 additions and 18 deletions

View file

@ -80,8 +80,9 @@ public:
inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
protected:
virtual void onScroll(int /*amt*/) { if(!mScrollSound.empty()) Sound::get(mScrollSound)->play(); }
virtual void onScroll() { soundfile->play(); }
virtual void onCursorChanged(const CursorState& state);
std::shared_ptr<Sound> soundfile;
private:
int mMarqueeOffset;
@ -390,9 +391,8 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme, c
const float selectorHeight = Math::max(mFont->getHeight(1.0), (float)mFont->getSize()) * mLineSpacing;
setSelectorHeight(selectorHeight);
if(properties & SOUND && elem->has("scrollSound"))
mScrollSound = elem->get<std::string>("scrollSound");
soundfile = Sound::getFromTheme(theme, "navigationsounds", "scrollSound");
if(properties & ALIGNMENT)
{
if(elem->has("alignment"))

View file

@ -8,6 +8,7 @@
#include "Settings.h"
#include "SystemData.h"
#include "Window.h"
#include "Sound.h"
// buffer values for scrolling velocity (left, stopped, right)
const int logoBuffersLeft[] = { -5, -2, -1 };
@ -28,6 +29,8 @@ SystemView::SystemView(Window* window) : IList<SystemViewData, SystemData*>(wind
void SystemView::populate()
{
mEntries.clear();
mSelectSound = "";
// mScrollSound = "";
for(auto it = SystemData::sSystemVector.cbegin(); it != SystemData::sSystemVector.cend(); it++)
{
@ -124,6 +127,8 @@ void SystemView::populate()
mWindow->pushGui(new GuiMsgBox(mWindow, "The selected UI mode has nothing to show,\n returning to UI mode: FULL", "OK", nullptr));
}
}
}
void SystemView::goToSystem(SystemData* system, bool animate)
@ -136,6 +141,9 @@ void SystemView::goToSystem(SystemData* system, bool animate)
bool SystemView::input(InputConfig* config, Input input)
{
auto it = SystemData::sSystemVector.cbegin();
const std::shared_ptr<ThemeData>& theme = (*it)->getTheme();
if(input.value != 0)
{
if(config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_r && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug"))
@ -151,11 +159,13 @@ bool SystemView::input(InputConfig* config, Input input)
case VERTICAL_WHEEL:
if (config->isMappedLike("up", input))
{
Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play();
listInput(-1);
return true;
}
if (config->isMappedLike("down", input))
{
Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play();
listInput(1);
return true;
}
@ -165,11 +175,13 @@ bool SystemView::input(InputConfig* config, Input input)
default:
if (config->isMappedLike("left", input))
{
Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play();
listInput(-1);
return true;
}
if (config->isMappedLike("right", input))
{
Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play();
listInput(1);
return true;
}
@ -178,6 +190,7 @@ bool SystemView::input(InputConfig* config, Input input)
if(config->isMappedTo("a", input))
{
Sound::getFromTheme(theme, "navigationsounds", "selectSound")->play();
stopScrolling();
ViewController::get()->goToGameList(getSelected());
return true;
@ -186,6 +199,7 @@ bool SystemView::input(InputConfig* config, Input input)
{
// get random system
// go to system
Sound::getFromTheme(theme, "navigationsounds", "systembrowseSound")->play();
setCursor(SystemData::getRandomSystem());
return true;
}

View file

@ -62,6 +62,9 @@ public:
std::vector<HelpPrompt> getHelpPrompts() override;
virtual HelpStyle getHelpStyle() override;
std::string mSelectSound;
// std::string mScrollSound;
protected:
void onCursorChanged(const CursorState& state) override;
@ -76,7 +79,6 @@ private:
void renderInfoBar(const Transform4x4f& trans);
void renderFade(const Transform4x4f& trans);
SystemViewCarousel mCarousel;
TextComponent mSystemInfo;

View file

@ -50,10 +50,6 @@ void BasicGameListView::populateList(const std::vector<FileData*>& files)
bool favoritesFirst = Settings::getInstance()->getBool("FavoritesFirst");
// auto fav = Settings::getInstance()->getString(mRoot->getSystem()->getName() + ".FavoritesFirst");
// if (fav == "1") favoritesFirst = true;
// else if (fav == "0") favoritesFirst = false;
bool showFavoriteIcon = (systemName != "favorites" && systemName != "recent");
if (!showFavoriteIcon)
favoritesFirst = false;

View file

@ -6,6 +6,7 @@
#include "CollectionSystemManager.h"
#include "Settings.h"
#include "SystemData.h"
#include "Sound.h"
#ifdef _RPI_
#include "components/VideoPlayerComponent.h"
#endif
@ -146,6 +147,10 @@ std::string GridGameListView::getQuickSystemSelectLeftButton()
bool GridGameListView::input(InputConfig* config, Input input)
{
if (input.value == 0 and (config->isMappedLike("left", input) || config->isMappedLike("right", input)
|| (config->isMappedLike("up", input)) || (config->isMappedLike("down", input)) ))
Sound::getFromTheme(getTheme(), "navigationsounds", "scrollSound")->play();
if(config->isMappedLike("left", input) || config->isMappedLike("right", input))
return GuiComponent::input(config, input);

View file

@ -11,7 +11,6 @@ bool IGameListView::input(InputConfig* config, Input input)
// select to open GuiGamelistOptions
if(!UIModeController::getInstance()->isUIModeKid() && config->isMappedTo("select", input) && input.value)
{
Sound::getFromTheme(mTheme, getName(), "menuOpen")->play();
mWindow->pushGui(new GuiGamelistOptions(mWindow, this->mRoot->getSystem()));
return true;

View file

@ -78,6 +78,8 @@ void ISimpleGameListView::onFileChanged(FileData* /*file*/, FileChangeType /*cha
bool ISimpleGameListView::input(InputConfig* config, Input input)
{
std::shared_ptr<Sound> soundfile;
if(input.value != 0)
{
if(config->isMappedTo("a", input))
@ -85,7 +87,9 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
FileData* cursor = getCursor();
if(cursor->getType() == GAME)
{
Sound::getFromTheme(getTheme(), getName(), "launch")->play();
soundfile = Sound::getFromTheme(getTheme(), "navigationsounds", "launchSound");
soundfile->play();
while(soundfile->isPlaying());
launch(cursor);
}else{
// it's a folder
@ -106,8 +110,8 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
populateList(mCursorStack.top()->getParent()->getChildren());
setCursor(mCursorStack.top());
mCursorStack.pop();
Sound::getFromTheme(getTheme(), getName(), "back")->play();
}else{
Sound::getFromTheme(getTheme(), "navigationsounds", "backSound")->play();
onFocusLost();
SystemData* systemToView = getCursor()->getSystem();
if (systemToView->isCollection())
@ -122,6 +126,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
{
if(Settings::getInstance()->getBool("QuickSystemSelect"))
{
Sound::getFromTheme(getTheme(), "navigationsounds", "quicksysselectSound")->play();
onFocusLost();
ViewController::get()->goToNextGameList();
return true;
@ -130,6 +135,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
{
if(Settings::getInstance()->getBool("QuickSystemSelect"))
{
Sound::getFromTheme(getTheme(), "navigationsounds", "quicksysselectSound")->play();
onFocusLost();
ViewController::get()->goToPrevGameList();
return true;
@ -139,6 +145,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
if (mRoot->getSystem()->isGameSystem())
{
// go to random system game
Sound::getFromTheme(getTheme(), "navigationsounds", "scrollSound")->play();
FileData* randomGame = getCursor()->getSystem()->getRandomGame();
if (randomGame)
{
@ -150,6 +157,7 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
{
if(mRoot->getSystem()->isGameSystem())
{
Sound::getFromTheme(getTheme(), "navigationsounds", "favoriteSound")->play();
if(CollectionSystemManager::get()->toggleGameInCollection(getCursor()))
{
return true;

View file

@ -21,15 +21,19 @@ std::shared_ptr<Sound> Sound::get(const std::string& path)
std::shared_ptr<Sound> Sound::getFromTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element)
{
LOG(LogInfo) << " req sound [" << view << "." << element << "]";
if(!Settings::getInstance()->getBool("EnableSounds"))
return get("");
LOG(LogInfo) << "Sound::getFromTheme() looking for [" << view << "." << element << "]";
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "sound");
if(!elem || !elem->has("path"))
{
LOG(LogInfo) << " (missing)";
LOG(LogInfo) << "[" << element << "] not found, can't play sound file";
return get("");
}
LOG(LogInfo) << "[" << element << "] found, ready to play sound file";
return get(elem->get<std::string>("path"));
}

View file

@ -10,10 +10,18 @@
#include <pugixml/src/pugixml.hpp>
#include <algorithm>
std::vector<std::string> ThemeData::sSupportedViews { { "system" }, { "basic" }, { "detailed" }, { "grid" }, { "video" } };
std::vector<std::string> ThemeData::sSupportedViews { { "navigationsounds" }, { "system" }, { "basic" }, { "detailed" }, { "grid" }, { "video" } };
std::vector<std::string> ThemeData::sSupportedFeatures { { "video" }, { "carousel" }, { "z-index" }, { "visible" } };
std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>> ThemeData::sElementMap {
{ "navigationsounds", {
{ "systembrowseSound", PATH },
{ "quicksysselectSound", PATH },
{ "selectSound", PATH },
{ "backSound", PATH },
{ "scrollSound", PATH },
{ "favoriteSound", PATH },
{ "launchSound", PATH } } },
{ "image", {
{ "pos", NORMALIZED_PAIR },
{ "size", NORMALIZED_PAIR },

View file

@ -299,14 +299,14 @@ protected:
}
if(cursor != mCursor)
onScroll(absAmt);
onScroll();
mCursor = cursor;
onCursorChanged((mScrollTier > 0) ? CURSOR_SCROLLING : CURSOR_STOPPED);
}
virtual void onCursorChanged(const CursorState& /*state*/) {}
virtual void onScroll(int /*amt*/) {}
virtual void onScroll() {}
};
#endif // ES_CORE_COMPONENTS_ILIST_H