Added support for menuIndex attribute for menus. This will allow multiple

menus to reside at the same menuIndex, effectively showing multiple menus at
the same time. The direction for the keys is taken from the first menu
definition at each level.
This commit is contained in:
Pieter Hulshoff 2017-05-24 20:24:10 +02:00
parent d30158ea67
commit cd98016449
5 changed files with 320 additions and 162 deletions

View File

@ -416,6 +416,13 @@ unsigned int ScrollingList::getSelectedIndex()
return loopIncrement(itemIndex_, selectedOffsetIndex_, items_->size()); return loopIncrement(itemIndex_, selectedOffsetIndex_, items_->size());
} }
void ScrollingList::setSelectedIndex(unsigned int index)
{
if(!items_) return;
itemIndex_ = loopDecrement(index, selectedOffsetIndex_, items_->size());
}
unsigned int ScrollingList::getSize() unsigned int ScrollingList::getSize()
{ {
if(!items_) return 0; if(!items_) return 0;

View File

@ -60,6 +60,7 @@ public:
void destroyItems(); void destroyItems();
void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints); void setPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints);
unsigned int getSelectedIndex(); unsigned int getSelectedIndex();
void setSelectedIndex(unsigned int index);
unsigned int getSize(); unsigned int getSize();
void pageUp(); void pageUp();
void pageDown(); void pageDown();

View File

@ -27,9 +27,9 @@
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
Page::Page(Configuration &config) Page::Page(Configuration &config)
: config_(config) : config_(config)
, activeMenu_(NULL)
, menuDepth_(0) , menuDepth_(0)
, scrollActive_(false) , scrollActive_(false)
, selectedItem_(NULL) , selectedItem_(NULL)
@ -42,6 +42,7 @@ Page::Page(Configuration &config)
{ {
} }
Page::~Page() Page::~Page()
{ {
} }
@ -52,9 +53,15 @@ void Page::DeInitialize()
MenuVector_T::iterator it = menus_.begin(); MenuVector_T::iterator it = menus_.begin();
while(it != menus_.end()) while(it != menus_.end())
{ {
ScrollingList *menu = *it; std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin();
while(it2 != menus_[std::distance(menus_.begin(), it)].end())
{
ScrollingList *menu = *it2;
menus_[std::distance(menus_.begin(), it)].erase(it2);
delete menu;
it2 = menus_[std::distance(menus_.begin(), it)].begin();
}
menus_.erase(it); menus_.erase(it);
delete menu;
it = menus_.begin(); it = menus_.begin();
} }
@ -110,18 +117,25 @@ bool Page::isMenusFull()
return (menuDepth_ > menus_.size()); return (menuDepth_ > menus_.size());
} }
void Page::setLoadSound(Sound *chunk) void Page::setLoadSound(Sound *chunk)
{ {
loadSoundChunk_ = chunk; loadSoundChunk_ = chunk;
} }
void Page::setUnloadSound(Sound *chunk) void Page::setUnloadSound(Sound *chunk)
{ {
unloadSoundChunk_ = chunk; unloadSoundChunk_ = chunk;
} }
void Page::setHighlightSound(Sound *chunk) void Page::setHighlightSound(Sound *chunk)
{ {
highlightSoundChunk_ = chunk; highlightSoundChunk_ = chunk;
} }
void Page::setSelectSound(Sound *chunk) void Page::setSelectSound(Sound *chunk)
{ {
selectSoundChunk_ = chunk; selectSoundChunk_ = chunk;
@ -130,12 +144,16 @@ void Page::setSelectSound(Sound *chunk)
void Page::onNewItemSelected() void Page::onNewItemSelected()
{ {
selectedItem_ = activeMenu_->getSelectedItem(); if(!(activeMenu_.size() > 0 && activeMenu_[0])) return;
selectedItem_ = activeMenu_[0]->getSelectedItem();
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
menu->setNewItemSelected(); {
ScrollingList *menu = *it2;
if(menu) menu->setNewItemSelected();
}
} }
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
@ -148,7 +166,8 @@ void Page::onNewItemSelected()
void Page::highlightLoadArt() void Page::highlightLoadArt()
{ {
selectedItem_ = activeMenu_->getSelectedItem(); if(!(activeMenu_.size() > 0 && activeMenu_[0])) return;
selectedItem_ = activeMenu_[0]->getSelectedItem();
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -158,21 +177,37 @@ void Page::highlightLoadArt()
} }
void Page::pushMenu(ScrollingList *s) void Page::pushMenu(ScrollingList *s, int index)
{ {
menus_.push_back(s); // If index < 0 then append to the menus_ vector
if(index < 0)
{
index = menus_.size();
}
// Increase menus_ as needed
while(index >= static_cast<int>(menus_.size()))
{
std::vector<ScrollingList *> menus;
menus_.push_back(menus);
}
menus_[index].push_back(s);
} }
unsigned int Page::getMenuDepth() unsigned int Page::getMenuDepth()
{ {
return menuDepth_; return menuDepth_;
} }
void Page::setStatusTextComponent(Text *t) void Page::setStatusTextComponent(Text *t)
{ {
textStatusComponent_ = t; textStatusComponent_ = t;
} }
bool Page::addComponent(Component *c) bool Page::addComponent(Component *c)
{ {
bool retVal = false; bool retVal = false;
@ -192,23 +227,28 @@ bool Page::addComponent(Component *c)
return retVal; return retVal;
} }
bool Page::isMenuIdle() bool Page::isMenuIdle()
{ {
bool idle = true; bool idle = true;
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(!menu->isIdle())
{ {
idle = false; ScrollingList *menu = *it2;
break;
if(!menu->isIdle())
{
idle = false;
break;
}
} }
} }
return idle; return idle;
} }
bool Page::isIdle() bool Page::isIdle()
{ {
bool idle = isMenuIdle(); bool idle = isMenuIdle();
@ -221,6 +261,7 @@ bool Page::isIdle()
return idle; return idle;
} }
bool Page::isGraphicsIdle() bool Page::isGraphicsIdle()
{ {
bool idle = true; bool idle = true;
@ -238,9 +279,12 @@ void Page::start()
{ {
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
menu->triggerEvent( "enter" ); {
menu->triggerEnterEvent(); ScrollingList *menu = *it2;
menu->triggerEvent( "enter" );
menu->triggerEnterEvent();
}
} }
if(loadSoundChunk_) if(loadSoundChunk_)
@ -259,9 +303,12 @@ void Page::stop()
{ {
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
menu->triggerEvent( "exit" ); {
menu->triggerExitEvent(); ScrollingList *menu = *it2;
menu->triggerEvent( "exit" );
menu->triggerExitEvent();
}
} }
if(unloadSoundChunk_) if(unloadSoundChunk_)
@ -281,9 +328,11 @@ Item *Page::getSelectedItem()
return selectedItem_; return selectedItem_;
} }
Item *Page::getSelectedItem(int offset) Item *Page::getSelectedItem(int offset)
{ {
return activeMenu_->getItemByOffset(offset); if(!(activeMenu_.size() > 0 && activeMenu_[0])) return NULL;
return activeMenu_[0]->getItemByOffset(offset);
} }
@ -300,35 +349,43 @@ void Page::removeSelectedItem()
} }
void Page::setScrollOffsetIndex(unsigned int i) void Page::setScrollOffsetIndex(unsigned int i)
{ {
if(!activeMenu_) return; if(!(activeMenu_.size() > 0 && activeMenu_[0])) return;
for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
activeMenu_->setScrollOffsetIndex(i); {
ScrollingList *menu = *it;
menu->setScrollOffsetIndex(i);
}
} }
unsigned int Page::getScrollOffsetIndex() unsigned int Page::getScrollOffsetIndex()
{ {
if(!activeMenu_) return -1; if(!(activeMenu_.size() > 0 && activeMenu_[0])) return -1;
return activeMenu_[0]->getScrollOffsetIndex();
return activeMenu_->getScrollOffsetIndex();
} }
void Page::setMinShowTime(float value) void Page::setMinShowTime(float value)
{ {
minShowTime_ = value; minShowTime_ = value;
} }
float Page::getMinShowTime() float Page::getMinShowTime()
{ {
return minShowTime_; return minShowTime_;
} }
void Page::playlistChange() void Page::playlistChange()
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->setPlaylist(playlist_->first); ScrollingList *menu = *it;
if(menu) menu->setPlaylist(playlist_->first);
} }
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
@ -358,17 +415,20 @@ void Page::highlightEnter()
if(!item) return; if(!item) return;
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "highlightEnter", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerHighlightEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "highlightEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerHighlightEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "highlightEnter", menuDepth_ - 1 ); }
menu->triggerHighlightEnterEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "highlightEnter", menuDepth_ - 1 );
menu->triggerHighlightEnterEvent( menuDepth_ - 1 );
}
} }
} }
@ -386,17 +446,20 @@ void Page::highlightExit()
if(!item) return; if(!item) return;
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "highlightExit", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerHighlightExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "highlightExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerHighlightExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "highlightExit", menuDepth_ - 1 ); }
menu->triggerHighlightExitEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "highlightExit", menuDepth_ - 1 );
menu->triggerHighlightExitEvent( menuDepth_ - 1 );
}
} }
} }
@ -433,56 +496,80 @@ void Page::setScrolling(ScrollDirection direction)
} }
bool Page::isHorizontalScroll() bool Page::isHorizontalScroll()
{ {
if(!activeMenu_) { return false; } if(!(activeMenu_.size() > 0 && activeMenu_[0])) return false;
return activeMenu_[0]->horizontalScroll;
return activeMenu_->horizontalScroll;
} }
void Page::pageScroll(ScrollDirection direction) void Page::pageScroll(ScrollDirection direction)
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
if(direction == ScrollDirectionForward) ScrollingList *menu = *it;
if(menu)
{ {
activeMenu_->pageDown(); if(direction == ScrollDirectionForward)
} {
if(direction == ScrollDirectionBack) menu->pageDown();
{ }
activeMenu_->pageUp(); if(direction == ScrollDirectionBack)
{
menu->pageUp();
}
} }
} }
} }
void Page::selectRandom() void Page::selectRandom()
{ {
if(activeMenu_) activeMenu_->random(); if(activeMenu_.size() > 0 && activeMenu_[0])
}
void Page::letterScroll(ScrollDirection direction)
{
if(activeMenu_)
{ {
if(direction == ScrollDirectionForward) activeMenu_[0]->random();
unsigned int index = activeMenu_[0]->getSelectedIndex();
for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->letterDown(); ScrollingList *menu = *it;
} menu->setSelectedIndex(index);
if(direction == ScrollDirectionBack)
{
activeMenu_->letterUp();
} }
} }
} }
void Page::letterScroll(ScrollDirection direction)
{
for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{
ScrollingList *menu = *it;
if(menu)
{
if(direction == ScrollDirectionForward)
{
menu->letterDown();
}
if(direction == ScrollDirectionBack)
{
menu->letterUp();
}
}
}
}
unsigned int Page::getCollectionSize() unsigned int Page::getCollectionSize()
{ {
return activeMenu_->getSize(); if(!(activeMenu_.size() > 0 && activeMenu_[0])) return 0;
return activeMenu_[0]->getSize();
} }
unsigned int Page::getSelectedIndex() unsigned int Page::getSelectedIndex()
{ {
return activeMenu_->getSelectedIndex(); if(!(activeMenu_.size() > 0 && activeMenu_[0])) return 0;
return activeMenu_[0]->getSelectedIndex();
} }
@ -490,20 +577,27 @@ bool Page::pushCollection(CollectionInfo *collection)
{ {
// grow the menu as needed // grow the menu as needed
if(menus_.size() <= menuDepth_ && activeMenu_) if(menus_.size() <= menuDepth_ && activeMenu_.size() > 0 && activeMenu_[0])
{ {
activeMenu_ = new ScrollingList(*activeMenu_); for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
pushMenu(activeMenu_); {
ScrollingList *menu = *it;
ScrollingList *newMenu = new ScrollingList(*menu);
pushMenu(newMenu, menuDepth_);
}
} }
activeMenu_ = menus_[menuDepth_]; activeMenu_ = menus_[menuDepth_];
activeMenu_->collectionName = collection->name; for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
activeMenu_->setItems(&collection->items); {
ScrollingList *menu = *it;
menu->collectionName = collection->name;
menu->setItems(&collection->items);
}
// build the collection info instance // build the collection info instance
MenuInfo_S info; MenuInfo_S info;
info.collection = collection; info.collection = collection;
info.menu = activeMenu_;
info.playlist = collection->playlists.begin(); info.playlist = collection->playlists.begin();
info.queueDelete = false; info.queueDelete = false;
collections_.push_back(info); collections_.push_back(info);
@ -524,10 +618,11 @@ bool Page::pushCollection(CollectionInfo *collection)
return true; return true;
} }
bool Page::popCollection() bool Page::popCollection()
{ {
if(!activeMenu_) return false; if(!(activeMenu_.size() > 0 && activeMenu_[0])) return false;
if(menuDepth_ <= 1) return false; if(menuDepth_ <= 1) return false;
if(collections_.size() <= 1) return false; if(collections_.size() <= 1) return false;
@ -559,17 +654,20 @@ void Page::enterMenu()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "menuEnter", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerMenuEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "menuEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerMenuEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "menuEnter", menuDepth_ - 1 ); }
menu->triggerMenuEnterEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "menuEnter", menuDepth_ - 1 );
menu->triggerMenuEnterEvent( menuDepth_ - 1 );
}
} }
} }
@ -587,17 +685,20 @@ void Page::exitMenu()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "menuExit", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerMenuExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "menuExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerMenuExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "menuExit", menuDepth_ - 1 ); }
menu->triggerMenuExitEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "menuExit", menuDepth_ - 1 );
menu->triggerMenuExitEvent( menuDepth_ - 1 );
}
} }
} }
@ -615,17 +716,20 @@ void Page::enterGame()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "gameEnter", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerGameEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "gameEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerGameEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "gameEnter", menuDepth_ - 1 ); }
menu->triggerGameEnterEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "gameEnter", menuDepth_ - 1 );
menu->triggerGameEnterEvent( menuDepth_ - 1 );
}
} }
} }
@ -643,17 +747,20 @@ void Page::exitGame()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
if(menus_[menuDepth_-1] == menu)
{ {
// Also trigger animations for index i for active menu ScrollingList *menu = *it2;
menu->triggerEvent( "gameExit", MENU_INDEX_HIGH + menuDepth_ - 1 ); if(menuDepth_-1 == distance(menus_.begin(), it))
menu->triggerGameExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 ); {
} // Also trigger animations for index i for active menu
else menu->triggerEvent( "gameExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
{ menu->triggerGameExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerEvent( "gameExit", menuDepth_ - 1 ); }
menu->triggerGameExitEvent( menuDepth_ - 1 ); else
{
menu->triggerEvent( "gameExit", menuDepth_ - 1 );
menu->triggerGameExitEvent( menuDepth_ - 1 );
}
} }
} }
@ -701,7 +808,11 @@ void Page::nextPlaylist()
if(playlist_->second->size() != 0) break; if(playlist_->second->size() != 0) break;
} }
activeMenu_->setItems(playlist_->second); for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{
ScrollingList *menu = *it;
menu->setItems(playlist_->second);
}
playlistChange(); playlistChange();
} }
@ -724,7 +835,11 @@ void Page::prevPlaylist()
if(playlist_->second->size() != 0) break; if(playlist_->second->size() != 0) break;
} }
activeMenu_->setItems(playlist_->second); for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{
ScrollingList *menu = *it;
menu->setItems(playlist_->second);
}
playlistChange(); playlistChange();
} }
@ -752,17 +867,24 @@ void Page::selectPlaylist(std::string playlist)
if ( playlist_->second->size() == 0 || playlist_->first != playlist) if ( playlist_->second->size() == 0 || playlist_->first != playlist)
playlist_ = playlist_store; playlist_ = playlist_store;
activeMenu_->setItems(playlist_->second); for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{
ScrollingList *menu = *it;
menu->setItems(playlist_->second);
}
playlistChange(); playlistChange();
} }
void Page::update(float dt) void Page::update(float dt)
{ {
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
{
menu->update(dt); ScrollingList *menu = *it2;
menu->update(dt);
}
} }
if(textStatusComponent_) if(textStatusComponent_)
@ -787,7 +909,7 @@ void Page::cleanup()
while(del != deleteCollections_.end()) while(del != deleteCollections_.end())
{ {
MenuInfo_S &info = *del; MenuInfo_S &info = *del;
if(info.queueDelete && info.menu) if(info.queueDelete)
{ {
std::list<MenuInfo_S>::iterator next = del; std::list<MenuInfo_S>::iterator next = del;
++next; ++next;
@ -819,13 +941,17 @@ void Page::draw()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
menu->draw(i); {
ScrollingList *menu = *it2;
menu->draw(i);
}
} }
} }
} }
void Page::removePlaylist() void Page::removePlaylist()
{ {
if(!selectedItem_) return; if(!selectedItem_) return;
@ -845,6 +971,7 @@ void Page::removePlaylist()
collection->Save(); collection->Save();
} }
void Page::addPlaylist() void Page::addPlaylist()
{ {
if(!selectedItem_) return; if(!selectedItem_) return;
@ -862,6 +989,7 @@ void Page::addPlaylist()
collection->Save(); collection->Save();
} }
std::string Page::getCollectionName() std::string Page::getCollectionName()
{ {
if(collections_.size() == 0) return ""; if(collections_.size() == 0) return "";
@ -871,12 +999,16 @@ std::string Page::getCollectionName()
} }
void Page::freeGraphicsMemory() void Page::freeGraphicsMemory()
{ {
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
menu->freeGraphicsMemory(); {
ScrollingList *menu = *it2;
menu->freeGraphicsMemory();
}
} }
if(loadSoundChunk_) loadSoundChunk_->free(); if(loadSoundChunk_) loadSoundChunk_->free();
@ -890,15 +1022,18 @@ void Page::freeGraphicsMemory()
} }
} }
void Page::allocateGraphicsMemory() void Page::allocateGraphicsMemory()
{ {
Logger::write(Logger::ZONE_DEBUG, "Page", "Allocating graphics memory"); Logger::write(Logger::ZONE_DEBUG, "Page", "Allocating graphics memory");
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; for(std::vector<ScrollingList *>::iterator it2 = menus_[std::distance(menus_.begin(), it)].begin(); it2 != menus_[std::distance(menus_.begin(), it)].end(); it2++)
{
menu->allocateGraphicsMemory(); ScrollingList *menu = *it2;
menu->allocateGraphicsMemory();
}
} }
if(loadSoundChunk_) loadSoundChunk_->allocate(); if(loadSoundChunk_) loadSoundChunk_->allocate();
@ -913,11 +1048,13 @@ void Page::allocateGraphicsMemory()
Logger::write(Logger::ZONE_DEBUG, "Page", "Allocate graphics memory complete"); Logger::write(Logger::ZONE_DEBUG, "Page", "Allocate graphics memory complete");
} }
void Page::launchEnter() void Page::launchEnter()
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->launchEnter(); ScrollingList *menu = *it;
if(menu) menu->launchEnter();
} }
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
@ -931,11 +1068,13 @@ void Page::launchEnter()
} }
} }
void Page::launchExit() void Page::launchExit()
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->launchExit(); ScrollingList *menu = *it;
if(menu) menu->launchExit();
} }
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
@ -947,10 +1086,14 @@ void Page::launchExit()
void Page::reallocateMenuSpritePoints() void Page::reallocateMenuSpritePoints()
{ {
if (activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->deallocateSpritePoints(); ScrollingList *menu = *it;
activeMenu_->allocateSpritePoints(); if(menu)
{
menu->deallocateSpritePoints();
menu->allocateSpritePoints();
}
} }
} }
@ -978,30 +1121,36 @@ bool Page::isPlaying()
void Page::resetScrollPeriod() void Page::resetScrollPeriod()
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->resetScrollPeriod(); ScrollingList *menu = *it;
} if(menu) menu->resetScrollPeriod();
return; }
return;
} }
void Page::updateScrollPeriod() void Page::updateScrollPeriod()
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->updateScrollPeriod(); ScrollingList *menu = *it;
} if(menu) menu->updateScrollPeriod();
return; }
return;
} }
void Page::scroll(bool forward) void Page::scroll(bool forward)
{ {
if(activeMenu_) for(std::vector<ScrollingList *>::iterator it = activeMenu_.begin(); it != activeMenu_.end(); it++)
{ {
activeMenu_->scroll(forward); ScrollingList *menu = *it;
highlightSoundChunk_->play(); if(menu)
} {
return; menu->scroll(forward);
highlightSoundChunk_->play();
}
}
return;
} }

View File

@ -56,7 +56,7 @@ public:
void nextPlaylist(); void nextPlaylist();
void prevPlaylist(); void prevPlaylist();
void selectPlaylist(std::string playlist); void selectPlaylist(std::string playlist);
void pushMenu(ScrollingList *s); void pushMenu(ScrollingList *s, int index = -1);
bool isMenusFull(); bool isMenusFull();
void setLoadSound(Sound *chunk); void setLoadSound(Sound *chunk);
void setUnloadSound(Sound *chunk); void setUnloadSound(Sound *chunk);
@ -112,15 +112,14 @@ private:
struct MenuInfo_S struct MenuInfo_S
{ {
CollectionInfo *collection; CollectionInfo *collection;
ScrollingList *menu;
CollectionInfo::Playlists_T::iterator playlist; CollectionInfo::Playlists_T::iterator playlist;
bool queueDelete; bool queueDelete;
}; };
typedef std::vector<ScrollingList *> MenuVector_T; typedef std::vector< std::vector<ScrollingList *> > MenuVector_T;
typedef std::list<MenuInfo_S> CollectionVector_T; typedef std::list<MenuInfo_S> CollectionVector_T;
ScrollingList *activeMenu_; std::vector<ScrollingList *> activeMenu_;
unsigned int menuDepth_; unsigned int menuDepth_;
MenuVector_T menus_; MenuVector_T menus_;
CollectionVector_T collections_; CollectionVector_T collections_;

View File

@ -334,7 +334,9 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page)
for(xml_node<> *componentXml = layout->first_node("menu"); componentXml; componentXml = componentXml->next_sibling("menu")) for(xml_node<> *componentXml = layout->first_node("menu"); componentXml; componentXml = componentXml->next_sibling("menu"))
{ {
ScrollingList *scrollingList = buildMenu(componentXml,*page); ScrollingList *scrollingList = buildMenu(componentXml,*page);
page->pushMenu(scrollingList); xml_attribute<> *indexXml = componentXml->first_attribute("menuIndex");
int index = indexXml ? Utils::convertInt(indexXml->value()) : -1;
page->pushMenu(scrollingList, index);
} }
for(xml_node<> *componentXml = layout->first_node("container"); componentXml; componentXml = componentXml->next_sibling("container")) for(xml_node<> *componentXml = layout->first_node("container"); componentXml; componentXml = componentXml->next_sibling("container"))