Remember the last highlighted item when re-entering a menu.

This commit is contained in:
emb 2015-05-29 19:25:16 -05:00
parent 836e18abd3
commit a3948b9ad2
6 changed files with 42 additions and 1 deletions

View File

@ -269,6 +269,21 @@ void ScrollingList::SetPoints(std::vector<ViewInfo *> *scrollPoints, std::vector
TweenPoints = tweenPoints;
}
unsigned int ScrollingList::GetScrollOffsetIndex()
{
return FirstSpriteIndex;
}
void ScrollingList::SetScrollOffsetIndex(unsigned int index)
{
if(SpriteList && index < SpriteList->size())
{
DeallocateSpritePoints();
FirstSpriteIndex = index;
AllocateSpritePoints();
}
}
void ScrollingList::SetSelectedIndex(int selectedIndex)
{
SelectedSpriteListIndex = selectedIndex;

View File

@ -68,6 +68,8 @@ public:
void LetterUp();
void LetterDown();
bool IsIdle();
unsigned int GetScrollOffsetIndex();
void SetScrollOffsetIndex(unsigned int index);
void SetSelectedIndex(int selectedIndex);
ComponentItemBinding *GetSelectedCollectionItemSprite();
ComponentItemBinding *GetPendingCollectionItemSprite();

View File

@ -291,6 +291,20 @@ void Page::RemoveSelectedItem()
}
void Page::SetScrollOffsetIndex(unsigned int i)
{
if(!ActiveMenu) return;
ActiveMenu->SetScrollOffsetIndex(i);
}
unsigned int Page::GetScrollOffsetIndex()
{
if(!ActiveMenu) return -1;
return ActiveMenu->GetScrollOffsetIndex();
}
void Page::SetMinShowTime(float value)
{
MinShowTime = value;

View File

@ -63,6 +63,8 @@ public:
unsigned int GetMenuDepth();
Item *GetSelectedItem();
void RemoveSelectedItem();
void SetScrollOffsetIndex(unsigned int i);
unsigned int GetScrollOffsetIndex();
bool IsIdle();
bool IsMenuIdle();
bool IsHidden();

View File

@ -307,6 +307,7 @@ void RetroFE::Run()
break;
case RETROFE_BACK_REQUEST:
LastMenuOffsets[CurrentPage->GetCollectionName()] = CurrentPage->GetScrollOffsetIndex();
CurrentPage->PopCollection();
Config.SetCurrentCollection(CurrentPage->GetCollectionName());
@ -419,7 +420,7 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
}
if (Input.GetKeyState(UserInput::KeyCodeDown))
{
page->SetScrolling(Page::ScrollDirectionForward);
page->SetScrolling(Page::ScrollDirectionForward);
}
}
if (Input.GetKeyState(UserInput::KeyCodePageUp))
@ -461,6 +462,11 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
MenuParser mp;
mp.GetMenuItems(info);
page->PushCollection(info);
if(LastMenuOffsets.find(NextPageItem->GetName()) != LastMenuOffsets.end())
{
page->SetScrollOffsetIndex(LastMenuOffsets[NextPageItem->GetName()]);
}
state = RETROFE_NEXT_PAGE_REQUEST;
}

View File

@ -26,6 +26,7 @@
#include <SDL2/SDL.h>
#include <list>
#include <vector>
#include <map>
class CollectionInfo;
class Configuration;
@ -78,5 +79,6 @@ private:
Item *NextPageItem;
FontCache FC;
AttractMode Attract;
std::map<std::string, unsigned int> LastMenuOffsets;
};