#include "guis/GuiScraperStart.h" #include "guis/GuiScraperMulti.h" #include "guis/GuiMsgBox.h" #include "views/ViewController.h" #include "components/TextComponent.h" #include "components/OptionListComponent.h" #include "components/SwitchComponent.h" GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), mMenu(window, "SCRAPE NOW") { addChild(&mMenu); // add filters (with first one selected) mFilters = std::make_shared< OptionListComponent >(mWindow, "SCRAPE THESE GAMES", false); mFilters->add("All Games", [](SystemData*, FileData*) -> bool { return true; }, false); mFilters->add("Only missing image", [](SystemData*, FileData* g) -> bool { return g->metadata.get("image").empty(); }, true); mMenu.addWithLabel("Filter", mFilters); //add systems (all with a platformid specified selected) mSystems = std::make_shared< OptionListComponent >(mWindow, "SCRAPE THESE SYSTEMS", true); for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++) { if(!(*it)->hasPlatformId(PlatformIds::PLATFORM_IGNORE)) mSystems->add((*it)->getFullName(), *it, !(*it)->getPlatformIds().empty()); } mMenu.addWithLabel("Systems", mSystems); mApproveResults = std::make_shared(mWindow); mApproveResults->setState(true); mMenu.addWithLabel("User decides on conflicts", mApproveResults); mMenu.addButton("START", "start", std::bind(&GuiScraperStart::pressedStart, this)); mMenu.addButton("BACK", "back", [&] { delete this; }); mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } void GuiScraperStart::pressedStart() { std::vector sys = mSystems->getSelectedObjects(); for(auto it = sys.begin(); it != sys.end(); it++) { if((*it)->getPlatformIds().empty()) { mWindow->pushGui(new GuiMsgBox(mWindow, strToUpper("Warning: some of your selected systems do not have a platform set. Results may be even more inaccurate than usual!\nContinue anyway?"), "YES", std::bind(&GuiScraperStart::start, this), "NO", nullptr)); return; } } start(); } void GuiScraperStart::start() { std::queue searches = getSearches(mSystems->getSelectedObjects(), mFilters->getSelected()); if(searches.empty()) { mWindow->pushGui(new GuiMsgBox(mWindow, "NO GAMES FIT THAT CRITERIA.")); }else{ GuiScraperMulti* gsm = new GuiScraperMulti(mWindow, searches, mApproveResults->getState()); mWindow->pushGui(gsm); delete this; } } std::queue GuiScraperStart::getSearches(std::vector systems, GameFilterFunc selector) { std::queue queue; for(auto sys = systems.begin(); sys != systems.end(); sys++) { std::vector games = (*sys)->getRootFolder()->getFilesRecursive(GAME); for(auto game = games.begin(); game != games.end(); game++) { if(selector((*sys), (*game))) { ScraperSearchParams search; search.game = *game; search.system = *sys; queue.push(search); } } } return queue; } bool GuiScraperStart::input(InputConfig* config, Input input) { bool consumed = GuiComponent::input(config, input); if(consumed) return true; if(input.value != 0 && config->isMappedTo("b", input)) { delete this; return true; } if(config->isMappedTo("start", input) && input.value != 0) { // close everything Window* window = mWindow; while(window->peekGui() && window->peekGui() != ViewController::get()) delete window->peekGui(); } return false; } std::vector GuiScraperStart::getHelpPrompts() { std::vector prompts = mMenu.getHelpPrompts(); prompts.push_back(HelpPrompt("b", "back")); prompts.push_back(HelpPrompt("start", "close")); return prompts; }