diff --git a/src/Window.cpp b/src/Window.cpp index c735e8cda..b4f456e02 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -214,11 +214,15 @@ void Window::setHelpPrompts(const std::vector& prompts) { mHelp->clearPrompts(); + std::vector addPrompts; + std::map seenMap; for(auto it = prompts.begin(); it != prompts.end(); it++) { // only add it if the same icon hasn't already been added if(seenMap.insert(std::make_pair(it->first, true)).second) - mHelp->addPrompt(it->first, it->second); + addPrompts.push_back(*it); } + + mHelp->setPrompts(addPrompts); } diff --git a/src/components/ComponentGrid.cpp b/src/components/ComponentGrid.cpp index d51f4e654..11a6522d7 100644 --- a/src/components/ComponentGrid.cpp +++ b/src/components/ComponentGrid.cpp @@ -436,11 +436,11 @@ std::vector ComponentGrid::getHelpPrompts() } if(canScrollHoriz && canScrollVert) - prompts.push_back(HelpPrompt("up/down/left/right", "move cursor")); + prompts.push_back(HelpPrompt("up/down/left/right", "move")); else if(canScrollHoriz) - prompts.push_back(HelpPrompt("left/right", "move cursor")); + prompts.push_back(HelpPrompt("left/right", "move")); else if(canScrollVert) - prompts.push_back(HelpPrompt("up/down", "move cursor")); + prompts.push_back(HelpPrompt("up/down", "move")); return prompts; } diff --git a/src/components/ComponentList.cpp b/src/components/ComponentList.cpp index f3a9ecd0c..ca285d851 100644 --- a/src/components/ComponentList.cpp +++ b/src/components/ComponentList.cpp @@ -288,7 +288,25 @@ std::vector ComponentList::getHelpPrompts() if(!size()) return std::vector(); - return mEntries.at(mCursor).data.elements.back().component->getHelpPrompts(); + std::vector prompts = mEntries.at(mCursor).data.elements.back().component->getHelpPrompts(); + + if(size() > 1) + { + bool addMovePrompt = true; + for(auto it = prompts.begin(); it != prompts.end(); it++) + { + if(it->first == "up/down" || it->first == "up/down/left/right") + { + addMovePrompt = false; + break; + } + } + + if(addMovePrompt) + prompts.push_back(HelpPrompt("up/down", "move")); + } + + return prompts; } bool ComponentList::moveCursor(int amt) diff --git a/src/components/HelpComponent.cpp b/src/components/HelpComponent.cpp index b9e27f92e..7fa9a3ddd 100644 --- a/src/components/HelpComponent.cpp +++ b/src/components/HelpComponent.cpp @@ -1,11 +1,22 @@ #include "HelpComponent.h" #include "../Renderer.h" -#include "ImageComponent.h" -#include "../resources/Font.h" #include "../Settings.h" #include "../Log.h" +#include "../Util.h" +#include "ImageComponent.h" +#include "TextComponent.h" +#include "ComponentGrid.h" + #include +#define OFFSET_X 6 // move the entire thing right by this amount (px) +#define OFFSET_Y 6 // move the entire thing up by this amount (px) + +#define ICON_TEXT_SPACING 8 // space between [icon] and [text] (px) +#define ENTRY_SPACING 16 // space between [text] and next [icon] (px) + +using namespace Eigen; + static const std::map ICON_PATH_MAP = boost::assign::map_list_of ("up/down", ":/help/dpad_updown.svg") ("left/right", ":/help/dpad_leftright.svg") @@ -26,37 +37,59 @@ HelpComponent::HelpComponent(Window* window) : GuiComponent(window) void HelpComponent::clearPrompts() { mPrompts.clear(); + updateGrid(); } -void HelpComponent::addPrompt(const char* icon, const char* text) +void HelpComponent::setPrompts(const std::vector& prompts) { - if(!Settings::getInstance()->getBool("ShowHelpPrompts")) + mPrompts = prompts; + updateGrid(); +} + +void HelpComponent::updateGrid() +{ + if(!Settings::getInstance()->getBool("ShowHelpPrompts") || mPrompts.empty()) + { + mGrid.reset(); return; + } - Prompt p; + mGrid = std::make_shared(mWindow, Vector2i(mPrompts.size() * 4, 1)); + // [icon] [spacer1] [text] [spacer2] - std::shared_ptr font = getFont(); - - // make the icon - p.icon = std::shared_ptr(new ImageComponent(mWindow)); - p.icon->setResize(0, (float)FONT_SIZE_SMALL); - p.icon->setImage(getIconTexture(icon)); - p.icon->setPosition(0.0f, mPrompts.size() ? mPrompts.back().icon->getPosition().y() + mPrompts.back().icon->getSize().y() + 10 : 0); - p.icon->setOpacity(0xEE); + std::shared_ptr font = Font::get(FONT_SIZE_SMALL); - // make the text - const float textY = (p.icon->getSize().y() - (float)font->getHeight())/2; - p.textCache = std::shared_ptr(font->buildTextCache(text, p.icon->getSize().x() + 6, textY, 0x888888EE)); + std::vector< std::shared_ptr > icons; + std::vector< std::shared_ptr > labels; - mPrompts.push_back(p); + float width = 0; + const float height = font->getHeight(); + for(auto it = mPrompts.begin(); it != mPrompts.end(); it++) + { + auto icon = std::make_shared(mWindow); + icon->setImage(getIconTexture(it->first)); + icon->setResize(0, height * 0.8f); + icons.push_back(icon); - setPosition(0, (float)Renderer::getScreenHeight() - (p.icon->getPosition().y() + p.icon->getSize().y() + 6)); -} + auto lbl = std::make_shared(mWindow, strToUpper(it->second), font, 0x777777FF); + labels.push_back(lbl); -std::shared_ptr HelpComponent::getFont() const -{ - // font size controls icon height - return Font::get(FONT_SIZE_SMALL); + width += icon->getSize().x() + lbl->getSize().x() + ICON_TEXT_SPACING + ENTRY_SPACING; + } + + mGrid->setSize(width, height); + for(unsigned int i = 0; i < icons.size(); i++) + { + const int col = i*4; + mGrid->setColWidthPerc(col, icons.at(i)->getSize().x() / width); + mGrid->setColWidthPerc(col + 1, ICON_TEXT_SPACING / width); + mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x() / width); + + mGrid->setEntry(icons.at(i), Vector2i(col, 0), false, false); + mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false); + } + + mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y); } std::shared_ptr HelpComponent::getIconTexture(const char* name) @@ -86,12 +119,6 @@ void HelpComponent::render(const Eigen::Affine3f& parentTrans) { Eigen::Affine3f trans = parentTrans * getTransform(); - std::shared_ptr font = getFont(); - for(auto it = mPrompts.begin(); it != mPrompts.end(); it++) - { - it->icon->render(trans); - // we actually depend on it->icon->render to call Renderer::setMatrix to draw at the right Y offset (efficiency!) - // if for some reason this breaks in the future, it should be equivalent to translating parentTrans by it->icon->getPosition() - font->renderTextCache(it->textCache.get()); - } + if(mGrid) + mGrid->render(trans); } diff --git a/src/components/HelpComponent.h b/src/components/HelpComponent.h index 10cd185cf..9cc76082f 100644 --- a/src/components/HelpComponent.h +++ b/src/components/HelpComponent.h @@ -4,8 +4,7 @@ class ImageComponent; class TextureResource; -class TextCache; -class Font; +class ComponentGrid; class HelpComponent : public GuiComponent { @@ -13,21 +12,16 @@ public: HelpComponent(Window* window); void clearPrompts(); - void addPrompt(const char* icon, const char* text); + void setPrompts(const std::vector& prompts); void render(const Eigen::Affine3f& parent) override; private: - std::shared_ptr getFont() const; std::shared_ptr getIconTexture(const char* name); - std::map< std::string, std::shared_ptr > mIconCache; - struct Prompt - { - std::shared_ptr icon; - std::shared_ptr textCache; - }; + std::shared_ptr mGrid; + void updateGrid(); - std::vector mPrompts; + std::vector mPrompts; }; diff --git a/src/components/RatingComponent.cpp b/src/components/RatingComponent.cpp index 61754c610..75266a35b 100644 --- a/src/components/RatingComponent.cpp +++ b/src/components/RatingComponent.cpp @@ -154,6 +154,6 @@ void RatingComponent::applyTheme(const std::shared_ptr& theme, const std::vector RatingComponent::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("a", "+1 star")); + prompts.push_back(HelpPrompt("a", "add star")); return prompts; } diff --git a/src/components/SliderComponent.cpp b/src/components/SliderComponent.cpp index 1de0065e1..65165cfb1 100644 --- a/src/components/SliderComponent.cpp +++ b/src/components/SliderComponent.cpp @@ -140,6 +140,6 @@ void SliderComponent::onValueChanged() std::vector SliderComponent::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("left/right", "adjust")); + prompts.push_back(HelpPrompt("left/right", "change")); return prompts; } diff --git a/src/components/SwitchComponent.cpp b/src/components/SwitchComponent.cpp index c6fdf61f0..bbf11bb09 100644 --- a/src/components/SwitchComponent.cpp +++ b/src/components/SwitchComponent.cpp @@ -55,6 +55,6 @@ void SwitchComponent::onStateChanged() std::vector SwitchComponent::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("a", "toggle")); + prompts.push_back(HelpPrompt("a", "change")); return prompts; } diff --git a/src/guis/GuiGameScraper.cpp b/src/guis/GuiGameScraper.cpp index cc84870a3..f2cae9480 100644 --- a/src/guis/GuiGameScraper.cpp +++ b/src/guis/GuiGameScraper.cpp @@ -29,7 +29,7 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std:: // buttons std::vector< std::shared_ptr > buttons; - buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search by name", [&] { + buttons.push_back(std::make_shared(mWindow, "INPUT", "search", [&] { mSearch->openInputScreen(mSearchParams); mGrid.resetCursor(); })); diff --git a/src/guis/GuiMenu.cpp b/src/guis/GuiMenu.cpp index a67544567..9f1fa393f 100644 --- a/src/guis/GuiMenu.cpp +++ b/src/guis/GuiMenu.cpp @@ -207,7 +207,7 @@ bool GuiMenu::input(InputConfig* config, Input input) std::vector GuiMenu::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("up/down", "move cursor")); - prompts.push_back(HelpPrompt("a", "accept")); + prompts.push_back(HelpPrompt("up/down", "move")); + prompts.push_back(HelpPrompt("a", "go")); return prompts; } diff --git a/src/guis/GuiMetaDataEd.cpp b/src/guis/GuiMetaDataEd.cpp index 98252686e..1e0274954 100644 --- a/src/guis/GuiMetaDataEd.cpp +++ b/src/guis/GuiMetaDataEd.cpp @@ -89,14 +89,14 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector } //add buttons - mMenu.addButton("SCRAPE", "download metadata from the Internet", std::bind(&GuiMetaDataEd::fetch, this)); - mMenu.addButton("SAVE", "save changes", [&] { save(); delete this; }); + mMenu.addButton("SCRAPE", "scrape", std::bind(&GuiMetaDataEd::fetch, this)); + mMenu.addButton("SAVE", "save", [&] { save(); delete this; }); if(mDeleteFunc) { auto deleteFileAndSelf = [&] { mDeleteFunc(); delete this; }; auto deleteBtnFunc = [this, deleteFileAndSelf] { mWindow->pushGui(new GuiMsgBox(mWindow, "This will delete a file!\nAre you sure?", "YES", deleteFileAndSelf, "NO", nullptr)); }; - mMenu.addButton("DELETE", "delete this game on disk", deleteBtnFunc); + mMenu.addButton("DELETE", "delete", deleteBtnFunc); } // initially put cursor on "SCRAPE" @@ -154,6 +154,6 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input) std::vector GuiMetaDataEd::getHelpPrompts() { std::vector prompts = mMenu.getHelpPrompts(); - prompts.push_back(HelpPrompt("b", "discard changes")); + prompts.push_back(HelpPrompt("b", "discard")); return prompts; } diff --git a/src/guis/GuiMsgBox.cpp b/src/guis/GuiMsgBox.cpp index 5f59a9d0b..7168c70c9 100644 --- a/src/guis/GuiMsgBox.cpp +++ b/src/guis/GuiMsgBox.cpp @@ -93,3 +93,8 @@ void GuiMsgBox::deleteMeAndCall(const std::function& func) delete this; } + +std::vector GuiMsgBox::getHelpPrompts() +{ + return mGrid.getHelpPrompts(); +} diff --git a/src/guis/GuiMsgBox.h b/src/guis/GuiMsgBox.h index bd95889de..d24c23459 100644 --- a/src/guis/GuiMsgBox.h +++ b/src/guis/GuiMsgBox.h @@ -15,8 +15,9 @@ public: const std::string& name2 = "", const std::function& func2 = nullptr, const std::string& name3 = "", const std::function& func3 = nullptr); - bool input(InputConfig* config, Input input); + bool input(InputConfig* config, Input input) override; void onSizeChanged() override; + std::vector getHelpPrompts() override; private: void deleteMeAndCall(const std::function& func); diff --git a/src/guis/GuiScraperMulti.cpp b/src/guis/GuiScraperMulti.cpp index 27cdb2b9c..a5017113e 100644 --- a/src/guis/GuiScraperMulti.cpp +++ b/src/guis/GuiScraperMulti.cpp @@ -33,12 +33,12 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue > buttons; - buttons.push_back(std::make_shared(mWindow, "INPUT", "manually search by name", [&] { + buttons.push_back(std::make_shared(mWindow, "INPUT", "search", [&] { mSearchComp->openInputScreen(mSearchQueue.front()); mGrid.resetCursor(); })); - buttons.push_back(std::make_shared(mWindow, "SKIP", "skip this game", std::bind(&GuiScraperMulti::skip, this))); - buttons.push_back(std::make_shared(mWindow, "STOP", "cancel scraping", std::bind(&GuiScraperMulti::finish, this))); + buttons.push_back(std::make_shared(mWindow, "SKIP", "skip", std::bind(&GuiScraperMulti::skip, this))); + buttons.push_back(std::make_shared(mWindow, "STOP", "stop (progress saved)", std::bind(&GuiScraperMulti::finish, this))); mButtonGrid = makeButtonGrid(mWindow, buttons); mGrid.setEntry(mButtonGrid, Vector2i(0, 3), true, false); diff --git a/src/guis/GuiScraperStart.cpp b/src/guis/GuiScraperStart.cpp index 8125c100a..033c17004 100644 --- a/src/guis/GuiScraperStart.cpp +++ b/src/guis/GuiScraperStart.cpp @@ -29,8 +29,8 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window), mApproveResults->setState(true); mMenu.addWithLabel("User decides on conflicts", mApproveResults); - mMenu.addButton("START", "start scraping", std::bind(&GuiScraperStart::pressedStart, this)); - mMenu.addButton("BACK", "cancel", [&] { delete this; }); + mMenu.addButton("START", "start", std::bind(&GuiScraperStart::pressedStart, this)); + mMenu.addButton("BACK", "back", [&] { delete this; }); mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); } @@ -102,6 +102,6 @@ bool GuiScraperStart::input(InputConfig* config, Input input) std::vector GuiScraperStart::getHelpPrompts() { std::vector prompts = mMenu.getHelpPrompts(); - prompts.push_back(HelpPrompt("b", "cancel")); + prompts.push_back(HelpPrompt("b", "back")); return prompts; } diff --git a/src/guis/GuiSettings.cpp b/src/guis/GuiSettings.cpp index 427c0976b..a57b85c6d 100644 --- a/src/guis/GuiSettings.cpp +++ b/src/guis/GuiSettings.cpp @@ -42,7 +42,7 @@ std::vector GuiSettings::getHelpPrompts() { std::vector prompts = mMenu.getHelpPrompts(); - prompts.push_back(HelpPrompt("b", "go back")); + prompts.push_back(HelpPrompt("b", "back")); return prompts; } diff --git a/src/guis/GuiTextEditPopup.cpp b/src/guis/GuiTextEditPopup.cpp index 74b076d90..7992e685b 100644 --- a/src/guis/GuiTextEditPopup.cpp +++ b/src/guis/GuiTextEditPopup.cpp @@ -56,4 +56,11 @@ bool GuiTextEditPopup::input(InputConfig* config, Input input) } return false; -} \ No newline at end of file +} + +std::vector GuiTextEditPopup::getHelpPrompts() +{ + std::vector prompts = mGrid.getHelpPrompts(); + prompts.push_back(HelpPrompt("b", "back")); + return prompts; +} diff --git a/src/guis/GuiTextEditPopup.h b/src/guis/GuiTextEditPopup.h index b891efb4f..aaa8a596d 100644 --- a/src/guis/GuiTextEditPopup.h +++ b/src/guis/GuiTextEditPopup.h @@ -14,6 +14,7 @@ public: bool input(InputConfig* config, Input input); void onSizeChanged(); + std::vector getHelpPrompts() override; private: NinePatchComponent mBackground; diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 6246553e8..9cf02ea1c 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -274,7 +274,7 @@ std::vector ViewController::getHelpPrompts() return prompts; prompts = mCurrentView->getHelpPrompts(); - prompts.push_back(HelpPrompt("start", "open menu")); + prompts.push_back(HelpPrompt("start", "menu")); return prompts; } diff --git a/src/views/gamelist/BasicGameListView.cpp b/src/views/gamelist/BasicGameListView.cpp index 24a3fa62f..4d4dc8e93 100644 --- a/src/views/gamelist/BasicGameListView.cpp +++ b/src/views/gamelist/BasicGameListView.cpp @@ -68,8 +68,8 @@ void BasicGameListView::launch(FileData* game) std::vector BasicGameListView::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("left/right", "change systems")); - prompts.push_back(HelpPrompt("up/down", "scroll")); + prompts.push_back(HelpPrompt("left/right", "switch")); + prompts.push_back(HelpPrompt("up/down", "choose")); prompts.push_back(HelpPrompt("a", "play")); prompts.push_back(HelpPrompt("b", "back")); return prompts;