From 2fd0870275819fd4f9318b4a2f95f5cddb3700be Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sat, 6 May 2023 21:32:23 -0700 Subject: [PATCH 1/8] initial playlist menu support; compiles but doesn't run --- RetroFE/Source/Collection/CollectionInfo.h | 1 + .../Collection/CollectionInfoBuilder.cpp | 7 +++++ .../Graphics/Component/ScrollingList.cpp | 5 ++++ .../Source/Graphics/Component/ScrollingList.h | 2 ++ RetroFE/Source/Graphics/Page.cpp | 30 +++++++++++++++++-- RetroFE/Source/Graphics/Page.h | 2 ++ RetroFE/Source/Graphics/PageBuilder.cpp | 9 +++++- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfo.h b/RetroFE/Source/Collection/CollectionInfo.h index f16f84918..ffe1046c8 100644 --- a/RetroFE/Source/Collection/CollectionInfo.h +++ b/RetroFE/Source/Collection/CollectionInfo.h @@ -39,6 +39,7 @@ class CollectionInfo std::string metadataType; std::string launcher; std::vector items; + std::vector playlistItems; typedef std::map *> Playlists_T; Playlists_T playlists; diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index b3ec9de1f..5b32cf018 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -444,6 +444,13 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) ImportBasicList(info, playlistFile, playlistFilter); info->playlists[basename] = new std::vector(); + Item* playlistItem = new Item(); + playlistItem->name = info->name; + playlistItem->title = info->name; + playlistItem->fullTitle = info->name; + playlistItem->leaf = false; + playlistItem->collectionInfo = info; + info->playlistItems.push_back(playlistItem); // add the playlist list for(std::map::iterator it = playlistFilter.begin(); it != playlistFilter.end(); it++) diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 16d78f80f..13daa0aaa 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -44,6 +44,7 @@ ScrollingList::ScrollingList( Configuration &c, Page &p, bool layoutMode, bool commonMode, + bool playlistType, Font *font, std::string layoutKey, std::string imageType, @@ -52,6 +53,7 @@ ScrollingList::ScrollingList( Configuration &c, , horizontalScroll( false ) , layoutMode_( layoutMode ) , commonMode_( commonMode ) + , playlistType_( playlistType ) , spriteList_( NULL ) , scrollPoints_( NULL ) , tweenPoints_( NULL ) @@ -76,6 +78,7 @@ ScrollingList::ScrollingList( const ScrollingList © ) , horizontalScroll( copy.horizontalScroll ) , layoutMode_( copy.layoutMode_ ) , commonMode_( copy.commonMode_ ) + , playlistType_(copy.playlistType_) , spriteList_( NULL ) , itemIndex_( 0 ) , selectedOffsetIndex_( copy.selectedOffsetIndex_ ) @@ -764,6 +767,8 @@ bool ScrollingList::allocateTexture( unsigned int index, Item *item ) names.push_back( item->rating ); if ( typeLC == "score" ) names.push_back( item->score ); + if (typeLC.rfind("playlist", 0) == 0) + names.push_back(item->name); names.push_back("default"); for ( unsigned int n = 0; n < names.size() && !t; ++n ) diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index e2033fcad..af3748b6f 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -37,6 +37,7 @@ class ScrollingList : public Component Page &p, bool layoutMode, bool commonMode, + bool playlistType, Font *font, std::string layoutKey, std::string imageType, @@ -101,6 +102,7 @@ class ScrollingList : public Component void resetScrollPeriod( ); void updateScrollPeriod( ); void scroll( bool forward ); + bool playlistType_; private: diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 2dc355205..4d4c2740a 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -40,6 +40,8 @@ Page::Page(Configuration &config, int layoutWidth, int layoutHeight) , selectSoundChunk_(NULL) , minShowTime_(0) , jukebox_(false) + , playlistMenu_(NULL) + , elapsedTime_(0) { for (int i = 0; i < SDL::getNumScreens(); i++) { @@ -441,6 +443,8 @@ void Page::playlistChange() { (*it)->setPlaylist(playlist_->first); } + + updatePlaylistMenuPosition(); } @@ -942,7 +946,11 @@ bool Page::pushCollection(CollectionInfo *collection) { ScrollingList *menu = *it; ScrollingList *newMenu = new ScrollingList(*menu); - pushMenu(newMenu, menuDepth_); + if (&newMenu->playlistType_) { + playlistMenu_ = newMenu; + } else { + pushMenu(newMenu, menuDepth_); + } } } @@ -961,6 +969,9 @@ bool Page::pushCollection(CollectionInfo *collection) info.queueDelete = false; collections_.push_back(info); + // build playlist menu + playlistMenu_->setItems(&collection->playlistItems); + playlist_ = info.playlist; playlistChange(); @@ -993,6 +1004,10 @@ bool Page::popCollection() // get the next collection off of the stack collections_.pop_back(); info = &collections_.back(); + + // build playlist menu + playlistMenu_->setItems(&info->collection->playlistItems); + playlist_ = info->playlist; playlistChange(); @@ -1161,10 +1176,12 @@ void Page::nextPlaylist() { playlist_++; // wrap - if(playlist_ == info.collection->playlists.end()) playlist_ = info.collection->playlists.begin(); + if(playlist_ == info.collection->playlists.end()) + playlist_ = info.collection->playlists.begin(); // find the first playlist - if(playlist_->second->size() != 0) break; + if(playlist_->second->size() != 0) + break; } for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) @@ -1234,6 +1251,13 @@ void Page::selectPlaylist(std::string playlist) playlistChange(); } +void Page::updatePlaylistMenuPosition() +{ + if (playlistMenu_) { + MenuInfo_S& info = collections_.back(); + playlistMenu_->setScrollOffsetIndex(distance(info.collection->playlists.begin(), playlist_)); + } +} void Page::nextCyclePlaylist(std::vector list) { diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 30eedd611..96b22ddb4 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -60,6 +60,7 @@ class Page void nextCyclePlaylist(std::vector list); void prevCyclePlaylist(std::vector list); void pushMenu(ScrollingList *s, int index = -1); + void updatePlaylistMenuPosition(); bool isMenusFull(); void setLoadSound(Sound *chunk); void setUnloadSound(Sound *chunk); @@ -158,6 +159,7 @@ class Page typedef std::list CollectionVector_T; std::vector activeMenu_; + ScrollingList *playlistMenu_; unsigned int menuDepth_; MenuVector_T menus_; CollectionVector_T collections_; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 3d4691925..f59fa97b2 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -1000,14 +1000,21 @@ ScrollingList * PageBuilder::buildMenu(xml_node<> *menuXml, Page &page) Logger::write(Logger::ZONE_WARNING, "Layout", "Menu tag is missing tag."); } + bool playlistType = false; if(imageTypeXml) { imageType = imageTypeXml->value(); + if (imageType.rfind("playlist", 0) == 0) { + playlistType = true; + } } if(videoTypeXml) { videoType = videoTypeXml->value(); + if (videoType.rfind("playlist", 0) == 0) { + playlistType = true; + } } bool layoutMode = false; @@ -1033,7 +1040,7 @@ ScrollingList * PageBuilder::buildMenu(xml_node<> *menuXml, Page &page) // on default, text will be rendered to the menu. Preload it into cache. Font *font = addFont(itemDefaults, NULL); - menu = new ScrollingList(config_, page, layoutMode, commonMode, font, layoutKey, imageType, videoType); + menu = new ScrollingList(config_, page, layoutMode, commonMode, playlistType, font, layoutKey, imageType, videoType); buildViewInfo(menuXml, menu->baseViewInfo); if(scrollTimeXml) From c1b052ac38b935c8ff06e151156086f14dda3557 Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 11:30:12 -0700 Subject: [PATCH 2/8] stopped crashing; populated page's playlistMenu_; now to figure how to fill the layouts menu with that menu --- RetroFE/Source/Collection/CollectionInfoBuilder.cpp | 1 + RetroFE/Source/Graphics/Component/ScrollingList.cpp | 4 ++-- RetroFE/Source/Graphics/Component/ScrollingList.h | 2 +- RetroFE/Source/Graphics/Page.cpp | 8 ++++++-- RetroFE/Source/Graphics/Page.h | 2 +- RetroFE/Source/Graphics/PageBuilder.cpp | 6 +++++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 5b32cf018..8966bcc26 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -444,6 +444,7 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) ImportBasicList(info, playlistFile, playlistFilter); info->playlists[basename] = new std::vector(); + Item* playlistItem = new Item(); playlistItem->name = info->name; playlistItem->title = info->name; diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 13daa0aaa..da3554e5a 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -114,9 +114,9 @@ ScrollingList::~ScrollingList( ) void ScrollingList::setItems( std::vector *items ) { - items_ = items; + items_ = items; if ( items_ ) - { + { itemIndex_ = loopDecrement( 0, selectedOffsetIndex_, items_->size( ) ); } } diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index af3748b6f..8c7331c85 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -102,7 +102,7 @@ class ScrollingList : public Component void resetScrollPeriod( ); void updateScrollPeriod( ); void scroll( bool forward ); - bool playlistType_; + bool playlistType_;//todo make getter private: diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 4d4c2740a..5bc295249 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -970,7 +970,9 @@ bool Page::pushCollection(CollectionInfo *collection) collections_.push_back(info); // build playlist menu - playlistMenu_->setItems(&collection->playlistItems); + if (playlistMenu_ && collection->playlistItems.size()) { + playlistMenu_->setItems(&collection->playlistItems); + } playlist_ = info.playlist; playlistChange(); @@ -1006,7 +1008,9 @@ bool Page::popCollection() info = &collections_.back(); // build playlist menu - playlistMenu_->setItems(&info->collection->playlistItems); + if (playlistMenu_ && info->collection->playlistItems.size()) { + playlistMenu_->setItems(&info->collection->playlistItems); + } playlist_ = info->playlist; playlistChange(); diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 96b22ddb4..d16ca6037 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -142,6 +142,7 @@ class Page unsigned long long getCurrent( ); unsigned long long getDuration( ); bool isPaused( ); + ScrollingList* playlistMenu_;//todo make getter private: void playlistChange(); @@ -159,7 +160,6 @@ class Page typedef std::list CollectionVector_T; std::vector activeMenu_; - ScrollingList *playlistMenu_; unsigned int menuDepth_; MenuVector_T menus_; CollectionVector_T collections_; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index f59fa97b2..bafcefc2f 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -366,7 +366,11 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page) ScrollingList *scrollingList = buildMenu(componentXml,*page); xml_attribute<> *indexXml = componentXml->first_attribute("menuIndex"); int index = indexXml ? Utils::convertInt(indexXml->value()) : -1; - page->pushMenu(scrollingList, index); + if (scrollingList->playlistType_) { + page->playlistMenu_ = scrollingList; + } else { + page->pushMenu(scrollingList, index); + } } for(xml_node<> *componentXml = layout->first_node("container"); componentXml; componentXml = componentXml->next_sibling("container")) From d072601e99800126dc5290b93a29035786d7eecf Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 12:43:11 -0700 Subject: [PATCH 3/8] working now; some code cleanup maybe --- .../Collection/CollectionInfoBuilder.cpp | 6 ++-- .../Graphics/Component/ScrollingList.cpp | 11 +++--- RetroFE/Source/Graphics/Page.cpp | 36 +++++++++++++------ RetroFE/Source/Graphics/PageBuilder.cpp | 3 +- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 8966bcc26..ca3af7f13 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -446,9 +446,9 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) info->playlists[basename] = new std::vector(); Item* playlistItem = new Item(); - playlistItem->name = info->name; - playlistItem->title = info->name; - playlistItem->fullTitle = info->name; + playlistItem->name = basename; + playlistItem->title = basename; + playlistItem->fullTitle = basename; playlistItem->leaf = false; playlistItem->collectionInfo = info; info->playlistItems.push_back(playlistItem); diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index da3554e5a..cf24fc937 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -114,10 +114,10 @@ ScrollingList::~ScrollingList( ) void ScrollingList::setItems( std::vector *items ) { - items_ = items; - if ( items_ ) - { - itemIndex_ = loopDecrement( 0, selectedOffsetIndex_, items_->size( ) ); + items_ = items; + if (items_) + { + itemIndex_ = loopDecrement(0, selectedOffsetIndex_, items_->size()); } } @@ -1055,6 +1055,9 @@ void ScrollingList::updateScrollPeriod( ) void ScrollingList::scroll( bool forward ) { + // playlist menus don't scroll + if (playlistType_) + return; if ( !items_ || items_->size( ) == 0 ) return; if ( !scrollPoints_ || scrollPoints_->size( ) == 0 ) return; diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 5bc295249..c2715d9f6 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -948,9 +948,8 @@ bool Page::pushCollection(CollectionInfo *collection) ScrollingList *newMenu = new ScrollingList(*menu); if (&newMenu->playlistType_) { playlistMenu_ = newMenu; - } else { - pushMenu(newMenu, menuDepth_); } + pushMenu(newMenu, menuDepth_); } } @@ -959,7 +958,13 @@ bool Page::pushCollection(CollectionInfo *collection) { ScrollingList *menu = *it; menu->collectionName = collection->name; - menu->setItems(&collection->items); + // add playlist menu items + if (menu->playlistType_ && collection->playlistItems.size()) { + menu->setItems(&collection->playlistItems); + } else { + // add item collection menu + menu->setItems(&collection->items); + } } // build the collection info instance @@ -969,11 +974,6 @@ bool Page::pushCollection(CollectionInfo *collection) info.queueDelete = false; collections_.push_back(info); - // build playlist menu - if (playlistMenu_ && collection->playlistItems.size()) { - playlistMenu_->setItems(&collection->playlistItems); - } - playlist_ = info.playlist; playlistChange(); @@ -1191,7 +1191,12 @@ void Page::nextPlaylist() for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { ScrollingList *menu = *it; - menu->setItems(playlist_->second); + // keep playlist menu + if (menu->playlistType_ && info.collection->playlistItems.size()) { + menu->setItems(&info.collection->playlistItems); + } else { + menu->setItems(playlist_->second); + } } playlistChange(); } @@ -1218,7 +1223,12 @@ void Page::prevPlaylist() for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { ScrollingList *menu = *it; - menu->setItems(playlist_->second); + // keep playlist menu + if (menu->playlistType_ && info.collection->playlistItems.size()) { + menu->setItems(&info.collection->playlistItems); + } else { + menu->setItems(playlist_->second); + } } playlistChange(); } @@ -1250,7 +1260,11 @@ void Page::selectPlaylist(std::string playlist) for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { ScrollingList *menu = *it; - menu->setItems(playlist_->second); + if (menu->playlistType_ && info.collection->playlistItems.size()) { + menu->setItems(&info.collection->playlistItems); + } else { + menu->setItems(playlist_->second); + } } playlistChange(); } diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index bafcefc2f..aa9f09ecd 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -368,9 +368,8 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page) int index = indexXml ? Utils::convertInt(indexXml->value()) : -1; if (scrollingList->playlistType_) { page->playlistMenu_ = scrollingList; - } else { - page->pushMenu(scrollingList, index); } + page->pushMenu(scrollingList, index); } for(xml_node<> *componentXml = layout->first_node("container"); componentXml; componentXml = componentXml->next_sibling("container")) From 38ba678fce7ab69db4a6d655d7e85c965d49d08b Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 13:40:21 -0700 Subject: [PATCH 4/8] fix item selection using first menu when it's a playlist menu --- RetroFE/Source/Graphics/Page.cpp | 19 ++++++++++++++++--- RetroFE/Source/Graphics/Page.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index c2715d9f6..41b156ff3 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -152,11 +152,22 @@ void Page::setSelectSound(Sound *chunk) selectSoundChunk_ = chunk; } +void Page::setSelectedItem() +{ + for (unsigned int i = 0; i < activeMenu_.size(); i++) + { + if (!activeMenu_[i]->playlistType_) { + selectedItem_ = activeMenu_[i]->getSelectedItem(); + break; + } + } +} void Page::onNewItemSelected() { if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; - selectedItem_ = activeMenu_[0]->getSelectedItem(); + + setSelectedItem(); for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) { @@ -178,7 +189,8 @@ void Page::onNewItemSelected() void Page::onNewScrollItemSelected() { if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; - selectedItem_ = activeMenu_[0]->getSelectedItem(); + + setSelectedItem(); for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) { @@ -191,7 +203,8 @@ void Page::onNewScrollItemSelected() void Page::highlightLoadArt() { if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; - selectedItem_ = activeMenu_[0]->getSelectedItem(); + + setSelectedItem(); for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) { diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index d16ca6037..2825c1c0f 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -66,6 +66,7 @@ class Page void setUnloadSound(Sound *chunk); void setHighlightSound(Sound *chunk); void setSelectSound(Sound *chunk); + void setSelectedItem(); bool addComponent(Component *c); void pageScroll(ScrollDirection direction); void letterScroll(ScrollDirection direction); From aa96a3842a000769eba30c362cfeb643a443ab24 Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 13:58:43 -0700 Subject: [PATCH 5/8] refactor setActiveMenuItemsFromPlaylist --- RetroFE/Source/Graphics/Page.cpp | 34 +++++++++++++------------------- RetroFE/Source/Graphics/Page.h | 1 + 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 41b156ff3..b3e542584 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -163,6 +163,17 @@ void Page::setSelectedItem() } } +void Page::setActiveMenuItemsFromPlaylist(MenuInfo_S info, ScrollingList* menu) +{ + // keep playlist menu + if (menu->playlistType_ && info.collection->playlistItems.size()) { + menu->setItems(&info.collection->playlistItems); + } + else { + menu->setItems(playlist_->second); + } +} + void Page::onNewItemSelected() { if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; @@ -1203,13 +1214,7 @@ void Page::nextPlaylist() for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { - ScrollingList *menu = *it; - // keep playlist menu - if (menu->playlistType_ && info.collection->playlistItems.size()) { - menu->setItems(&info.collection->playlistItems); - } else { - menu->setItems(playlist_->second); - } + setActiveMenuItemsFromPlaylist(info, *it); } playlistChange(); } @@ -1235,13 +1240,7 @@ void Page::prevPlaylist() for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { - ScrollingList *menu = *it; - // keep playlist menu - if (menu->playlistType_ && info.collection->playlistItems.size()) { - menu->setItems(&info.collection->playlistItems); - } else { - menu->setItems(playlist_->second); - } + setActiveMenuItemsFromPlaylist(info, *it); } playlistChange(); } @@ -1272,12 +1271,7 @@ void Page::selectPlaylist(std::string playlist) for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { - ScrollingList *menu = *it; - if (menu->playlistType_ && info.collection->playlistItems.size()) { - menu->setItems(&info.collection->playlistItems); - } else { - menu->setItems(playlist_->second); - } + setActiveMenuItemsFromPlaylist(info, *it); } playlistChange(); } diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 2825c1c0f..aee813880 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -159,6 +159,7 @@ class Page typedef std::vector< std::vector > MenuVector_T; typedef std::list CollectionVector_T; + void setActiveMenuItemsFromPlaylist(MenuInfo_S info, ScrollingList* menu); std::vector activeMenu_; unsigned int menuDepth_; From 019f023722a62b72aeb80a6d3696ae8ea61c001d Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 17:13:53 -0700 Subject: [PATCH 6/8] refactor to be able to select an acvtive menu that isn't a playlist menu --- RetroFE/Source/Graphics/Page.cpp | 112 ++++++++++++++++++------------- RetroFE/Source/Graphics/Page.h | 1 + 2 files changed, 66 insertions(+), 47 deletions(-) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index b3e542584..487961cfc 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -154,13 +154,23 @@ void Page::setSelectSound(Sound *chunk) void Page::setSelectedItem() { - for (unsigned int i = 0; i < activeMenu_.size(); i++) - { - if (!activeMenu_[i]->playlistType_) { - selectedItem_ = activeMenu_[i]->getSelectedItem(); - break; + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return; + + selectedItem_ = amenu->getSelectedItem(); +} + +ScrollingList* Page::getAnActiveMenu() { + if (activeMenu_.size()) { + for (unsigned int i = 0; i < activeMenu_.size(); i++) + { + if (!activeMenu_[i]->playlistType_) { + return activeMenu_[i]; + } } } + + return NULL; } void Page::setActiveMenuItemsFromPlaylist(MenuInfo_S info, ScrollingList* menu) @@ -176,7 +186,7 @@ void Page::setActiveMenuItemsFromPlaylist(MenuInfo_S info, ScrollingList* menu) void Page::onNewItemSelected() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; + if(!getAnActiveMenu()) return; setSelectedItem(); @@ -199,7 +209,7 @@ void Page::onNewItemSelected() void Page::onNewScrollItemSelected() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; + if(!getAnActiveMenu()) return; setSelectedItem(); @@ -213,7 +223,7 @@ void Page::onNewScrollItemSelected() void Page::highlightLoadArt() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; + if(!getAnActiveMenu()) return; setSelectedItem(); @@ -406,8 +416,10 @@ Item *Page::getSelectedItem() Item *Page::getSelectedItem(int offset) { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return NULL; - return activeMenu_[0]->getItemByOffset(offset); + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return NULL; + + return amenu->getItemByOffset(offset); } @@ -427,7 +439,8 @@ void Page::removeSelectedItem() void Page::setScrollOffsetIndex(unsigned int i) { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return; + if (!getAnActiveMenu()) return; + for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { ScrollingList *menu = *it; @@ -438,8 +451,10 @@ void Page::setScrollOffsetIndex(unsigned int i) unsigned int Page::getScrollOffsetIndex() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return -1; - return activeMenu_[0]->getScrollOffsetIndex(); + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return -1; + + return amenu->getScrollOffsetIndex(); } @@ -842,46 +857,46 @@ void Page::setScrolling(ScrollDirection direction) bool Page::isHorizontalScroll() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return false; - return activeMenu_[0]->horizontalScroll; + ScrollingList* amenu = getAnActiveMenu(); + if(!amenu) return false; + + return amenu->horizontalScroll; } void Page::pageScroll(ScrollDirection direction) { - if(activeMenu_.size() > 0 && activeMenu_[0]) + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return; + + if(direction == ScrollDirectionForward) { - if(direction == ScrollDirectionForward) - { - activeMenu_[0]->pageDown(); - } - if(direction == ScrollDirectionBack) - { - activeMenu_[0]->pageUp(); - } + amenu->pageDown(); + } else if(direction == ScrollDirectionBack) + { + amenu->pageUp(); + } - unsigned int index = activeMenu_[0]->getScrollOffsetIndex(); - for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) - { - ScrollingList *menu = *it; - if (menu) - menu->setScrollOffsetIndex(index); - } + unsigned int index = amenu->getScrollOffsetIndex(); + for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) + { + ScrollingList *menu = *it; + if (menu) + menu->setScrollOffsetIndex(index); } } - void Page::selectRandom() { - if(activeMenu_.size() > 0 && activeMenu_[0]) + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return; + + amenu->random(); + unsigned int index = amenu->getScrollOffsetIndex(); + for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { - activeMenu_[0]->random(); - unsigned int index = activeMenu_[0]->getScrollOffsetIndex(); - for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) - { - ScrollingList *menu = *it; - menu->setScrollOffsetIndex(index); - } + ScrollingList *menu = *it; + menu->setScrollOffsetIndex(index); } } @@ -948,15 +963,19 @@ void Page::cfwLetterSubScroll(ScrollDirection direction) unsigned int Page::getCollectionSize() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return 0; - return activeMenu_[0]->getSize(); + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return 0; + + return amenu->getSize(); } unsigned int Page::getSelectedIndex() { - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return 0; - return activeMenu_[0]->getSelectedIndex(); + ScrollingList* amenu = getAnActiveMenu(); + if (!amenu) return 0; + + return amenu->getSelectedIndex(); } @@ -964,7 +983,7 @@ bool Page::pushCollection(CollectionInfo *collection) { // grow the menu as needed - if(menus_.size() <= menuDepth_ && activeMenu_.size() > 0 && activeMenu_[0]) + if(menus_.size() <= menuDepth_ && getAnActiveMenu()) { for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) { @@ -1017,8 +1036,7 @@ bool Page::pushCollection(CollectionInfo *collection) bool Page::popCollection() { - - if(!(activeMenu_.size() > 0 && activeMenu_[0])) return false; + if (!getAnActiveMenu()) return false; if(menuDepth_ <= 1) return false; if(collections_.size() <= 1) return false; diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index aee813880..1c4461e85 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -67,6 +67,7 @@ class Page void setHighlightSound(Sound *chunk); void setSelectSound(Sound *chunk); void setSelectedItem(); + ScrollingList* getAnActiveMenu(); bool addComponent(Component *c); void pageScroll(ScrollDirection direction); void letterScroll(ScrollDirection direction); From 5e2d80143df10ced99cafdd55382681640fa15bd Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 19:34:09 -0700 Subject: [PATCH 7/8] fix ordering of menu according to playlist cycle --- .../Collection/CollectionInfoBuilder.cpp | 25 ++++++++++- .../Graphics/Component/ScrollingList.cpp | 4 ++ .../Source/Graphics/Component/ScrollingList.h | 1 + RetroFE/Source/Graphics/Page.cpp | 41 ++++++++++++------- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index ca3af7f13..c7f93ff96 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -422,6 +422,7 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) info->playlists["favorites"] = new std::vector(); return; } + std::map playlistItems; while((dirp = readdir(dp)) != NULL) { @@ -451,7 +452,7 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) playlistItem->fullTitle = basename; playlistItem->leaf = false; playlistItem->collectionInfo = info; - info->playlistItems.push_back(playlistItem); + playlistItems[basename] = playlistItem; // add the playlist list for(std::map::iterator it = playlistFilter.begin(); it != playlistFilter.end(); it++) @@ -488,6 +489,28 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) } } } + // if cyclePlaylist then order playlist menu items by that + std::string cycleString; + conf_.getProperty("cyclePlaylist", cycleString); + std::vector cycleVector; + Utils::listToVector(cycleString, cycleVector, ','); + if (cycleVector.size()) + { + // add in order according to cycle list + for (std::vector::iterator itP = cycleVector.begin(); itP != cycleVector.end(); itP++) + { + if (playlistItems[*itP]) { + info->playlistItems.push_back(playlistItems[*itP]); + } + } + } + else { + // convert lookup playlist map to vector + for (std::map::iterator itP = playlistItems.begin(); itP != playlistItems.end(); itP++) + { + info->playlistItems.push_back(itP->second); + } + } if (dp) closedir(dp); diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index cf24fc937..3a3bba5c1 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -111,6 +111,10 @@ ScrollingList::~ScrollingList( ) } } +std::vector ScrollingList::getItems() +{ + return *items_; +} void ScrollingList::setItems( std::vector *items ) { diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index 8c7331c85..ffa37ad81 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -45,6 +45,7 @@ class ScrollingList : public Component ScrollingList( const ScrollingList © ); virtual ~ScrollingList( ); + std::vector getItems(); void triggerEnterEvent( ); void triggerExitEvent( ); void triggerMenuEnterEvent( int menuIndex = -1 ); diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 487961cfc..85896b733 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -995,20 +995,25 @@ bool Page::pushCollection(CollectionInfo *collection) pushMenu(newMenu, menuDepth_); } } - - activeMenu_ = menus_[menuDepth_]; - for(std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) - { - ScrollingList *menu = *it; - menu->collectionName = collection->name; - // add playlist menu items - if (menu->playlistType_ && collection->playlistItems.size()) { - menu->setItems(&collection->playlistItems); - } else { - // add item collection menu - menu->setItems(&collection->items); + if (menus_.size()) { + activeMenu_ = menus_[menuDepth_]; + for (std::vector::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++) + { + ScrollingList* menu = *it; + menu->collectionName = collection->name; + // add playlist menu items + if (menu->playlistType_ && collection->playlistItems.size()) { + menu->setItems(&collection->playlistItems); + } + else { + // add item collection menu + menu->setItems(&collection->items); + } } } + else { + Logger::write(Logger::ZONE_WARNING, "RetroFE", "layout.xml doesn't have any menus"); + } // build the collection info instance MenuInfo_S info; @@ -1297,8 +1302,16 @@ void Page::selectPlaylist(std::string playlist) void Page::updatePlaylistMenuPosition() { if (playlistMenu_) { - MenuInfo_S& info = collections_.back(); - playlistMenu_->setScrollOffsetIndex(distance(info.collection->playlists.begin(), playlist_)); + unsigned int i = 0; + std::string name = getPlaylistName(); + std::vector items = playlistMenu_->getItems(); + for (std::vector::iterator it = items.begin(); it != items.end(); ++it) { + Item* item = *it; + if (item->name == name) { + playlistMenu_->setScrollOffsetIndex(i); + } + i++; + } } } From 3a0fd4a0fabc3a9ccae76c659d8ce64b0d1f9b8f Mon Sep 17 00:00:00 2001 From: Tobias Contreras Date: Sun, 7 May 2023 20:00:40 -0700 Subject: [PATCH 8/8] fix empty playlistcycle list --- RetroFE/Source/Graphics/Page.cpp | 2 ++ RetroFE/Source/RetroFE.cpp | 4 ++-- RetroFE/Source/Utility/Utils.cpp | 18 ++++++++++++++++-- RetroFE/Source/Utility/Utils.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 85896b733..6af07e982 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -1309,6 +1309,8 @@ void Page::updatePlaylistMenuPosition() Item* item = *it; if (item->name == name) { playlistMenu_->setScrollOffsetIndex(i); + + return; } i++; } diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 05ff59e0b..f3b0f88c5 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -75,7 +75,7 @@ RetroFE::RetroFE( Configuration &c ) menuMode_ = false; attractMode_ = false; attractModePlaylistCollectionNumber_ = 0; - firstPlaylist_ = "all"; + firstPlaylist_ = "all"; // todo } @@ -1353,7 +1353,7 @@ bool RetroFE::run( ) std::string cycleString; config_.getProperty( "cyclePlaylist", cycleString ); std::vector cycleVector; - Utils::listToVector( cycleString, cycleVector, ',' ); + Utils::listToVector(cycleString, cycleVector, ',' ); if ( cyclePlaylist ) currentPage_->nextCyclePlaylist( cycleVector ); diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index f6d9cef4c..b27631119 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -256,15 +256,22 @@ std::string Utils::trimEnds(std::string str) void Utils::listToVector( std::string str, std::vector &vec, char delimiter = ',' ) { + std::string value; 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 ) ) ); + value = Utils::trimEnds(str.substr(previous, current - previous)); + if (value != "") { + vec.push_back(value); + } previous = current + 1; current = str.find( delimiter, previous ); } - vec.push_back( Utils::trimEnds( str.substr( previous, current - previous ) ) ); + value = Utils::trimEnds(str.substr(previous, current - previous)); + if (value != "") { + vec.push_back(value); + } } @@ -274,3 +281,10 @@ int Utils::gcd( int a, int b ) return a; return gcd( b, a % b ); } + +std::string Utils::trim(std::string& str) +{ + str.erase(str.find_last_not_of(' ') + 1); //suffixing spaces + str.erase(0, str.find_first_not_of(' ')); //prefixing spaces + return str; +} \ No newline at end of file diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 2b1d26f1d..08c636f19 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -37,6 +37,7 @@ class Utils static std::string trimEnds(std::string str); static void listToVector( std::string str, std::vector &vec, char delimiter ); static int gcd( int a, int b ); + static std::string trim(std::string& str); //todo: there has to be a better way to do this static std::string combinePath(std::list &paths);