Give priority to parent art over default art. Menu code still WIP.

This commit is contained in:
Pieter Hulshoff 2018-10-02 21:49:46 +02:00
parent 3dabe7e0a8
commit 51da8ad436
12 changed files with 149 additions and 45 deletions

View File

@ -155,6 +155,7 @@ void CollectionInfo::extensionList(std::vector<std::string> &extensionlist)
while(std::getline(ss, token, ','))
{
token = Utils::trimEnds(token);
extensionlist.push_back(token);
}
}

View File

@ -286,7 +286,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
std::string launcher;
bool showMissing = false;
bool romHierarchy = false;
bool truRIP = false;
bool emuarc = false;
if (mergedCollectionName != "")
{
@ -300,8 +300,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
}
(void)conf_.getProperty("collections." + info->name + ".list.includeMissingItems", showMissing);
(void)conf_.getProperty("collections." + info->name + ".list.romHierarchy", romHierarchy);
(void)conf_.getProperty("collections." + info->name + ".list.truRIP", truRIP);
if (truRIP)
(void)conf_.getProperty("collections." + info->name + ".list.emuarc", emuarc);
if (emuarc)
romHierarchy = true;
// If no merged file exists, or it is empty, attempt to use the include and exclude from the subcollection
@ -342,7 +342,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me
rompath = path;
path = "";
}
ImportRomDirectory(rompath, info, includeFilter, excludeFilter, romHierarchy, truRIP);
ImportRomDirectory(rompath, info, includeFilter, excludeFilter, romHierarchy, emuarc);
} while (path != "");
}
@ -443,7 +443,7 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info)
}
void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter, bool romHierarchy, bool truRIP)
void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter, bool romHierarchy, bool emuarc)
{
DIR *dp;
@ -470,7 +470,7 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo
struct stat sb;
if (romHierarchy && file != "." && file != ".." && stat( Utils::combinePath( path, file ).c_str(), &sb ) == 0 && S_ISDIR( sb.st_mode ))
{
ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter, romHierarchy, truRIP );
ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter, romHierarchy, emuarc );
}
else if (file != "." && file != "..")
{
@ -500,7 +500,7 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo
i->collectionInfo = info;
i->filepath = path + Utils::pathSeparator;
if ( truRIP )
if ( emuarc )
{
i->file = basename;
i->name = Utils::getFileName( path );
@ -508,7 +508,13 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo
i->title = i->name;
}
info->items.push_back(i);
// Add item if it doesn't already exist
bool found = false;
for ( std::vector<Item*>::iterator it = info->items.begin(); it != info->items.end( ); it++ )
if ( (*it)->name == basename )
found = true;
if ( !found )
info->items.push_back(i);
}
}
}

View File

@ -41,5 +41,5 @@ private:
MetadataDatabase &metaDB_;
bool ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list);
bool ImportDirectory(CollectionInfo *info, std::string mergedCollectionName);
void ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter, bool romHierarchy, bool truRIP);
void ImportRomDirectory(std::string path, CollectionInfo *info, std::map<std::string, Item *> includeFilter, std::map<std::string, Item *> excludeFilter, bool romHierarchy, bool emuarc);
};

View File

@ -355,4 +355,18 @@ void UserInput::clearJoysticks( )
{
joysticks_[i] = -1;
}
}
}
void UserInput::reconfigure( )
{
for (unsigned int i = 0; i < keyHandlers_.size(); ++i)
{
if (keyHandlers_[i].first)
{
delete keyHandlers_[i].first;
}
}
keyHandlers_.clear();
initialize( );
}

View File

@ -62,6 +62,7 @@ public:
bool keystate(KeyCode_E);
bool newKeyPressed(KeyCode_E code);
void clearJoysticks( );
void reconfigure( );
private:
bool MapKey(std::string keyDescription, KeyCode_E key);

View File

@ -121,7 +121,7 @@ bool MetadataDatabase::importDirectory()
struct dirent *dirp;
std::string hyperListPath = Utils::combinePath(Configuration::absolutePath, "meta", "hyperlist");
std::string mameListPath = Utils::combinePath(Configuration::absolutePath, "meta", "mamelist");
std::string truripListPath = Utils::combinePath(Configuration::absolutePath, "meta", "trurip");
std::string emuarcListPath = Utils::combinePath(Configuration::absolutePath, "meta", "emuarc");
dp = opendir(hyperListPath.c_str());
@ -188,11 +188,11 @@ bool MetadataDatabase::importDirectory()
closedir(dp);
}
dp = opendir(truripListPath.c_str());
dp = opendir(emuarcListPath.c_str());
if(dp == NULL)
{
Logger::write(Logger::ZONE_INFO, "MetadataDatabase", "Could not read directory \"" + truripListPath + "\"");
Logger::write(Logger::ZONE_INFO, "MetadataDatabase", "Could not read directory \"" + emuarcListPath + "\"");
}
else
{
@ -209,9 +209,9 @@ bool MetadataDatabase::importDirectory()
if(extension == ".dat")
{
std::string importFile = Utils::combinePath(truripListPath, std::string(dirp->d_name));
Logger::write(Logger::ZONE_INFO, "Metadata", "Importing truriplist: " + importFile);
importTruriplist(importFile);
std::string importFile = Utils::combinePath(emuarcListPath, std::string(dirp->d_name));
Logger::write(Logger::ZONE_INFO, "Metadata", "Importing emuarclist: " + importFile);
importEmuArclist(importFile);
}
}
}
@ -556,13 +556,13 @@ bool MetadataDatabase::importMamelist(std::string filename, std::string collecti
}
bool MetadataDatabase::importTruriplist(std::string truriplistFile)
bool MetadataDatabase::importEmuArclist(std::string emuarclistFile)
{
char *error = NULL;
config_.setProperty("status", "Scraping data from \"" + truriplistFile + "\"");
config_.setProperty("status", "Scraping data from \"" + emuarclistFile + "\"");
rapidxml::xml_document<> doc;
std::ifstream file(truriplistFile.c_str());
std::ifstream file(emuarclistFile.c_str());
std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
try
@ -575,20 +575,20 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile)
if(!root)
{
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList file (missing <datafile> tag)");
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList file (missing <datafile> tag)");
return false;
}
rapidxml::xml_node<> *header = root->first_node("header");
if (!header)
{
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList file (missing <header> tag)");
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList file (missing <header> tag)");
return false;
}
rapidxml::xml_node<> *name = header->first_node("name");
if (!name)
{
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList SuperDat file (missing <name> in <header> tag)");
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList SuperDat file (missing <name> in <header> tag)");
return false;
}
std::string collectionName = name->value();
@ -604,22 +604,22 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile)
for(rapidxml::xml_node<> *game = root->first_node("game"); game; game = game->next_sibling("game"))
{
rapidxml::xml_node<> *descriptionXml = game->first_node("description");
rapidxml::xml_node<> *truripXml = game->first_node("EmuArc");
if (!truripXml)
rapidxml::xml_node<> *emuarcXml = game->first_node("EmuArc");
if (!emuarcXml)
{
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList SuperDat file (missing <trurip> tag)");
Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList SuperDat file (missing <emuarc> tag)");
return false;
}
rapidxml::xml_node<> *cloneofXml = truripXml->first_node("cloneof");
rapidxml::xml_node<> *manufacturerXml = truripXml->first_node("publisher");
rapidxml::xml_node<> *developerXml = truripXml->first_node("developer");
rapidxml::xml_node<> *yearXml = truripXml->first_node("year");
rapidxml::xml_node<> *genreXml = truripXml->first_node("genre");
rapidxml::xml_node<> *subgenreXml = truripXml->first_node("subgenre");
rapidxml::xml_node<> *ratingXml = truripXml->first_node("ratings");
rapidxml::xml_node<> *scoreXml = truripXml->first_node("score");
rapidxml::xml_node<> *numberPlayersXml = truripXml->first_node("players");
rapidxml::xml_node<> *enabledXml = truripXml->first_node("enabled");
rapidxml::xml_node<> *cloneofXml = emuarcXml->first_node("cloneof");
rapidxml::xml_node<> *manufacturerXml = emuarcXml->first_node("publisher");
rapidxml::xml_node<> *developerXml = emuarcXml->first_node("developer");
rapidxml::xml_node<> *yearXml = emuarcXml->first_node("year");
rapidxml::xml_node<> *genreXml = emuarcXml->first_node("genre");
rapidxml::xml_node<> *subgenreXml = emuarcXml->first_node("subgenre");
rapidxml::xml_node<> *ratingXml = emuarcXml->first_node("ratings");
rapidxml::xml_node<> *scoreXml = emuarcXml->first_node("score");
rapidxml::xml_node<> *numberPlayersXml = emuarcXml->first_node("players");
rapidxml::xml_node<> *enabledXml = emuarcXml->first_node("enabled");
std::string name = (descriptionXml) ? descriptionXml->value() : "";
std::string description = (descriptionXml) ? descriptionXml->value() : "";
std::string crc = "";
@ -664,7 +664,7 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile)
sqlite3_finalize(stmt);
}
}
config_.setProperty("status", "Saving data from \"" + truriplistFile + "\" to database");
config_.setProperty("status", "Saving data from \"" + emuarclistFile + "\" to database");
sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error);
return true;
@ -681,7 +681,7 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile)
catch(std::exception &e)
{
std::string what = e.what();
Logger::write(Logger::ZONE_ERROR, "Metadata", "Could not parse truriplist file. Reason: " + what);
Logger::write(Logger::ZONE_ERROR, "Metadata", "Could not parse EmuArclist file. Reason: " + what);
}

View File

@ -35,7 +35,7 @@ public:
void injectMetadata(CollectionInfo *collection);
bool importHyperlist(std::string hyperlistFile, std::string collectionName);
bool importMamelist(std::string filename, std::string collectionName);
bool importTruriplist(std::string filename);
bool importEmuArclist(std::string filename);
private:
bool importDirectory();

View File

@ -132,12 +132,11 @@ void ReloadableMedia::reloadTexture()
names.push_back(selectedItem->name);
names.push_back(selectedItem->fullTitle);
names.push_back("default");
if(selectedItem->cloneof.length() > 0)
{
names.push_back(selectedItem->cloneof);
}
names.push_back("default");
if(isVideo_)
{

View File

@ -17,11 +17,15 @@
#include "Menu.h"
#include "../Collection/Item.h"
#include "../Control/UserInput.h"
#include "../Database/Configuration.h"
#include <SDL2/SDL.h>
#include <iostream>
Menu::Menu( Configuration &c )
: config_( c )
Menu::Menu( Configuration &c, UserInput &ui )
: config_( c ),
input_( ui )
{
page_ = nullptr;
}
@ -30,6 +34,12 @@ Menu::Menu( Configuration &c )
void Menu::handleEntry( Item *item )
{
std::cout << "Handling " + item->ctrlType + "." << std::endl;
std::string key = getKey();
std::string ctrl = item->ctrlType;
ctrl.erase( 0, 1 );
std::cout << "Setting " + ctrl + " = " + key << std::endl;
config_.setProperty( "controls." + ctrl, key );
input_.reconfigure();
return;
}
@ -44,3 +54,70 @@ void Menu::clearPage( )
{
page_ = nullptr;
}
std::string Menu::getKey()
{
SDL_Event event;
std::string return_value = "";
while ( return_value == "" )
{
while ( SDL_PollEvent( &event ) )
{
switch (event.type)
{
case SDL_KEYDOWN:
if ( return_value.empty() )
return_value = SDL_GetKeyName( event.key.keysym.sym);
break;
case SDL_JOYBUTTONDOWN:
if ( return_value.empty() )
return_value = "joyButton" + std::to_string( int( event.jbutton.button ) );
break;
case SDL_JOYAXISMOTION:
if ((event.jaxis.value > 30000 || event.jaxis.value < -30000) && event.jaxis.axis <= 3)
{
if ( event.jaxis.value > 0 )
{
if ( return_value.empty() )
return_value = "joyAxis" + std::to_string( int( event.jaxis.axis ) ) + "+";
}
else
{
if ( return_value.empty() )
return_value = "joyAxis" + std::to_string( int( event.jaxis.axis ) ) + "-";
}
}
break;
case SDL_JOYHATMOTION:
switch( event.jhat.value )
{
case SDL_HAT_UP:
if ( return_value.empty() )
return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Up";
break;
case SDL_HAT_DOWN:
if ( return_value.empty() )
return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Down";
break;
case SDL_HAT_LEFT:
if ( return_value.empty() )
return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Left";
break;
case SDL_HAT_RIGHT:
if ( return_value.empty() )
return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Right";
break;
}
break;
default:
break;
}
}
}
return return_value;
}

View File

@ -16,7 +16,11 @@
#pragma once
#include <string>
class Configuration;
class UserInput;
class Item;
class Page;
@ -25,13 +29,15 @@ class Menu
{
public:
Menu( Configuration &c );
Menu( Configuration &c, UserInput &ui );
void handleEntry( Item *item );
void setPage( Page *page );
void clearPage( );
private:
std::string getKey();
Configuration &config_;
UserInput &input_;
Page *page_;
};

View File

@ -320,7 +320,7 @@ void RetroFE::run( )
bool exitSplashMode = false;
Launcher l( config_ );
Menu m( config_ );
Menu m( config_, input_ );
preloadTime = static_cast<float>( SDL_GetTicks( ) ) / 1000;
while ( running )

View File

@ -21,7 +21,7 @@
std::string retrofe_version_major = "0";
std::string retrofe_version_minor = "8";
std::string retrofe_version_build = "18";
std::string retrofe_version_build = "19";
std::string Version::getString( )