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, SystemData* system,
std::function<void(bool)> filterChangedCallback) std::function<void(bool)> filterChangedCallback)
: GuiComponent(window) : GuiComponent(window)
, mMenu(window, "FILTER GAMELIST BY") , mMenu(window, "FILTER GAMELIST")
, mSystem(system) , mSystem(system)
, mFiltersChangedCallback(filterChangedCallback) , mFiltersChangedCallback(filterChangedCallback)
, mFiltersChanged(false) , mFiltersChanged(false)
@ -92,8 +92,6 @@ void GuiGamelistFilter::resetAllFilters()
mFiltersChanged = true; mFiltersChanged = true;
} }
GuiGamelistFilter::~GuiGamelistFilter() { mFilterOptions.clear(); }
void GuiGamelistFilter::addFiltersToMenu() void GuiGamelistFilter::addFiltersToMenu()
{ {
ComponentListRow row; ComponentListRow row;
@ -151,17 +149,48 @@ void GuiGamelistFilter::addFiltersToMenu()
it != decls.cend(); it++) { it != decls.cend(); it++) {
FilterIndexType type = (*it).type; // Type of filter. FilterIndexType type = (*it).type; // Type of filter.
// All possible filters for this type.
std::map<std::string, int>* allKeys = (*it).allIndexKeys; 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::string menuLabel = (*it).menuLabel; // Text to show in menu.
std::shared_ptr<OptionListComponent<std::string>> optionList; std::shared_ptr<OptionListComponent<std::string>> optionList;
// Add genres. // 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(), optionList = std::make_shared<OptionListComponent<std::string>>(mWindow, getHelpStyle(),
menuLabel, true); 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) 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));
if (allKeys->size() > 0)
if (allKeys->size() == 0)
optionList->add("", "", false);
mMenu.addWithLabel(menuLabel, optionList); mMenu.addWithLabel(menuLabel, optionList);
mFilterOptions[type] = optionList; mFilterOptions[type] = optionList;

View file

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