From ff85f971b2bd8f94bc4da22e72805e3fa9b94016 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 10 Oct 2013 19:55:57 -0500 Subject: [PATCH] More work on multi-game scraping UI. --- src/components/GuiGameList.cpp | 2 +- src/components/GuiScraperStart.cpp | 75 +++++++++++++++++++++++++--- src/components/GuiScraperStart.h | 14 +++++- src/components/GuiSettingsMenu.cpp | 2 +- src/components/OptionListComponent.h | 25 ++++++++-- 5 files changed, 105 insertions(+), 13 deletions(-) diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index f23ae169c..ed1668446 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -388,7 +388,7 @@ void GuiGameList::updateDetailData() mScreenshot.setPosition(getImagePos() - imgOffset); mImageAnimation.fadeIn(35); - mImageAnimation.move(imgOffset.x(), imgOffset.y(), 20); + mImageAnimation.move((int)imgOffset.x(), (int)imgOffset.y(), 20); mDescContainer.setPosition(Eigen::Vector3f(Renderer::getScreenWidth() * 0.03f, getImagePos().y() + mScreenshot.getSize().y() + 12, 0)); mDescContainer.setSize(Eigen::Vector2f(Renderer::getScreenWidth() * (mTheme->getFloat("listOffsetX") - 0.03f), Renderer::getScreenHeight() - mDescContainer.getPosition().y())); diff --git a/src/components/GuiScraperStart.cpp b/src/components/GuiScraperStart.cpp index cb7821e45..ecb789636 100644 --- a/src/components/GuiScraperStart.cpp +++ b/src/components/GuiScraperStart.cpp @@ -7,8 +7,9 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), mSystemsLabel(mWindow), mManualLabel(mWindow), mFiltersOpt(mWindow), - mSystemsOpt(mWindow), - mManualSwitch(mWindow) + mSystemsOpt(mWindow, true), + mManualSwitch(mWindow), + mStartButton(mWindow) { mFilterLabel.setText("Filter: "); mSystemsLabel.setText("Systems: "); @@ -18,15 +19,77 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), addChild(&mList); using namespace Eigen; + + //add filters (with first one selected) + mFiltersOpt.addEntry(mFiltersOpt.makeEntry("All Games", + [](SystemData*, GameData*) -> bool { return true; }, true)); + mFiltersOpt.addEntry(mFiltersOpt.makeEntry("Missing Image", + [](SystemData*, GameData* g) -> bool { return g->metadata()->get("image").empty(); })); + mList.setEntry(Vector2i(0, 0), Vector2i(1, 1), &mFilterLabel, false, ComponentListComponent::AlignRight); - mList.setEntry(Vector2i(1, 0), Vector2i(1, 1), &mFiltersOpt, true, ComponentListComponent::AlignCenter); + mList.setEntry(Vector2i(1, 0), Vector2i(1, 1), &mFiltersOpt, true, ComponentListComponent::AlignLeft); + + //add systems (with all selected) + std::vector sys = SystemData::sSystemVector; + mSystemsOpt.populate(sys, + [&](SystemData* s) { + return mSystemsOpt.makeEntry(s->getName(), s, true); + }); mList.setEntry(Vector2i(0, 1), Vector2i(1, 1), &mSystemsLabel, false, ComponentListComponent::AlignRight); - mList.setEntry(Vector2i(1, 1), Vector2i(1, 1), &mSystemsOpt, true, ComponentListComponent::AlignCenter); + mList.setEntry(Vector2i(1, 1), Vector2i(1, 1), &mSystemsOpt, true, ComponentListComponent::AlignLeft); mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mManualLabel, false, ComponentListComponent::AlignRight); - mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mManualSwitch, true, ComponentListComponent::AlignCenter); + mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mManualSwitch, true, ComponentListComponent::AlignLeft); - mBox.fitTo(mList.getSize()); + mStartButton.setText("GO GO GO GO", 0x00FF00FF); + mStartButton.setPressedFunc(std::bind(&GuiScraperStart::start, this)); + mList.setEntry(Vector2i(0, 3), Vector2i(2, 1), &mStartButton, true, ComponentListComponent::AlignCenter); + + mList.setPosition(Renderer::getScreenWidth() / 2 - mList.getSize().x() / 2, Renderer::getScreenHeight() / 2 - mList.getSize().y() / 2); + + mBox.setEdgeColor(0x333333FF); + mBox.fitTo(mList.getSize(), mList.getPosition(), Eigen::Vector2f(8, 8)); } +void GuiScraperStart::start() +{ + std::queue searches = getSearches(mSystemsOpt.getSelectedObjects(), mFiltersOpt.getSelectedObjects()[0]); +} + +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(true); + for(auto game = games.begin(); game != games.end(); game++) + { + if(selector((*sys), (GameData*)(*game))) + { + ScraperSearchParams search; + search.game = (GameData*)(*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; + } + + return false; +} diff --git a/src/components/GuiScraperStart.h b/src/components/GuiScraperStart.h index c32a5f5cb..e5f4250fb 100644 --- a/src/components/GuiScraperStart.h +++ b/src/components/GuiScraperStart.h @@ -6,13 +6,23 @@ #include "ComponentListComponent.h" #include "OptionListComponent.h" #include "SwitchComponent.h" +#include "ButtonComponent.h" +#include "../scrapers/Scraper.h" +#include + +typedef std::function GameFilterFunc; class GuiScraperStart : public GuiComponent { public: GuiScraperStart(Window* window); + bool input(InputConfig* config, Input input) override; + private: + void start(); + std::queue getSearches(std::vector systems, GameFilterFunc selector); + NinePatchComponent mBox; ComponentListComponent mList; @@ -20,9 +30,11 @@ private: TextComponent mSystemsLabel; TextComponent mManualLabel; - OptionListComponent mFiltersOpt; + OptionListComponent mFiltersOpt; OptionListComponent mSystemsOpt; SwitchComponent mManualSwitch; + + ButtonComponent mStartButton; }; /* diff --git a/src/components/GuiSettingsMenu.cpp b/src/components/GuiSettingsMenu.cpp index e67a58fa9..af4106653 100644 --- a/src/components/GuiSettingsMenu.cpp +++ b/src/components/GuiSettingsMenu.cpp @@ -65,7 +65,7 @@ GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window), scrapers.push_back(std::shared_ptr(new GamesDBScraper())); scrapers.push_back(std::shared_ptr(new TheArchiveScraper())); mScraperOptList.populate(scrapers, [&] (const std::shared_ptr& s) { - return mScraperOptList.makeEntry(s->getName(), 0x00FF00FF, s, s->getName() == Settings::getInstance()->getScraper()->getName()); + return mScraperOptList.makeEntry(s->getName(), s, s->getName() == Settings::getInstance()->getScraper()->getName()); } ); mList.setEntry(Vector2i(1, 3), Vector2i(1, 1), &mScraperOptList, true, ComponentListComponent::AlignCenter); diff --git a/src/components/OptionListComponent.h b/src/components/OptionListComponent.h index 02ed9dd4d..c73690f7c 100644 --- a/src/components/OptionListComponent.h +++ b/src/components/OptionListComponent.h @@ -17,12 +17,12 @@ public: OptionListComponent(Window* window, bool multiSelect = false) : GuiComponent(window), mCursor(0), mScrollOffset(0), mMultiSelect(multiSelect), mEditing(false), mBox(window, ":/textbox.png") { + setSize(getFont()->sizeText("Not set")); } struct ListEntry { std::string text; - unsigned int color; bool selected; T object; }; @@ -149,9 +149,12 @@ public: renderChildren(parentTrans * getTransform()); } - ListEntry makeEntry(const std::string& name, unsigned int color, T obj, bool selected = false) const + ListEntry makeEntry(const std::string& name, T obj, bool selected = false) const { - ListEntry e = {name, color, selected, obj}; + ListEntry e; + e.text = name; + e.object = obj; + e.selected = selected; return e; } @@ -184,6 +187,19 @@ public: return ret; } + + std::vector getSelectedObjects() + { + std::vector ret; + for(auto it = mEntries.begin(); it != mEntries.end(); it++) + { + if((*it).selected) + ret.push_back(it->object); + } + + return ret; + } + private: void select(unsigned int i) { @@ -205,6 +221,7 @@ private: void open() { + mCursor = 0; mEditing = true; } @@ -222,7 +239,7 @@ private: newSize[1] = (float)font->getHeight(); for(unsigned int i = 0; i < mEntries.size(); i++) { - cache = font->buildTextCache(mEntries.at(i).text, 0, 0, mEntries.at(i).color); + cache = font->buildTextCache(mEntries.at(i).text, 0, 0, 0x000000FF); mTextCaches.push_back(cache); if(cache->metrics.size.x() > newSize.x())