mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Filters are now applied only when there were actual changes made.
Also disabled the free text filter entry if the system has no games.
This commit is contained in:
parent
60ee29f2ea
commit
3e9e592c3b
|
@ -18,10 +18,13 @@
|
||||||
|
|
||||||
GuiGamelistFilter::GuiGamelistFilter(
|
GuiGamelistFilter::GuiGamelistFilter(
|
||||||
Window* window,
|
Window* window,
|
||||||
SystemData* system)
|
SystemData* system,
|
||||||
|
std::function<void(bool)> filterChangedCallback)
|
||||||
: GuiComponent(window),
|
: GuiComponent(window),
|
||||||
mMenu(window, "FILTER GAMELIST BY"),
|
mMenu(window, "FILTER GAMELIST BY"),
|
||||||
mSystem(system)
|
mSystem(system),
|
||||||
|
mFiltersChangedCallback(filterChangedCallback),
|
||||||
|
mFiltersChanged(false)
|
||||||
{
|
{
|
||||||
initializeMenu();
|
initializeMenu();
|
||||||
}
|
}
|
||||||
|
@ -49,6 +52,16 @@ void GuiGamelistFilter::initializeMenu()
|
||||||
|
|
||||||
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2,
|
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2,
|
||||||
Renderer::getScreenHeight() * 0.15f);
|
Renderer::getScreenHeight() * 0.15f);
|
||||||
|
|
||||||
|
// Save the initial filter values to be able to check later if any changes were made.
|
||||||
|
mInitialTextFilter = mTextFilterField->getValue();
|
||||||
|
|
||||||
|
for (std::map<FilterIndexType, std::shared_ptr<OptionListComponent<std::string>>>::
|
||||||
|
const_iterator it = mFilterOptions.cbegin(); it != mFilterOptions.cend(); it++) {
|
||||||
|
std::shared_ptr<OptionListComponent<std::string>> optionList = it->second;
|
||||||
|
std::vector<std::string> filters = optionList->getSelectedObjects();
|
||||||
|
mInitialFilters.push_back(filters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGamelistFilter::resetAllFilters()
|
void GuiGamelistFilter::resetAllFilters()
|
||||||
|
@ -62,6 +75,7 @@ void GuiGamelistFilter::resetAllFilters()
|
||||||
|
|
||||||
mFilterIndex->setTextFilter("");
|
mFilterIndex->setTextFilter("");
|
||||||
mTextFilterField->setValue("");
|
mTextFilterField->setValue("");
|
||||||
|
mFiltersChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiGamelistFilter::~GuiGamelistFilter()
|
GuiGamelistFilter::~GuiGamelistFilter()
|
||||||
|
@ -80,19 +94,22 @@ void GuiGamelistFilter::addFiltersToMenu()
|
||||||
mTextFilterField = std::make_shared<TextComponent>(mWindow, "",
|
mTextFilterField = std::make_shared<TextComponent>(mWindow, "",
|
||||||
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_RIGHT);
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_RIGHT);
|
||||||
|
|
||||||
row.addElement(lbl, true);
|
// Don't show the free text filter entry unless there are any games in the system.
|
||||||
row.addElement(mTextFilterField, true);
|
if (mSystem->getRootFolder()->getChildren().size() > 0) {
|
||||||
|
row.addElement(lbl, true);
|
||||||
|
row.addElement(mTextFilterField, true);
|
||||||
|
|
||||||
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
auto spacer = std::make_shared<GuiComponent>(mWindow);
|
||||||
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
|
spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0);
|
||||||
row.addElement(spacer, false);
|
row.addElement(spacer, false);
|
||||||
|
|
||||||
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
auto bracket = std::make_shared<ImageComponent>(mWindow);
|
||||||
bracket->setImage(":/graphics/arrow.svg");
|
bracket->setImage(":/graphics/arrow.svg");
|
||||||
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
bracket->setResize(Vector2f(0, lbl->getFont()->getLetterHeight()));
|
||||||
row.addElement(bracket, false);
|
row.addElement(bracket, false);
|
||||||
|
|
||||||
mTextFilterField->setValue(mFilterIndex->getTextFilter());
|
mTextFilterField->setValue(mFilterIndex->getTextFilter());
|
||||||
|
}
|
||||||
|
|
||||||
// Callback function.
|
// Callback function.
|
||||||
auto updateVal = [this](const std::string& newVal) {
|
auto updateVal = [this](const std::string& newVal) {
|
||||||
|
@ -136,14 +153,21 @@ void GuiGamelistFilter::addFiltersToMenu()
|
||||||
|
|
||||||
void GuiGamelistFilter::applyFilters()
|
void GuiGamelistFilter::applyFilters()
|
||||||
{
|
{
|
||||||
|
if (mInitialTextFilter != mTextFilterField->getValue())
|
||||||
|
mFiltersChanged = true;
|
||||||
|
|
||||||
std::vector<FilterDataDecl> decls = mFilterIndex->getFilterDataDecls();
|
std::vector<FilterDataDecl> decls = mFilterIndex->getFilterDataDecls();
|
||||||
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;
|
||||||
std::vector<std::string> filters = optionList->getSelectedObjects();
|
std::vector<std::string> filters = optionList->getSelectedObjects();
|
||||||
|
auto iteratorDistance = std::distance(mFilterOptions.cbegin(), it);
|
||||||
|
if (mInitialFilters[iteratorDistance] != filters)
|
||||||
|
mFiltersChanged = true;
|
||||||
mFilterIndex->setFilter(it->first, &filters);
|
mFilterIndex->setFilter(it->first, &filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mFiltersChangedCallback(mFiltersChanged);
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ class SystemData;
|
||||||
class GuiGamelistFilter : public GuiComponent
|
class GuiGamelistFilter : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiGamelistFilter(Window* window, SystemData* system);
|
GuiGamelistFilter(Window* window,
|
||||||
|
SystemData* system, std::function<void(bool)> filtersChangedCallback);
|
||||||
|
|
||||||
~GuiGamelistFilter();
|
~GuiGamelistFilter();
|
||||||
bool input(InputConfig* config, Input input) override;
|
bool input(InputConfig* config, Input input) override;
|
||||||
|
@ -37,11 +38,15 @@ private:
|
||||||
void addFiltersToMenu();
|
void addFiltersToMenu();
|
||||||
|
|
||||||
std::map<FilterIndexType, std::shared_ptr<OptionListComponent<std::string>>> mFilterOptions;
|
std::map<FilterIndexType, std::shared_ptr<OptionListComponent<std::string>>> mFilterOptions;
|
||||||
|
std::vector<std::vector<std::string>> mInitialFilters;
|
||||||
|
std::string mInitialTextFilter;
|
||||||
|
|
||||||
MenuComponent mMenu;
|
MenuComponent mMenu;
|
||||||
SystemData* mSystem;
|
SystemData* mSystem;
|
||||||
FileFilterIndex* mFilterIndex;
|
FileFilterIndex* mFilterIndex;
|
||||||
std::shared_ptr<TextComponent> mTextFilterField;
|
std::shared_ptr<TextComponent> mTextFilterField;
|
||||||
|
std::function<void(bool)> mFiltersChangedCallback;
|
||||||
|
bool mFiltersChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_APP_GUIS_GUI_GAME_LIST_FILTER_H
|
#endif // ES_APP_GUIS_GUI_GAME_LIST_FILTER_H
|
||||||
|
|
|
@ -277,12 +277,16 @@ GuiGamelistOptions::~GuiGamelistOptions()
|
||||||
void GuiGamelistOptions::openGamelistFilter()
|
void GuiGamelistOptions::openGamelistFilter()
|
||||||
{
|
{
|
||||||
GuiGamelistFilter* ggf;
|
GuiGamelistFilter* ggf;
|
||||||
mFiltersChanged = true;
|
|
||||||
|
auto filtersChangedFunc = [this](bool filtersChanged) {
|
||||||
|
mFiltersChanged = filtersChanged;
|
||||||
|
};
|
||||||
|
|
||||||
if (mIsCustomCollection)
|
if (mIsCustomCollection)
|
||||||
ggf = new GuiGamelistFilter(mWindow, getGamelist()->getCursor()->getSystem());
|
ggf = new GuiGamelistFilter(mWindow, getGamelist()->getCursor()->getSystem(),
|
||||||
|
filtersChangedFunc);
|
||||||
else
|
else
|
||||||
ggf = new GuiGamelistFilter(mWindow, mSystem);
|
ggf = new GuiGamelistFilter(mWindow, mSystem, filtersChangedFunc);
|
||||||
|
|
||||||
mWindow->pushGui(ggf);
|
mWindow->pushGui(ggf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue