Some cosmetic improvements to the scraper.

This commit is contained in:
Leon Styhre 2020-07-30 16:29:38 +02:00
parent 9c755f2d0b
commit bd7e0e5820
2 changed files with 17 additions and 9 deletions

View file

@ -38,7 +38,8 @@ GuiScraperSearch::GuiScraperSearch(
: GuiComponent(window), : GuiComponent(window),
mGrid(window, Vector2i(4, 3)), mGrid(window, Vector2i(4, 3)),
mBusyAnim(window), mBusyAnim(window),
mSearchType(type) mSearchType(type),
mScrapeRatings(false)
{ {
addChild(&mGrid); addChild(&mGrid);
@ -74,9 +75,13 @@ GuiScraperSearch::GuiScraperSearch(
mMD_Publisher = std::make_shared<TextComponent>(mWindow, "", font, mdColor); mMD_Publisher = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor); mMD_Genre = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
mMD_Players = std::make_shared<TextComponent>(mWindow, "", font, mdColor); mMD_Players = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
mMD_Filler = std::make_shared<TextComponent>(mWindow, "", font, mdColor);
if (Settings::getInstance()->getBool("ScrapeRatings") && if (Settings::getInstance()->getBool("ScrapeRatings") &&
Settings::getInstance()->getString("Scraper") != "thegamesdb") Settings::getInstance()->getString("Scraper") != "thegamesdb")
mScrapeRatings = true;
if (mScrapeRatings)
mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent> mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent>
(mWindow, "RATING:", font, mdLblColor), mMD_Rating, false)); (mWindow, "RATING:", font, mdLblColor), mMD_Rating, false));
mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent> mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent>
@ -89,6 +94,11 @@ GuiScraperSearch::GuiScraperSearch(
(mWindow, "GENRE:", font, mdLblColor), mMD_Genre)); (mWindow, "GENRE:", font, mdLblColor), mMD_Genre));
mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent> mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent>
(mWindow, "PLAYERS:", font, mdLblColor), mMD_Players)); (mWindow, "PLAYERS:", font, mdLblColor), mMD_Players));
// If no rating is being scraped, add a filler to make sure the fonts keep the same
// size and the GUI looks consistent.
if (!mScrapeRatings)
mMD_Pairs.push_back(MetaDataPair(std::make_shared<TextComponent>
(mWindow, "", font, mdLblColor), mMD_Filler));
mMD_Grid = std::make_shared<ComponentGrid>(mWindow, mMD_Grid = std::make_shared<ComponentGrid>(mWindow,
Vector2i(2, (int)mMD_Pairs.size()*2 - 1)); Vector2i(2, (int)mMD_Pairs.size()*2 - 1));
@ -192,8 +202,7 @@ void GuiScraperSearch::resizeMetadata()
mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x()); mMD_Grid->setColWidthPerc(0, maxLblWidth / mMD_Grid->getSize().x());
if (Settings::getInstance()->getBool("ScrapeRatings") && if (mScrapeRatings) {
Settings::getInstance()->getString("Scraper") != "thegamesdb") {
// Rating is manually sized. // Rating is manually sized.
mMD_Rating->setSize(mMD_Grid->getColWidth(1), fontLbl->getHeight() * 0.65f); mMD_Rating->setSize(mMD_Grid->getColWidth(1), fontLbl->getHeight() * 0.65f);
mMD_Grid->onSizeChanged(); mMD_Grid->onSizeChanged();
@ -391,8 +400,7 @@ void GuiScraperSearch::updateInfoPane()
} }
// Metadata. // Metadata.
if (Settings::getInstance()->getBool("ScrapeRatings") && if (mScrapeRatings) {
Settings::getInstance()->getString("Scraper") != "thegamesdb") {
mMD_Rating->setValue(Utils::String::toUpper(res.mdl.get("rating"))); mMD_Rating->setValue(Utils::String::toUpper(res.mdl.get("rating")));
mMD_Rating->setOpacity(255); mMD_Rating->setOpacity(255);
} }
@ -409,8 +417,7 @@ void GuiScraperSearch::updateInfoPane()
mResultThumbnail->setImage(""); mResultThumbnail->setImage("");
// Metadata. // Metadata.
if (Settings::getInstance()->getBool("ScrapeRatings") && if (mScrapeRatings) {
Settings::getInstance()->getString("Scraper") != "thegamesdb") {
mMD_Rating->setValue(""); mMD_Rating->setValue("");
mMD_Rating->setOpacity(0); mMD_Rating->setOpacity(0);
} }
@ -439,11 +446,10 @@ void GuiScraperSearch::render(const Transform4x4f& parentTrans)
Transform4x4f trans = parentTrans * getTransform(); Transform4x4f trans = parentTrans * getTransform();
renderChildren(trans); renderChildren(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x00000009, 0x00000009);
if (mBlockAccept) { if (mBlockAccept) {
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), 0x00000011, 0x00000011);
mBusyAnim.render(trans); mBusyAnim.render(trans);
} }
} }

View file

@ -96,6 +96,7 @@ private:
std::shared_ptr<TextComponent> mMD_Publisher; std::shared_ptr<TextComponent> mMD_Publisher;
std::shared_ptr<TextComponent> mMD_Genre; std::shared_ptr<TextComponent> mMD_Genre;
std::shared_ptr<TextComponent> mMD_Players; std::shared_ptr<TextComponent> mMD_Players;
std::shared_ptr<TextComponent> mMD_Filler;
// Label-component pair. // Label-component pair.
struct MetaDataPair { struct MetaDataPair {
@ -117,6 +118,7 @@ private:
std::function<void()> mCancelCallback; std::function<void()> mCancelCallback;
bool mBlockAccept; bool mBlockAccept;
bool mFoundGame; bool mFoundGame;
bool mScrapeRatings;
std::unique_ptr<ScraperSearchHandle> mSearchHandle; std::unique_ptr<ScraperSearchHandle> mSearchHandle;
std::unique_ptr<ScraperSearchHandle> mMDRetrieveURLsHandle; std::unique_ptr<ScraperSearchHandle> mMDRetrieveURLsHandle;