From 18b428f79a0bb2a5ad29f15b44ba1f53ee9696b3 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 13 Mar 2014 14:09:50 -0500 Subject: [PATCH] Fixed help system being broken for MenuComponent. Still missing in a few places. Added some "BACK" buttons to various GUIs. --- src/components/ComponentGrid.cpp | 4 ++-- src/components/ComponentList.cpp | 10 ++++++++ src/components/ComponentList.h | 1 + src/components/MenuComponent.cpp | 5 ++++ src/components/MenuComponent.h | 2 ++ src/components/OptionListComponent.h | 36 ++++++++++++++++++++++------ src/components/TextListComponent.h | 3 +-- src/guis/GuiMenu.cpp | 14 ++++++++--- src/guis/GuiMenu.h | 1 + src/guis/GuiScraperStart.cpp | 18 ++++++-------- src/guis/GuiScraperStart.h | 2 +- src/guis/GuiSettings.cpp | 8 ++++++- 12 files changed, 77 insertions(+), 27 deletions(-) diff --git a/src/components/ComponentGrid.cpp b/src/components/ComponentGrid.cpp index 37c379142..f73257876 100644 --- a/src/components/ComponentGrid.cpp +++ b/src/components/ComponentGrid.cpp @@ -412,8 +412,8 @@ std::vector ComponentGrid::getHelpPrompts() if(e) prompts = e->component->getHelpPrompts(); - bool canScrollVert = true; - bool canScrollHoriz = true; + bool canScrollVert = mGridSize.y() > 1; + bool canScrollHoriz = mGridSize.x() > 1; for(auto it = prompts.begin(); it != prompts.end(); it++) { if(it->first == "up/down/left/right") diff --git a/src/components/ComponentList.cpp b/src/components/ComponentList.cpp index d21ede3ff..2b03190e2 100644 --- a/src/components/ComponentList.cpp +++ b/src/components/ComponentList.cpp @@ -117,6 +117,8 @@ void ComponentList::onCursorChanged(const CursorState& state) else if(mCameraOffset + mSize.y() > totalHeight) mCameraOffset = totalHeight - mSize.y(); } + + updateHelpPrompts(); } void ComponentList::render(const Eigen::Affine3f& parentTrans) @@ -238,3 +240,11 @@ void ComponentList::updateElementSize(const ComponentListRow& row) (*it)->setSize(width, (*it)->getSize().y()); } } + +std::vector ComponentList::getHelpPrompts() +{ + if(!size()) + return std::vector(); + + return mEntries.at(mCursor).data.elements.back().component->getHelpPrompts(); +} diff --git a/src/components/ComponentList.h b/src/components/ComponentList.h index 23dad2f32..baf736e10 100644 --- a/src/components/ComponentList.h +++ b/src/components/ComponentList.h @@ -50,6 +50,7 @@ public: bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; void render(const Eigen::Affine3f& parentTrans) override; + virtual std::vector getHelpPrompts() override; void onSizeChanged() override; void onFocusGained() override; diff --git a/src/components/MenuComponent.cpp b/src/components/MenuComponent.cpp index fa053d648..3bc1eac68 100644 --- a/src/components/MenuComponent.cpp +++ b/src/components/MenuComponent.cpp @@ -77,3 +77,8 @@ void MenuComponent::updateGrid() mButtonGrid.reset(); } } + +std::vector MenuComponent::getHelpPrompts() +{ + return mGrid.getHelpPrompts(); +} diff --git a/src/components/MenuComponent.h b/src/components/MenuComponent.h index 937515c47..a39bfef33 100644 --- a/src/components/MenuComponent.h +++ b/src/components/MenuComponent.h @@ -30,6 +30,8 @@ public: inline void setCursorToList() { mGrid.setCursorTo(mList); } inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); } + virtual std::vector getHelpPrompts() override; + private: void updateSize(); void updateGrid(); diff --git a/src/components/OptionListComponent.h b/src/components/OptionListComponent.h index 3f7da5a98..1c9ac6d07 100644 --- a/src/components/OptionListComponent.h +++ b/src/components/OptionListComponent.h @@ -37,8 +37,8 @@ private: OptionListComponent* mParent; public: - OptionListPopup(Window* window, OptionListComponent* parent) : GuiComponent(window), - mMenu(window, ""), mParent(parent) + OptionListPopup(Window* window, OptionListComponent* parent, const std::string& title) : GuiComponent(window), + mMenu(window, title.c_str()), mParent(parent) { auto font = Font::get(FONT_SIZE_MEDIUM); ComponentListRow row; @@ -85,7 +85,10 @@ private: mMenu.addRow(row, (!mParent->mMultiSelect && it->selected)); } - mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, (Renderer::getScreenHeight() - mMenu.getSize().y()) / 2); + if(mParent->mMultiSelect) + mMenu.addButton("BACK", "accept", [this] { delete this; }); + + mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); addChild(&mMenu); } @@ -102,7 +105,7 @@ private: }; public: - OptionListComponent(Window* window, bool multiSelect = false) : GuiComponent(window), mMultiSelect(multiSelect), + OptionListComponent(Window* window, const std::string& name, bool multiSelect = false) : GuiComponent(window), mMultiSelect(multiSelect), mName(name), mText(window), mLeftArrow(window), mRightArrow(window) { auto font = Font::get(FONT_SIZE_MEDIUM); @@ -124,10 +127,10 @@ public: addChild(&mRightArrow); } - // handles positioning/resizing of text and arrows - setSize(Renderer::getScreenWidth() * 0.2f, (float)font->getHeight()); + setSize(mLeftArrow.getSize().x() + mRightArrow.getSize().x(), (float)font->getHeight()); } + // handles positioning/resizing of text and arrows void onSizeChanged() override { // size @@ -239,7 +242,7 @@ private: void open() { - mWindow->pushGui(new OptionListPopup(mWindow, this)); + mWindow->pushGui(new OptionListPopup(mWindow, this, mName)); } void onSelectedChanged() @@ -250,6 +253,10 @@ private: std::stringstream ss; ss << getSelectedObjects().size() << " selected"; mText.setText(ss.str()); + mText.setSize(0, mText.getSize().y()); + setSize(mText.getSize().x() + mRightArrow.getSize().x() + 16, mText.getSize().y()); + if(mParent) // hack since theres no "on child size changed" callback atm... + mParent->onSizeChanged(); }else{ // display currently selected + l/r cursors for(auto it = mEntries.begin(); it != mEntries.end(); it++) @@ -257,14 +264,29 @@ private: if(it->selected) { mText.setText(it->name); + mText.setSize(0, mText.getSize().y()); + setSize(mText.getSize().x() + mLeftArrow.getSize().x() + mRightArrow.getSize().x() + 16, mText.getSize().y()); + if(mParent) // hack since theres no "on child size changed" callback atm... + mParent->onSizeChanged(); break; } } } } + std::vector getHelpPrompts() override + { + std::vector prompts; + if(!mMultiSelect) + prompts.push_back(HelpPrompt("left/right", "change")); + + prompts.push_back(HelpPrompt("a", "change")); + return prompts; + } + bool mMultiSelect; + std::string mName; TextComponent mText; ImageComponent mLeftArrow; ImageComponent mRightArrow; diff --git a/src/components/TextListComponent.h b/src/components/TextListComponent.h index 973709321..55072be15 100644 --- a/src/components/TextListComponent.h +++ b/src/components/TextListComponent.h @@ -60,8 +60,7 @@ public: inline void setFont(const std::shared_ptr& font) { mFont = font; - this->mTitleOverlayFont = Font::get(FONT_SIZE_LARGE, mFont->getPath()); - + for(auto it = mEntries.begin(); it != mEntries.end(); it++) it->data.textCache.reset(); } diff --git a/src/guis/GuiMenu.cpp b/src/guis/GuiMenu.cpp index 35271ef4e..e0c731260 100644 --- a/src/guis/GuiMenu.cpp +++ b/src/guis/GuiMenu.cpp @@ -44,7 +44,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN auto s = new GuiSettings(mWindow, "SCRAPER"); // scrape from - auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr > >(mWindow, false); + auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr > >(mWindow, "SCRAPE FROM", false); std::vector< std::shared_ptr > scrapers; scrapers.push_back(std::make_shared()); scrapers.push_back(std::make_shared()); @@ -152,14 +152,14 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN { row.elements.clear(); row.makeAcceptInputHandler([window] { - window->pushGui(new GuiMsgBoxYesNo(window, "REALLY EXIT?", + window->pushGui(new GuiMsgBoxYesNo(window, "REALLY QUIT?", [] { SDL_Event ev; ev.type = SDL_QUIT; SDL_PushEvent(&ev); })); }); - row.addElement(std::make_shared(window, "EXIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x770000FF), true); + row.addElement(std::make_shared(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); s->addRow(row); } @@ -199,3 +199,11 @@ bool GuiMenu::input(InputConfig* config, Input input) return GuiComponent::input(config, input); } + +std::vector GuiMenu::getHelpPrompts() +{ + std::vector prompts; + prompts.push_back(HelpPrompt("up/down", "move cursor")); + prompts.push_back(HelpPrompt("a", "accept")); + return prompts; +} diff --git a/src/guis/GuiMenu.h b/src/guis/GuiMenu.h index 8dc13d636..a9f746e38 100644 --- a/src/guis/GuiMenu.h +++ b/src/guis/GuiMenu.h @@ -10,6 +10,7 @@ public: GuiMenu(Window* window); bool input(InputConfig* config, Input input) override; + std::vector getHelpPrompts() override; private: void addEntry(const char* name, unsigned int color, bool add_arrow, const std::function& func); diff --git a/src/guis/GuiScraperStart.cpp b/src/guis/GuiScraperStart.cpp index a12e6f091..8275d7b93 100644 --- a/src/guis/GuiScraperStart.cpp +++ b/src/guis/GuiScraperStart.cpp @@ -12,7 +12,7 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), addChild(&mMenu); // add filters (with first one selected) - mFilters = std::make_shared< OptionListComponent >(mWindow, false); + mFilters = std::make_shared< OptionListComponent >(mWindow, "SCRAPE THESE GAMES", false); mFilters->add("All Games", [](SystemData*, FileData*) -> bool { return true; }, true); mFilters->add("Only missing image", @@ -20,20 +20,16 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), mMenu.addWithLabel("Filter", mFilters); //add systems (all with a platformid specified selected) - mSystems = std::make_shared< OptionListComponent >(mWindow, true); + mSystems = std::make_shared< OptionListComponent >(mWindow, "SCRAPE THESE SYSTEMS", true); for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++) mSystems->add((*it)->getFullName(), *it, (*it)->getPlatformId() != PlatformIds::PLATFORM_UNKNOWN); mMenu.addWithLabel("Systems", mSystems); - mAutoStyle = std::make_shared< OptionListComponent >(mWindow, false); - mAutoStyle->add("Never automatically accept result", 0, true); - mAutoStyle->add("Always accept first result", 1, false); - mMenu.addWithLabel("Auto style", mAutoStyle); + mApproveResults = std::make_shared(mWindow); + mApproveResults->setState(true); + mMenu.addWithLabel("User decides on conflicts", mApproveResults); - ComponentListRow row; - row.addElement(std::make_shared(mWindow, "GO GO GO", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true); - row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this)); - mMenu.addRow(row); + mMenu.addButton("START", "start scraping", std::bind(&GuiScraperStart::pressedStart, this)); mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } @@ -58,7 +54,7 @@ void GuiScraperStart::start() { std::queue searches = getSearches(mSystems->getSelectedObjects(), mFilters->getSelected()); - GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mAutoStyle->getSelected() == 0); + GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mApproveResults->getState()); mWindow->pushGui(gsl); gsl->start(); delete this; diff --git a/src/guis/GuiScraperStart.h b/src/guis/GuiScraperStart.h index 50bd298b6..d6d854f8a 100644 --- a/src/guis/GuiScraperStart.h +++ b/src/guis/GuiScraperStart.h @@ -32,7 +32,7 @@ private: std::shared_ptr< OptionListComponent > mFilters; std::shared_ptr< OptionListComponent > mSystems; - std::shared_ptr< OptionListComponent > mAutoStyle; + std::shared_ptr mApproveResults; MenuComponent mMenu; }; diff --git a/src/guis/GuiSettings.cpp b/src/guis/GuiSettings.cpp index 1b4416e71..427c0976b 100644 --- a/src/guis/GuiSettings.cpp +++ b/src/guis/GuiSettings.cpp @@ -5,6 +5,8 @@ GuiSettings::GuiSettings(Window* window, const char* title) : GuiComponent(windo { addChild(&mMenu); + mMenu.addButton("BACK", "go back", [this] { delete this; }); + setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } @@ -38,5 +40,9 @@ bool GuiSettings::input(InputConfig* config, Input input) std::vector GuiSettings::getHelpPrompts() { - return mMenu.getHelpPrompts(); + std::vector prompts = mMenu.getHelpPrompts(); + + prompts.push_back(HelpPrompt("b", "go back")); + + return prompts; }