Merge with 2 axis navigation

This commit is contained in:
emb 2015-03-03 12:32:22 -06:00
commit 2a52b66ace
9 changed files with 91 additions and 29 deletions

View File

@ -1,7 +1,9 @@
previousItem = Up
nextItem = Down
pageUp = Left
pageDown = Right
up = Up
down = Down
left = Left
right = Right
pageUp = A
pageDown = B
select = Space
back = Escape
quit = Q

View File

@ -31,8 +31,23 @@ bool UserInput::Initialize()
{
bool retVal = true;
retVal = MapKey("nextItem", KeyCodeNextItem) && retVal;
retVal = MapKey("previousItem", KeyCodePreviousItem) && retVal;
if(!MapKey("up", KeyCodeUp))
{
retVal = MapKey("left", KeyCodeUp) && retVal;
}
if(!MapKey("left", KeyCodeLeft))
{
retVal = MapKey("up", KeyCodeLeft) && retVal;
}
if(!MapKey("down", KeyCodeDown))
{
retVal = MapKey("right", KeyCodeDown) && retVal;
}
if(!MapKey("right", KeyCodeRight))
{
retVal = MapKey("down", KeyCodeRight) && retVal;
}
retVal = MapKey("pageDown", KeyCodePageDown) && retVal;
retVal = MapKey("pageUp", KeyCodePageUp) && retVal;
retVal = MapKey("select", KeyCodeSelect) && retVal;
@ -61,7 +76,6 @@ SDL_Scancode UserInput::GetScancode(KeyCode_E key)
bool UserInput::MapKey(std::string keyDescription, KeyCode_E key)
{
bool retVal = false;
SDL_Scancode scanCode;
std::string description;
@ -70,22 +84,18 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key)
if(!Config.GetProperty(configKey, description))
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Missing property " + configKey);
return false;
}
else
scanCode = SDL_GetScancodeFromName(description.c_str());
if(scanCode == SDL_SCANCODE_UNKNOWN)
{
scanCode = SDL_GetScancodeFromName(description.c_str());
if(scanCode == SDL_SCANCODE_UNKNOWN)
{
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Unsupported property value for " + configKey + "(" + description + "). See Documentation/Keycodes.txt for valid inputs");
}
else
{
KeyMap[key] = scanCode;
retVal = true;
}
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Unsupported property value for " + configKey + "(" + description + "). See Documentation/Keycodes.txt for valid inputs");
return false;
}
return retVal;
KeyMap[key] = scanCode;
return true;
}

View File

@ -25,8 +25,10 @@ class UserInput
public:
enum KeyCode_E
{
KeyCodeNextItem,
KeyCodePreviousItem,
KeyCodeUp,
KeyCodeDown,
KeyCodeLeft,
KeyCodeRight,
KeyCodeSelect,
KeyCodeBack,
KeyCodePageDown,

View File

@ -65,6 +65,7 @@ ScrollingList::ScrollingList(Configuration &c,
, FontInst(font)
, LayoutKey(layoutKey)
, ImageType(imageType)
, HorizontalScroll(false)
{
}
@ -155,6 +156,16 @@ void ScrollingList::SetItems(std::vector<ComponentItemBinding *> *spriteList)
AllocateSpritePoints();
}
bool ScrollingList::IsHorizontalScroll()
{
return HorizontalScroll;
}
void ScrollingList::SetScrollOrientation(bool horizontal)
{
HorizontalScroll = horizontal;
}
void ScrollingList::SetScrollAcceleration(float value)
{
ScrollAcceleration = value;

View File

@ -61,6 +61,8 @@ public:
void DestroyItems();
void SetPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<AnimationEvents *> *tweenPoints);
void SetScrollDirection(ScrollDirection direction);
void SetScrollOrientation(bool horizontal);
bool IsHorizontalScroll();
void PageUp();
void PageDown();
bool IsIdle();
@ -127,5 +129,6 @@ private:
Font *FontInst;
std::string LayoutKey;
std::string ImageType;
bool HorizontalScroll;
};

View File

@ -335,6 +335,13 @@ void Page::SetScrolling(ScrollDirection direction)
ActiveMenu->SetScrollDirection(menuDirection);
}
bool Page::IsHorizontalScroll()
{
if(!ActiveMenu) { return false; }
return ActiveMenu->IsHorizontalScroll();
}
void Page::PageScroll(ScrollDirection direction)
{
if(ActiveMenu)

View File

@ -58,6 +58,7 @@ public:
void StartComponents();
void Stop();
void SetScrolling(ScrollDirection direction);
bool IsHorizontalScroll();
unsigned int GetMenuDepth();
Item *GetSelectedItem();
Item *GetPendingSelectedItem();

View File

@ -580,6 +580,7 @@ ScrollingList * PageBuilder::BuildMenu(xml_node<> *menuXml)
xml_attribute<> *menuTypeXml = menuXml->first_attribute("type");
xml_attribute<> *scrollTimeXml = menuXml->first_attribute("scrollTime");
xml_attribute<> *scrollAccelerationXml = menuXml->first_attribute("scrollAcceleration");
xml_attribute<> *scrollOrientationXml = menuXml->first_attribute("orientation");
if(menuTypeXml)
{
@ -612,6 +613,15 @@ ScrollingList * PageBuilder::BuildMenu(xml_node<> *menuXml)
menu->SetScrollAcceleration(Utils::ConvertFloat(scrollAccelerationXml->value()));
}
if(scrollOrientationXml)
{
std::string scrollOrientation = scrollOrientationXml->value();
if(scrollOrientation == "horizontal")
{
menu->SetScrollOrientation(true);
}
}
ViewInfo *v = menu->GetBaseViewInfo();
BuildViewInfo(menuXml, v);

View File

@ -378,13 +378,27 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
Attract.Reset();
if (keys[Input.GetScancode(UserInput::KeyCodePreviousItem)])
if(page->IsHorizontalScroll())
{
page->SetScrolling(Page::ScrollDirectionBack);
if (keys[Input.GetScancode(UserInput::KeyCodeLeft)])
{
page->SetScrolling(Page::ScrollDirectionBack);
}
if (keys[Input.GetScancode(UserInput::KeyCodeRight)])
{
page->SetScrolling(Page::ScrollDirectionForward);
}
}
if (keys[Input.GetScancode(UserInput::KeyCodeNextItem)])
{
page->SetScrolling(Page::ScrollDirectionForward);
else
{
if (keys[Input.GetScancode(UserInput::KeyCodeUp)])
{
page->SetScrolling(Page::ScrollDirectionBack);
}
if (keys[Input.GetScancode(UserInput::KeyCodeDown)])
{
page->SetScrolling(Page::ScrollDirectionForward);
}
}
if (keys[Input.GetScancode(UserInput::KeyCodePageUp)])
{
@ -432,8 +446,10 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
state = RETROFE_QUIT_REQUEST;
}
if(!keys[Input.GetScancode(UserInput::KeyCodePreviousItem)] &&
!keys[Input.GetScancode(UserInput::KeyCodeNextItem)] &&
if(!keys[Input.GetScancode(UserInput::KeyCodeUp)] &&
!keys[Input.GetScancode(UserInput::KeyCodeLeft)] &&
!keys[Input.GetScancode(UserInput::KeyCodeDown)] &&
!keys[Input.GetScancode(UserInput::KeyCodeRight)] &&
!keys[Input.GetScancode(UserInput::KeyCodePageUp)] &&
!keys[Input.GetScancode(UserInput::KeyCodePageDown)])
{