#pragma once #include "GuiComponent.h" #include "scrapers/Scraper.h" #include "components/ComponentGrid.h" #include "components/BusyComponent.h" #include class ComponentList; class ImageComponent; class RatingComponent; class TextComponent; class DateTimeComponent; class ScrollableContainer; class HttpReq; class AnimatedImageComponent; class ScraperSearchComponent : public GuiComponent { public: enum SearchType { ALWAYS_ACCEPT_FIRST_RESULT, ALWAYS_ACCEPT_MATCHING_CRC, NEVER_AUTO_ACCEPT }; ScraperSearchComponent(Window* window, SearchType searchType = NEVER_AUTO_ACCEPT); void search(const ScraperSearchParams& params); void openInputScreen(ScraperSearchParams& from); void stop(); inline SearchType getSearchType() const { return mSearchType; } // Metadata assets will be resolved before calling the accept callback (e.g. result.mdl's "image" is automatically downloaded and properly set). inline void setAcceptCallback(const std::function& acceptCallback) { mAcceptCallback = acceptCallback; } inline void setSkipCallback(const std::function& skipCallback) { mSkipCallback = skipCallback; }; inline void setCancelCallback(const std::function& cancelCallback) { mCancelCallback = cancelCallback; } bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Transform4x4f& parentTrans) override; std::vector getHelpPrompts() override; void onSizeChanged() override; void onFocusGained() override; void onFocusLost() override; private: void updateViewStyle(); void updateThumbnail(); void updateInfoPane(); void resizeMetadata(); void onSearchError(const std::string& error); void onSearchDone(const std::vector& results); int getSelectedIndex(); // resolve any metadata assets that need to be downloaded and return void returnResult(ScraperSearchResult result); ComponentGrid mGrid; std::shared_ptr mResultName; std::shared_ptr mDescContainer; std::shared_ptr mResultDesc; std::shared_ptr mResultThumbnail; std::shared_ptr mResultList; std::shared_ptr mMD_Grid; std::shared_ptr mMD_Rating; std::shared_ptr mMD_ReleaseDate; std::shared_ptr mMD_Developer; std::shared_ptr mMD_Publisher; std::shared_ptr mMD_Genre; std::shared_ptr mMD_Players; // label-component pair struct MetaDataPair { std::shared_ptr first; std::shared_ptr second; bool resize; MetaDataPair(const std::shared_ptr& f, const std::shared_ptr& s, bool r = true) : first(f), second(s), resize(r) {}; }; std::vector mMD_Pairs; SearchType mSearchType; ScraperSearchParams mLastSearch; std::function mAcceptCallback; std::function mSkipCallback; std::function mCancelCallback; bool mBlockAccept; std::unique_ptr mSearchHandle; std::unique_ptr mMDResolveHandle; std::vector mScraperResults; std::unique_ptr mThumbnailReq; BusyComponent mBusyAnim; };