Improvements to the gamelist filter GUI.

This commit is contained in:
Leon Styhre 2021-09-25 10:54:53 +02:00
parent 3649684501
commit 78db6cd18c
2 changed files with 40 additions and 10 deletions

View file

@ -21,7 +21,7 @@ GuiGamelistFilter::GuiGamelistFilter(Window* window,
SystemData* system,
std::function<void(bool)> filterChangedCallback)
: GuiComponent(window)
, mMenu(window, "FILTER GAMELIST BY")
, mMenu(window, "FILTER GAMELIST")
, mSystem(system)
, mFiltersChangedCallback(filterChangedCallback)
, mFiltersChanged(false)
@ -92,8 +92,6 @@ void GuiGamelistFilter::resetAllFilters()
mFiltersChanged = true;
}
GuiGamelistFilter::~GuiGamelistFilter() { mFilterOptions.clear(); }
void GuiGamelistFilter::addFiltersToMenu()
{
ComponentListRow row;
@ -151,18 +149,49 @@ void GuiGamelistFilter::addFiltersToMenu()
it != decls.cend(); it++) {
FilterIndexType type = (*it).type; // Type of filter.
// All possible filters for this type.
std::map<std::string, int>* allKeys = (*it).allIndexKeys;
bool exclusiveSelect = false;
if (type == FAVORITES_FILTER || type == KIDGAME_FILTER || type == COMPLETED_FILTER ||
type == BROKEN_FILTER)
exclusiveSelect = true;
// Don't display the hidden games filter if we're actually hiding these games.
if (type == HIDDEN_FILTER) {
if (Settings::getInstance()->getBool("ShowHiddenGames"))
exclusiveSelect = true;
else
continue;
}
std::string menuLabel = (*it).menuLabel; // Text to show in menu.
std::shared_ptr<OptionListComponent<std::string>> optionList;
// Add genres.
optionList = std::make_shared<OptionListComponent<std::string>>(mWindow, getHelpStyle(),
menuLabel, true);
// For bool values, make the selection exclusive so that both True and False can't be
// selected at the same time. This should be changed to a SwitchComponent at some point.
if (exclusiveSelect)
optionList = std::make_shared<OptionListComponent<std::string>>(mWindow, getHelpStyle(),
menuLabel, true, true);
else
optionList = std::make_shared<OptionListComponent<std::string>>(mWindow, getHelpStyle(),
menuLabel, true, false);
// Still display fields that can't be filtered in the menu, but notify the user and set
// the OptionListComponent as disabled.
if (allKeys->size() == 1 || allKeys->empty()) {
optionList->setEnabled(false);
optionList->setOpacity(DISABLED_OPACITY);
optionList->setOverrideMultiText("NOTHING TO FILTER");
}
for (auto it : *allKeys)
optionList->add(it.first, it.first, mFilterIndex->isKeyBeingFilteredBy(it.first, type));
if (allKeys->size() > 0)
mMenu.addWithLabel(menuLabel, optionList);
if (allKeys->size() == 0)
optionList->add("", "", false);
mMenu.addWithLabel(menuLabel, optionList);
mFilterOptions[type] = optionList;
}

View file

@ -25,7 +25,8 @@ public:
SystemData* system,
std::function<void(bool)> filtersChangedCallback);
~GuiGamelistFilter();
~GuiGamelistFilter() { mFilterOptions.clear(); }
bool input(InputConfig* config, Input input) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;