Merge with playlists

This commit is contained in:
Don Honerbrink 2015-08-06 13:26:52 -05:00
commit a1821475a9
11 changed files with 437 additions and 749 deletions

View File

@ -6,6 +6,7 @@ pageUp = A
pageDown = B
letterUp = N
letterDown = M
nextPlaylist = P
select = Space
back = Escape
quit = Q

View File

@ -46,6 +46,18 @@ CollectionInfo::~CollectionInfo()
}
Playlists_T::iterator pit = playlists.begin();
while(pit != playlists.end())
{
if(pit->second != &items)
{
delete pit->second;
}
playlists.erase(pit);
pit = playlists.begin();
}
std::vector<Item *>::iterator it = items.begin();
while(it != items.end())
{

View File

@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include <map>
class Item;
@ -35,6 +36,10 @@ public:
std::string metadataType;
std::string launcher;
std::vector<Item *> items;
typedef std::map<std::string, std::vector <Item *> *> Playlists_T;
Playlists_T playlists;
bool menusort;
private:
std::vector<CollectionInfo *> subcollections_;

View File

@ -231,8 +231,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
struct dirent *dirp;
std::string path = info->listpath;
std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> favoritesFilter;
std::map<std::string, Item *> excludeFilter;
std::string includeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "include.txt");
std::string favoritesFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "favorites.txt");
std::string excludeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "exclude.txt");
std::string launcher;
@ -258,6 +260,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
{
Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + includeFile + "\"");
ImportBasicList(info, includeFile, includeFilter);
ImportBasicList(info, favoritesFile, favoritesFilter);
ImportBasicList(info, excludeFile, excludeFilter);
}
@ -265,6 +268,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
std::vector<std::string>::iterator extensionsIt;
info->extensionList(extensions);
info->playlists["all"] = &info->items;
info->playlists["favorites"] = new std::vector<Item *>();
dp = opendir(path.c_str());
@ -286,6 +291,11 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
}
}
}
// add the favorites list
for(std::map<std::string, Item *>::iterator it = favoritesFilter.begin(); it != favoritesFilter.end(); it++)
{
info->playlists["favorites"]->push_back(it->second);
}
while((dirp = readdir(dp)) != NULL)
{

View File

@ -73,6 +73,7 @@ bool UserInput::initialize()
retVal = MapKey("select", KeyCodeSelect) && retVal;
retVal = MapKey("back", KeyCodeBack) && retVal;
retVal = MapKey("quit", KeyCodeQuit) && retVal;
MapKey("nextPlaylist", KeyCodeNextPlaylist);
// these features will need to be implemented at a later time
// retVal = MapKey("admin", KeyCodeAdminMode) && retVal;
// retVal = MapKey("remove", KeyCodeHideItem) && retVal;

View File

@ -39,6 +39,7 @@ public:
KeyCodePageUp,
KeyCodeLetterDown,
KeyCodeLetterUp,
KeyCodeNextPlaylist,
KeyCodeAdminMode,
KeyCodeHideItem,
KeyCodeQuit,

File diff suppressed because it is too large Load Diff

View File

@ -1,136 +1,133 @@
/* This file is part of RetroFE.
*
* RetroFE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RetroFE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RetroFE. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include "Component.h"
#include "../Animate/Tween.h"
#include "../ComponentItemBinding.h"
#include "../MenuNotifierInterface.h"
#include "../ViewInfo.h"
#include "../../Database/Configuration.h"
#include <SDL2/SDL.h>
//todo: This scrolling implementation needs to be overhauled
// It needs to have a common interface to support different menu types
// (It was originally sandbox code that creeped into here)
class Configuration;
class Font;
class ScrollingList : public Component
{
public:
enum ScrollDirection
{
ScrollDirectionBack,
ScrollDirectionForward,
ScrollDirectionIdle,
};
ScrollingList(Configuration &c,
float scaleX,
float scaleY,
Font *font,
std::string layoutKey,
std::string imageType);
ScrollingList(const ScrollingList &copy);
virtual ~ScrollingList();
void triggerMenuEnterEvent();
void triggerMenuExitEvent();
bool allocateTexture(ComponentItemBinding *s);
void deallocateTexture(ComponentItemBinding *s);
void setItems(std::vector<ComponentItemBinding *> *spriteList);
void destroyItems();
void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints);
void setScrollDirection(ScrollDirection direction);
void pageUp();
void pageDown();
void letterUp();
void letterDown();
bool isIdle();
/* This file is part of RetroFE.
*
* RetroFE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RetroFE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RetroFE. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vector>
#include "Component.h"
#include "../Animate/Tween.h"
#include "../MenuNotifierInterface.h"
#include "../ViewInfo.h"
#include "../../Database/Configuration.h"
#include <SDL2/SDL.h>
//todo: This scrolling implementation needs to be overhauled
// It needs to have a common interface to support different menu types
// (It was originally sandbox code that creeped into here)
class Configuration;
class Font;
class ScrollingList : public Component
{
public:
enum ScrollDirection
{
ScrollDirectionBack,
ScrollDirectionForward,
ScrollDirectionIdle,
};
ScrollingList(Configuration &c,
float scaleX,
float scaleY,
Font *font,
std::string layoutKey,
std::string imageType);
ScrollingList(const ScrollingList &copy);
virtual ~ScrollingList();
void triggerMenuEnterEvent();
void triggerMenuExitEvent();
bool allocateTexture(unsigned int index, Item *i);
void deallocateTexture(unsigned int index);
void setItems(std::vector<Item *> *items);
void destroyItems();
void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints);
void setScrollDirection(ScrollDirection direction);
void pageUp();
void pageDown();
void letterUp();
void letterDown();
void letterChange(bool increment);
bool isIdle();
unsigned int getScrollOffsetIndex();
void setScrollOffsetIndex(unsigned int index);
void setSelectedIndex(int selectedIndex);
ComponentItemBinding *getSelectedCollectionItemSprite();
ComponentItemBinding *getPendingCollectionItemSprite();
ComponentItemBinding *getPendingSelectedCollectionItemSprite();
void addComponentForNotifications(MenuNotifierInterface *c);
void removeComponentForNotifications(MenuNotifierInterface *c);
std::vector<ComponentItemBinding *> *getCollectionItemSprites();
void removeSelectedItem();
void freeGraphicsMemory();
void update(float dt);
void draw();
void draw(unsigned int layer);
void setScrollAcceleration(float value);
void setStartScrollTime(float value);
bool horizontalScroll;
private:
void click(double nextScrollTime);
void deallocateSpritePoints();
void allocateSpritePoints();
void updateSprite(unsigned int spriteIndex, unsigned int pointIndex, bool newScroll, float dt, double nextScrollTime);
unsigned int getNextTween(unsigned int currentIndex, std::vector<ViewInfo *> *list);
void resetTweens(Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime);
enum ScrollState
{
ScrollStateActive,
ScrollStatePageChange,
ScrollStateStopping,
ScrollStateIdle
};
std::vector<ComponentItemBinding *> *spriteList_;
std::vector<ViewInfo *> *scrollPoints_;
std::vector<AnimationEvents *> *tweenPoints_;
std::vector<MenuNotifierInterface *> notificationComponents_;
float tweenEnterTime_;
bool focus_;
unsigned int firstSpriteIndex_;
unsigned int selectedSpriteListIndex_;
bool scrollStopRequested_;
bool notifyAllRequested_;
ScrollDirection currentScrollDirection_;
ScrollDirection requestedScrollDirection_;
ScrollState currentScrollState_;
float scrollAcceleration_;
float startScrollTime_;
float scrollPeriod_;
int circularIncrement(unsigned int index, unsigned int offset, std::vector<ComponentItemBinding *> *list);
void circularIncrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
void circularDecrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
void circularIncrement(unsigned &index, std::vector<ViewInfo *> *list);
void circularDecrement(unsigned &index, std::vector<ViewInfo *> *list);
void updateOffset(float dt);
std::string collection_;
Configuration &config_;
float scaleX_;
float scaleY_;
Font *fontInst_;
std::string layoutKey_;
std::string imageType_;
};
void setSelectedIndex(int selectedIndex);
void addComponentForNotifications(MenuNotifierInterface *c);
void removeComponentForNotifications(MenuNotifierInterface *c);
void freeGraphicsMemory();
void update(float dt);
void draw();
void draw(unsigned int layer);
void setScrollAcceleration(float value);
void setStartScrollTime(float value);
bool horizontalScroll;
private:
void click(double nextScrollTime);
void deallocateSpritePoints();
void allocateSpritePoints();
void resetTweens(Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime);
unsigned int loopIncrement(unsigned int offset, unsigned int i, unsigned int size);
unsigned int loopDecrement(unsigned int offset, unsigned int i, unsigned int size);
enum ScrollState
{
ScrollStateActive,
ScrollStatePageChange,
ScrollStateStopping,
ScrollStateIdle
};
std::vector<Component *> *spriteList_;
std::vector<ViewInfo *> *scrollPoints_;
std::vector<AnimationEvents *> *tweenPoints_;
std::vector<MenuNotifierInterface *> notificationComponents_;
bool focus_;
unsigned int itemIndex_;
unsigned int componentIndex_;
unsigned int selectedOffsetIndex_;
bool scrollStopRequested_;
bool notifyAllRequested_;
ScrollDirection currentScrollDirection_;
ScrollDirection requestedScrollDirection_;
ScrollState currentScrollState_;
float scrollAcceleration_;
float startScrollTime_;
float scrollPeriod_;
Configuration &config_;
float scaleX_;
float scaleY_;
Font *fontInst_;
std::string layoutKey_;
std::string imageType_;
std::vector<Item *> *items_;
std::vector<Component *> components_;
};

View File

@ -23,13 +23,13 @@
#include "Component/ScrollingList.h"
#include "../Sound/Sound.h"
#include "ComponentItemBindingBuilder.h"
#include <algorithm>
#include <sstream>
Page::Page(Configuration &config)
: config_(config)
, activeMenu_(NULL)
, menuDepth_(0)
, items_(NULL)
, scrollActive_(false)
, selectedItem_(NULL)
, textStatusComponent_(NULL)
@ -410,8 +410,6 @@ void Page::letterScroll(ScrollDirection direction)
bool Page::pushCollection(CollectionInfo *collection)
{
collections_.push_back(collection);
std::vector<ComponentItemBinding *> *sprites = ComponentItemBindingBuilder::buildCollectionItems(&collection->items);
int menuExitIndex = -1;
int menuEnterIndex = -1;
@ -426,6 +424,7 @@ bool Page::pushCollection(CollectionInfo *collection)
menuExitIndex = menuDepth_ - 1;
}
// grow the menu as needed
if(menus_.size() >= menuDepth_ && activeMenu_)
{
ScrollingList *newList = new ScrollingList(*activeMenu_);
@ -433,12 +432,22 @@ bool Page::pushCollection(CollectionInfo *collection)
pushMenu(newList);
}
activeMenu_ = menus_[menuDepth_];
activeMenu_->collectionName = collection->name;
activeMenu_->destroyItems();
activeMenu_->setItems(sprites);
activeMenu_->setItems(&collection->items);
activeMenu_->triggerMenuEnterEvent();
// build the collection info instance
MenuInfo_S info;
info.collection = collection;
info.menu = activeMenu_;
info.playlist = collection->playlists.begin();
info.queueDelete = false;
collections_.push_back(info);
playlist_ = info.playlist;
if(menuDepth_ < menus_.size())
{
menuEnterIndex = menuDepth_;
@ -469,18 +478,19 @@ bool Page::popCollection()
{
int menuExitIndex = -1;
int menuEnterIndex = -1;
CollectionInfo *collection = NULL;
if(menuDepth_ <= 1)
{
return false;
}
if(collections_.size() <= 1)
{
return false;
}
if(!activeMenu_) return false;
if(menuDepth_ <= 1) return false;
if(collections_.size() <= 1) return false;
// queue the collection for deletion
MenuInfo_S &info = collections_.back();
info.queueDelete = true;
// get the next collection off of the stack
collections_.pop_back();
collection = collections_.back();
info = collections_.back();
playlist_ = info.playlist;
if(activeMenu_)
{
@ -500,7 +510,7 @@ bool Page::popCollection()
{
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
{
(*it)->collectionName = collection->name;
(*it)->collectionName = info.collection->name;
if(menuEnterIndex >= 0)
{
@ -517,6 +527,24 @@ bool Page::popCollection()
return true;
}
void Page::nextPlaylist()
{
MenuInfo_S &info = collections_.back();
unsigned int numlists = info.collection->playlists.size();
for(unsigned int i = 0; i <= numlists; ++i)
{
playlist_++;
// wrap
if(playlist_ == info.collection->playlists.end()) playlist_ = info.collection->playlists.begin();
// find the first playlist
if(playlist_->second->size() != 0) break;
}
activeMenu_->setItems(playlist_->second);
activeMenu_->triggerMenuEnterEvent();
}
void Page::update(float dt)
{
@ -544,7 +572,28 @@ void Page::update(float dt)
{
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
{
(*it)->update(dt);
if(*it) (*it)->update(dt);
}
}
// many nodes still have handles on the collection info. We need to delete
// them once everything is done using them
std::list<MenuInfo_S>::iterator del = collections_.begin();
while(del != collections_.end())
{
MenuInfo_S &info = *del;
if(info.queueDelete && info.menu && info.menu->isIdle())
{
std::list<MenuInfo_S>::iterator next = del;
++next;
if(info.collection) delete info.collection;
collections_.erase(del);
}
else
{
++del;
}
}
}
@ -555,7 +604,7 @@ void Page::draw()
{
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
{
(*it)->draw();
if(*it) (*it)->draw();
}
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
@ -569,14 +618,11 @@ void Page::draw()
std::string Page::getCollectionName()
{
CollectionInfo *info = collections_.back();
if(collections_.size() == 0) return "";
if(info)
{
return info->name;
}
MenuInfo_S &info = collections_.back();
return info.collection->name;
return "";
}
void Page::freeGraphicsMemory()

View File

@ -16,13 +16,13 @@
#pragma once
#include "MenuNotifierInterface.h"
#include "../Collection/CollectionInfo.h"
#include <map>
#include <string>
#include <list>
#include <vector>
class CollectionInfo;
class Component;
class Configuration;
class ScrollingList;
@ -46,6 +46,7 @@ public:
virtual void onNewItemSelected(Item *);
bool pushCollection(CollectionInfo *collection);
bool popCollection();
void nextPlaylist();
void pushMenu(ScrollingList *s);
bool isMenusFull();
void setLoadSound(Sound *chunk);
@ -83,17 +84,28 @@ private:
void highlight();
std::string collectionName_;
Configuration &config_;
struct MenuInfo_S
{
CollectionInfo *collection;
ScrollingList *menu;
CollectionInfo::Playlists_T::iterator playlist;
bool queueDelete;
};
typedef std::vector<ScrollingList *> MenuVector_T;
typedef std::vector<CollectionInfo *> CollectionInfo_T;
typedef std::list<MenuInfo_S> CollectionVector_T;
ScrollingList *activeMenu_;
unsigned int menuDepth_;
MenuVector_T menus_;
CollectionInfo_T collections_;
CollectionVector_T collections_;
static const unsigned int NUM_LAYERS = 8;
std::vector<Component *> LayerComponents[NUM_LAYERS];
std::vector<Item *> *items_;
std::list<ScrollingList *> deleteMenuList_;
std::list<CollectionInfo *> deleteCollectionList_;
bool scrollActive_;
Item *selectedItem_;
@ -105,6 +117,7 @@ private:
Sound *selectSoundChunk_;
float minShowTime_;
float elapsedTime_;
CollectionInfo::Playlists_T::iterator playlist_;
};

View File

@ -512,6 +512,10 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page)
}
}
}
if(input_.keystate(UserInput::KeyCodeNextPlaylist) && page->isMenuIdle())
{
page->nextPlaylist();
}
if (input_.keystate(UserInput::KeyCodeBack) && page->isMenuIdle())
{