From 298b42404986b191129c4c6f51003fe388230b52 Mon Sep 17 00:00:00 2001 From: Don Honerbrink Date: Thu, 28 May 2015 17:02:21 -0500 Subject: [PATCH] Sandboxing for remembering the last selected item when leaving and re-entering a menu. --- .../Source/Graphics/Component/ScrollingList.cpp | 7 +++++++ .../Source/Graphics/Component/ScrollingList.h | 1 + RetroFE/Source/Graphics/Page.cpp | 17 +++++++++++++++++ RetroFE/Source/Graphics/Page.h | 2 ++ RetroFE/Source/RetroFE.cpp | 6 ++++++ RetroFE/Source/RetroFE.h | 2 ++ 6 files changed, 35 insertions(+) diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 029a29d..4bc1c07 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -267,8 +267,15 @@ void ScrollingList::SetPoints(std::vector *scrollPoints, std::vector TweenPoints = tweenPoints; } +int ScrollingList::GetSelectedIndex() +{ + return SelectedSpriteListIndex; +} + void ScrollingList::SetSelectedIndex(int selectedIndex) { + if(selectedIndex >= SpriteList.size()) return; + SelectedSpriteListIndex = selectedIndex; for(unsigned int i = 0; SpriteList && ScrollPoints && i < SelectedSpriteListIndex; ++i) diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index 0038599..5247034 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -67,6 +67,7 @@ public: void PageDown(); bool IsIdle(); void SetSelectedIndex(int selectedIndex); + int GetSelectedIndex(); ComponentItemBinding *GetSelectedCollectionItemSprite(); ComponentItemBinding *GetPendingCollectionItemSprite(); ComponentItemBinding *GetPendingSelectedCollectionItemSprite(); diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index c45cc46..07159d0 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -291,6 +291,23 @@ void Page::RemoveSelectedItem() } +void Page::SetSelectedIndex(int i) +{ + if(!ActiveMenu) return; + + ActiveMenu->SetSelectedIndex(); +} + +int Page::GetSelectedIndex() +{ + if(!ActiveMenu) return -1; + + return ActiveMenu->GetSelectedIndex(); +} + + + + void Page::SetMinShowTime(float value) { MinShowTime = value; diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 96d1ec7..6d342cd 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -62,6 +62,8 @@ public: unsigned int GetMenuDepth(); Item *GetSelectedItem(); void RemoveSelectedItem(); + void SetSelectedIndex(int i); + int GetSelectedIndex(); bool IsIdle(); bool IsMenuIdle(); bool IsHidden(); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 661c36a..e47879e 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -283,6 +283,11 @@ void RetroFE::Run() MenuParser mp; mp.GetMenuItems(info); CurrentPage->PushCollection(info); + + if(LastSelectedItems.find(firstCollection) != LastSelectedItems.end()) + { + CurrentPage->SetSelectedIndex(LastSelectedItems[firstCollection]); + } } else { @@ -307,6 +312,7 @@ void RetroFE::Run() break; case RETROFE_BACK_REQUEST: + LastSelectedItems[CurrentPage->GetCollectionName()] = CurrentPage->GetSelectedIndex(); CurrentPage->PopCollection(); Config.SetCurrentCollection(CurrentPage->GetCollectionName()); diff --git a/RetroFE/Source/RetroFE.h b/RetroFE/Source/RetroFE.h index 6aee750..9c51045 100644 --- a/RetroFE/Source/RetroFE.h +++ b/RetroFE/Source/RetroFE.h @@ -26,6 +26,7 @@ #include #include #include +#include class CollectionInfo; class Configuration; @@ -78,5 +79,6 @@ private: Item *NextPageItem; FontCache FC; AttractMode Attract; + std::map LastSelectedItems; };