Commit 7ca0b0fe authored by Aloshi's avatar Aloshi

Help is now horizontal instead of vertical.

Shortened most help texts.
parent c3d69332
......@@ -214,11 +214,15 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts)
{
mHelp->clearPrompts();
std::vector<HelpPrompt> addPrompts;
std::map<std::string, bool> 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<std::string, bool>(it->first, true)).second)
mHelp->addPrompt(it->first, it->second);
addPrompts.push_back(*it);
}
mHelp->setPrompts(addPrompts);
}
......@@ -436,11 +436,11 @@ std::vector<HelpPrompt> 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;
}
......@@ -288,7 +288,25 @@ std::vector<HelpPrompt> ComponentList::getHelpPrompts()
if(!size())
return std::vector<HelpPrompt>();
return mEntries.at(mCursor).data.elements.back().component->getHelpPrompts();
std::vector<HelpPrompt> 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)
......
#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 <boost/assign.hpp>
#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<std::string, const char*> 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<HelpPrompt>& prompts)
{
if(!Settings::getInstance()->getBool("ShowHelpPrompts"))
return;
mPrompts = prompts;
updateGrid();
}
Prompt p;
void HelpComponent::updateGrid()
{
if(!Settings::getInstance()->getBool("ShowHelpPrompts") || mPrompts.empty())
{
mGrid.reset();
return;
}
std::shared_ptr<Font> font = getFont();
mGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(mPrompts.size() * 4, 1));
// [icon] [spacer1] [text] [spacer2]
// make the icon
p.icon = std::shared_ptr<ImageComponent>(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 = Font::get(FONT_SIZE_SMALL);
// make the text
const float textY = (p.icon->getSize().y() - (float)font->getHeight())/2;
p.textCache = std::shared_ptr<TextCache>(font->buildTextCache(text, p.icon->getSize().x() + 6, textY, 0x888888EE));
std::vector< std::shared_ptr<ImageComponent> > icons;
std::vector< std::shared_ptr<TextComponent> > 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<ImageComponent>(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<TextComponent>(mWindow, strToUpper(it->second), font, 0x777777FF);
labels.push_back(lbl);
std::shared_ptr<Font> 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<TextureResource> 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> 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);
}
......@@ -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<HelpPrompt>& prompts);
void render(const Eigen::Affine3f& parent) override;
private:
std::shared_ptr<Font> getFont() const;
std::shared_ptr<TextureResource> getIconTexture(const char* name);
std::map< std::string, std::shared_ptr<TextureResource> > mIconCache;
struct Prompt
{
std::shared_ptr<ImageComponent> icon;
std::shared_ptr<TextCache> textCache;
};
std::shared_ptr<ComponentGrid> mGrid;
void updateGrid();
std::vector<Prompt> mPrompts;
std::vector<HelpPrompt> mPrompts;
};
......@@ -154,6 +154,6 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const
std::vector<HelpPrompt> RatingComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("a", "+1 star"));
prompts.push_back(HelpPrompt("a", "add star"));
return prompts;
}
......@@ -140,6 +140,6 @@ void SliderComponent::onValueChanged()
std::vector<HelpPrompt> SliderComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("left/right", "adjust"));
prompts.push_back(HelpPrompt("left/right", "change"));
return prompts;
}
......@@ -55,6 +55,6 @@ void SwitchComponent::onStateChanged()
std::vector<HelpPrompt> SwitchComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("a", "toggle"));
prompts.push_back(HelpPrompt("a", "change"));
return prompts;
}
......@@ -29,7 +29,7 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
// buttons
std::vector< std::shared_ptr<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search by name", [&] {
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearch->openInputScreen(mSearchParams);
mGrid.resetCursor();
}));
......
......@@ -207,7 +207,7 @@ bool GuiMenu::input(InputConfig* config, Input input)
std::vector<HelpPrompt> GuiMenu::getHelpPrompts()
{
std::vector<HelpPrompt> 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;
}
......@@ -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<HelpPrompt> GuiMetaDataEd::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "discard changes"));
prompts.push_back(HelpPrompt("b", "discard"));
return prompts;
}
......@@ -93,3 +93,8 @@ void GuiMsgBox::deleteMeAndCall(const std::function<void()>& func)
delete this;
}
std::vector<HelpPrompt> GuiMsgBox::getHelpPrompts()
{
return mGrid.getHelpPrompts();
}
......@@ -15,8 +15,9 @@ public:
const std::string& name2 = "", const std::function<void()>& func2 = nullptr,
const std::string& name3 = "", const std::function<void()>& func3 = nullptr);
bool input(InputConfig* config, Input input);
bool input(InputConfig* config, Input input) override;
void onSizeChanged() override;
std::vector<HelpPrompt> getHelpPrompts() override;
private:
void deleteMeAndCall(const std::function<void()>& func);
......
......@@ -33,12 +33,12 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP
mGrid.setEntry(mSearchComp, Vector2i(0, 2), approveResults, true);
std::vector< std::shared_ptr<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "manually search by name", [&] {
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearchComp->openInputScreen(mSearchQueue.front());
mGrid.resetCursor();
}));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip this game", std::bind(&GuiScraperMulti::skip, this)));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP", "cancel scraping", std::bind(&GuiScraperMulti::finish, this)));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip", std::bind(&GuiScraperMulti::skip, this)));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP", "stop (progress saved)", std::bind(&GuiScraperMulti::finish, this)));
mButtonGrid = makeButtonGrid(mWindow, buttons);
mGrid.setEntry(mButtonGrid, Vector2i(0, 3), true, false);
......
......@@ -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<HelpPrompt> GuiScraperStart::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "cancel"));
prompts.push_back(HelpPrompt("b", "back"));
return prompts;
}
......@@ -42,7 +42,7 @@ std::vector<HelpPrompt> GuiSettings::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "go back"));
prompts.push_back(HelpPrompt("b", "back"));
return prompts;
}
......@@ -56,4 +56,11 @@ bool GuiTextEditPopup::input(InputConfig* config, Input input)
}
return false;
}
\ No newline at end of file
}
std::vector<HelpPrompt> GuiTextEditPopup::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "back"));
return prompts;
}
......@@ -14,6 +14,7 @@ public:
bool input(InputConfig* config, Input input);
void onSizeChanged();
std::vector<HelpPrompt> getHelpPrompts() override;
private:
NinePatchComponent mBackground;
......
......@@ -274,7 +274,7 @@ std::vector<HelpPrompt> ViewController::getHelpPrompts()
return prompts;
prompts = mCurrentView->getHelpPrompts();
prompts.push_back(HelpPrompt("start", "open menu"));
prompts.push_back(HelpPrompt("start", "menu"));
return prompts;
}
......@@ -68,8 +68,8 @@ void BasicGameListView::launch(FileData* game)
std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
{
std::vector<HelpPrompt> 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment