From 94e32f198bfb902ea9ef4c2b24a500902884d410 Mon Sep 17 00:00:00 2001 From: Bim Date: Sun, 30 Jun 2013 19:24:09 +0200 Subject: [PATCH] Make sort order changeable via fast-select menu Use the left/right keys to switch it. --- src/FolderData.h | 3 ++- src/components/GuiFastSelect.cpp | 34 +++++++++++++++++++++----------- src/components/GuiFastSelect.h | 6 +++--- src/components/GuiGameList.cpp | 27 ++++++++++++++----------- src/components/GuiGameList.h | 1 + 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/FolderData.h b/src/FolderData.h index 6f47329c7..ecbd844fb 100644 --- a/src/FolderData.h +++ b/src/FolderData.h @@ -18,8 +18,9 @@ public: { ComparisonFunction & comparisonFunction; bool ascending; + std::string description; - SortState(ComparisonFunction & sortFunction, bool sortAscending) : comparisonFunction(sortFunction), ascending(sortAscending) {} + SortState(ComparisonFunction & sortFunction, bool sortAscending, const std::string & sortDescription) : comparisonFunction(sortFunction), ascending(sortAscending), description(sortDescription) {} }; private: diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index 008f4b972..fee1ba337 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -7,17 +7,15 @@ const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int GuiFastSelect::SCROLLSPEED = 100; const int GuiFastSelect::SCROLLDELAY = 507; -GuiFastSelect::GuiFastSelect(Window* window, GuiGameList* parent, TextListComponent* list, char startLetter, GuiBoxData data, - int textcolor, std::shared_ptr & scrollsound, Font* font) : GuiComponent(window) +GuiFastSelect::GuiFastSelect(Window* window, GuiGameList* parent, TextListComponent* list, char startLetter, ThemeComponent * theme) + : GuiComponent(window), mParent(parent), mList(list), mTheme(theme) { mLetterID = LETTERS.find(toupper(startLetter)); if(mLetterID == std::string::npos) mLetterID = 0; - mParent = parent; - mList = list; - mScrollSound = scrollsound; - mFont = font; + mScrollSound = mTheme->getSound("menuScroll"); + mTextColor = mTheme->getColor("fastSelect"); mScrolling = false; mScrollTimer = 0; @@ -25,9 +23,7 @@ GuiFastSelect::GuiFastSelect(Window* window, GuiGameList* parent, TextListCompon unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); mBox = new GuiBox(window, (int)(sw * 0.2f), (int)(sh * 0.2f), (int)(sw * 0.6f), (int)(sh * 0.6f)); - mBox->setData(data); - - mTextColor = textcolor; + mBox->setData(mTheme->getBoxData()); } GuiFastSelect::~GuiFastSelect() @@ -41,11 +37,14 @@ void GuiFastSelect::render() unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); if(!mBox->hasBackground()) - Renderer::drawRect((int)(sw * 0.2f), (int)(sh * 0.2f), (int)(sw * 0.6f), (int)(sh * 0.6f), 0x000FF0FF); + Renderer::drawRect((int)(sw * 0.3f), (int)(sh * 0.3f), (int)(sw * 0.4f), (int)(sh * 0.4f), 0x000FF0AA); mBox->render(); - Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, (int)(sh * 0.5f - (mFont->getHeight() * 0.5f)), mTextColor, mFont); + Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, (int)(sh * 0.5f - (mTheme->getFastSelectFont()->getHeight() * 0.5f)), mTextColor, mTheme->getFastSelectFont()); + Renderer::drawCenteredText("Sort order:", 0, (int)(sh * 0.6f - (mTheme->getDescriptionFont()->getHeight() * 0.5f)), mTextColor, mTheme->getDescriptionFont()); + std::string sortString = "<- " + mParent->getSortState().description + " ->"; + Renderer::drawCenteredText(sortString, 0, (int)(sh * 0.6f + (mTheme->getDescriptionFont()->getHeight() * 0.5f)), mTextColor, mTheme->getDescriptionFont()); } bool GuiFastSelect::input(InputConfig* config, Input input) @@ -64,6 +63,19 @@ bool GuiFastSelect::input(InputConfig* config, Input input) return true; } + if(config->isMappedTo("left", input) && input.value != 0) + { + mParent->setPreviousSortIndex(); + mScrollSound->play(); + return true; + } + else if(config->isMappedTo("right", input) && input.value != 0) + { + mParent->setNextSortIndex(); + mScrollSound->play(); + return true; + } + if((config->isMappedTo("up", input) || config->isMappedTo("down", input)) && input.value == 0) { mScrolling = false; diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h index 67032e1f1..81ae2ec4d 100644 --- a/src/components/GuiFastSelect.h +++ b/src/components/GuiFastSelect.h @@ -5,6 +5,7 @@ #include "../SystemData.h" #include "../FolderData.h" #include "../Sound.h" +#include "ThemeComponent.h" #include "TextListComponent.h" #include "GuiBox.h" @@ -13,8 +14,7 @@ class GuiGameList; class GuiFastSelect : public GuiComponent { public: - GuiFastSelect(Window* window, GuiGameList* parent, TextListComponent* list, char startLetter, GuiBoxData data, - int textcolor, std::shared_ptr & scrollsound, Font* font); + GuiFastSelect(Window* window, GuiGameList* parent, TextListComponent* list, char startLetter, ThemeComponent * theme); ~GuiFastSelect(); bool input(InputConfig* config, Input input); @@ -41,7 +41,7 @@ private: bool mScrolling; std::shared_ptr mScrollSound; - Font* mFont; + ThemeComponent * mTheme; }; #endif diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index c77775f46..e222de28e 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -21,16 +21,16 @@ GuiGameList::GuiGameList(Window* window, bool useDetail) : GuiComponent(window), { //first object initializes the vector if (sortStates.empty()) { - sortStates.push_back(FolderData::SortState(FolderData::compareFileName, true)); - sortStates.push_back(FolderData::SortState(FolderData::compareFileName, false)); - sortStates.push_back(FolderData::SortState(FolderData::compareRating, true)); - sortStates.push_back(FolderData::SortState(FolderData::compareRating, false)); - sortStates.push_back(FolderData::SortState(FolderData::compareUserRating, true)); - sortStates.push_back(FolderData::SortState(FolderData::compareUserRating, false)); - sortStates.push_back(FolderData::SortState(FolderData::compareTimesPlayed, true)); - sortStates.push_back(FolderData::SortState(FolderData::compareTimesPlayed, false)); - sortStates.push_back(FolderData::SortState(FolderData::compareLastPlayed, true)); - sortStates.push_back(FolderData::SortState(FolderData::compareLastPlayed, false)); + sortStates.push_back(FolderData::SortState(FolderData::compareFileName, true, "file name, ascending")); + sortStates.push_back(FolderData::SortState(FolderData::compareFileName, false, "file name, descending")); + sortStates.push_back(FolderData::SortState(FolderData::compareRating, true, "database rating, ascending")); + sortStates.push_back(FolderData::SortState(FolderData::compareRating, false, "database rating, descending")); + sortStates.push_back(FolderData::SortState(FolderData::compareUserRating, true, "your rating, ascending")); + sortStates.push_back(FolderData::SortState(FolderData::compareUserRating, false, "your rating, descending")); + sortStates.push_back(FolderData::SortState(FolderData::compareTimesPlayed, true, "played least often")); + sortStates.push_back(FolderData::SortState(FolderData::compareTimesPlayed, false, "played most often")); + sortStates.push_back(FolderData::SortState(FolderData::compareLastPlayed, true, "played least recently")); + sortStates.push_back(FolderData::SortState(FolderData::compareLastPlayed, false, "played most recently")); } mTheme = new ThemeComponent(mWindow, mDetailed); @@ -227,7 +227,7 @@ bool GuiGameList::input(InputConfig* config, Input input) //open the fast select menu if(config->isMappedTo("select", input) && input.value != 0) { - mWindow->pushGui(new GuiFastSelect(mWindow, this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getColor("fastSelect"), mTheme->getSound("menuScroll"), mTheme->getFastSelectFont())); + mWindow->pushGui(new GuiFastSelect(mWindow, this, mList, mList->getSelectedObject()->getName()[0], mTheme)); return true; } @@ -246,6 +246,11 @@ bool GuiGameList::input(InputConfig* config, Input input) return false; } +const FolderData::SortState & GuiGameList::getSortState() const +{ + return sortStates.at(sortStateIndex); +} + void GuiGameList::setSortIndex(size_t index) { //make the index valid diff --git a/src/components/GuiGameList.h b/src/components/GuiGameList.h index 2dae2f2ba..8d270510b 100644 --- a/src/components/GuiGameList.h +++ b/src/components/GuiGameList.h @@ -35,6 +35,7 @@ public: void updateDetailData(); + const FolderData::SortState & getSortState() const; void setSortIndex(size_t index); void setNextSortIndex(); void setPreviousSortIndex();