mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Added the ability to filter on game names.
This commit is contained in:
parent
61998ac1a3
commit
cfad51fdb4
|
@ -47,7 +47,7 @@ https://google.github.io/styleguide/cppguide.html
|
||||||
* Name member variables starting with a small 'm', e.g. mMyMemberVariable
|
* Name member variables starting with a small 'm', e.g. mMyMemberVariable
|
||||||
* Use the same naming convention for functions as for local variables, e.g. someFunction()
|
* Use the same naming convention for functions as for local variables, e.g. someFunction()
|
||||||
* Inline functions makes perfect sense to use, but don't overdo it by using them for functions that won't be called very frequently
|
* Inline functions makes perfect sense to use, but don't overdo it by using them for functions that won't be called very frequently
|
||||||
* Never put more than one statement on a single line (there are some exceptions though like lambda expressions and some switch statements)
|
* Never put more than one statement on a single line (there are some exceptions though like lambda expressions and possibly switch statements)
|
||||||
* Avoid overoptimizations, especially if it sacrifices readability, makes the code hard to expand on or is error prone
|
* Avoid overoptimizations, especially if it sacrifices readability, makes the code hard to expand on or is error prone
|
||||||
* For the rest, check the code and have fun! :)
|
* For the rest, check the code and have fun! :)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@
|
||||||
#define INCLUDE_UNKNOWN false;
|
#define INCLUDE_UNKNOWN false;
|
||||||
|
|
||||||
FileFilterIndex::FileFilterIndex()
|
FileFilterIndex::FileFilterIndex()
|
||||||
: filterByFavorites(false),
|
: mFilterByText(false),
|
||||||
|
filterByFavorites(false),
|
||||||
filterByGenre(false),
|
filterByGenre(false),
|
||||||
filterByPlayers(false),
|
filterByPlayers(false),
|
||||||
filterByPubDev(false),
|
filterByPubDev(false),
|
||||||
|
@ -269,6 +270,16 @@ void FileFilterIndex::setFilter(FilterIndexType type, std::vector<std::string>*
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileFilterIndex::setTextFilter(std::string textFilter)
|
||||||
|
{
|
||||||
|
mTextFilter = textFilter;
|
||||||
|
|
||||||
|
if (textFilter == "")
|
||||||
|
mFilterByText = false;
|
||||||
|
else
|
||||||
|
mFilterByText = true;
|
||||||
|
};
|
||||||
|
|
||||||
void FileFilterIndex::clearAllFilters()
|
void FileFilterIndex::clearAllFilters()
|
||||||
{
|
{
|
||||||
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
||||||
|
@ -353,8 +364,19 @@ bool FileFilterIndex::showFile(FileData* game)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nameMatch = false;
|
||||||
bool keepGoing = false;
|
bool keepGoing = false;
|
||||||
|
|
||||||
|
// Name filters take precedence over all other filters, so if there is no match for
|
||||||
|
// the game name, then always return false.
|
||||||
|
if (mTextFilter != "" && !(Utils::String::toUpper(game->
|
||||||
|
getName()).find(mTextFilter) != std::string::npos)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (mTextFilter != "") {
|
||||||
|
nameMatch = true;
|
||||||
|
}
|
||||||
|
|
||||||
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
for (std::vector<FilterDataDecl>::const_iterator it = filterDataDecl.cbegin();
|
||||||
it != filterDataDecl.cend(); ++it ) {
|
it != filterDataDecl.cend(); ++it ) {
|
||||||
FilterDataDecl filterData = (*it);
|
FilterDataDecl filterData = (*it);
|
||||||
|
@ -377,7 +399,13 @@ bool FileFilterIndex::showFile(FileData* game)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keepGoing;
|
|
||||||
|
// If there is a match for the game name, but not for any other filters, then return
|
||||||
|
// true as it means that the name filter is the only applied filter.
|
||||||
|
if (!keepGoing && nameMatch)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return keepGoing;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
|
bool FileFilterIndex::isKeyBeingFilteredBy(std::string key, FilterIndexType type)
|
||||||
|
|
|
@ -50,12 +50,14 @@ public:
|
||||||
void addToIndex(FileData* game);
|
void addToIndex(FileData* game);
|
||||||
void removeFromIndex(FileData* game);
|
void removeFromIndex(FileData* game);
|
||||||
void setFilter(FilterIndexType type, std::vector<std::string>* values);
|
void setFilter(FilterIndexType type, std::vector<std::string>* values);
|
||||||
|
void setTextFilter(std::string textFilter);
|
||||||
|
std::string getTextFilter() { return mTextFilter; };
|
||||||
void clearAllFilters();
|
void clearAllFilters();
|
||||||
void debugPrintIndexes();
|
void debugPrintIndexes();
|
||||||
bool showFile(FileData* game);
|
bool showFile(FileData* game);
|
||||||
bool isFiltered() { return (filterByFavorites || filterByGenre || filterByPlayers ||
|
bool isFiltered() { return (mFilterByText || filterByFavorites || filterByGenre ||
|
||||||
filterByPubDev || filterByRatings || filterByKidGame || filterByCompleted ||
|
filterByPlayers || filterByPubDev || filterByRatings || filterByKidGame ||
|
||||||
filterByBroken || filterByHidden ); };
|
filterByCompleted || filterByBroken || filterByHidden ); };
|
||||||
bool isKeyBeingFilteredBy(std::string key, FilterIndexType type);
|
bool isKeyBeingFilteredBy(std::string key, FilterIndexType type);
|
||||||
std::vector<FilterDataDecl>& getFilterDataDecls();
|
std::vector<FilterDataDecl>& getFilterDataDecls();
|
||||||
|
|
||||||
|
@ -82,6 +84,9 @@ private:
|
||||||
|
|
||||||
void clearIndex(std::map<std::string, int> indexMap);
|
void clearIndex(std::map<std::string, int> indexMap);
|
||||||
|
|
||||||
|
std::string mTextFilter;
|
||||||
|
bool mFilterByText;
|
||||||
|
|
||||||
bool filterByFavorites;
|
bool filterByFavorites;
|
||||||
bool filterByGenre;
|
bool filterByGenre;
|
||||||
bool filterByPlayers;
|
bool filterByPlayers;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "guis/GuiGamelistFilter.h"
|
#include "guis/GuiGamelistFilter.h"
|
||||||
|
|
||||||
#include "components/OptionListComponent.h"
|
#include "components/OptionListComponent.h"
|
||||||
|
#include "guis/GuiTextEditPopup.h"
|
||||||
#include "views/UIModeController.h"
|
#include "views/UIModeController.h"
|
||||||
#include "views/ViewController.h"
|
#include "views/ViewController.h"
|
||||||
#include "SystemData.h"
|
#include "SystemData.h"
|
||||||
|
@ -73,11 +74,15 @@ void GuiGamelistFilter::resetAllFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
mFilterIndex->resetFilters();
|
mFilterIndex->resetFilters();
|
||||||
for (std::map<FilterIndexType, std::shared_ptr< OptionListComponent<std::string>
|
for (std::map<FilterIndexType, std::shared_ptr< OptionListComponent<std::string>>>::
|
||||||
>>::const_iterator it = mFilterOptions.cbegin(); it != mFilterOptions.cend(); ++it ) {
|
const_iterator it = mFilterOptions.cbegin(); it != mFilterOptions.cend(); ++it ) {
|
||||||
std::shared_ptr< OptionListComponent<std::string> > optionList = it->second;
|
std::shared_ptr<OptionListComponent<std::string>> optionList = it->second;
|
||||||
optionList->selectNone();
|
optionList->selectNone();
|
||||||
}
|
}
|
||||||
|
bool testbool = mFilterIndex->isFiltered();
|
||||||
|
|
||||||
|
mFilterIndex->setTextFilter("");
|
||||||
|
mTextFilterField->setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiGamelistFilter::~GuiGamelistFilter()
|
GuiGamelistFilter::~GuiGamelistFilter()
|
||||||
|
@ -87,6 +92,43 @@ GuiGamelistFilter::~GuiGamelistFilter()
|
||||||
|
|
||||||
void GuiGamelistFilter::addFiltersToMenu()
|
void GuiGamelistFilter::addFiltersToMenu()
|
||||||
{
|
{
|
||||||
|
ComponentListRow row;
|
||||||
|
|
||||||
|
auto lbl = std::make_shared<TextComponent>(mWindow,
|
||||||
|
Utils::String::toUpper("TEXT FILTER (GAME NAME)"),
|
||||||
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
|
||||||
|
|
||||||
|
mTextFilterField = std::make_shared<TextComponent>(mWindow, "",
|
||||||
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_RIGHT);
|
||||||
|
|
||||||
|
row.addElement(lbl, true);
|
||||||
|
row.addElement(mTextFilterField, true);
|
||||||
|
|
||||||
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
||||||
|
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
|
||||||
|
row.addElement(spacer, false);
|
||||||
|
|
||||||
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
||||||
|
bracket->setImage(":/graphics/arrow.svg");
|
||||||
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
||||||
|
row.addElement(bracket, false);
|
||||||
|
|
||||||
|
mTextFilterField->setValue(mFilterIndex->getTextFilter());
|
||||||
|
|
||||||
|
// Callback function.
|
||||||
|
auto updateVal = [this](const std::string& newVal) {
|
||||||
|
mTextFilterField->setValue(Utils::String::toUpper(newVal));
|
||||||
|
mFilterIndex->setTextFilter(Utils::String::toUpper(newVal));
|
||||||
|
};
|
||||||
|
|
||||||
|
row.makeAcceptInputHandler([this, updateVal] {
|
||||||
|
mWindow->pushGui(new GuiTextEditPopup(mWindow, getHelpStyle(),
|
||||||
|
"TEXT FILTER (GAME NAME)", mTextFilterField->getValue(),
|
||||||
|
updateVal, false, "OK", "APPLY CHANGES?"));
|
||||||
|
});
|
||||||
|
|
||||||
|
mMenu.addRow(row);
|
||||||
|
|
||||||
std::vector<FilterDataDecl> decls = mFilterIndex->getFilterDataDecls();
|
std::vector<FilterDataDecl> decls = mFilterIndex->getFilterDataDecls();
|
||||||
|
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
@ -108,7 +150,7 @@ void GuiGamelistFilter::addFiltersToMenu()
|
||||||
ComponentListRow row;
|
ComponentListRow row;
|
||||||
|
|
||||||
// Add genres.
|
// Add genres.
|
||||||
optionList = std::make_shared< OptionListComponent<std::string>>
|
optionList = std::make_shared<OptionListComponent<std::string>>
|
||||||
(mWindow, getHelpStyle(), menuLabel, true);
|
(mWindow, getHelpStyle(), menuLabel, true);
|
||||||
for (auto it: *allKeys)
|
for (auto it: *allKeys)
|
||||||
optionList->add(it.first, it.first, mFilterIndex->isKeyBeingFilteredBy(it.first, type));
|
optionList->add(it.first, it.first, mFilterIndex->isKeyBeingFilteredBy(it.first, type));
|
||||||
|
|
|
@ -41,6 +41,7 @@ private:
|
||||||
MenuComponent mMenu;
|
MenuComponent mMenu;
|
||||||
SystemData* mSystem;
|
SystemData* mSystem;
|
||||||
FileFilterIndex* mFilterIndex;
|
FileFilterIndex* mFilterIndex;
|
||||||
|
std::shared_ptr<TextComponent> mTextFilterField;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_APP_GUIS_GUI_GAME_LIST_FILTER_H
|
#endif // ES_APP_GUIS_GUI_GAME_LIST_FILTER_H
|
||||||
|
|
Loading…
Reference in a new issue