Added functionality to show favorites on top of the gamelists (mostly ported from batocera-emulationstation)

This commit is contained in:
Leon Styhre 2020-05-15 17:42:36 +02:00
parent 37dd9874f2
commit 1007f19bdc
8 changed files with 98 additions and 9 deletions

View file

@ -258,6 +258,10 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
if (name == "favorites" && file->metadata.get("favorite") == "false") {
// need to check if still marked as favorite, if not remove
ViewController::get()->getGameListView(curSys).get()->remove(collectionEntry, false);
// Send an event when removing from favorites
ViewController::get()->onFileChanged(file, FILE_METADATA_CHANGED);
ViewController::get()->getGameListView(curSys)->onFileChanged(collectionEntry, FILE_METADATA_CHANGED);
}
else
{

View file

@ -7,7 +7,7 @@
#define PROGRAM_VERSION_MAJOR 2
#define PROGRAM_VERSION_MINOR 10
#define PROGRAM_VERSION_MAINTENANCE 0
#define PROGRAM_VERSION_STRING "2.10.0rp-dev"
#define PROGRAM_VERSION_STRING "2.10.0DE-dev"
#define PROGRAM_BUILT_STRING __DATE__ " - " __TIME__

View file

@ -79,6 +79,7 @@ const std::string FileData::getThumbnailPath() const
return thumbnail;
}
const std::string& FileData::getName()
{
return metadata.get("name");
@ -92,6 +93,14 @@ const std::string& FileData::getSortName()
return metadata.get("sortname");
}
const bool FileData::getFavorite()
{
if (metadata.get("favorite") == "true")
return true;
else
return false;
}
const std::vector<FileData*>& FileData::getChildrenListToDisplay() {
FileFilterIndex* idx = CollectionSystemManager::get()->getSystemToView(mSystem)->getIndex();

View file

@ -38,6 +38,7 @@ public:
virtual const std::string& getName();
virtual const std::string& getSortName();
virtual const bool getFavorite();
inline FileType getType() const { return mType; }
inline const std::string& getPath() const { return mPath; }
inline FileData* getParent() const { return mParent; }

View file

@ -372,6 +372,16 @@ void GuiMenu::openUISettings()
s->addWithLabel("DISABLE START MENU IN KID MODE", disable_start);
s->addSaveFunc([disable_start] { Settings::getInstance()->setBool("DisableKidStartMenu", disable_start->getState()); });
// Show favorites first in gamelists
auto favoritesFirstSwitch = std::make_shared<SwitchComponent>(mWindow);
favoritesFirstSwitch->setState(Settings::getInstance()->getBool("FavoritesFirst"));
s->addWithLabel("SHOW FAVORITES ON TOP OF GAMELIST", favoritesFirstSwitch);
s->addSaveFunc([favoritesFirstSwitch]
{
if (Settings::getInstance()->setBool("FavoritesFirst", favoritesFirstSwitch->getState()))
ViewController::get()->reloadAll();
});
mWindow->pushGui(s);
}
@ -487,6 +497,7 @@ void GuiMenu::openQuitMenu()
ComponentListRow row;
if (UIModeController::getInstance()->isUIModeFull())
{
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
[] {
@ -514,6 +525,7 @@ void GuiMenu::openQuitMenu()
s->addRow(row);
}
}
row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
@ -527,6 +539,8 @@ void GuiMenu::openQuitMenu()
row.addElement(std::make_shared<TextComponent>(window, "RESTART SYSTEM", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
s->addRow(row);
row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",

View file

@ -45,9 +45,57 @@ void BasicGameListView::populateList(const std::vector<FileData*>& files)
mHeaderText.setText(mRoot->getSystem()->getFullName());
if (files.size() > 0)
{
for(auto it = files.cbegin(); it != files.cend(); it++)
std::string systemName = mRoot->getSystem()->getName();
bool favoritesFirst = Settings::getInstance()->getBool("FavoritesFirst");
// auto fav = Settings::getInstance()->getString(mRoot->getSystem()->getName() + ".FavoritesFirst");
// if (fav == "1") favoritesFirst = true;
// else if (fav == "0") favoritesFirst = false;
bool showFavoriteIcon = (systemName != "favorites" && systemName != "recent");
if (!showFavoriteIcon)
favoritesFirst = false;
if (favoritesFirst)
{
mList.add((*it)->getName(), *it, ((*it)->getType() == FOLDER));
for (auto file : files)
{
if (!file->getFavorite())
continue;
if (showFavoriteIcon)
// mList.add(("\uF006 ") + file->getName(), file, file->getType() == FOLDER);
// Quick fix for now until I've fixed the issue with Unicode rendering (Leon)
mList.add("** " + file->getName(), file, file->getType() == FOLDER);
else if (file->getType() == FOLDER)
mList.add(("\uF07C ") + file->getName(), file, true);
else
mList.add(file->getName(), file, false);
}
}
for (auto file : files)
{
if (file->getFavorite())
{
if (favoritesFirst)
continue;
if (showFavoriteIcon)
{
// mList.add(("\uF006 ") + file->getName(), file, file->getType() == FOLDER);
// Quick fix for now until I've fixed the issue with Unicode rendering (Leon)
mList.add(("** ") + file->getName(), file, file->getType() == FOLDER);
continue;
}
}
if (file->getType() == FOLDER)
mList.add(("\uF07C ") + file->getName(), file, true);
else
mList.add(file->getName(), file, false);
}
}
else

View file

@ -38,6 +38,7 @@ std::vector<const char*> settings_dont_save {
Settings::Settings()
{
mWasChanged = false;
setDefaults();
loadFile();
}
@ -139,6 +140,8 @@ void Settings::setDefaults()
mBoolMap["SortAllSystems"] = false;
mBoolMap["UseCustomCollectionsSystem"] = true;
mBoolMap["FavoritesFirst"] = true;
mBoolMap["LocalArt"] = false;
// Audio out device for volume control
@ -251,9 +254,17 @@ void Settings::processBackwardCompatibility()
} \
return mapName[name]; \
} \
void Settings::setMethodName(const std::string& name, type value) \
bool Settings::setMethodName(const std::string& name, type value) \
{ \
mapName[name] = value; \
if (mapName.count(name) == 0 || mapName[name] != value) { \
mapName[name] = value; \
\
if (std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) == settings_dont_save.cend()) \
mWasChanged = true; \
\
return true; \
} \
return false; \
}
SETTINGS_GETSET(bool, mBoolMap, getBool, setBool);

View file

@ -19,10 +19,10 @@ public:
float getFloat(const std::string& name);
const std::string& getString(const std::string& name);
void setBool(const std::string& name, bool value);
void setInt(const std::string& name, int value);
void setFloat(const std::string& name, float value);
void setString(const std::string& name, const std::string& value);
bool setBool(const std::string& name, bool value);
bool setInt(const std::string& name, int value);
bool setFloat(const std::string& name, float value);
bool setString(const std::string& name, const std::string& value);
private:
static Settings* sInstance;
@ -33,6 +33,8 @@ private:
void setDefaults();
void processBackwardCompatibility();
bool mWasChanged;
std::map<std::string, bool> mBoolMap;
std::map<std::string, int> mIntMap;
std::map<std::string, float> mFloatMap;