Fixed letter up/down selection.

This commit is contained in:
Pieter Hulshoff
2016-05-04 10:01:28 +02:00
parent 11afa1dad4
commit 93f6b65c1e

View File

@@ -327,7 +327,7 @@ void ScrollingList::letterChange(bool increment)
notifyAllRequested_ = true; notifyAllRequested_ = true;
deallocateSpritePoints(); deallocateSpritePoints();
std::string startname = items_->at(itemIndex_)->lowercaseFullTitle(); std::string startname = items_->at((itemIndex_+selectedOffsetIndex_)%items_->size())->lowercaseFullTitle();
for(unsigned int i = 0; i < items_->size(); ++i) for(unsigned int i = 0; i < items_->size(); ++i)
{ {
@@ -335,21 +335,37 @@ void ScrollingList::letterChange(bool increment)
if(increment) index = loopIncrement(itemIndex_, i, items_->size()); if(increment) index = loopIncrement(itemIndex_, i, items_->size());
else index = loopDecrement(itemIndex_, i, items_->size()); else index = loopDecrement(itemIndex_, i, items_->size());
std::string endname = items_->at(index)->lowercaseFullTitle(); std::string endname = items_->at((index+selectedOffsetIndex_)%items_->size())->lowercaseFullTitle();
// check if we are changing characters from a-z, or changing from alpha character to non-alpha character // check if we are changing characters from a-z, or changing from alpha character to non-alpha character
if(isalpha(startname[0]) ^ isalpha(endname[0])) if((isalpha(startname[0]) ^ isalpha(endname[0])) ||
{ (isalpha(startname[0]) && isalpha(endname[0]) && startname[0] != endname[0]))
break;
itemIndex_ = index;
}
else if(isalpha(startname[0]) && isalpha(endname[0]) && startname[0] != endname[0])
{ {
itemIndex_ = index; itemIndex_ = index;
break; break;
} }
} }
if (!increment) // For decrement, find the first game of the new letter
{
startname = items_->at((itemIndex_+selectedOffsetIndex_)%items_->size())->lowercaseFullTitle();
for(unsigned int i = 0; i < items_->size(); ++i)
{
unsigned int index = loopDecrement(itemIndex_, i, items_->size());
std::string endname = items_->at((index+selectedOffsetIndex_)%items_->size())->lowercaseFullTitle();
// check if we are changing characters from a-z, or changing from alpha character to non-alpha character
if((isalpha(startname[0]) ^ isalpha(endname[0])) ||
(isalpha(startname[0]) && isalpha(endname[0]) && startname[0] != endname[0]))
{
itemIndex_ = loopIncrement(index,1,items_->size());
break;
}
}
}
allocateSpritePoints(); allocateSpritePoints();
} }