2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// GuiGameScraper.cpp
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Single game scraping user interface.
|
|
|
|
// This interface is triggered from GuiMetaDataEd.
|
|
|
|
// GuiScraperSearch is called from here.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiGameScraper.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "components/ButtonComponent.h"
|
|
|
|
#include "components/MenuComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/TextComponent.h"
|
2020-06-07 18:09:02 +00:00
|
|
|
#include "views/ViewController.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "FileData.h"
|
2021-01-06 20:29:23 +00:00
|
|
|
#include "MameNames.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
GuiGameScraper::GuiGameScraper(
|
2020-06-21 12:25:28 +00:00
|
|
|
Window* window,
|
|
|
|
ScraperSearchParams params,
|
|
|
|
std::function<void(const ScraperSearchResult&)> doneFunc)
|
|
|
|
: GuiComponent(window),
|
|
|
|
mGrid(window, Vector2i(1, 7)),
|
2021-01-14 21:56:49 +00:00
|
|
|
mBox(window, ":/graphics/frame.svg"),
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchParams(params),
|
|
|
|
mClose(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
addChild(&mBox);
|
|
|
|
addChild(&mGrid);
|
|
|
|
|
|
|
|
// Row 0 is a spacer.
|
|
|
|
|
2021-01-06 20:29:23 +00:00
|
|
|
std::string scrapeName;
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) {
|
|
|
|
scrapeName = mSearchParams.game->getName();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (params.game->isArcadeGame() &&
|
|
|
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath()) + " (" +
|
|
|
|
MameNames::getInstance()->getCleanName(mSearchParams.game->getCleanName()) +
|
|
|
|
")";
|
|
|
|
else
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
mGameName = std::make_shared<TextComponent>(mWindow, scrapeName +
|
2020-12-25 14:28:19 +00:00
|
|
|
((mSearchParams.game->getType() == FOLDER) ? " " + ViewController::FOLDER_CHAR : ""),
|
2020-06-21 12:25:28 +00:00
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mGameName, Vector2i(0, 1), false, true);
|
|
|
|
|
|
|
|
// Row 2 is a spacer.
|
|
|
|
|
|
|
|
mSystemName = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(
|
|
|
|
mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
|
|
|
|
0x888888FF, ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mSystemName, Vector2i(0, 3), false, true);
|
|
|
|
|
|
|
|
// Row 4 is a spacer.
|
|
|
|
|
|
|
|
// GuiScraperSearch.
|
|
|
|
mSearch = std::make_shared<GuiScraperSearch>(window,
|
2020-07-31 12:24:14 +00:00
|
|
|
GuiScraperSearch::NEVER_AUTO_ACCEPT, 1);
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setEntry(mSearch, Vector2i(0, 5), true);
|
|
|
|
|
|
|
|
// Buttons
|
|
|
|
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
|
|
|
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH",
|
|
|
|
"refine search", [&] {
|
|
|
|
mSearch->openInputScreen(mSearchParams);
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}));
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(
|
|
|
|
mWindow, "CANCEL", "cancel", [&] { delete this; }));
|
|
|
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
|
|
|
|
|
|
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 6), true, false);
|
|
|
|
|
|
|
|
// We call this->close() instead of just 'delete this' in the accept callback.
|
|
|
|
// This is because of how GuiComponent::update works. If it was just 'delete this',
|
|
|
|
// the following would happen when the metadata resolver is done:
|
|
|
|
// GuiGameScraper::update()
|
|
|
|
// GuiComponent::update()
|
|
|
|
// it = mChildren.cbegin();
|
|
|
|
// mBox::update()
|
|
|
|
// it++;
|
|
|
|
// mSearchComponent::update()
|
|
|
|
// acceptCallback -> delete this
|
|
|
|
// it++; // Error, mChildren has been deleted because it was part of 'this'.
|
|
|
|
|
|
|
|
// So instead we do this:
|
|
|
|
// GuiGameScraper::update()
|
|
|
|
// GuiComponent::update()
|
|
|
|
// it = mChildren.cbegin();
|
|
|
|
// mBox::update()
|
|
|
|
// it++;
|
|
|
|
// mSearchComponent::update()
|
|
|
|
// acceptCallback -> close() -> mClose = true
|
|
|
|
// it++; // OK.
|
2020-07-13 18:58:25 +00:00
|
|
|
// if (mClose)
|
2020-06-21 12:25:28 +00:00
|
|
|
// delete this;
|
|
|
|
mSearch->setAcceptCallback([this, doneFunc](const ScraperSearchResult& result) {
|
|
|
|
doneFunc(result); close(); });
|
|
|
|
mSearch->setCancelCallback([&] { delete this; });
|
|
|
|
|
|
|
|
setSize(Renderer::getScreenWidth() * 0.95f, Renderer::getScreenHeight() * 0.747f);
|
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() -
|
|
|
|
mSize.y()) / 2);
|
|
|
|
|
|
|
|
mGrid.resetCursor();
|
|
|
|
mSearch->search(params); // Start the search.
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameScraper::onSizeChanged()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
|
|
|
|
|
|
|
mGrid.setRowHeightPerc(0, 0.04f, false);
|
|
|
|
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() /
|
|
|
|
mSize.y(), false); // Game name.
|
|
|
|
mGrid.setRowHeightPerc(2, 0.04f, false);
|
|
|
|
mGrid.setRowHeightPerc(3, mSystemName->getFont()->getLetterHeight() /
|
|
|
|
mSize.y(), false); // System name.
|
|
|
|
mGrid.setRowHeightPerc(4, 0.04f, false);
|
|
|
|
mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y() / mSize.y(), false); // Buttons.
|
|
|
|
mGrid.setSize(mSize);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiGameScraper::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-07-13 18:58:25 +00:00
|
|
|
if (config->isMappedTo("b", input) && input.value) {
|
2020-06-21 12:25:28 +00:00
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return GuiComponent::input(config, input);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameScraper::update(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
GuiComponent::update(deltaTime);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (mClose)
|
2020-06-21 12:25:28 +00:00
|
|
|
delete this;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiGameScraper::getHelpPrompts()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
return mGrid.getHelpPrompts();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 18:09:02 +00:00
|
|
|
HelpStyle GuiGameScraper::getHelpStyle()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
2020-06-07 18:09:02 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void GuiGameScraper::close()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mClose = true;
|
2017-08-11 17:03:12 +00:00
|
|
|
}
|