From b4f5577bd5f10e1b7bceb9bbbac7f215b8b03d78 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 21 Mar 2014 13:07:17 -0500 Subject: [PATCH] Hooked up the "INPUT" button on scraper searches. --- src/components/ScraperSearchComponent.cpp | 24 +++++++++++++++++++++++ src/components/ScraperSearchComponent.h | 2 ++ src/guis/GuiGameScraper.cpp | 7 ++++++- src/guis/GuiScraperMulti.cpp | 5 ++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/components/ScraperSearchComponent.cpp b/src/components/ScraperSearchComponent.cpp index 06a485442..e7dcd0199 100644 --- a/src/components/ScraperSearchComponent.cpp +++ b/src/components/ScraperSearchComponent.cpp @@ -11,6 +11,7 @@ #include "../Settings.h" #include "../Log.h" #include "../Util.h" +#include "../guis/GuiTextEditPopup.h" ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type) : GuiComponent(window), mGrid(window, Eigen::Vector2i(4, 3)), @@ -161,6 +162,14 @@ void ScraperSearchComponent::search(const ScraperSearchParams& params) mSearchHandle = Settings::getInstance()->getScraper()->getResultsAsync(params); } +void ScraperSearchComponent::stop() +{ + mThumbnailReq.reset(); + mSearchHandle.reset(); + mMDResolveHandle.reset(); + mBlockAccept = false; +} + void ScraperSearchComponent::onSearchDone(const std::vector& results) { mResultList->clear(); @@ -365,6 +374,21 @@ void ScraperSearchComponent::updateThumbnail() mGrid.onSizeChanged(); // a hack to fix the thumbnail position since its size changed } +void ScraperSearchComponent::openInputScreen(ScraperSearchParams& params) +{ + auto searchForFunc = [&](const std::string& name) + { + params.nameOverride = name; + search(params); + }; + + stop(); + mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR", + // initial value is last search if there was one, otherwise the clean path name + params.nameOverride.empty() ? getCleanFileName(params.game->getPath()) : params.nameOverride, + searchForFunc, false, "SEARCH")); +} + std::vector ScraperSearchComponent::getHelpPrompts() { std::vector prompts = mGrid.getHelpPrompts(); diff --git a/src/components/ScraperSearchComponent.h b/src/components/ScraperSearchComponent.h index fa8f1cbf7..28dc49d27 100644 --- a/src/components/ScraperSearchComponent.h +++ b/src/components/ScraperSearchComponent.h @@ -29,6 +29,8 @@ public: ScraperSearchComponent(Window* window, SearchType searchType = NEVER_AUTO_ACCEPT); void search(const ScraperSearchParams& params); + void openInputScreen(ScraperSearchParams& from); + void stop(); // Metadata assets will be resolved before calling the accept callback (e.g. result.mdl's "image" is automatically downloaded and properly set). inline void setAcceptCallback(const std::function& acceptCallback) { mAcceptCallback = acceptCallback; } diff --git a/src/guis/GuiGameScraper.cpp b/src/guis/GuiGameScraper.cpp index 7d1f48af5..422e3dbd9 100644 --- a/src/guis/GuiGameScraper.cpp +++ b/src/guis/GuiGameScraper.cpp @@ -7,6 +7,7 @@ #include "../components/TextComponent.h" #include "../components/ButtonComponent.h" #include "../components/MenuComponent.h" +#include "GuiTextEditPopup.h" GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::function doneFunc) : GuiComponent(window), mGrid(window, Eigen::Vector2i(1, 3)), @@ -27,7 +28,11 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std:: // buttons std::vector< std::shared_ptr > buttons; - buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search")); + + buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search by name", [&] { + mSearch->openInputScreen(mSearchParams); + mGrid.resetCursor(); + })); buttons.push_back(std::make_shared(mWindow, "CANCEL", "cancel", [&] { delete this; })); mButtonGrid = makeButtonGrid(mWindow, buttons); diff --git a/src/guis/GuiScraperMulti.cpp b/src/guis/GuiScraperMulti.cpp index efa4d7d5b..96c766dc3 100644 --- a/src/guis/GuiScraperMulti.cpp +++ b/src/guis/GuiScraperMulti.cpp @@ -33,7 +33,10 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue > buttons; - buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search by name", nullptr)); + buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search by name", [&] { + mSearchComp->openInputScreen(mSearchQueue.front()); + mGrid.resetCursor(); + })); buttons.push_back(std::make_shared(mWindow, "SKIP", "skip this game", std::bind(&GuiScraperMulti::skip, this))); buttons.push_back(std::make_shared(mWindow, "STOP", "cancel scraping", std::bind(&GuiScraperMulti::finish, this))); mButtonGrid = makeButtonGrid(mWindow, buttons);