2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
// GuiGameScraper.cpp
|
|
|
|
//
|
|
|
|
// Single game scraping user interface.
|
|
|
|
// This interface is triggered from GuiMetaDataEd.
|
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/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"
|
2017-07-20 07:07:02 +00:00
|
|
|
#include "PowerSaver.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(
|
|
|
|
Window* window,
|
|
|
|
ScraperSearchParams params,
|
|
|
|
std::function<void(const ScraperSearchResult&)> doneFunc)
|
|
|
|
: GuiComponent(window),
|
|
|
|
mGrid(window, Vector2i(1, 7)),
|
|
|
|
mBox(window, ":/frame.png"),
|
|
|
|
mSearchParams(params),
|
|
|
|
mClose(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-08-11 17:03:12 +00:00
|
|
|
PowerSaver::pause();
|
2014-06-25 16:29:58 +00:00
|
|
|
addChild(&mBox);
|
|
|
|
addChild(&mGrid);
|
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Row 0 is a spacer.
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
mGameName = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(
|
|
|
|
Utils::FileSystem::getFileName(mSearchParams.game->getPath())),
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
2017-10-28 20:24:35 +00:00
|
|
|
mGrid.setEntry(mGameName, Vector2i(0, 1), false, true);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Row 2 is a spacer.
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
mSystemName = std::make_shared<TextComponent>(mWindow, Utils::String::toUpper(
|
|
|
|
mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
|
|
|
|
0x888888FF, ALIGN_CENTER);
|
2017-10-28 20:24:35 +00:00
|
|
|
mGrid.setEntry(mSystemName, Vector2i(0, 3), false, true);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Row 4 is a spacer.
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 12:14:13 +00:00
|
|
|
// GuiScraperSearch.
|
|
|
|
mSearch = std::make_shared<GuiScraperSearch>(window,
|
|
|
|
GuiScraperSearch::NEVER_AUTO_ACCEPT);
|
2017-10-28 20:24:35 +00:00
|
|
|
mGrid.setEntry(mSearch, Vector2i(0, 5), true);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// Buttons
|
2014-06-25 16:29:58 +00:00
|
|
|
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
|
|
|
|
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
|
|
|
mSearch->openInputScreen(mSearchParams);
|
|
|
|
mGrid.resetCursor();
|
2014-06-25 16:29:58 +00:00
|
|
|
}));
|
2020-05-26 16:34:33 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(
|
|
|
|
mWindow, "CANCEL", "cancel", [&] { delete this; }));
|
2014-06-25 16:29:58 +00:00
|
|
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 6), true, false);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// 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:
|
2014-06-25 16:29:58 +00:00
|
|
|
// GuiGameScraper::update()
|
|
|
|
// GuiComponent::update()
|
2017-11-11 14:56:22 +00:00
|
|
|
// it = mChildren.cbegin();
|
2014-06-25 16:29:58 +00:00
|
|
|
// mBox::update()
|
|
|
|
// it++;
|
|
|
|
// mSearchComponent::update()
|
|
|
|
// acceptCallback -> delete this
|
2020-05-26 16:34:33 +00:00
|
|
|
// it++; // Error, mChildren has been deleted because it was part of 'this'.
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
// So instead we do this:
|
2014-06-25 16:29:58 +00:00
|
|
|
// GuiGameScraper::update()
|
|
|
|
// GuiComponent::update()
|
2017-11-11 14:56:22 +00:00
|
|
|
// it = mChildren.cbegin();
|
2014-06-25 16:29:58 +00:00
|
|
|
// mBox::update()
|
|
|
|
// it++;
|
|
|
|
// mSearchComponent::update()
|
|
|
|
// acceptCallback -> close() -> mClose = true
|
2020-05-26 16:34:33 +00:00
|
|
|
// it++; // OK.
|
2014-06-25 16:29:58 +00:00
|
|
|
// if(mClose)
|
|
|
|
// delete this;
|
2020-05-26 16:34:33 +00:00
|
|
|
mSearch->setAcceptCallback([this, doneFunc](const ScraperSearchResult& result) {
|
|
|
|
doneFunc(result); close(); });
|
2014-06-25 16:29:58 +00:00
|
|
|
mSearch->setCancelCallback([&] { delete this; });
|
|
|
|
|
|
|
|
setSize(Renderer::getScreenWidth() * 0.95f, Renderer::getScreenHeight() * 0.747f);
|
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
|
|
|
|
|
|
|
mGrid.resetCursor();
|
2020-05-26 16:34:33 +00:00
|
|
|
mSearch->search(params); // Start the search.
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameScraper::onSizeChanged()
|
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
mBox.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
mGrid.setRowHeightPerc(0, 0.04f, false);
|
2020-05-26 16:34:33 +00:00
|
|
|
mGrid.setRowHeightPerc(1, mGameName->getFont()->getLetterHeight() /
|
|
|
|
mSize.y(), false); // Game name.
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setRowHeightPerc(2, 0.04f, false);
|
2020-05-26 16:34:33 +00:00
|
|
|
mGrid.setRowHeightPerc(3, mSystemName->getFont()->getLetterHeight() /
|
|
|
|
mSize.y(), false); // System name.
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setRowHeightPerc(4, 0.04f, false);
|
2020-05-26 16:34:33 +00:00
|
|
|
mGrid.setRowHeightPerc(6, mButtonGrid->getSize().y() / mSize.y(), false); // Buttons.
|
2014-06-25 16:29:58 +00:00
|
|
|
mGrid.setSize(mSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiGameScraper::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-05-26 16:34:33 +00:00
|
|
|
if(config->isMappedTo("b", input) && input.value) {
|
2017-08-11 17:03:12 +00:00
|
|
|
PowerSaver::resume();
|
2014-06-25 16:29:58 +00:00
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GuiComponent::input(config, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiGameScraper::update(int deltaTime)
|
|
|
|
{
|
|
|
|
GuiComponent::update(deltaTime);
|
|
|
|
|
|
|
|
if(mClose)
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiGameScraper::getHelpPrompts()
|
|
|
|
{
|
|
|
|
return mGrid.getHelpPrompts();
|
|
|
|
}
|
|
|
|
|
2020-06-07 18:09:02 +00:00
|
|
|
HelpStyle GuiGameScraper::getHelpStyle()
|
|
|
|
{
|
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void GuiGameScraper::close()
|
|
|
|
{
|
|
|
|
mClose = true;
|
2017-08-11 17:03:12 +00:00
|
|
|
}
|