Support for alphabetical scrolling

This commit is contained in:
emb
2015-05-29 06:15:23 -05:00
parent 7bd25cb079
commit 24db185788
7 changed files with 97 additions and 2 deletions

View File

@@ -50,6 +50,8 @@ bool UserInput::Initialize()
retVal = MapKey("pageDown", KeyCodePageDown) && retVal; retVal = MapKey("pageDown", KeyCodePageDown) && retVal;
retVal = MapKey("pageUp", KeyCodePageUp) && retVal; retVal = MapKey("pageUp", KeyCodePageUp) && retVal;
retVal = MapKey("letterDown", KeyCodeLetterDown) && retVal;
retVal = MapKey("letterUp", KeyCodeLetterUp) && retVal;
retVal = MapKey("select", KeyCodeSelect) && retVal; retVal = MapKey("select", KeyCodeSelect) && retVal;
retVal = MapKey("back", KeyCodeBack) && retVal; retVal = MapKey("back", KeyCodeBack) && retVal;
retVal = MapKey("quit", KeyCodeQuit) && retVal; retVal = MapKey("quit", KeyCodeQuit) && retVal;

View File

@@ -34,6 +34,8 @@ public:
KeyCodeBack, KeyCodeBack,
KeyCodePageDown, KeyCodePageDown,
KeyCodePageUp, KeyCodePageUp,
KeyCodeLetterDown,
KeyCodeLetterUp,
KeyCodeAdminMode, KeyCodeAdminMode,
KeyCodeHideItem, KeyCodeHideItem,
KeyCodeQuit KeyCodeQuit

View File

@@ -29,6 +29,7 @@
#include "Text.h" #include "Text.h"
#include "../../Database/Configuration.h" // todo: decouple the GUI from the data #include "../../Database/Configuration.h" // todo: decouple the GUI from the data
#include "../../Collection/Item.h" #include "../../Collection/Item.h"
#include "../../Utility/Utils.h"
#include "../../Utility/Log.h" #include "../../Utility/Log.h"
#include "../../SDL.h" #include "../../SDL.h"
#include "../ViewInfo.h" #include "../ViewInfo.h"
@@ -377,10 +378,72 @@ void ScrollingList::PageDown()
} }
AllocateSpritePoints(); AllocateSpritePoints();
//todo: may want to handle this properly
// CurrentScrollState = ScrollStatePageChange;
} }
void ScrollingList::LetterUp()
{
NotifyAllRequested = true;
DeallocateSpritePoints();
if(SpriteList && ScrollPoints)
{
unsigned int i = 0;
// Select the previous item in the list in case we are at the top of all the items
// for the currently selected letter.
CircularDecrement(FirstSpriteIndex, SpriteList);
std::string startname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle();
++i;
bool done = false;
// traverse up through the list until we find the first item that starts with a different letter
while(!done && i < SpriteList->size())
{
CircularDecrement(FirstSpriteIndex, SpriteList);
std::string endname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle();
++i;
done = (startname[0] != endname[0]);
if(done)
{
// our searching went too far, rewind to the first item in the list that matches the starting letter
CircularIncrement(FirstSpriteIndex, SpriteList);
}
}
}
AllocateSpritePoints();
}
void ScrollingList::LetterDown()
{
NotifyAllRequested = true;
DeallocateSpritePoints();
if(SpriteList && ScrollPoints)
{
std::string startname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle();
std::string endname = startname;
unsigned int i = 0;
while(startname[0] == endname[0] && i < SpriteList->size())
{
CircularIncrement(FirstSpriteIndex, SpriteList);
endname = GetSelectedCollectionItemSprite()->GetCollectionItem()->GetLCFullTitle();
++i;
}
}
AllocateSpritePoints();
}
void ScrollingList::FreeGraphicsMemory() void ScrollingList::FreeGraphicsMemory()
{ {
Component::FreeGraphicsMemory(); Component::FreeGraphicsMemory();

View File

@@ -65,6 +65,8 @@ public:
bool IsHorizontalScroll(); bool IsHorizontalScroll();
void PageUp(); void PageUp();
void PageDown(); void PageDown();
void LetterUp();
void LetterDown();
bool IsIdle(); bool IsIdle();
void SetSelectedIndex(int selectedIndex); void SetSelectedIndex(int selectedIndex);
ComponentItemBinding *GetSelectedCollectionItemSprite(); ComponentItemBinding *GetSelectedCollectionItemSprite();

View File

@@ -378,6 +378,22 @@ void Page::PageScroll(ScrollDirection direction)
} }
} }
void Page::LetterScroll(ScrollDirection direction)
{
if(ActiveMenu)
{
if(direction == ScrollDirectionForward)
{
ActiveMenu->LetterDown();
}
if(direction == ScrollDirectionBack)
{
ActiveMenu->LetterUp();
}
}
}
bool Page::PushCollection(CollectionInfo *collection) bool Page::PushCollection(CollectionInfo *collection)
{ {
Collections.push_back(collection); Collections.push_back(collection);

View File

@@ -54,6 +54,7 @@ public:
void SetSelectSound(Sound *chunk); void SetSelectSound(Sound *chunk);
bool AddComponent(Component *c); bool AddComponent(Component *c);
void PageScroll(ScrollDirection direction); void PageScroll(ScrollDirection direction);
void LetterScroll(ScrollDirection direction);
void Start(); void Start();
void StartComponents(); void StartComponents();
void Stop(); void Stop();

View File

@@ -430,6 +430,15 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
{ {
page->PageScroll(Page::ScrollDirectionForward); page->PageScroll(Page::ScrollDirectionForward);
} }
if (Input.GetKeyState(UserInput::KeyCodeLetterUp))
{
page->LetterScroll(Page::ScrollDirectionBack);
}
if (Input.GetKeyState(UserInput::KeyCodeLetterDown))
{
page->LetterScroll(Page::ScrollDirectionForward);
}
if (Input.GetKeyState(UserInput::KeyCodeAdminMode)) if (Input.GetKeyState(UserInput::KeyCodeAdminMode))
{ {
//todo: add admin mode support //todo: add admin mode support