2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
// GuiScraperMulti.cpp
|
|
|
|
//
|
|
|
|
// Multiple game scraping user interface.
|
|
|
|
// Shows the progress for the scraping as it's running.
|
2020-06-06 11:10:33 +00:00
|
|
|
// This interface is triggered from GuiScraperMenu.
|
2020-06-06 12:14:13 +00:00
|
|
|
// GuiScraperSearch is called from here.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiScraperMulti.h"
|
|
|
|
|
|
|
|
#include "components/ButtonComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/MenuComponent.h"
|
|
|
|
#include "components/TextComponent.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiMsgBox.h"
|
2020-06-06 12:14:13 +00:00
|
|
|
#include "guis/GuiScraperSearch.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "Gamelist.h"
|
|
|
|
#include "PowerSaver.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Window.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
GuiScraperMulti::GuiScraperMulti(
|
|
|
|
Window* window,
|
|
|
|
const std::queue<ScraperSearchParams>& searches,
|
|
|
|
bool approveResults)
|
|
|
|
: GuiComponent(window),
|
|
|
|
mBackground(window, ":/frame.png"),
|
|
|
|
mGrid(window, Vector2i(1, 5)),
|
|
|
|
mSearchQueue(searches)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
assert(mSearchQueue.size());
|
|
|
|
|
|
|
|
addChild(&mBackground);
|
|
|
|
addChild(&mGrid);
|
|
|
|
|
2017-08-11 17:03:12 +00:00
|
|
|
PowerSaver::pause();
|
2016-09-12 11:31:44 +00:00
|
|
|
mIsProcessing = true;
|
|
|
|
|
2017-11-17 14:58:52 +00:00
|
|
|
mTotalGames = (int)mSearchQueue.size();
|
2014-06-25 16:29:58 +00:00
|
|
|
mCurrentGame = 0;
|
|
|
|
mTotalSuccessful = 0;
|
|
|
|
mTotalSkipped = 0;
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Set up grid.
|
|
|
|
mTitle = std::make_shared<TextComponent>(mWindow, "SCRAPING IN PROGRESS",
|
|
|
|
Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true);
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
mSystem = std::make_shared<TextComponent>(mWindow, "SYSTEM",
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setEntry(mSystem, Vector2i(0, 1), false, true);
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
mSubtitle = std::make_shared<TextComponent>(mWindow, "subtitle text",
|
|
|
|
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setEntry(mSubtitle, Vector2i(0, 2), false, true);
|
|
|
|
|
2020-06-13 14:47:12 +00:00
|
|
|
if (approveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
|
|
|
GuiScraperSearch::NEVER_AUTO_ACCEPT);
|
|
|
|
else if (approveResults && Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
|
|
|
GuiScraperSearch::ACCEPT_SINGLE_MATCHES);
|
|
|
|
else if (!approveResults)
|
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
|
|
|
GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT);
|
2020-05-26 16:34:33 +00:00
|
|
|
mSearchComp->setAcceptCallback(std::bind(&GuiScraperMulti::acceptResult,
|
|
|
|
this, std::placeholders::_1));
|
2014-06-25 16:29:58 +00:00
|
|
|
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
|
|
|
|
mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this));
|
2020-05-26 16:34:33 +00:00
|
|
|
mGrid.setEntry(mSearchComp, Vector2i(0, 3), mSearchComp->getSearchType() !=
|
2020-06-06 12:14:13 +00:00
|
|
|
GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, true);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
if (approveResults) {
|
2020-06-09 18:03:31 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH",
|
|
|
|
"refine search", [&] {
|
2017-08-11 17:03:12 +00:00
|
|
|
mSearchComp->openInputScreen(mSearchQueue.front());
|
|
|
|
mGrid.resetCursor();
|
2014-06-25 16:29:58 +00:00
|
|
|
}));
|
|
|
|
|
2020-06-09 18:03:31 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip game", [&] {
|
2014-06-25 16:29:58 +00:00
|
|
|
skip();
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP",
|
|
|
|
"stop (progress saved)", std::bind(&GuiScraperMulti::finish, this)));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
|
|
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 4), true, false);
|
|
|
|
|
|
|
|
setSize(Renderer::getScreenWidth() * 0.95f, Renderer::getScreenHeight() * 0.849f);
|
2020-05-26 16:34:33 +00:00
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() -
|
|
|
|
mSize.y()) / 2);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
doNextSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiScraperMulti::~GuiScraperMulti()
|
|
|
|
{
|
2020-05-26 16:34:33 +00:00
|
|
|
// View type probably changed (basic -> detailed).
|
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
|
|
|
it !=SystemData::sSystemVector.cend(); it++)
|
2014-06-25 16:29:58 +00:00
|
|
|
ViewController::get()->reloadGameListView(*it, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::onSizeChanged()
|
|
|
|
{
|
|
|
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
|
|
|
|
|
|
|
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false);
|
|
|
|
mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2) / mSize.y(), false);
|
|
|
|
mGrid.setRowHeightPerc(2, mSubtitle->getFont()->getHeight() * 1.75f / mSize.y(), false);
|
|
|
|
mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y(), false);
|
|
|
|
mGrid.setSize(mSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::doNextSearch()
|
|
|
|
{
|
2020-05-26 16:34:33 +00:00
|
|
|
if (mSearchQueue.empty()) {
|
2014-06-25 16:29:58 +00:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Update title.
|
2014-06-25 16:29:58 +00:00
|
|
|
std::stringstream ss;
|
2018-01-27 17:04:28 +00:00
|
|
|
mSystem->setText(Utils::String::toUpper(mSearchQueue.front().system->getFullName()));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Update subtitle.
|
|
|
|
ss.str(""); // Clear.
|
|
|
|
ss << "GAME " << (mCurrentGame + 1) << " OF " << mTotalGames << " - " <<
|
|
|
|
Utils::String::toUpper(Utils::FileSystem::getFileName(
|
|
|
|
mSearchQueue.front().game->getPath()));
|
2014-06-25 16:29:58 +00:00
|
|
|
mSubtitle->setText(ss.str());
|
|
|
|
|
|
|
|
mSearchComp->search(mSearchQueue.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::acceptResult(const ScraperSearchResult& result)
|
|
|
|
{
|
|
|
|
ScraperSearchParams& search = mSearchQueue.front();
|
|
|
|
|
2020-06-06 12:14:13 +00:00
|
|
|
GuiScraperSearch::saveMetadata(result, search.game->metadata);
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
updateGamelist(search.system);
|
|
|
|
|
|
|
|
mSearchQueue.pop();
|
|
|
|
mCurrentGame++;
|
|
|
|
mTotalSuccessful++;
|
|
|
|
doNextSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::skip()
|
|
|
|
{
|
|
|
|
mSearchQueue.pop();
|
|
|
|
mCurrentGame++;
|
|
|
|
mTotalSkipped++;
|
|
|
|
doNextSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::finish()
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2020-05-26 16:34:33 +00:00
|
|
|
if (mTotalSuccessful == 0) {
|
2020-06-06 11:10:33 +00:00
|
|
|
ss << "NO GAMES WERE SCRAPED";
|
2020-05-26 16:34:33 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ss << mTotalSuccessful << " GAME" << ((mTotalSuccessful > 1) ? "S" : "") <<
|
2020-06-06 11:10:33 +00:00
|
|
|
" SUCCESSFULLY SCRAPED";
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
if (mTotalSkipped > 0)
|
|
|
|
ss << "\n" << mTotalSkipped << " GAME" << ((mTotalSkipped > 1) ? "S" : "") <<
|
2020-06-06 11:10:33 +00:00
|
|
|
" SKIPPED";
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 18:09:02 +00:00
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, getHelpStyle(), ss.str(), "OK", [&] {
|
2020-05-26 16:34:33 +00:00
|
|
|
delete this; }));
|
2016-09-12 11:31:44 +00:00
|
|
|
|
|
|
|
mIsProcessing = false;
|
2017-08-11 17:03:12 +00:00
|
|
|
PowerSaver::resume();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()
|
|
|
|
{
|
|
|
|
return mGrid.getHelpPrompts();
|
|
|
|
}
|
2020-06-07 18:09:02 +00:00
|
|
|
|
|
|
|
HelpStyle GuiScraperMulti::getHelpStyle()
|
|
|
|
{
|
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
|
|
|
}
|