From 97635859d5ead738ba39832ea6c5e9c91be5b3c3 Mon Sep 17 00:00:00 2001 From: emb <> Date: Thu, 26 Feb 2015 12:35:58 -0600 Subject: [PATCH] Fixed VerticalMenu selectedIndex bug (selecting wrong item) --- RetroFE/Source/Graphics/PageBuilder.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 549d7c6..5033ae5 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -629,6 +629,9 @@ void PageBuilder::BuildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xm points->push_back(viewInfo); tweenPoints->push_back(CreateTweenInstance(component)); height += viewInfo->GetHeight(); + + // increment the selected index to account for the new "invisible" menu item + selectedIndex++; } while(!end) { @@ -679,16 +682,22 @@ void PageBuilder::BuildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xm tweenPoints->push_back(CreateTweenInstance(component)); } - if(selectedIndex >= ((int)points->size()-2)) + if(selectedIndex >= ((int)points->size())) { - //todo: print debug statements when out of range - selectedIndex = 1; - } - else - { - menu->SetSelectedIndex(selectedIndex+1); + + std::stringstream ss; + + ss << "Design error! Selected menu item was set to " << selectedIndex + << " although there are only " << points->size() + << " menu points that can be displayed"; + + Logger::Write(Logger::ZONE_ERROR, "Layout", "Design error! \"duration\" attribute"); + + selectedIndex = 0; } + + menu->SetSelectedIndex(selectedIndex); menu->SetPoints(points, tweenPoints); }