Skip to content

Commit

Permalink
Made the help system themable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloshi committed May 29, 2014
1 parent 09312a5 commit 4439bec
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/FileSorts.h
${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/HelpStyle.h
${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ImageIO.h
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.h
Expand Down Expand Up @@ -232,6 +233,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/FileSorts.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HelpStyle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ImageIO.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/InputConfig.cpp
Expand Down
37 changes: 15 additions & 22 deletions THEMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ Reference
## Views, their elements, and themable properties:

#### basic
* `helpsystem name="help"` - ALL
- The help system style for this view.
* `image name="background"` - ALL
- This is a background image that exists for convenience. It goes from (0, 0) to (1, 1).
* `text name="logoText"` - ALL
Expand All @@ -282,6 +284,8 @@ Reference
---

#### detailed
* `helpsystem name="help"` - ALL
- The help system style for this view.
* `image name="background"` - ALL
- This is a background image that exists for convenience. It goes from (0, 0) to (1, 1).
* `text name="logoText"` - ALL
Expand Down Expand Up @@ -329,6 +333,8 @@ Reference
---

#### grid
* `helpsystem name="help"` - ALL
- The help system style for this view.
* `image name="background"` - ALL
- This is a background image that exists for convenience. It goes from (0, 0) to (1, 1).
* `text name="logoText"` - ALL
Expand All @@ -339,32 +345,12 @@ Reference
---

#### system
* `helpsystem name="help"` - ALL
- The help system style for this view.
* `image name="logo"` - PATH
- A logo image, to be displayed in the system logo carousel.
* You can use extra elements (elements with `extra="true"`) to add your own backgrounds, etc. They will be displayed behind the carousel, and scroll relative to the carousel.

---

#### fastSelect
* `ninepatch name="windowBackground"` - PATH
- Fit around the fast select UI as a background.
* `text name="letter"` - FONT_PATH | COLOR
- The big letter that shows what letter you'll jump to when you let go of the fast select button.
* `text name="subtext"` - FONT_PATH | COLOR
- The text that displays the current sort mode.

---

#### menu
* `ninepatch name="windowBackground"` - PATH
- Background for the menu. Fit from top-left corner at (0.175, 0.05) to bottom-right corner at (0.825, 0.95).
* `textlist name="menulist"` - FONT_PATH | COLOR | SOUND
- The list of menu options. `primaryColor` is for most options, `secondaryColor` is for the "shutdown" option.
* `sound name="menuOpen"` - PATH
- Played when the menu opens.
* `sound name="menuClose"` - PATH
- Played when the menu closes.


## Types of properties:

Expand Down Expand Up @@ -479,7 +465,14 @@ EmulationStation borrows the concept of "nine patches" from Android (or "9-Slice
* `path` - type: PATH.
- Path to the sound file. Only .wav files are currently supported.

#### helpsystem

* `pos` - type: NORMALIZED_PAIR.
* `textColor` - type: COLOR.
* `fontPath` - type: PATH.
* `fontSize` - type: FLOAT.

The help system is a special element that displays a context-sensitive list of actions the user can take at any time. You should try and keep the position constant throughout every screen. Keep in mind the "default" settings (including position) are used whenever the user opens a menu.

[*Check out the "official" themes for some more examples!*](http://aloshi.com/emulationstation#themes)

Expand Down
9 changes: 7 additions & 2 deletions src/GuiComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void GuiComponent::setOpacity(unsigned char opacity)
}
}

const Eigen::Affine3f GuiComponent::getTransform()
const Eigen::Affine3f& GuiComponent::getTransform()
{
mTransform.setIdentity();
mTransform.translate(mPosition);
Expand Down Expand Up @@ -325,5 +325,10 @@ void GuiComponent::updateHelpPrompts()
std::vector<HelpPrompt> prompts = getHelpPrompts();

if(mWindow->peekGui() == this)
mWindow->setHelpPrompts(prompts);
mWindow->setHelpPrompts(prompts, getHelpStyle());
}

HelpStyle GuiComponent::getHelpStyle()
{
return HelpStyle();
}
11 changes: 6 additions & 5 deletions src/GuiComponent.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef _GUICOMPONENT_H_
#define _GUICOMPONENT_H_
#pragma once

#include "InputConfig.h"
#include <memory>
#include <Eigen/Dense>
#include "HelpStyle.h"

class Window;
class Animation;
class AnimationController;
class ThemeData;
class Font;

typedef std::pair<const char*, const char*> HelpPrompt;

Expand Down Expand Up @@ -69,7 +70,7 @@ class GuiComponent
virtual unsigned char getOpacity() const;
virtual void setOpacity(unsigned char opacity);

const Eigen::Affine3f getTransform();
const Eigen::Affine3f& getTransform();

virtual std::string getValue() const;
virtual void setValue(const std::string& value);
Expand All @@ -86,6 +87,8 @@ class GuiComponent

// Called whenever help prompts change.
void updateHelpPrompts();

virtual HelpStyle getHelpStyle();

protected:
void renderChildren(const Eigen::Affine3f& transform) const;
Expand All @@ -106,5 +109,3 @@ class GuiComponent
Eigen::Affine3f mTransform; //Don't access this directly! Use getTransform()!
AnimationController* mAnimationMap[MAX_ANIMATIONS];
};

#endif
28 changes: 28 additions & 0 deletions src/HelpStyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "HelpStyle.h"
#include "ThemeData.h"
#include "Renderer.h"
#include "resources/Font.h"

HelpStyle::HelpStyle()
{
position = Eigen::Vector2f(12.0f, Renderer::getScreenHeight() * 0.955f);
iconColor = 0x777777FF;
textColor = 0x777777FF;
font = Font::get(FONT_SIZE_SMALL);
}

void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view)
{
auto elem = theme->getElement(view, "help", "helpsystem");
if(!elem)
return;

if(elem->has("pos"))
position = elem->get<Eigen::Vector2f>("pos").cwiseProduct(Eigen::Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()));

if(elem->has("textColor"))
textColor = elem->get<unsigned int>("textColor");

if(elem->has("fontPath") || elem->has("fontSize"))
font = Font::getFromTheme(elem, ThemeFlags::ALL, font);
}
19 changes: 19 additions & 0 deletions src/HelpStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <Eigen/Dense>
#include <memory>
#include <string>

class ThemeData;
class Font;

struct HelpStyle
{
Eigen::Vector2f position;
unsigned int iconColor;
unsigned int textColor;
std::shared_ptr<Font> font;

HelpStyle(); // default values
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view);
};
7 changes: 6 additions & 1 deletion src/ThemeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
("filledPath", PATH)
("unfilledPath", PATH)))
("sound", makeMap(boost::assign::map_list_of
("path", PATH)));
("path", PATH)))
("helpsystem", makeMap(boost::assign::map_list_of
("pos", NORMALIZED_PAIR)
("textColor", COLOR)
("fontPath", PATH)
("fontSize", FLOAT)));

namespace fs = boost::filesystem;

Expand Down
9 changes: 5 additions & 4 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Window::~Window()
void Window::pushGui(GuiComponent* gui)
{
mGuiStack.push_back(gui);
setHelpPrompts(gui->getHelpPrompts());
gui->updateHelpPrompts();
}

void Window::removeGui(GuiComponent* gui)
Expand All @@ -49,7 +49,7 @@ void Window::removeGui(GuiComponent* gui)
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());
mGuiStack.back()->updateHelpPrompts();

return;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ bool Window::init(unsigned int width, unsigned int height)

// update our help because font sizes probably changed
if(peekGui())
setHelpPrompts(peekGui()->getHelpPrompts());
peekGui()->updateHelpPrompts();

return true;
}
Expand Down Expand Up @@ -257,9 +257,10 @@ void Window::renderHelpPromptsEarly()
mRenderedHelpPrompts = true;
}

void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts)
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style)
{
mHelp->clearPrompts();
mHelp->setStyle(style);

std::vector<HelpPrompt> addPrompts;

Expand Down
2 changes: 1 addition & 1 deletion src/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Window
void renderLoadingScreen();

void renderHelpPromptsEarly(); // used by ViewController to render HelpPrompts before a fade
void setHelpPrompts(const std::vector<HelpPrompt>& prompts);
void setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpStyle& style);

private:
ViewController* mViewController;
Expand Down
15 changes: 11 additions & 4 deletions src/components/HelpComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ void HelpComponent::setPrompts(const std::vector<HelpPrompt>& prompts)
updateGrid();
}

void HelpComponent::setStyle(const HelpStyle& style)
{
mStyle = style;
updateGrid();
}

void HelpComponent::updateGrid()
{
if(!Settings::getInstance()->getBool("ShowHelpPrompts") || mPrompts.empty())
Expand All @@ -54,10 +60,10 @@ void HelpComponent::updateGrid()
return;
}

std::shared_ptr<Font>& font = mStyle.font;

mGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(mPrompts.size() * 4, 1));
// [icon] [spacer1] [text] [spacer2]

std::shared_ptr<Font> font = Font::get(FONT_SIZE_SMALL);

std::vector< std::shared_ptr<ImageComponent> > icons;
std::vector< std::shared_ptr<TextComponent> > labels;
Expand All @@ -71,7 +77,7 @@ void HelpComponent::updateGrid()
icon->setResize(0, height);
icons.push_back(icon);

auto lbl = std::make_shared<TextComponent>(mWindow, strToUpper(it->second), font, 0x777777FF);
auto lbl = std::make_shared<TextComponent>(mWindow, strToUpper(it->second), font, mStyle.textColor);
labels.push_back(lbl);

width += icon->getSize().x() + lbl->getSize().x() + ICON_TEXT_SPACING + ENTRY_SPACING;
Expand All @@ -89,7 +95,8 @@ void HelpComponent::updateGrid()
mGrid->setEntry(labels.at(i), Vector2i(col + 2, 0), false, false);
}

mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y);
mGrid->setPosition(Eigen::Vector3f(mStyle.position.x(), mStyle.position.y(), 0.0f));
//mGrid->setPosition(OFFSET_X, Renderer::getScreenHeight() - mGrid->getSize().y() - OFFSET_Y);
}

std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
Expand Down
4 changes: 4 additions & 0 deletions src/components/HelpComponent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../GuiComponent.h"
#include "../HelpStyle.h"

class ImageComponent;
class TextureResource;
Expand All @@ -17,6 +18,8 @@ class HelpComponent : public GuiComponent
void render(const Eigen::Affine3f& parent) override;
void setOpacity(unsigned char opacity) override;

void setStyle(const HelpStyle& style);

private:
std::shared_ptr<TextureResource> getIconTexture(const char* name);
std::map< std::string, std::shared_ptr<TextureResource> > mIconCache;
Expand All @@ -25,4 +28,5 @@ class HelpComponent : public GuiComponent
void updateGrid();

std::vector<HelpPrompt> mPrompts;
HelpStyle mStyle;
};
7 changes: 7 additions & 0 deletions src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,10 @@ std::vector<HelpPrompt> SystemView::getHelpPrompts()
prompts.push_back(HelpPrompt("a", "select"));
return prompts;
}

HelpStyle SystemView::getHelpStyle()
{
HelpStyle style;
style.applyTheme(mEntries.at(mCursor).object->getTheme(), "system");
return style;
}
3 changes: 2 additions & 1 deletion src/views/SystemView.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SystemView : public IList<SystemViewData, SystemData*>
void render(const Eigen::Affine3f& parentTrans) override;

std::vector<HelpPrompt> getHelpPrompts() override;

virtual HelpStyle getHelpStyle() override;

protected:
void onCursorChanged(const CursorState& state) override;

Expand Down
8 changes: 8 additions & 0 deletions src/views/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,11 @@ std::vector<HelpPrompt> ViewController::getHelpPrompts()

return prompts;
}

HelpStyle ViewController::getHelpStyle()
{
if(!mCurrentView)
return GuiComponent::getHelpStyle();

return mCurrentView->getHelpStyle();
}
1 change: 1 addition & 0 deletions src/views/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ViewController : public GuiComponent
inline const State& getState() const { return mState; }

virtual std::vector<HelpPrompt> getHelpPrompts() override;
virtual HelpStyle getHelpStyle() override;

std::shared_ptr<IGameListView> getGameListView(SystemData* system);
std::shared_ptr<SystemView> getSystemListView();
Expand Down
7 changes: 7 additions & 0 deletions src/views/gamelist/IGameListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ void IGameListView::setTheme(const std::shared_ptr<ThemeData>& theme)
mTheme = theme;
onThemeChanged(theme);
}

HelpStyle IGameListView::getHelpStyle()
{
HelpStyle style;
style.applyTheme(mTheme, getName());
return style;
}
2 changes: 2 additions & 0 deletions src/views/gamelist/IGameListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class IGameListView : public GuiComponent
virtual bool input(InputConfig* config, Input input) override;

virtual const char* getName() const = 0;

virtual HelpStyle getHelpStyle() override;
protected:
FileData* mRoot;
std::shared_ptr<ThemeData> mTheme;
Expand Down

0 comments on commit 4439bec

Please sign in to comment.