Added support for graying out menu entries via switch callbacks.

This commit is contained in:
Leon Styhre 2020-12-15 18:49:43 +01:00
parent ed77c7a9aa
commit 98d99ef8bb
7 changed files with 97 additions and 27 deletions

View file

@ -201,11 +201,10 @@ void GuiScraperMenu::openContentSettings()
// Ratings are not supported by TheGamesDB, so disable the option if this scraper is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scrape_ratings->setDisabled();
scrape_ratings->setEnabled(false);
scrape_ratings->setOpacity(DISABLED_OPACITY);
// I'm sure there is a better way to find the text component...
scrape_ratings->getParent()->getChild(
scrape_ratings->getParent()->getChildCount()-2)->setOpacity(DISABLED_OPACITY);
scrape_ratings->getParent()->getChild(scrape_ratings->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Scrape other metadata.
@ -232,11 +231,10 @@ void GuiScraperMenu::openContentSettings()
// Videos are not supported by TheGamesDB, so disable the option if this scraper is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scrape_videos->setDisabled();
scrape_videos->setEnabled(false);
scrape_videos->setOpacity(DISABLED_OPACITY);
// I'm sure there is a better way to find the text component...
scrape_videos->getParent()->getChild(
scrape_videos->getParent()->getChildCount()-2)->setOpacity(DISABLED_OPACITY);
scrape_videos->getParent()->getChild(scrape_videos->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Scrape screenshots images.
@ -287,11 +285,10 @@ void GuiScraperMenu::openContentSettings()
// 3D box images are not supported by TheGamesDB, so disable the option if this scraper
// is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scrape_3dboxes->setDisabled();
scrape_3dboxes->setEnabled(false);
scrape_3dboxes->setOpacity(DISABLED_OPACITY);
// I'm sure there is a better way to find the text component...
scrape_3dboxes->getParent()->getChild(
scrape_3dboxes->getParent()->getChildCount()-2)->setOpacity(DISABLED_OPACITY);
scrape_3dboxes->getParent()->getChild(scrape_3dboxes->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
mWindow->pushGui(s);
@ -328,11 +325,10 @@ void GuiScraperMenu::openOtherSettings()
// Regions are not supported by TheGamesDB, so disable the option if this scraper is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scraper_region->setDisabled();
scraper_region->setEnabled(false);
scraper_region->setOpacity(DISABLED_OPACITY);
// I'm sure there is a better way to find the text component...
scraper_region->getParent()->getChild(
scraper_region->getParent()->getChildCount()-2)->setOpacity(DISABLED_OPACITY);
scraper_region->getParent()->getChild(scraper_region->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Scraper language.
@ -361,11 +357,10 @@ void GuiScraperMenu::openOtherSettings()
// Languages are not supported by TheGamesDB, so disable the option if this scraper is selected.
if (Settings::getInstance()->getString("Scraper") == "thegamesdb") {
scraper_language->setDisabled();
scraper_language->setEnabled(false);
scraper_language->setOpacity(DISABLED_OPACITY);
// I'm sure there is a better way to find the text component...
scraper_language->getParent()->getChild(
scraper_language->getParent()->getChildCount()-2)->setOpacity(DISABLED_OPACITY);
scraper_language->getParent()->getChild(scraper_language->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Overwrite files and data.
@ -420,6 +415,15 @@ void GuiScraperMenu::openOtherSettings()
}
});
// If interactive mode is set to off, then disable this option.
if (!Settings::getInstance()->getBool("ScraperInteractive")) {
scraper_semiautomatic->setEnabled(false);
scraper_semiautomatic->setOpacity(DISABLED_OPACITY);
scraper_semiautomatic->getParent()->getChild(scraper_semiautomatic->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Respect the per-file multi-scraper exclusion flag.
auto scraper_respect_exclusions = std::make_shared<SwitchComponent>(mWindow);
scraper_respect_exclusions->setState(
@ -448,6 +452,14 @@ void GuiScraperMenu::openOtherSettings()
}
});
// If respecting excluded files is set to off, then disable this option.
if (!Settings::getInstance()->getBool("ScraperRespectExclusions")) {
scraper_exclude_recursively->setEnabled(false);
scraper_exclude_recursively->setOpacity(DISABLED_OPACITY);
scraper_exclude_recursively->getParent()->getChild(scraper_exclude_recursively->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
// Include actual folders when scraping.
auto scraper_include_folders = std::make_shared<SwitchComponent>(mWindow);
scraper_include_folders->setState(
@ -462,6 +474,40 @@ void GuiScraperMenu::openOtherSettings()
}
});
// Switch callbacks.
auto interactiveToggleFunc = [scraper_semiautomatic]() {
if (scraper_semiautomatic->getEnabled()) {
scraper_semiautomatic->setEnabled(false);
scraper_semiautomatic->setOpacity(DISABLED_OPACITY);
scraper_semiautomatic->getParent()->getChild(scraper_semiautomatic->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
else {
scraper_semiautomatic->setEnabled(true);
scraper_semiautomatic->setOpacity(255);
scraper_semiautomatic->getParent()->getChild(scraper_semiautomatic->
getChildIndex() - 1)->setOpacity(255);
}
};
auto excludeRecursivelyToggleFunc = [scraper_exclude_recursively]() {
if (scraper_exclude_recursively->getEnabled()) {
scraper_exclude_recursively->setEnabled(false);
scraper_exclude_recursively->setOpacity(DISABLED_OPACITY);
scraper_exclude_recursively->getParent()->getChild(scraper_exclude_recursively->
getChildIndex() - 1)->setOpacity(DISABLED_OPACITY);
}
else {
scraper_exclude_recursively->setEnabled(true);
scraper_exclude_recursively->setOpacity(255);
scraper_exclude_recursively->getParent()->getChild(scraper_exclude_recursively->
getChildIndex() - 1)->setOpacity(255);
}
};
scraper_interactive->setCallback(interactiveToggleFunc);
scraper_respect_exclusions->setCallback(excludeRecursivelyToggleFunc);
mWindow->pushGui(s);
}

View file

@ -239,6 +239,17 @@ unsigned int GuiComponent::getChildCount() const
return static_cast<int>(mChildren.size());
}
int GuiComponent::getChildIndex() const
{
std::vector<GuiComponent*>::iterator it =
std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this);
if (it != getParent()->mChildren.end())
return std::distance(getParent()->mChildren.begin(), it);
else
return -1;
}
GuiComponent* GuiComponent::getChild(unsigned int i) const
{
return mChildren.at(i);

View file

@ -120,6 +120,7 @@ public:
void clearChildren();
void sortChildren();
unsigned int getChildCount() const;
int getChildIndex() const;
GuiComponent* getChild(unsigned int i) const;
// Animation will be automatically deleted when it completes or is stopped.
@ -155,8 +156,8 @@ public:
virtual void setChangedColor(unsigned int color) { mColorChangedValue = color; };
// These functions are used to enable and disable options in menus, i.e. switches and similar.
virtual void setEnabled() { mEnabled = true; };
virtual void setDisabled() { mEnabled = false; };
virtual bool getEnabled() { return mEnabled; };
virtual void setEnabled(bool state) { mEnabled = state; };
const Transform4x4f& getTransform();

View file

@ -73,9 +73,9 @@ void ButtonComponent::onFocusLost()
updateImage();
}
void ButtonComponent::setEnabled(bool enabled)
void ButtonComponent::setEnabled(bool state)
{
mEnabled = enabled;
mEnabled = state;
updateImage();
}

View file

@ -21,7 +21,7 @@ public:
const std::string& helpText = "", const std::function<void()>& func = nullptr);
void setPressedFunc(std::function<void()> f);
void setEnabled(bool enable);
void setEnabled(bool state) override;
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;

View file

@ -3,7 +3,7 @@
// EmulationStation Desktop Edition
// SwitchComponent.cpp
//
// Basic switch used in the menus.
// Basic on/off switch used in menus.
//
#include "SwitchComponent.h"
@ -39,6 +39,10 @@ bool SwitchComponent::input(InputConfig* config, Input input)
mState = !mState;
onStateChanged();
if (mToggleCallback)
mToggleCallback();
return true;
}
@ -79,6 +83,11 @@ void SwitchComponent::setValue(const std::string& statestring)
onStateChanged();
}
unsigned char SwitchComponent::getOpacity() const
{
return mImage.getOpacity();
}
void SwitchComponent::setOpacity(unsigned char opacity)
{
mImage.setOpacity(opacity);

View file

@ -3,7 +3,7 @@
// EmulationStation Desktop Edition
// SwitchComponent.h
//
// Basic switch used in the menus.
// Basic on/off switch used in menus.
//
#ifndef ES_CORE_COMPONENTS_SWITCH_COMPONENT_H
@ -29,7 +29,9 @@ public:
void setOriginalColor(unsigned int color) override { mColorOriginalValue = color; };
void setChangedColor(unsigned int color) override { mColorChangedValue = color; };
void setCallback(const std::function<void()>& callbackFunc) { mToggleCallback = callbackFunc; };
unsigned char getOpacity() const override;
void setOpacity(unsigned char opacity) override;
// Multiply all pixels in the image by this color when rendering.
void setColorShift(unsigned int color) override;
@ -46,6 +48,7 @@ private:
bool mOriginalValue;
unsigned int mColorOriginalValue;
unsigned int mColorChangedValue;
std::function<void()> mToggleCallback;
};
#endif // ES_CORE_COMPONENTS_SWITCH_COMPONENT_H