From b2165dd17b09e79115540a3200a1f708bff6e723 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 8 Mar 2014 12:19:21 -0600 Subject: [PATCH] Redid scraper start menu. --- src/components/MenuComponent.h | 8 ++++ src/guis/GuiScraperStart.cpp | 69 ++++++++++++++-------------------- src/guis/GuiScraperStart.h | 26 +++++-------- 3 files changed, 46 insertions(+), 57 deletions(-) diff --git a/src/components/MenuComponent.h b/src/components/MenuComponent.h index a309623d5..1dd577bd1 100644 --- a/src/components/MenuComponent.h +++ b/src/components/MenuComponent.h @@ -13,6 +13,14 @@ public: inline void addRow(const ComponentListRow& row, bool setCursorHere = false) { mList.addRow(row, setCursorHere); } + inline void addWithLabel(const std::string& label, const std::shared_ptr& comp, bool setCursorHere = false) + { + ComponentListRow row; + row.addElement(std::make_shared(mWindow, label, Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + row.addElement(comp, false); + addRow(row, setCursorHere); + } + private: NinePatchComponent mBackground; TextComponent mTitle; diff --git a/src/guis/GuiScraperStart.cpp b/src/guis/GuiScraperStart.cpp index 0003dd062..99e572173 100644 --- a/src/guis/GuiScraperStart.cpp +++ b/src/guis/GuiScraperStart.cpp @@ -2,58 +2,45 @@ #include "GuiScraperLog.h" #include "GuiMsgBoxYesNo.h" +#include "../components/TextComponent.h" +#include "../components/OptionListComponent.h" +#include "../components/SwitchComponent.h" + GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), - mBox(window, ":/frame.png"), - mList(window, Eigen::Vector2i(2, 4)), - mFilterLabel(mWindow), - mSystemsLabel(mWindow), - mManualLabel(mWindow), - mFiltersOpt(mWindow), - mSystemsOpt(mWindow, true), - mManualSwitch(mWindow), - mStartButton(mWindow) + mMenu(window, "SCRAPE NOW") { - mFilterLabel.setText("Filter: "); - mSystemsLabel.setText("Systems: "); - mManualLabel.setText("Manual mode: "); + addChild(&mMenu); - addChild(&mBox); - addChild(&mList); - - using namespace Eigen; - - //add filters (with first one selected) - mFiltersOpt.add("All Games", + // add filters (with first one selected) + mFilters = std::make_shared< OptionListComponent >(mWindow, false); + mFilters->add("All Games", [](SystemData*, FileData*) -> bool { return true; }, true); - mFiltersOpt.add("Missing Image", + mFilters->add("Only missing image", [](SystemData*, FileData* g) -> bool { return g->metadata.get("image").empty(); }, false); - - mList.setEntry(Vector2i(0, 0), Vector2i(1, 1), &mFilterLabel, false, ComponentGrid::AlignRight); - mList.setEntry(Vector2i(1, 0), Vector2i(1, 1), &mFiltersOpt, true, ComponentGrid::AlignLeft); + mMenu.addWithLabel("Filter", mFilters); //add systems (all with a platformid specified selected) - std::vector sys = SystemData::sSystemVector; - for(auto it = sys.begin(); it != sys.end(); it++) - mSystemsOpt.add((*it)->getFullName(), *it, (*it)->getPlatformId() != PlatformIds::PLATFORM_UNKNOWN); + mSystems = std::make_shared< OptionListComponent >(mWindow, true); + for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++) + mSystems->add((*it)->getFullName(), *it, (*it)->getPlatformId() != PlatformIds::PLATFORM_UNKNOWN); + mMenu.addWithLabel("Systems", mSystems); - mList.setEntry(Vector2i(0, 1), Vector2i(1, 1), &mSystemsLabel, false, ComponentGrid::AlignRight); - mList.setEntry(Vector2i(1, 1), Vector2i(1, 1), &mSystemsOpt, true, ComponentGrid::AlignLeft); + mAutoStyle = std::make_shared< OptionListComponent >(mWindow, false); + mAutoStyle->add("Never automatically accept result", 0, true); + mAutoStyle->add("Always accept first result", 1, false); + mMenu.addWithLabel("Auto style", mAutoStyle); - mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mManualLabel, false, ComponentGrid::AlignRight); - mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mManualSwitch, true, ComponentGrid::AlignLeft); + ComponentListRow row; + row.addElement(std::make_shared(mWindow, "GO GO GO", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); + row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this)); + mMenu.addRow(row); - mStartButton.setText("GO GO GO GO", "begin"); - mStartButton.setPressedFunc(std::bind(&GuiScraperStart::pressedStart, this)); - mList.setEntry(Vector2i(0, 3), Vector2i(2, 1), &mStartButton, true, ComponentGrid::AlignCenter); - - mList.setPosition(Renderer::getScreenWidth() / 2 - mList.getSize().x() / 2, Renderer::getScreenHeight() / 2 - mList.getSize().y() / 2); - - mBox.fitTo(mList.getSize(), mList.getPosition(), Eigen::Vector2f(-32, -32)); + mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, (Renderer::getScreenHeight() - mMenu.getSize().y()) / 2); } void GuiScraperStart::pressedStart() { - std::vector sys = mSystemsOpt.getSelectedObjects(); + std::vector sys = mSystems->getSelectedObjects(); for(auto it = sys.begin(); it != sys.end(); it++) { if((*it)->getPlatformId() == PlatformIds::PLATFORM_UNKNOWN) @@ -69,9 +56,9 @@ void GuiScraperStart::pressedStart() void GuiScraperStart::start() { - std::queue searches = getSearches(mSystemsOpt.getSelectedObjects(), mFiltersOpt.getSelectedObjects()[0]); + std::queue searches = getSearches(mSystems->getSelectedObjects(), mFilters->getSelected()); - GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mManualSwitch.getState()); + GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mAutoStyle->getSelected() == 0); mWindow->pushGui(gsl); gsl->start(); delete this; @@ -116,7 +103,7 @@ bool GuiScraperStart::input(InputConfig* config, Input input) std::vector GuiScraperStart::getHelpPrompts() { - std::vector prompts = mList.getHelpPrompts(); + std::vector prompts = mMenu.getHelpPrompts(); prompts.push_back(HelpPrompt("b", "cancel")); return prompts; } diff --git a/src/guis/GuiScraperStart.h b/src/guis/GuiScraperStart.h index 60a82b8b7..50bd298b6 100644 --- a/src/guis/GuiScraperStart.h +++ b/src/guis/GuiScraperStart.h @@ -2,16 +2,17 @@ #include "../GuiComponent.h" #include "../SystemData.h" -#include "../components/TextComponent.h" -#include "../components/ComponentGrid.h" -#include "../components/OptionListComponent.h" -#include "../components/SwitchComponent.h" -#include "../components/ButtonComponent.h" #include "../scrapers/Scraper.h" +#include "../components/MenuComponent.h" #include typedef std::function GameFilterFunc; +template +class OptionListComponent; + +class SwitchComponent; + //The starting point for a multi-game scrape. //Allows the user to set various parameters (to set filters, to set which systems to scrape, to enable manual mode). //Generates a list of "searches" that will be carried out by GuiScraperLog. @@ -29,16 +30,9 @@ private: void start(); std::queue getSearches(std::vector systems, GameFilterFunc selector); - NinePatchComponent mBox; - ComponentGrid mList; + std::shared_ptr< OptionListComponent > mFilters; + std::shared_ptr< OptionListComponent > mSystems; + std::shared_ptr< OptionListComponent > mAutoStyle; - TextComponent mFilterLabel; - TextComponent mSystemsLabel; - TextComponent mManualLabel; - - OptionListComponent mFiltersOpt; - OptionListComponent mSystemsOpt; - SwitchComponent mManualSwitch; - - ButtonComponent mStartButton; + MenuComponent mMenu; };