Fixed focus navigations with missing widget IDs. For now up to 10 IDs may be missing and navigation will still work, I don't think we need more than 10

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5557 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-06-25 01:13:15 +00:00
parent 0502408d60
commit b0b3faf53a

View File

@ -267,9 +267,19 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b
el = NULL;
}
bool found = false;
// find closest widget
if (el != NULL && el->getTabGroup() != NULL &&
el->getTabGroup()->getNextElement(el->getTabOrder(), true /* reverse */, false /* group */, first, closest))
if (el != NULL && el->getTabGroup() != NULL)
{
// if the current widget is e.g. 15, search for widget 14, 13, 12, ... (up to 10 IDs may be missing)
for (int n=0; n<10 && !found; n++)
{
const bool success = el->getTabGroup()->getNextElement(el->getTabOrder() - n,
true /* reverse */, false /* group */,
first, closest);
if (success)
{
//std::cout << "Navigating up to " << closest->getID() << std::endl;
Widget* closestWidget = GUIEngine::getWidget( closest->getID() );
@ -288,9 +298,13 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b
list->setSelected( list->getItemCount()-1 );
return;
}
found = true;
}
} // end for
}
else
if (!found)
{
//std::cout << "EventHandler::navigateUp : warp around, selecting the last widget\n";
//if (el == NULL) std::cout << " because el is null\n";
@ -372,8 +386,17 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const
el = NULL;
}
if (el != NULL && el->getTabGroup() != NULL &&
el->getTabGroup()->getNextElement(el->getTabOrder(), false, false, first, closest))
bool found = false;
if (el != NULL && el->getTabGroup() != NULL)
{
// if the current widget is e.g. 5, search for widget 6, 7, 8, 9, ..., 15 (up to 10 IDs may be missing)
for (int n=0; n<10 && !found; n++)
{
const bool success = el->getTabGroup()->getNextElement(el->getTabOrder()+n,
false, false, first, closest);
if (success)
{
Widget* closestWidget = GUIEngine::getWidget( closest->getID() );
if (playerID != PLAYER_ID_GAME_MASTER && !closestWidget->m_supports_multiplayer) return;
@ -389,8 +412,13 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const
list->setSelected(0);
}
found = true;
}
else
} // end for
}
if (!found)
{
// select the first widget