From e6f9192bb8aeba65064bbd25a4d815c9793de846 Mon Sep 17 00:00:00 2001 From: Pieter Hulshoff Date: Sun, 6 Oct 2019 14:40:37 +0200 Subject: [PATCH] Added support for cyclePlaylist key control. --- RetroFE/Source/Control/UserInput.cpp | 1 + RetroFE/Source/Control/UserInput.h | 1 + RetroFE/Source/Graphics/Page.cpp | 37 ++++++++++++++++++++++++++++ RetroFE/Source/Graphics/Page.h | 1 + RetroFE/Source/RetroFE.cpp | 10 ++++++++ RetroFE/Source/Utility/Utils.cpp | 13 ++++++++++ RetroFE/Source/Utility/Utils.h | 1 + RetroFE/Source/Version.cpp | 2 +- 8 files changed, 65 insertions(+), 1 deletion(-) diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index db03cc4..1c88364 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -60,6 +60,7 @@ bool UserInput::initialize() MapKey("favPlaylist", KeyCodeFavPlaylist, false); MapKey("nextPlaylist", KeyCodeNextPlaylist, false); MapKey("prevPlaylist", KeyCodePrevPlaylist, false); + MapKey("cyclePlaylist", KeyCodeCyclePlaylist, false); MapKey("addPlaylist", KeyCodeAddPlaylist, false); MapKey("removePlaylist", KeyCodeRemovePlaylist, false); MapKey("random", KeyCodeRandom, false); diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index 067231c..2e28029 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -44,6 +44,7 @@ public: KeyCodeFavPlaylist, KeyCodeNextPlaylist, KeyCodePrevPlaylist, + KeyCodeCyclePlaylist, KeyCodeRandom, KeyCodeMenu, KeyCodeAddPlaylist, diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index f9cf29f..82bf57f 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -1071,6 +1071,43 @@ void Page::selectPlaylist(std::string playlist) } +void Page::cyclePlaylist(std::vector list) +{ + + // Empty list + if (list.size() == 0) + return; + + // Find the current playlist in the list + std::vector::iterator it = list.begin(); + while (*it != getPlaylistName() && it != list.end()) + ++it; + + // If current playlist not found, switch to the first found cycle playlist in the playlist list + if (it == list.end()) + { + for (std::vector::iterator it2 = list.begin(); it2 != list.end(); ++it2) + { + selectPlaylist( *it2 ); + if (*it2 == getPlaylistName()) + break; + } + } + // Current playlist found; switch to the next found playlist in the list + else + { + for(;; ++it) + { + if (it == list.end()) it = list.begin(); // wrap + selectPlaylist( *it ); + if (*it == getPlaylistName()) + break; + } + } + +} + + void Page::update(float dt) { for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 2f99e6d..dbf8e11 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -57,6 +57,7 @@ public: void nextPlaylist(); void prevPlaylist(); void selectPlaylist(std::string playlist); + void cyclePlaylist(std::vector list); void pushMenu(ScrollingList *s, int index = -1); bool isMenusFull(); void setLoadSound(Sound *chunk); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 2b7b57c..30abe78 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -1067,6 +1067,16 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput( Page *page ) page->prevPlaylist( ); state = RETROFE_PLAYLIST_REQUEST; } + if ( input_.keystate(UserInput::KeyCodeCyclePlaylist) ) + { + attract_.reset( ); + std::string cycleString; + config_.getProperty( "cyclePlaylist", cycleString ); + std::vector cycleVector; + Utils::listToVector( cycleString, cycleVector, ',' ); + page->cyclePlaylist( cycleVector ); + state = RETROFE_PLAYLIST_REQUEST; + } if ( input_.newKeyPressed(UserInput::KeyCodeRemovePlaylist) ) { attract_.reset( ); diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index 3049966..19978bf 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -253,3 +253,16 @@ std::string Utils::trimEnds(std::string str) return str; } + +void Utils::listToVector( std::string str, std::vector &vec, char delimiter = ',' ) +{ + std::size_t current, previous = 0; + current = str.find( delimiter ); + while (current != std::string::npos) + { + vec.push_back( Utils::trimEnds( str.substr( previous, current - previous ) ) ); + previous = current + 1; + current = str.find( delimiter, previous ); + } + vec.push_back( Utils::trimEnds( str.substr( previous, current - previous ) ) ); +} diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index a66e8f3..7a41b74 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -35,6 +35,7 @@ public: static std::string uppercaseFirst(std::string str); static std::string filterComments(std::string line); static std::string trimEnds(std::string str); + static void listToVector( std::string str, std::vector &vec, char delimiter ); //todo: there has to be a better way to do this static std::string combinePath(std::list &paths); diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index 70e3583..1c3d054 100644 --- a/RetroFE/Source/Version.cpp +++ b/RetroFE/Source/Version.cpp @@ -21,7 +21,7 @@ std::string retrofe_version_major = "0"; std::string retrofe_version_minor = "9"; -std::string retrofe_version_build = "2"; +std::string retrofe_version_build = "3"; std::string Version::getString( )