Commit 4ef5f64f authored by Aloshi's avatar Aloshi

Added on-screen help system.

Very intrusive right now. You can turn it off in the Settings menu until
that gets worked out.
parent 752746b0
......@@ -164,6 +164,7 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentListComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageGridComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.h
......@@ -243,6 +244,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ButtonComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ComponentListComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/DateTimeComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.cpp
......@@ -292,6 +294,12 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/textbox_glow_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/star_filled_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/star_unfilled_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_a_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_b_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_menu_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_dpad_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_up_down_png.cpp
${CMAKE_CURRENT_SOURCE_DIR}/data/converted/help_left_right_png.cpp
)
SOURCE_GROUP(resources FILES ResourceUtil.cpp)
......
......@@ -2,7 +2,7 @@
#include "Resources.h"
const size_t res2hNrOfFiles = 8;
const size_t res2hNrOfFiles = 14;
const Res2hEntry res2hFiles[res2hNrOfFiles] = {
{":/button.png", button_png_size, button_png_data},
{":/ES_logo_16.png", ES_logo_16_png_size, ES_logo_16_png_data},
......@@ -11,7 +11,13 @@ const Res2hEntry res2hFiles[res2hNrOfFiles] = {
{":/star_filled.png", star_filled_png_size, star_filled_png_data},
{":/star_unfilled.png", star_unfilled_png_size, star_unfilled_png_data},
{":/textbox.png", textbox_png_size, textbox_png_data},
{":/textbox_glow.png", textbox_glow_png_size, textbox_glow_png_data}
{":/textbox_glow.png", textbox_glow_png_size, textbox_glow_png_data},
{":/help/a.png", help_a_png_size, help_a_png_data},
{":/help/b.png", help_b_png_size, help_b_png_data},
{":/help/dpad.png", help_dpad_png_size, help_dpad_png_data},
{":/help/left_right.png", help_left_right_png_size, help_left_right_png_data},
{":/help/menu.png", help_menu_png_size, help_menu_png_data},
{":/help/up_down.png", help_up_down_png_size, help_up_down_png_data}
};
res2hMapType::value_type mapTemp[] = {
......@@ -22,7 +28,13 @@ res2hMapType::value_type mapTemp[] = {
std::make_pair(":/star_filled.png", res2hFiles[4]),
std::make_pair(":/star_unfilled.png", res2hFiles[5]),
std::make_pair(":/textbox.png", res2hFiles[6]),
std::make_pair(":/textbox_glow.png", res2hFiles[7])
std::make_pair(":/textbox_glow.png", res2hFiles[7]),
std::make_pair(":/help/a.png", res2hFiles[8]),
std::make_pair(":/help/b.png", res2hFiles[9]),
std::make_pair(":/help/dpad.png", res2hFiles[10]),
std::make_pair(":/help/left_right.png", res2hFiles[11]),
std::make_pair(":/help/menu.png", res2hFiles[12]),
std::make_pair(":/help/up_down.png", res2hFiles[13])
};
res2hMapType res2hMap(mapTemp, mapTemp + sizeof mapTemp / sizeof mapTemp[0]);
......@@ -29,6 +29,24 @@ extern const unsigned char textbox_png_data[];
extern const size_t textbox_glow_png_size;
extern const unsigned char textbox_glow_png_data[];
extern const size_t help_a_png_size;
extern const unsigned char help_a_png_data[];
extern const size_t help_b_png_size;
extern const unsigned char help_b_png_data[];
extern const size_t help_dpad_png_size;
extern const unsigned char help_dpad_png_data[];
extern const size_t help_left_right_png_size;
extern const unsigned char help_left_right_png_data[];
extern const size_t help_menu_png_size;
extern const unsigned char help_menu_png_data[];
extern const size_t help_up_down_png_size;
extern const unsigned char help_up_down_png_data[];
struct Res2hEntry {
const std::string relativeFileName;
const size_t size;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -262,3 +262,17 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const std
if(properties & ThemeFlags::SIZE && elem->has("size"))
setSize(elem->get<Eigen::Vector2f>("size").cwiseProduct(scale));
}
void GuiComponent::updateHelpPrompts()
{
if(getParent())
{
getParent()->updateHelpPrompts();
return;
}
std::vector<HelpPrompt> prompts = getHelpPrompts();
if(mWindow->peekGui() == this)
mWindow->setHelpPrompts(prompts);
}
......@@ -10,6 +10,8 @@ class Animation;
class AnimationController;
class ThemeData;
typedef std::pair<const char*, const char*> HelpPrompt;
class GuiComponent
{
public:
......@@ -74,6 +76,12 @@ public:
// You probably want to keep this behavior for any derived classes as well as add your own.
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties);
// Returns a list of help prompts.
virtual std::vector<HelpPrompt> getHelpPrompts() { return std::vector<HelpPrompt>(); };
// Called whenever help prompts change.
void updateHelpPrompts();
protected:
void renderChildren(const Eigen::Affine3f& transform) const;
......
......@@ -33,6 +33,7 @@ void Settings::setDefaults()
mBoolMap["DEBUG"] = false;
mBoolMap["WINDOWED"] = false;
mBoolMap["DISABLESOUNDS"] = false;
mBoolMap["DISABLEHELP"] = false;
mBoolMap["DisableGamelistWrites"] = false;
mBoolMap["ScrapeRatings"] = true;
......
......@@ -7,12 +7,14 @@
#include "Settings.h"
#include <iomanip>
#include "views/ViewController.h"
#include "components/HelpComponent.h"
Window::Window() : mNormalizeNextUpdate(false), mFrameTimeElapsed(0), mFrameCountElapsed(0), mAverageDeltaTime(10),
mAllowSleep(true)
{
mInputManager = new InputManager(this);
mViewController = new ViewController(this);
mHelp = new HelpComponent(this);
pushGui(mViewController);
}
......@@ -24,12 +26,14 @@ Window::~Window()
while(peekGui())
delete peekGui();
delete mHelp;
delete mInputManager;
}
void Window::pushGui(GuiComponent* gui)
{
mGuiStack.push_back(gui);
setHelpPrompts(gui->getHelpPrompts());
}
void Window::removeGui(GuiComponent* gui)
......@@ -38,7 +42,11 @@ void Window::removeGui(GuiComponent* gui)
{
if(*i == gui)
{
mGuiStack.erase(i);
i = mGuiStack.erase(i);
if(i == mGuiStack.end() && mGuiStack.size()) // we just popped the stack and the stack is not empty
setHelpPrompts(mGuiStack.back()->getHelpPrompts());
return;
}
}
......@@ -49,7 +57,7 @@ GuiComponent* Window::peekGui()
if(mGuiStack.size() == 0)
return NULL;
return mGuiStack.at(mGuiStack.size() - 1);
return mGuiStack.back();
}
bool Window::init(unsigned int width, unsigned int height)
......@@ -72,6 +80,10 @@ bool Window::init(unsigned int width, unsigned int height)
mDefaultFonts.push_back(Font::get(FONT_SIZE_LARGE));
}
// update our help because font sizes probably changed
if(peekGui())
setHelpPrompts(peekGui()->getHelpPrompts());
return true;
}
......@@ -138,6 +150,8 @@ void Window::render()
mGuiStack.at(i)->render(transform);
}
mHelp->render(transform);
if(Settings::getInstance()->getBool("DRAWFRAMERATE"))
{
Renderer::setMatrix(Eigen::Affine3f::Identity());
......@@ -167,3 +181,16 @@ void Window::renderLoadingScreen()
mDefaultFonts.at(2)->drawCenteredText("LOADING", 0, (Renderer::getScreenHeight() - mDefaultFonts.at(2)->getHeight()) / 2.0f , 0xFFFFFFFF);
Renderer::swapBuffers();
}
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts)
{
mHelp->clearPrompts();
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);
}
}
......@@ -7,6 +7,7 @@
#include "resources/Font.h"
class ViewController;
class HelpComponent;
class Window
{
......@@ -35,9 +36,12 @@ public:
void renderLoadingScreen();
void setHelpPrompts(const std::vector<HelpPrompt>& prompts);
private:
InputManager* mInputManager;
ViewController* mViewController;
HelpComponent* mHelp;
std::vector<GuiComponent*> mGuiStack;
std::vector< std::shared_ptr<Font> > mDefaultFonts;
......
......@@ -42,3 +42,10 @@ void AsyncReqComponent::render(const Eigen::Affine3f& parentTrans)
Eigen::Vector3f point(cos(mTime * 0.01f) * 12, sin(mTime * 0.01f) * 12, 0);
Renderer::drawRect((int)point.x(), (int)point.y(), 8, 8, 0x0000FFFF);
}
std::vector<HelpPrompt> AsyncReqComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("b", "cancel"));
return prompts;
}
......@@ -35,6 +35,7 @@ public:
void update(int deltaTime) override;
void render(const Eigen::Affine3f& parentTrans) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
std::function<void(std::shared_ptr<HttpReq>)> mSuccessFunc;
std::function<void()> mCancelFunc;
......
......@@ -32,9 +32,10 @@ bool ButtonComponent::input(InputConfig* config, Input input)
return GuiComponent::input(config, input);
}
void ButtonComponent::setText(const std::string& text, unsigned int focusedColor, unsigned int unfocusedColor)
void ButtonComponent::setText(const std::string& text, const std::string& helpText, unsigned int focusedColor, unsigned int unfocusedColor)
{
mText = text;
mHelpText = helpText;
mTextColorFocused = focusedColor;
mTextColorUnfocused = unfocusedColor;
......@@ -42,6 +43,8 @@ void ButtonComponent::setText(const std::string& text, unsigned int focusedColor
mTextCache = std::unique_ptr<TextCache>(f->buildTextCache(mText, 0, 0, getCurTextColor()));
setSize(mTextCache->metrics.size + Eigen::Vector2f(12, 12));
updateHelpPrompts();
}
void ButtonComponent::onFocusGained()
......@@ -86,3 +89,10 @@ unsigned int ButtonComponent::getCurTextColor() const
else
return mTextColorFocused;
}
std::vector<HelpPrompt> ButtonComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("a", mHelpText.empty() ? mText.c_str() : mHelpText.c_str()));
return prompts;
}
......@@ -15,12 +15,14 @@ public:
bool input(InputConfig* config, Input input) override;
void render(const Eigen::Affine3f& parentTrans) override;
void setText(const std::string& text, unsigned int focusedTextColor, unsigned int unfocusedTextColor = 0x555555FF);
void setText(const std::string& text, const std::string& helpText, unsigned int focusedTextColor, unsigned int unfocusedTextColor = 0x555555FF);
void onSizeChanged() override;
void onFocusGained() override;
void onFocusLost() override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
std::shared_ptr<Font> getFont();
std::function<void()> mPressedFunc;
......@@ -33,6 +35,7 @@ private:
unsigned int getCurTextColor() const;
std::string mText;
std::string mHelpText;
std::unique_ptr<TextCache> mTextCache;
NinePatchComponent mBox;
};
......@@ -484,4 +484,40 @@ void ComponentListComponent::onCursorMoved(Eigen::Vector2i from, Eigen::Vector2i
if(to != Eigen::Vector2i(-1, -1))
getCell(to.x(), to.y())->component->onFocusGained();
updateHelpPrompts();
}
std::vector<HelpPrompt> ComponentListComponent::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
if(cursorValid())
prompts = getSelectedComponent()->getHelpPrompts();
bool canScrollVert = true;
bool canScrollHoriz = true;
for(auto it = prompts.begin(); it != prompts.end(); it++)
{
if(it->first == "up/down/left/right")
{
canScrollHoriz = false;
canScrollVert = false;
break;
}else if(it->first == "up/down")
{
canScrollVert = false;
}else if(it->first == "left/right")
{
canScrollHoriz = false;
}
}
if(canScrollHoriz && canScrollVert)
prompts.push_back(HelpPrompt("up/down/left/right", "move cursor"));
else if(canScrollHoriz)
prompts.push_back(HelpPrompt("left/right", "move cursor"));
else if(canScrollVert)
prompts.push_back(HelpPrompt("up/down", "move cursor"));
return prompts;
}
......@@ -43,6 +43,8 @@ public:
void moveCursor(Eigen::Vector2i dir);
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
class ComponentEntry
{
......
......@@ -41,10 +41,11 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
float sw = (float)Renderer::getScreenWidth();
float sh = (float)Renderer::getScreenHeight();
float colWidth = sw * 0.35f;
mList.forceColumnWidth(0, (unsigned int)colWidth);
mList.forceColumnWidth(1, (unsigned int)colWidth);
float listWidth = sw * 0.7f;
float col1Width = listWidth * 0.7f;
float col2Width = listWidth * 0.3f;
mList.forceColumnWidth(0, (unsigned int)col1Width);
mList.forceColumnWidth(1, (unsigned int)col2Width);
using namespace Eigen;
......@@ -57,20 +58,19 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
mList.setEntry(Vector2i(0, 1), Vector2i(1, 1), &mResultName, false, ComponentListComponent::AlignLeft);
mResultDesc.setText(params.game->metadata.get("desc"));
mResultDesc.setSize(colWidth, 0);
mResultDesc.setSize(col1Width, 0);
mResultInfo.addChild(&mResultDesc);
mResultInfo.setSize(mResultDesc.getSize().x(), mResultDesc.getFont()->getHeight() * 3.0f);
mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mResultInfo, false, ComponentListComponent::AlignLeft);
mResultThumbnail.setOrigin(0.5f, 0.5f);
mResultThumbnail.setMaxSize(colWidth, mResultInfo.getSize().y() + mResultName.getSize().y());
mList.setEntry(Vector2i(1, 1), Vector2i(1, 2), &mResultThumbnail, false, ComponentListComponent::AlignCenter);
mResultThumbnail.setMaxSize(col2Width, mResultInfo.getSize().y());
mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mResultThumbnail, false, ComponentListComponent::AlignCenter);
//y = 3 is a spacer row
mList.setEntry(Vector2i(0, 4), Vector2i(1, 1), &mSearchLabel, false, ComponentListComponent::AlignLeft);
mSearchText.setValue(!params.nameOverride.empty() ? params.nameOverride : getCleanFileName(params.game->getPath()));
mSearchText.setSize(colWidth * 2 - mSearchLabel.getSize().x() - 20, mSearchText.getSize().y());
mSearchText.setSize(listWidth - mSearchLabel.getSize().x() - 20, mSearchText.getSize().y());
mList.setEntry(Vector2i(1, 4), Vector2i(1, 1), &mSearchText, true, ComponentListComponent::AlignRight);
//y = 5 is a spacer row
......@@ -216,4 +216,15 @@ void GuiGameScraper::updateThumbnail()
}
mThumbnailReq.reset();
mList.onPositionChanged(); // a hack to fix the thumbnail position since its size changed
}
std::vector<HelpPrompt> GuiGameScraper::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mList.getHelpPrompts();
if(getSelectedIndex() != -1)
prompts.push_back(HelpPrompt("a", "accept result"));
prompts.push_back(HelpPrompt("b", "cancel/skip"));
return prompts;
}
......@@ -22,6 +22,9 @@ public:
void update(int deltaTime) override;
void search();
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
int getSelectedIndex();
void onSearchDone(std::vector<MetaDataList> results);
......
......@@ -29,7 +29,7 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
mHeader.setText(header);
//initialize buttons
mDeleteButton.setText("DELETE", mDeleteFunc ? 0xFF0000FF : 0x555555FF);
mDeleteButton.setText("DELETE", "delete file", mDeleteFunc ? 0xFF0000FF : 0x555555FF);
if(mDeleteFunc)
{
std::function<void()> deleteFileAndSelf = [&] { mDeleteFunc(); delete this; };
......@@ -37,10 +37,10 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector
mDeleteButton.setPressedFunc(pressedFunc);
}
mFetchButton.setText("FETCH", 0x00FF00FF);
mFetchButton.setText("FETCH", "download metadata", 0x00FF00FF);
mFetchButton.setPressedFunc(std::bind(&GuiMetaDataEd::fetch, this));
mSaveButton.setText("SAVE", 0x0000FFFF);
mSaveButton.setText("SAVE", "save", 0x0000FFFF);
mSaveButton.setPressedFunc([&] { save(); delete this; });
//initialize metadata list
......@@ -184,3 +184,10 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input)
return false;
}
std::vector<HelpPrompt> GuiMetaDataEd::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mList.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "discard changes"));
return prompts;
}
......@@ -18,6 +18,8 @@ public:
bool input(InputConfig* config, Input input) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
void save();
void fetch();
......
......@@ -44,7 +44,7 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
mList.setEntry(Vector2i(0, 2), Vector2i(1, 1), &mManualLabel, false, ComponentListComponent::AlignRight);
mList.setEntry(Vector2i(1, 2), Vector2i(1, 1), &mManualSwitch, true, ComponentListComponent::AlignLeft);
mStartButton.setText("GO GO GO GO", 0x00FF00FF);
mStartButton.setText("GO GO GO GO", "begin", 0x00FF00FF);
mStartButton.setPressedFunc(std::bind(&GuiScraperStart::pressedStart, this));
mList.setEntry(Vector2i(0, 3), Vector2i(2, 1), &mStartButton, true, ComponentListComponent::AlignCenter);
......@@ -116,3 +116,10 @@ bool GuiScraperStart::input(InputConfig* config, Input input)
return false;
}
std::vector<HelpPrompt> GuiScraperStart::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mList.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "cancel"));
return prompts;
}
......@@ -22,6 +22,8 @@ public:
bool input(InputConfig* config, Input input) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
void pressedStart();
void start();
......
......@@ -7,7 +7,7 @@
#include "../scrapers/GamesDBScraper.h"
GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
mList(window, Eigen::Vector2i(2, 7)),
mList(window, Eigen::Vector2i(2, 8)),
mBox(mWindow, ":/frame.png", 0x444444FF),
mDrawFramerateSwitch(window),
mVolumeSlider(window, 0, 100, 1, "%"),
......@@ -15,6 +15,7 @@ GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
mScraperOptList(window),
mScrapeRatingsSwitch(window),
mDimSlider(window, 0, 60, 1, "s"),
mDisableHelpSwitch(window),
mSaveButton(window)
{
loadStates();
......@@ -87,14 +88,20 @@ GuiSettingsMenu::GuiSettingsMenu(Window* window) : GuiComponent(window),
label->setColor(0x0000FFFF);
mLabels.push_back(label);
mList.setEntry(Vector2i(0, 5), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight);
// dim slider
mList.setEntry(Vector2i(1, 5), Vector2i(1, 1), &mDimSlider, true, ComponentListComponent::AlignCenter);
// disable help switch
label = new TextComponent(mWindow);
label->setText("Disable help: ");
label->setColor(0x0000FFFF);
mLabels.push_back(label);
mList.setEntry(Vector2i(0, 6), Vector2i(1, 1), label, false, ComponentListComponent::AlignRight);
mList.setEntry(Vector2i(1, 6), Vector2i(1, 1), &mDisableHelpSwitch, true, ComponentListComponent::AlignCenter);
//save button
mSaveButton.setText("SAVE", 0x00FF00FF);
mSaveButton.setText("SAVE", "apply & save", 0x00FF00FF);
mSaveButton.setPressedFunc([this] () { applyStates(); delete this; });
mList.setEntry(Vector2i(0, 6), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(false, true));
mList.setEntry(Vector2i(0, 7), Vector2i(2, 1), &mSaveButton, true, ComponentListComponent::AlignCenter, Matrix<bool, 1, 2>(false, true));
//center list
mList.setPosition(Renderer::getScreenWidth() / 2 - mList.getSize().x() / 2, Renderer::getScreenHeight() / 2 - mList.getSize().y() / 2);
......@@ -139,6 +146,8 @@ void GuiSettingsMenu::loadStates()
mScrapeRatingsSwitch.setState(s->getBool("ScrapeRatings"));
mDimSlider.setValue((float)(s->getInt("DIMTIME") / 1000));
mDisableHelpSwitch.setState(s->getBool("DISABLEHELP"));
}
void GuiSettingsMenu::applyStates()
......@@ -157,5 +166,14 @@ void GuiSettingsMenu::applyStates()
s->setInt("DIMTIME", (int)(mDimSlider.getValue() * 1000));
s->setBool("DISABLEHELP", mDisableHelpSwitch.getState());
s->saveFile();
}
std::vector<HelpPrompt> GuiSettingsMenu::getHelpPrompts()
{
std::vector<HelpPrompt> prompts = mList.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "discard changes"));
return prompts;
}
......@@ -20,6 +20,8 @@ public:
bool input(InputConfig* config, Input input) override;
std::vector<HelpPrompt> getHelpPrompts() override;
private:
void loadStates();
void applyStates();
......@@ -34,6 +36,7 @@ private:
OptionListComponent< std::shared_ptr<Scraper> > mScraperOptList;
SwitchComponent mScrapeRatingsSwitch;
SliderComponent mDimSlider;
SwitchComponent mDisableHelpSwitch;
ButtonComponent mSaveButton;
std::vector<GuiComponent*> mLabels;
......
#include "HelpComponent.h"
#include "../Renderer.h"
#include "ImageComponent.h"
#include "../resources/Font.h"
#include "../Settings.h"
#include "../Log.h"
#include <boost/assign.hpp>
static const std::map<std::string, const char*> ICON_PATH_MAP = boost::assign::map_list_of
("up/down", ":/help/up_down.png")
("left/right", ":/help/left_right.png")
("up/down/left/right", ":/help/dpad.png")
("a", ":/help/a.png")
("b", ":/help/b.png")
("menu", ":/help/menu.png");
HelpComponent::HelpComponent(Window* window) : GuiComponent(window)
{
}
void HelpComponent::clearPrompts()
{
mPrompts.clear();
}
void HelpComponent::addPrompt(const char* icon, const char* text)
{
if(Settings::getInstance()->getBool("DISABLEHELP"))
return;
Prompt p;
std::shared_ptr<Font> font = getFont();
// 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);
// 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));
mPrompts.push_back(p);
setPosition(0, (float)Renderer::getScreenHeight() - (p.icon->getPosition().y() + p.icon->getSize().y() + 6));
}
std::shared_ptr<Font> HelpComponent::getFont() const
{
// font size controls icon height
return Font::get(FONT_SIZE_SMALL);
}
std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
{
auto it = mIconCache.find(name);
if(it != mIconCache.end())
return it->second;
auto pathLookup = ICON_PATH_MAP.find(name);
if(pathLookup == ICON_PATH_MAP.end())
{
LOG(LogError) << "Unknown help icon \"" << name << "\"!";
return nullptr;
}
if(!ResourceManager::getInstance()->fileExists(pathLookup->second))
{
LOG(LogError) << "Help icon \"" << name << "\" - corresponding image file \"" << pathLookup->second << "\" misisng!";
return nullptr;
}
std::shared_ptr<TextureResource> tex = TextureResource::get(pathLookup->second);
mIconCache[std::string(name)] = tex;
return tex;
}