More work on multi-game scraping UI.

This commit is contained in:
Aloshi 2013-10-10 19:55:57 -05:00
parent f3695a7545
commit ff85f971b2
5 changed files with 105 additions and 13 deletions

View file

@ -388,7 +388,7 @@ void GuiGameList::updateDetailData()
mScreenshot.setPosition(getImagePos() - imgOffset); mScreenshot.setPosition(getImagePos() - imgOffset);
mImageAnimation.fadeIn(35); 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.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())); mDescContainer.setSize(Eigen::Vector2f(Renderer::getScreenWidth() * (mTheme->getFloat("listOffsetX") - 0.03f), Renderer::getScreenHeight() - mDescContainer.getPosition().y()));

View file

@ -7,8 +7,9 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
mSystemsLabel(mWindow), mSystemsLabel(mWindow),
mManualLabel(mWindow), mManualLabel(mWindow),
mFiltersOpt(mWindow), mFiltersOpt(mWindow),
mSystemsOpt(mWindow), mSystemsOpt(mWindow, true),
mManualSwitch(mWindow) mManualSwitch(mWindow),
mStartButton(mWindow)
{ {
mFilterLabel.setText("Filter: "); mFilterLabel.setText("Filter: ");
mSystemsLabel.setText("Systems: "); mSystemsLabel.setText("Systems: ");
@ -18,15 +19,77 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
addChild(&mList); addChild(&mList);
using namespace Eigen; 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(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<SystemData*> 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(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(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<ScraperSearchParams> searches = getSearches(mSystemsOpt.getSelectedObjects(), mFiltersOpt.getSelectedObjects()[0]);
}
std::queue<ScraperSearchParams> GuiScraperStart::getSearches(std::vector<SystemData*> systems, GameFilterFunc selector)
{
std::queue<ScraperSearchParams> queue;
for(auto sys = systems.begin(); sys != systems.end(); sys++)
{
std::vector<FileData*> 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;
}

View file

@ -6,13 +6,23 @@
#include "ComponentListComponent.h" #include "ComponentListComponent.h"
#include "OptionListComponent.h" #include "OptionListComponent.h"
#include "SwitchComponent.h" #include "SwitchComponent.h"
#include "ButtonComponent.h"
#include "../scrapers/Scraper.h"
#include <queue>
typedef std::function<bool(SystemData*, GameData*)> GameFilterFunc;
class GuiScraperStart : public GuiComponent class GuiScraperStart : public GuiComponent
{ {
public: public:
GuiScraperStart(Window* window); GuiScraperStart(Window* window);
bool input(InputConfig* config, Input input) override;
private: private:
void start();
std::queue<ScraperSearchParams> getSearches(std::vector<SystemData*> systems, GameFilterFunc selector);
NinePatchComponent mBox; NinePatchComponent mBox;
ComponentListComponent mList; ComponentListComponent mList;
@ -20,9 +30,11 @@ private:
TextComponent mSystemsLabel; TextComponent mSystemsLabel;
TextComponent mManualLabel; TextComponent mManualLabel;
OptionListComponent<unsigned int> mFiltersOpt; OptionListComponent<GameFilterFunc> mFiltersOpt;
OptionListComponent<SystemData*> mSystemsOpt; OptionListComponent<SystemData*> mSystemsOpt;
SwitchComponent mManualSwitch; SwitchComponent mManualSwitch;
ButtonComponent mStartButton;
}; };
/* /*

View file

@ -65,7 +65,7 @@ GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
scrapers.push_back(std::shared_ptr<Scraper>(new GamesDBScraper())); scrapers.push_back(std::shared_ptr<Scraper>(new GamesDBScraper()));
scrapers.push_back(std::shared_ptr<Scraper>(new TheArchiveScraper())); scrapers.push_back(std::shared_ptr<Scraper>(new TheArchiveScraper()));
mScraperOptList.populate(scrapers, [&] (const std::shared_ptr<Scraper>& s) { mScraperOptList.populate(scrapers, [&] (const std::shared_ptr<Scraper>& 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); mList.setEntry(Vector2i(1, 3), Vector2i(1, 1), &mScraperOptList, true, ComponentListComponent::AlignCenter);

View file

@ -17,12 +17,12 @@ public:
OptionListComponent(Window* window, bool multiSelect = false) : GuiComponent(window), OptionListComponent(Window* window, bool multiSelect = false) : GuiComponent(window),
mCursor(0), mScrollOffset(0), mMultiSelect(multiSelect), mEditing(false), mBox(window, ":/textbox.png") mCursor(0), mScrollOffset(0), mMultiSelect(multiSelect), mEditing(false), mBox(window, ":/textbox.png")
{ {
setSize(getFont()->sizeText("Not set"));
} }
struct ListEntry struct ListEntry
{ {
std::string text; std::string text;
unsigned int color;
bool selected; bool selected;
T object; T object;
}; };
@ -149,9 +149,12 @@ public:
renderChildren(parentTrans * getTransform()); 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; return e;
} }
@ -184,6 +187,19 @@ public:
return ret; return ret;
} }
std::vector<T> getSelectedObjects()
{
std::vector<T> ret;
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
{
if((*it).selected)
ret.push_back(it->object);
}
return ret;
}
private: private:
void select(unsigned int i) void select(unsigned int i)
{ {
@ -205,6 +221,7 @@ private:
void open() void open()
{ {
mCursor = 0;
mEditing = true; mEditing = true;
} }
@ -222,7 +239,7 @@ private:
newSize[1] = (float)font->getHeight(); newSize[1] = (float)font->getHeight();
for(unsigned int i = 0; i < mEntries.size(); i++) 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); mTextCaches.push_back(cache);
if(cache->metrics.size.x() > newSize.x()) if(cache->metrics.size.x() > newSize.x())