Allow JUMP TO... in case of filtered lists (such as when UIMODE != FULL).

Also add support for numbers and some symbols.
This commit is contained in:
D. Polders 2017-11-03 12:11:11 +01:00
parent c70acc88de
commit 5693e4a20c

View file

@ -18,39 +18,53 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
// check it's not a placeholder folder - if it is, only show "Filter Options"
FileData* file = getGamelist()->getCursor();
fromPlaceholder = file->isPlaceHolder();
bool isFiltered = system->getIndex()->isFiltered();
ComponentListRow row;
if (!fromPlaceholder) {
// jump to letter
row.elements.clear();
if (!isFiltered) {
// jump to letter
row.elements.clear();
char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
if(curChar < 'A' || curChar > 'Z')
curChar = 'A';
// define supported character range
// this range includes all numbers, capital letters, and most reasonable symbols
char startChar = '!';
char endChar = '_';
mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO LETTER", false);
for(char c = 'A'; c <= 'Z'; c++)
mJumpToLetterList->add(std::string(1, c), c, c == curChar);
char curChar = toupper(getGamelist()->getCursor()->getName()[0]);
if(curChar < startChar || curChar > endChar)
curChar = startChar;
row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO LETTER", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.addElement(mJumpToLetterList, false);
row.input_handler = [&](InputConfig* config, Input input) {
if(config->isMappedTo("a", input) && input.value)
mJumpToLetterList = std::make_shared<LetterList>(mWindow, "JUMP TO...", false);
for (char c = startChar; c <= endChar; c++)
{
// check if c is a valid first letter in current list
const std::vector<FileData*>& files = getGamelist()->getCursor()->getParent()->getChildrenListToDisplay();
for (auto file : files)
{
char candidate = toupper(file->getName()[0]);
if (c == candidate)
{
jumpToLetter();
return true;
mJumpToLetterList->add(std::string(1, c), c, c == curChar);
break;
}
else if(mJumpToLetterList->input(config, input))
{
return true;
}
return false;
};
mMenu.addRow(row);
}
}
row.addElement(std::make_shared<TextComponent>(mWindow, "JUMP TO...", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.addElement(mJumpToLetterList, false);
row.input_handler = [&](InputConfig* config, Input input) {
if(config->isMappedTo("a", input) && input.value)
{
jumpToLetter();
return true;
}
else if(mJumpToLetterList->input(config, input))
{
return true;
}
return false;
};
mMenu.addRow(row);
// sort list by
mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
@ -189,7 +203,7 @@ void GuiGamelistOptions::jumpToLetter()
IGameListView* gamelist = getGamelist();
// this is a really shitty way to get a list of files
const std::vector<FileData*>& files = gamelist->getCursor()->getParent()->getChildren();
const std::vector<FileData*>& files = gamelist->getCursor()->getParent()->getChildrenListToDisplay();
long min = 0;
long max = files.size() - 1;