ES-DE/src/components/GuiScraperStart.cpp

119 lines
3.8 KiB
C++
Raw Normal View History

#include "GuiScraperStart.h"
#include "GuiScraperLog.h"
#include "GuiMsgBoxYesNo.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),
2013-10-11 00:55:57 +00:00
mSystemsOpt(mWindow, true),
mManualSwitch(mWindow),
mStartButton(mWindow)
{
mFilterLabel.setText("Filter: ");
mSystemsLabel.setText("Systems: ");
mManualLabel.setText("Manual mode: ");
addChild(&mBox);
addChild(&mList);
using namespace Eigen;
2013-10-11 00:55:57 +00:00
//add filters (with first one selected)
mFiltersOpt.addEntry(mFiltersOpt.makeEntry("All Games",
[](SystemData*, FileData*) -> bool { return true; }, true));
2013-10-11 00:55:57 +00:00
mFiltersOpt.addEntry(mFiltersOpt.makeEntry("Missing Image",
[](SystemData*, FileData* g) -> bool { return g->metadata.get("image").empty(); }));
2013-10-11 00:55:57 +00:00
mList.setEntry(Vector2i(0, 0), Vector2i(1, 1), &mFilterLabel, false, ComponentListComponent::AlignRight);
2013-10-11 00:55:57 +00:00
mList.setEntry(Vector2i(1, 0), Vector2i(1, 1), &mFiltersOpt, true, ComponentListComponent::AlignLeft);
//add systems (all with a platformid specified selected)
2013-10-11 00:55:57 +00:00
std::vector<SystemData*> sys = SystemData::sSystemVector;
mSystemsOpt.populate(sys,
[&](SystemData* s) {
return mSystemsOpt.makeEntry(s->getName(), s, s->getPlatformId() != PlatformIds::PLATFORM_UNKNOWN);
2013-10-11 00:55:57 +00:00
});
mList.setEntry(Vector2i(0, 1), Vector2i(1, 1), &mSystemsLabel, false, ComponentListComponent::AlignRight);
2013-10-11 00:55:57 +00:00
mList.setEntry(Vector2i(1, 1), Vector2i(1, 1), &mSystemsOpt, true, ComponentListComponent::AlignLeft);
mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mManualLabel, false, ComponentListComponent::AlignRight);
2013-10-11 00:55:57 +00:00
mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mManualSwitch, true, ComponentListComponent::AlignLeft);
mStartButton.setText("GO GO GO GO", 0x00FF00FF);
mStartButton.setPressedFunc(std::bind(&GuiScraperStart::pressedStart, this));
2013-10-11 00:55:57 +00:00
mList.setEntry(Vector2i(0, 3), Vector2i(2, 1), &mStartButton, true, ComponentListComponent::AlignCenter);
2013-10-11 00:55:57 +00:00
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::pressedStart()
{
std::vector<SystemData*> sys = mSystemsOpt.getSelectedObjects();
for(auto it = sys.begin(); it != sys.end(); it++)
{
if((*it)->getPlatformId() == PlatformIds::PLATFORM_UNKNOWN)
{
mWindow->pushGui(new GuiMsgBoxYesNo(mWindow, "Warning: some of your selected systems do not have a platform ID set. Results may be even more inaccurate than usual!\nContinue anyway?",
std::bind(&GuiScraperStart::start, this)));
return;
}
}
start();
}
2013-10-11 00:55:57 +00:00
void GuiScraperStart::start()
{
std::queue<ScraperSearchParams> searches = getSearches(mSystemsOpt.getSelectedObjects(), mFiltersOpt.getSelectedObjects()[0]);
2013-10-12 20:08:27 +00:00
GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mManualSwitch.getState());
mWindow->pushGui(gsl);
gsl->start();
delete this;
}
2013-10-11 00:55:57 +00:00
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(GAME);
2013-10-11 00:55:57 +00:00
for(auto game = games.begin(); game != games.end(); game++)
{
if(selector((*sys), (*game)))
2013-10-11 00:55:57 +00:00
{
ScraperSearchParams search;
search.game = *game;
2013-10-11 00:55:57 +00:00
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;
}