diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 764ef0b3f..95e7dddce 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -35,6 +35,26 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui curChar = startChar; mJumpToLetterList = std::make_shared(mWindow, "JUMP TO...", false); + + if(Settings::getInstance()->getBool("FavoritesFirst") && system->getName() != "favorites" && system->getName() != "recent") + { + // set firstFavorite to the numerical entry of the first favorite game in the list + // if no favorites are found set it to -1 + findFirstFavorite(); + + // if the currently selected game is a favorite, set curChar to 0 so we don't get two current positions + if(getGamelist()->getCursor()->getFavorite()) + curChar = 0; + + if (firstFavorite != -1) + { + if (getGamelist()->getCursor()->getFavorite()) + mJumpToLetterList->add(std::string(1, FAV_CHAR), FAV_CHAR, 1); + else + mJumpToLetterList->add(std::string(1, FAV_CHAR), FAV_CHAR, 0); + } + } + for (char c = startChar; c <= endChar; c++) { // check if c is a valid first letter in current list @@ -44,6 +64,10 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui char candidate = (char)toupper(file->getSortName()[0]); if (c == candidate) { + // if the game is a favorite, continue to the next entry in the list + if (firstFavorite != -1 && file->getFavorite()) + continue; + mJumpToLetterList->add(std::string(1, c), c, c == curChar); break; } @@ -54,7 +78,12 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui row.addElement(mJumpToLetterList, false); row.input_handler = [&](InputConfig* config, Input input) { if(config->isMappedTo("a", input) && input.value) - { + { + if(mJumpToLetterList->getSelected() == FAV_CHAR) + { + jumpToFirstFavorite(); + return true; + } jumpToLetter(); return true; } @@ -228,7 +257,16 @@ void GuiGamelistOptions::jumpToLetter() else if(checkLetter > letter || (mid > 0 && (letter == toupper(files.at(mid - 1)->getSortName()[0])))) max = mid - 1; else - break; //exact match found + { + // exact match found + // step through games to exclude favorites + if (firstFavorite != -1) + { + while(files[mid]->getFavorite()) + mid++; + } + break; + } } gamelist->setCursor(files.at(mid)); @@ -236,6 +274,42 @@ void GuiGamelistOptions::jumpToLetter() delete this; } +void GuiGamelistOptions::findFirstFavorite() +{ + IGameListView* gamelist = getGamelist(); + + // this is a really shitty way to get a list of files + const std::vector& files = gamelist->getCursor()->getParent()->getChildrenListToDisplay(); + + long loop = 0; + long max = (long)files.size() - 1; + + // Loop through the game list looking for the first game marked as a favorite + while (!files[loop]->getFavorite() and loop < max) + loop++; + + // if the last entry in the game list was not a favorite then there were none for this system + if (!files[loop]->getFavorite()) + { + firstFavorite = -1; + return; + } + + firstFavorite = loop; +} + +void GuiGamelistOptions::jumpToFirstFavorite() +{ + IGameListView* gamelist = getGamelist(); + + // this is a really shitty way to get a list of files + const std::vector& files = gamelist->getCursor()->getParent()->getChildrenListToDisplay(); + + gamelist->setCursor(files.at(firstFavorite)); + + 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 acf861669..0fc2ee735 100644 --- a/es-app/src/guis/GuiGamelistOptions.h +++ b/es-app/src/guis/GuiGamelistOptions.h @@ -2,6 +2,8 @@ #ifndef ES_APP_GUIS_GUI_GAME_LIST_OPTIONS_H #define ES_APP_GUIS_GUI_GAME_LIST_OPTIONS_H +#define FAV_CHAR '*' + #include "components/MenuComponent.h" #include "components/OptionListComponent.h" #include "FileData.h" @@ -26,6 +28,10 @@ private: void startEditMode(); void exitEditMode(); void jumpToLetter(); + void findFirstFavorite(); + void jumpToFirstFavorite(); + + long firstFavorite = -1; MenuComponent mMenu; diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 00de042df..e103ef6ab 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -526,11 +526,11 @@ void SystemView::renderCarousel(const Transform4x4f& trans) float distance = i - mCamOffset; - float scale = 1.0f + ((mCarousel.logoScale - 1.0f) * (1.0f - fabs(distance))); + float scale = 1.0f + ((mCarousel.logoScale - 1.0f) * (1.0f - abs(distance))); scale = Math::min(mCarousel.logoScale, Math::max(1.0f, scale)); scale /= mCarousel.logoScale; - int opacity = (int)Math::round(0x80 + ((0xFF - 0x80) * (1.0f - fabs(distance)))); + int opacity = (int)Math::round(0x80 + ((0xFF - 0x80) * (1.0f - abs(distance)))); opacity = Math::max((int) 0x80, opacity); const std::shared_ptr &comp = mEntries.at(index).data.logo;