Hooked up the "INPUT" button on scraper searches.

This commit is contained in:
Aloshi 2014-03-21 13:07:17 -05:00
parent 9fe7ceeb72
commit b4f5577bd5
4 changed files with 36 additions and 2 deletions

View file

@ -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<ScraperSearchResult>& 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<HelpPrompt> ScraperSearchComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();

View file

@ -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<void(const ScraperSearchResult&)>& acceptCallback) { mAcceptCallback = acceptCallback; }

View file

@ -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<void(const ScraperSearchResult&)> 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<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search"));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search by name", [&] {
mSearch->openInputScreen(mSearchParams);
mGrid.resetCursor();
}));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { delete this; }));
mButtonGrid = makeButtonGrid(mWindow, buttons);

View file

@ -33,7 +33,10 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP
mGrid.setEntry(mSearchComp, Vector2i(0, 2), approveResults, true);
std::vector< std::shared_ptr<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search by name", nullptr));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search by name", [&] {
mSearchComp->openInputScreen(mSearchQueue.front());
mGrid.resetCursor();
}));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip this game", std::bind(&GuiScraperMulti::skip, this)));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP", "cancel scraping", std::bind(&GuiScraperMulti::finish, this)));
mButtonGrid = makeButtonGrid(mWindow, buttons);