From 4d4d4bc108296652484b59b99693a02d398e2f41 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 27 Jul 2014 17:49:43 -0500 Subject: [PATCH] Re-added the "jump to letter" functionality. --- es-app/src/guis/GuiGamelistOptions.cpp | 62 +++++++++++++++++++++++++- es-app/src/guis/GuiGamelistOptions.h | 6 ++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 6801fa3a9..635f97e19 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -9,6 +9,31 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui { addChild(&mMenu); + // jump to letter + char curChar = getGamelist()->getCursor()->getName()[0]; + mJumpToLetterList = std::make_shared(mWindow, "JUMP TO LETTER", false); + for(char c = 'A'; c <= 'Z'; c++) + { + mJumpToLetterList->add(std::string(1, c), c, c == curChar); + } + + ComponentListRow row; + row.addElement(std::make_shared(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) + { + jumpToLetter(); + return true; + } + else if(mJumpToLetterList->input(config, input)) + { + return true; + } + return false; + }; + mMenu.addRow(row); + // sort list by mListSort = std::make_shared(mWindow, "SORT GAMES BY", false); for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) @@ -20,7 +45,7 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui mMenu.addWithLabel("SORT GAMES BY", mListSort); // edit game metadata - ComponentListRow row; + row.elements.clear(); row.addElement(std::make_shared(mWindow, "EDIT THIS GAME'S METADATA", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); row.addElement(makeArrow(mWindow), false); row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openMetaDataEd, this)); @@ -57,6 +82,41 @@ void GuiGamelistOptions::openMetaDataEd() })); } +void GuiGamelistOptions::jumpToLetter() +{ + char letter = mJumpToLetterList->getSelected(); + IGameListView* gamelist = getGamelist(); + + // this is a really shitty way to get a list of files + const std::vector& files = gamelist->getCursor()->getParent()->getChildren(); + + long min = 0; + long max = files.size() - 1; + long mid = 0; + + while(max >= min) + { + mid = ((max - min) / 2) + min; + + // game somehow has no first character to check + if(files.at(mid)->getName().empty()) + continue; + + char checkLetter = toupper(files.at(mid)->getName()[0]); + + if(checkLetter < letter) + min = mid + 1; + else if(checkLetter > letter) + max = mid - 1; + else + break; //exact match found + } + + gamelist->setCursor(files.at(mid)); + + delete this; +} + bool GuiGamelistOptions::input(InputConfig* config, Input input) { if((config->isMappedTo("b", input) || config->isMappedTo("select", input)) && input.value) diff --git a/es-app/src/guis/GuiGamelistOptions.h b/es-app/src/guis/GuiGamelistOptions.h index 9a49aacd0..2ce685c9e 100644 --- a/es-app/src/guis/GuiGamelistOptions.h +++ b/es-app/src/guis/GuiGamelistOptions.h @@ -16,9 +16,13 @@ public: private: void openMetaDataEd(); - + void jumpToLetter(); + MenuComponent mMenu; + typedef OptionListComponent LetterList; + std::shared_ptr mJumpToLetterList; + typedef OptionListComponent SortList; std::shared_ptr mListSort;