Skip to content

Commit

Permalink
properly add favorites back
Browse files Browse the repository at this point in the history
  • Loading branch information
Cpasjuste committed Dec 7, 2019
1 parent f2bd63a commit e4085c3
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 165 deletions.
2 changes: 1 addition & 1 deletion sscrap
77 changes: 9 additions & 68 deletions ui/c2dui_romlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,8 @@ void RomList::build() {
ui->getConfig()->reset();
ui->getConfig()->load();

/*
* TODO: add/fix favorites back
// build favorites
std::string favPath = ui->getConfig()->getHomePath() + "favorites.bin";
std::ifstream favFile(favPath);
if (favFile.is_open()) {
std::string line;
while (std::getline(favFile, line)) {
auto rom = std::find_if(list.begin(), list.end(), [line](Rom *rom) -> bool {
return line == rom->path;
});
if (rom != list.end()) {
(*rom)->hardware |= HARDWARE_PREFIX_FAV;
}
}
favFile.close();
}
*/
gameListFav = GameList("favorites.xml", ui->getConfig()->getRomPaths().at(0));
printf("RomList::build: %zu favorites\n", gameListFav.games.size());

float time_spent = ui->getElapsedTime().asSeconds() - time_start;
printf("RomList::build(): list built in %f\n", time_spent);
Expand All @@ -138,64 +122,21 @@ void RomList::build() {
delete (rect);
}

void RomList::addFav(Game *rom) {
void RomList::addFav(const Game &game) {

/*
if (!rom || rom->hardware & HARDWARE_PREFIX_FAV) {
printf("RomList::addFav: already in favorites\n");
return;
if (!gameListFav.exist(game.romid)) {
gameListFav.games.emplace_back(game);
gameListFav.save("favorites.xml", Game::Language::EN, GameList::Format::ScreenScrapper);
}
rom->hardware |= HARDWARE_PREFIX_FAV;
std::string favPath = ui->getConfig()->getHomePath() + "favorites.bin";
std::ofstream favFile(favPath, std::ios::app);
if (favFile.is_open()) {
favFile << rom->path;
favFile << "\n";
favFile.close();
}
*/
}

void RomList::removeFav(Game *rom) {
void RomList::removeFav(const Game &game) {

/*
if (!rom || !(rom->hardware & HARDWARE_PREFIX_FAV)) {
printf("RomList::addFav: not in favorites\n");
return;
if (gameListFav.remove(game.romid)) {
gameListFav.save("favorites.xml", Game::Language::EN, GameList::Format::ScreenScrapper);
}
rom->hardware &= ~HARDWARE_PREFIX_FAV;
// TODO: only remove specific line ?
std::string favPath = ui->getConfig()->getHomePath() + "favorites.bin";
std::ofstream favFile(favPath, std::ios::trunc);
if (favFile.is_open()) {
for (auto &r : list) {
if (r->flags & HARDWARE_PREFIX_FAV) {
favFile << rom->path;
favFile << "\n";
}
}
favFile.close();
}
*/
}

RomList::~RomList() {

printf("~RomList()\n");

/*
for (auto &rom : list.games) {
if (rom && !rom->parent && rom->icon) {
delete (rom->icon);
rom->icon = nullptr;
}
if (rom) {
delete (rom);
}
}
*/
}
13 changes: 3 additions & 10 deletions ui/c2dui_romlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <vector>
#include "ss_gamelist.h"

#define HARDWARE_PREFIX_ALL 0xffffffff

namespace c2dui {

class UIMain;
Expand All @@ -24,20 +22,15 @@ namespace c2dui {

virtual void build();

void addFav(ss_api::Game *rom);

void removeFav(ss_api::Game *rom);
void addFav(const ss_api::Game &game);

enum RomState {
NOT_WORKING = 0,
MISSING,
WORKING
};
void removeFav(const ss_api::Game &game);

UIMain *ui;
c2d::RectangleShape *rect;
c2d::Text *text;
ss_api::GameList gameList;
ss_api::GameList gameListFav;
std::vector<std::string> paths;
char icon_path[1024];
char text_str[512];
Expand Down
59 changes: 39 additions & 20 deletions ui/c2dui_ui_romlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ using namespace c2d;
using namespace c2dui;
using namespace ss_api;

UIRomList::UIRomList(UIMain *u, RomList *romList, const c2d::Vector2f &size) : RectangleShape(size) {
UIRomList::UIRomList(UIMain *u, RomList *rList, const c2d::Vector2f &size) : RectangleShape(size) {

printf("UIRomList\n");

ui = u;
rom_list = romList;
gameList = rom_list->gameList;
romList = rList;
gameList = romList->gameList;
}

Game UIRomList::getSelection() {
return Game();
}

RomList *UIRomList::getRomList() {
return rom_list;
return romList;
}

Texture *UIRomList::getPreviewTexture(const ss_api::Game &game) {
Expand Down Expand Up @@ -68,27 +68,46 @@ Texture *UIRomList::getPreviewTexture(const ss_api::Game &game) {

void UIRomList::filterRomList() {

gameList = rom_list->gameList.filter(
ui->getConfig()->get(Option::Id::GUI_SHOW_ALL)->getValueString() == "AVAILABLE",
ui->getConfig()->get(Option::Id::GUI_FILTER_CLONES)->getValueBool(),
ui->getConfig()->get(Option::Id::GUI_FILTER_SYSTEM)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_EDITOR)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DEVELOPER)->getValueString(),

ui->getConfig()->get(Option::Id::GUI_FILTER_PLAYERS)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RATING)->getValueString(),
"All",
ui->getConfig()->get(Option::Id::GUI_FILTER_ROTATION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RESOLUTION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DATE)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_GENRE)->getValueString()
);
Option *opt = ui->getConfig()->get(Option::Id::GUI_SHOW_ALL);
if (opt->getValueString() == "FAVORITES") {
gameList = romList->gameListFav.filter(
false,
ui->getConfig()->get(Option::Id::GUI_FILTER_CLONES)->getValueBool(),
ui->getConfig()->get(Option::Id::GUI_FILTER_SYSTEM)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_EDITOR)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DEVELOPER)->getValueString(),

ui->getConfig()->get(Option::Id::GUI_FILTER_PLAYERS)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RATING)->getValueString(),
"All",
ui->getConfig()->get(Option::Id::GUI_FILTER_ROTATION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RESOLUTION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DATE)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_GENRE)->getValueString()
);
} else {
gameList = romList->gameList.filter(
ui->getConfig()->get(Option::Id::GUI_SHOW_ALL)->getValueString() == "AVAILABLE",
ui->getConfig()->get(Option::Id::GUI_FILTER_CLONES)->getValueBool(),
ui->getConfig()->get(Option::Id::GUI_FILTER_SYSTEM)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_EDITOR)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DEVELOPER)->getValueString(),

ui->getConfig()->get(Option::Id::GUI_FILTER_PLAYERS)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RATING)->getValueString(),
"All",
ui->getConfig()->get(Option::Id::GUI_FILTER_ROTATION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_RESOLUTION)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_DATE)->getValueString(),
ui->getConfig()->get(Option::Id::GUI_FILTER_GENRE)->getValueString()
);
}
}

void UIRomList::updateRomList() {
}

UIRomList::~UIRomList() {
printf("~UIRomList\n");
delete (rom_list);
delete (romList);
}
2 changes: 1 addition & 1 deletion ui/c2dui_ui_romlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace c2dui {
protected:

UIMain *ui = nullptr;
RomList *rom_list = nullptr;
RomList *romList = nullptr;
ss_api::GameList gameList;
};
}
Expand Down
Loading

0 comments on commit e4085c3

Please sign in to comment.