From 2c6bc918d6e818360afd522abe73c0c899bf1b7a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 5 Aug 2020 19:31:59 +0200 Subject: [PATCH] Scraping options not supported by TheGamesDB are now grayed out in the menu. This required some general logic to be added to disable GUI components, and this functionality could hopefully be useful elsewhere. --- es-app/src/guis/GuiScraperMenu.cpp | 51 +++++++++++++++++++- es-core/src/GuiComponent.cpp | 3 +- es-core/src/GuiComponent.h | 6 +++ es-core/src/components/OptionListComponent.h | 9 ++++ es-core/src/components/SwitchComponent.cpp | 14 ++++++ es-core/src/components/SwitchComponent.h | 4 ++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index 51c68ee15..223caa1e3 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -62,8 +62,18 @@ GuiScraperMenu::GuiScraperMenu(Window* window) : GuiComponent(window), } mMenu.addWithLabel("Systems", mSystems); - addEntry("CONTENT SETTINGS", 0x777777FF, true, [this] { openContentSettings(); }); - addEntry("OTHER SETTINGS", 0x777777FF, true, [this] { openOtherSettings(); }); + addEntry("CONTENT SETTINGS", 0x777777FF, true, [this] { + // Always save the settings when entering this menu, so the options that are + // not supported by TheGamesDB can be disabled. + mMenu.save(); + openContentSettings(); + }); + addEntry("OTHER SETTINGS", 0x777777FF, true, [this] { + // Always save the settings when entering this menu, so the options that are + // not supported by TheGamesDB can be disabled. + mMenu.save(); + openOtherSettings(); + }); addChild(&mMenu); @@ -109,6 +119,15 @@ void GuiScraperMenu::openContentSettings() s->addSaveFunc([scrape_ratings] { Settings::getInstance()->setBool("ScrapeRatings", scrape_ratings->getState()); }); + // 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->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 other metadata. auto scrape_metadata = std::make_shared(mWindow); scrape_metadata->setState(Settings::getInstance()->getBool("ScrapeMetadata")); @@ -144,6 +163,16 @@ void GuiScraperMenu::openContentSettings() s->addSaveFunc([scrape_3dboxes] { Settings::getInstance()->setBool("Scrape3DBoxes", scrape_3dboxes->getState()); }); + // 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->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); + } + mWindow->pushGui(s); } @@ -174,6 +203,15 @@ void GuiScraperMenu::openOtherSettings() Settings::getInstance()->setString("ScraperRegion", scraper_region->getSelected()); }); + // 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->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 language. auto scraper_language = std::make_shared> (mWindow, getHelpStyle(), "LANGUAGE", false); @@ -195,6 +233,15 @@ void GuiScraperMenu::openOtherSettings() Settings::getInstance()->setString("ScraperLanguage", scraper_language->getSelected()); }); + // 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->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); + } + // Overwrite files and data. auto scrape_overwrite = std::make_shared(mWindow); scrape_overwrite->setState(Settings::getInstance()->getBool("ScraperOverwriteData")); diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index d796bcb9f..14e9c501b 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -24,7 +24,8 @@ GuiComponent::GuiComponent(Window* window) mSize(Vector2f::Zero()), mTransform(Transform4x4f::Identity()), mIsProcessing(false), - mVisible(true) + mVisible(true), + mEnabled(true) { for (unsigned char i = 0; i < MAX_ANIMATIONS; i++) mAnimationMap[i] = nullptr; diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 71ad22ad5..bcc71a511 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -23,6 +23,7 @@ #define ICONCOLOR_USERMARKED 0x5555FFFF #define TEXTCOLOR_SCRAPERMARKED 0x992222FF #define TEXTCOLOR_USERMARKED 0x222299FF +#define DISABLED_OPACITY 80 class Animation; class AnimationController; @@ -144,6 +145,10 @@ public: virtual void setChangedColor(unsigned int color) { mColorChangedValue = color; }; virtual unsigned int getColor() const; + // 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; }; + const Transform4x4f& getTransform(); virtual std::string getValue() const; @@ -210,6 +215,7 @@ protected: bool mIsProcessing; bool mVisible; + bool mEnabled; private: // Don't access this directly! Use getTransform()! diff --git a/es-core/src/components/OptionListComponent.h b/es-core/src/components/OptionListComponent.h index 2249b9909..907ac4538 100644 --- a/es-core/src/components/OptionListComponent.h +++ b/es-core/src/components/OptionListComponent.h @@ -91,11 +91,17 @@ public: { if (input.value != 0) { if (config->isMappedTo("a", input)) { + // Ignore input if the component has been disabled. + if (!mEnabled) + return true; open(); return true; } if (!mMultiSelect) { if (config->isMappedLike("left", input)) { + // Ignore input if the component has been disabled. + if (!mEnabled) + return true; // Move selection to previous. unsigned int i = getSelectedId(); int next = (int)i - 1; @@ -109,6 +115,9 @@ public: } else if (config->isMappedLike("right", input)) { + // Ignore input if the component has been disabled. + if (!mEnabled) + return true; // Move selection to next. unsigned int i = getSelectedId(); int next = (i + 1) % mEntries.size(); diff --git a/es-core/src/components/SwitchComponent.cpp b/es-core/src/components/SwitchComponent.cpp index e923f1c11..79968d179 100644 --- a/es-core/src/components/SwitchComponent.cpp +++ b/es-core/src/components/SwitchComponent.cpp @@ -30,6 +30,10 @@ void SwitchComponent::onSizeChanged() bool SwitchComponent::input(InputConfig* config, Input input) { if (config->isMappedTo("a", input) && input.value) { + // Ignore input if the component has been disabled. + if (!mEnabled) + return true; + mState = !mState; onStateChanged(); return true; @@ -72,6 +76,16 @@ void SwitchComponent::setValue(const std::string& statestring) onStateChanged(); } +void SwitchComponent::setOpacity(unsigned char opacity) +{ + mImage.setOpacity(opacity); +} + +void SwitchComponent::setColorShift(unsigned int color) +{ + mImage.setColorShift(color); +} + void SwitchComponent::onStateChanged() { mImage.setImage(mState ? ":/graphics/on.svg" : ":/graphics/off.svg"); diff --git a/es-core/src/components/SwitchComponent.h b/es-core/src/components/SwitchComponent.h index dc977ac64..1e3f4c75b 100644 --- a/es-core/src/components/SwitchComponent.h +++ b/es-core/src/components/SwitchComponent.h @@ -29,6 +29,10 @@ public: void setOriginalColor(unsigned int color) override { mColorOriginalValue = color; }; void setChangedColor(unsigned int color) override { mColorChangedValue = color; }; + void setOpacity(unsigned char opacity) override; + // Multiply all pixels in the image by this color when rendering. + void setColorShift(unsigned int color) override; + virtual std::vector getHelpPrompts() override; private: