Skip to content

Commit

Permalink
added favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalLumberjack committed Jun 24, 2015
1 parent 3b28e2a commit 61eafba
Show file tree
Hide file tree
Showing 26 changed files with 424 additions and 47 deletions.
2 changes: 2 additions & 0 deletions GAMELISTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Some metadata is also marked as "statistic" - these are kept track of by ES and
* `players` - integer, the number of players the game supports.
* `playcount` - statistic, integer, the number of times this game has been played
* `lastplayed` - statistic, datetime, the last date and time this game was played.
* `favorite` - string, yes / no is this a favorite.


#### `<folder>`
Expand Down Expand Up @@ -85,3 +86,4 @@ Things to be Aware Of
* If at least one game in a system has an image specified, ES will use the detailed view for that system (which displays metadata alongside the game list).

* If you want to write your own scraper, the built-in scraping system is actually pretty extendable if you can get past the ugly function declarations and your instinctual fear of C++. Check out `src/scrapers/GamesDBScraper.cpp` for an example (it's less than a hundred lines of actual code). An offline scraper is also possible (though you'll have to subclass `ScraperRequest`). I hope to write a more complete guide on how to do this in the future.

6 changes: 6 additions & 0 deletions THEMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ Which is equivalent to:
<text name="md_lbl_playcount">
<color>48474D</color>
</text>
<text name="md_lbl_favorite">
<color>48474D</color>
</text>
</view>
</theme>
```
Expand Down Expand Up @@ -307,6 +310,7 @@ Reference
* `text name="md_lbl_players"` - ALL
* `text name="md_lbl_lastplayed"` - ALL
* `text name="md_lbl_playcount"` - ALL
* `text name="md_lbl_favorite"` - ALL

* Values
* All values will follow to the right of their labels if a position isn't specified.
Expand All @@ -329,6 +333,8 @@ Reference
- The "lastplayed" metadata. Displayed as a string representing the time relative to "now" (e.g. "3 hours ago").
* `text name="md_playcount"` - ALL
- The "playcount" metadata (number of times the game has been played).
* `text name="md_favorite"` - ALL
- The "favorite" metadata (is this game a favorite).
* `text name="md_description"` - POSITION | SIZE | FONT_PATH | FONT_SIZE | COLOR
- Text is the "desc" metadata. If no `pos`/`size` is specified, will move and resize to fit under the lowest label and reach to the bottom of the screen.

Expand Down
16 changes: 16 additions & 0 deletions es-app/src/FileData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask) const
return out;
}

std::vector<FileData*> FileData::getFavoritesRecursive(unsigned int typeMask) const
{
std::vector<FileData*> out;
std::vector<FileData*> files = getFilesRecursive(typeMask);

for (auto it = files.begin(); it != files.end(); it++)
{
if ((*it)->metadata.get("favorite").compare("yes") == 0)
{
out.push_back(*it);
}
}

return out;
}

void FileData::addChild(FileData* file)
{
assert(mType == FOLDER);
Expand Down
1 change: 1 addition & 0 deletions es-app/src/FileData.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FileData
virtual const std::string& getThumbnailPath() const;

std::vector<FileData*> getFilesRecursive(unsigned int typeMask) const;
std::vector<FileData*> getFavoritesRecursive(unsigned int typeMask) const;

void addChild(FileData* file); // Error if mType != FOLDER
void removeChild(FileData* file); //Error if mType != FOLDER
Expand Down
3 changes: 2 additions & 1 deletion es-app/src/MetaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ MetaDataDecl gameDecls[] = {
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
{"players", MD_INT, "1", false, "players", "enter number of players"},
{"playcount", MD_INT, "0", true, "play count", "enter number of times played"},
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"}
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"},
{"favorite", MD_STRING, "no", false, "favorite", "enter favorite"}
};
const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0]));

Expand Down
6 changes: 6 additions & 0 deletions es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ unsigned int SystemData::getGameCount() const
return mRootFolder->getFilesRecursive(GAME).size();
}

unsigned int SystemData::getFavoritesCount() const
{
return mRootFolder->getFavoritesRecursive(GAME).size();
}

void SystemData::loadTheme()
{
mTheme = std::make_shared<ThemeData>();
Expand All @@ -450,6 +455,7 @@ void SystemData::loadTheme()
try
{
mTheme->loadFile(path);
mHasFavorites = mTheme->getHasFavoritesInTheme();
} catch(ThemeException& e)
{
LOG(LogError) << e.what();
Expand Down
4 changes: 4 additions & 0 deletions es-app/src/SystemData.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SystemData
inline const std::string& getStartPath() const { return mStartPath; }
inline const std::vector<std::string>& getExtensions() const { return mSearchExtensions; }
inline const std::string& getThemeFolder() const { return mThemeFolder; }
inline bool getHasFavorites() const { return mHasFavorites; }

inline const std::vector<PlatformIds::PlatformId>& getPlatformIds() const { return mPlatformIds; }
inline bool hasPlatformId(PlatformIds::PlatformId id) { return std::find(mPlatformIds.begin(), mPlatformIds.end(), id) != mPlatformIds.end(); }
Expand All @@ -32,6 +33,7 @@ class SystemData
std::string getThemePath() const;

unsigned int getGameCount() const;
unsigned int getFavoritesCount() const;

void launchGame(Window* window, FileData* game);

Expand Down Expand Up @@ -74,6 +76,8 @@ class SystemData
std::string mThemeFolder;
std::shared_ptr<ThemeData> mTheme;

bool mHasFavorites;

void populateFolder(FileData* folder);

FileData* mRootFolder;
Expand Down
3 changes: 1 addition & 2 deletions es-app/src/guis/GuiFastSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class GuiFastSelect : public GuiComponent

bool input(InputConfig* config, Input input);
void update(int deltaTime);

virtual void setScrollDir(int dir);
private:
void setScrollDir(int dir);
void scroll();
void updateGameListCursor();
void updateGameListSort();
Expand Down
28 changes: 28 additions & 0 deletions es-app/src/guis/GuiGamelistOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "GuiGamelistOptions.h"
#include "GuiMetaDataEd.h"
#include "Settings.h"
#include "views/gamelist/IGameListView.h"
#include "views/ViewController.h"
#include "components/SwitchComponent.h"
#include "guis/GuiSettings.h"

GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : GuiComponent(window),
mSystem(system),
Expand Down Expand Up @@ -45,6 +48,11 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui

mMenu.addWithLabel("SORT GAMES BY", mListSort);

auto favorite_only = std::make_shared<SwitchComponent>(mWindow);
favorite_only->setState(Settings::getInstance()->getBool("FavoritesOnly"));
mMenu.addWithLabel("FAVORITES ONLY", favorite_only);
addSaveFunc([favorite_only] { Settings::getInstance()->setBool("FavoritesOnly", favorite_only->getState()); });

// edit game metadata
row.elements.clear();
row.addElement(std::make_shared<TextComponent>(mWindow, "EDIT THIS GAME'S METADATA", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
Expand All @@ -55,6 +63,8 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
// center the menu
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);

mFavoriteState = Settings::getInstance()->getBool("FavoritesOnly");
}

GuiGamelistOptions::~GuiGamelistOptions()
Expand All @@ -65,6 +75,12 @@ GuiGamelistOptions::~GuiGamelistOptions()

// notify that the root folder was sorted
getGamelist()->onFileChanged(root, FILE_SORTED);

if (Settings::getInstance()->getBool("FavoritesOnly") != mFavoriteState)
{
ViewController::get()->setAllInvalidGamesList(getGamelist()->getCursor()->getSystem());
ViewController::get()->reloadGameListView(getGamelist()->getCursor()->getSystem());
}
}

void GuiGamelistOptions::openMetaDataEd()
Expand Down Expand Up @@ -122,6 +138,7 @@ bool GuiGamelistOptions::input(InputConfig* config, Input input)
{
if((config->isMappedTo("b", input) || config->isMappedTo("select", input)) && input.value)
{
save();
delete this;
return true;
}
Expand All @@ -140,3 +157,14 @@ IGameListView* GuiGamelistOptions::getGamelist()
{
return ViewController::get()->getGameListView(mSystem).get();
}

void GuiGamelistOptions::save()
{
if (!mSaveFuncs.size())
return;

for (auto it = mSaveFuncs.begin(); it != mSaveFuncs.end(); it++)
(*it)();

Settings::getInstance()->saveFile();
}
10 changes: 10 additions & 0 deletions es-app/src/guis/GuiGamelistOptions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "GuiComponent.h"
#include "components/MenuComponent.h"
#include "components/OptionListComponent.h"
#include "components/SwitchComponent.h"
#include "FileSorts.h"

class IGameListView;
Expand All @@ -11,6 +12,9 @@ class GuiGamelistOptions : public GuiComponent
GuiGamelistOptions(Window* window, SystemData* system);
virtual ~GuiGamelistOptions();

void save();
inline void addSaveFunc(const std::function<void()>& func) { mSaveFuncs.push_back(func); };

virtual bool input(InputConfig* config, Input input) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;

Expand All @@ -20,11 +24,17 @@ class GuiGamelistOptions : public GuiComponent

MenuComponent mMenu;

std::vector< std::function<void()> > mSaveFuncs;

typedef OptionListComponent<char> LetterList;
std::shared_ptr<LetterList> mJumpToLetterList;

typedef OptionListComponent<const FileData::SortType*> SortList;
std::shared_ptr<SortList> mListSort;

std::shared_ptr<SwitchComponent> mFavoriteOption;

bool mFavoriteState;

SystemData* mSystem;
IGameListView* getGamelist();
Expand Down
32 changes: 18 additions & 14 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,34 @@ void SystemView::onCursorChanged(const CursorState& state)
}, (int)(infoStartOpacity * 150));

unsigned int gameCount = getSelected()->getGameCount();
unsigned int favoritesCount = getSelected()->getFavoritesCount();

// also change the text after we've fully faded out
setAnimation(infoFadeOut, 0, [this, gameCount] {
setAnimation(infoFadeOut, 0, [this, gameCount, favoritesCount] {
std::stringstream ss;

// only display a game count if there are at least 2 games
if(gameCount > 1)
if (gameCount > 1)
{
ss << gameCount << boost::locale::gettext(" GAMES AVAILABLE");
}

else if (favoritesCount > 1)
{
ss << ", " << favoritesCount << boost::locale::gettext(" FAVORITES");
}

mSystemInfo.setText(ss.str());
mSystemInfo.setText(ss.str());
}, false, 1);

// only display a game count if there are at least 2 games
if(gameCount > 1)
Animation* infoFadeIn = new LambdaAnimation(
[this](float t)
{
Animation* infoFadeIn = new LambdaAnimation(
[this](float t)
{
mSystemInfo.setOpacity((unsigned char)(lerp<float>(0.f, 1.f, t) * 255));
}, 300);
mSystemInfo.setOpacity((unsigned char)(lerp<float>(0.f, 1.f, t) * 255));
}, 300);

// wait 600ms to fade in
setAnimation(infoFadeIn, 2000, nullptr, false, 2);
}
// wait ms to fade in
setAnimation(infoFadeIn, 800, nullptr, false, 2);

// no need to animate transition, we're not going anywhere (probably mEntries.size() == 1)
if(endPos == mCamOffset && endPos == mExtrasCamOffset)
Expand Down
Loading

0 comments on commit 61eafba

Please sign in to comment.