Skip to content

Commit

Permalink
Added ability use emulator templates when adding a new emulator
Browse files Browse the repository at this point in the history
- templates are loaded from the <config>/emulators/templates dir
  • Loading branch information
mickelson committed Dec 31, 2017
1 parent 36d97c8 commit d2ffea1
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 17 deletions.
1 change: 1 addition & 0 deletions config/language/cn.msg
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ Joystick Mappings;Joystick Mappings
Non-Blocking Mode Wait;Non-Blocking Mode Wait
Overview;Overview
Remove tag: '$1';Remove tag: '$1'
Select template to use for emulator settings;Select template to use for emulator settings
Window (No Border);Window (No Border)
Working Directory;Working Directory
multi;multi
Expand Down
1 change: 1 addition & 0 deletions config/language/de.msg
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Remove '$1' from Favourites?;Remove '$1' from Favourites?
Remove tag: '$1';Remove tag: '$1'
Scrape Fanart;Scrape Fanart
Scrape Videos (MAME only);Scrape Videos (MAME only)
Select template to use for emulator settings;Select template to use for emulator settings
Show Displays Menu;Show Displays Menu
Show Last Selection (Default);Show Last Selection (Default)
Show in Cycle;Show in Cycle
Expand Down
1 change: 1 addition & 0 deletions config/language/es.msg
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ Remove '$1' from Favourites?;Remove '$1' from Favourites?
Remove tag: '$1';Remove tag: '$1'
Scrape Fanart;Scrape Fanart
Scrape Videos (MAME only);Scrape Videos (MAME only)
Select template to use for emulator settings;Select template to use for emulator settings
Show Displays Menu;Show Displays Menu
Show Last Selection (Default);Show Last Selection (Default)
Show in Cycle;Show in Cycle
Expand Down
1 change: 1 addition & 0 deletions config/language/fr.msg
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Previous Game;Previous Game
Remove '$1' from Favourites?;Remove '$1' from Favourites?
Remove tag: '$1';Remove tag: '$1'
Scrape Videos (MAME only);Scrape Videos (MAME only)
Select template to use for emulator settings;Select template to use for emulator settings
Show Displays Menu;Show Displays Menu
Show Last Selection (Default);Show Last Selection (Default)
Show in Cycle;Show in Cycle
Expand Down
1 change: 1 addition & 0 deletions config/language/it.msg
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ Insert Menu Entry;Insert Menu Entry
Joystick $1;Joystick $1
Joystick Mappings;Joystick Mappings
Non-Blocking Mode Wait;Non-Blocking Mode Wait
Select template to use for emulator settings;Select template to use for emulator settings
_help_hide_console;Hide console on startup. Note that this only works if starting Attract-Mode from a Windows GUI. If started from an existing console window (e.g. a batch file) then the process will always "attach" to the existing console and output to it.
_help_joystick_map;Map the frontend's joystick slots to specifically named joystick/gamepad devices attached to your computer (You can use this to force the frontend to always use 'Microsoft X-Box 360 pad' as Joystick 0, for example.)
_help_shortcut_artwork_name_edit;Optionally provide an artwork name to be associated with this shortcut. The frontend will try to load artworks with this name when displaying the shortcut
Expand Down
1 change: 1 addition & 0 deletions config/language/jp.msg
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ Remove '$1' from Favourites?;Remove '$1' from Favourites?
Remove tag: '$1';Remove tag: '$1'
Scrape Fanart;Scrape Fanart
Scrape Videos (MAME only);Scrape Videos (MAME only)
Select template to use for emulator settings;Select template to use for emulator settings
Show Displays Menu;Show Displays Menu
Show Last Selection (Default);Show Last Selection (Default)
Show in Cycle;Show in Cycle
Expand Down
1 change: 1 addition & 0 deletions config/language/kr.msg
Original file line number Diff line number Diff line change
Expand Up @@ -416,5 +416,6 @@ _help_scrape_mamedb;MAME snap과 marquee를 mamedb.com에서 가져올 지 여
# Strings still needing translation
#
Non-Blocking Mode Wait;Non-Blocking Mode Wait
Select template to use for emulator settings;Select template to use for emulator settings
_help_input_action;
_help_joystick_map;Map the frontend's joystick slots to specifically named joystick/gamepad devices attached to your computer (You can use this to force the frontend to always use 'Microsoft X-Box 360 pad' as Joystick 0, for example.)
1 change: 1 addition & 0 deletions config/language/msg_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Screen Saver;Screen Saver
Screen Saver Timeout;Screen Saver Timeout
Screenshot;Screenshot
Select;Select
Select template to use for emulator settings;Select template to use for emulator settings
Show in Cycle;Show in Cycle
Show in Menu;Show in Menu
Show Displays Menu;Show Displays Menu
Expand Down
1 change: 1 addition & 0 deletions src/fe_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const char *FE_DIR_TOKEN = "<DIR>";
const char *FE_DEFAULT_ARTWORK = "snap";

const char *FE_EMULATOR_SUBDIR = "emulators/";
const char *FE_EMULATOR_TEMPLATES_SUBDIR = "emulators/templates/";
const char *FE_EMULATOR_FILE_EXTENSION = ".cfg";
const char *FE_EMULATOR_DEFAULT = "default-emulator.cfg";

Expand Down
1 change: 1 addition & 0 deletions src/fe_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern const char *FE_DIR_TOKEN;
extern const char *FE_DEFAULT_ARTWORK;

extern const char *FE_EMULATOR_SUBDIR;
extern const char *FE_EMULATOR_TEMPLATES_SUBDIR;
extern const char *FE_EMULATOR_FILE_EXTENSION;
extern const char *FE_EMULATOR_DEFAULT;

Expand Down
22 changes: 20 additions & 2 deletions src/fe_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void FeEmulatorEditMenu::get_options( FeConfigContext &ctx )

if ( m_emulator )
{
// Don't allow editting of the name. User can set it when adding new
// Don't allow editing of the name. User can set it when adding new
//
ctx.add_optl( Opt::INFO, "Emulator Name",
m_emulator->get_info( FeEmulatorInfo::Name ) );
Expand Down Expand Up @@ -422,6 +422,8 @@ bool FeEmulatorEditMenu::on_option_select(

ctx.fe_settings.delete_emulator(
m_emulator->get_info(FeEmulatorInfo::Name) );

m_emulator = NULL;
}
break;

Expand Down Expand Up @@ -702,7 +704,23 @@ bool FeEmulatorSelMenu::on_option_select(
if ( !ctx.edit_dialog( "Enter Emulator Name", res ) || res.empty() )
return false;

e = ctx.fe_settings.create_emulator( res );
std::vector<std::string> t_list;
ctx.fe_settings.get_list_of_emulators( t_list, true );

std::string et;
if ( t_list.size() > 0 )
{
std::string default_str;
ctx.fe_settings.get_resource( "Default", default_str );

t_list.insert( t_list.begin(), default_str );
int sel = ctx.option_dialog( "Select template to use for emulator settings", t_list, 0 );

if ( sel > 0 )
et = t_list[ sel ];
}

e = ctx.fe_settings.create_emulator( res, et );
flag = true;
}
else if ( o.opaque == 2 )
Expand Down
4 changes: 4 additions & 0 deletions src/fe_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class FeConfigContext
virtual bool confirm_dialog( const std::string &msg,
const std::string &rep="" )=0;

virtual int option_dialog( const std::string &title,
const std::vector < std::string > &options,
int default_sel=0 )=0;

virtual void splash_message( const std::string &msg,
const std::string &rep,
const std::string &aux )=0;
Expand Down
13 changes: 12 additions & 1 deletion src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class FeConfigContextImp : public FeConfigContext
bool confirm_dialog( const std::string &m,
const std::string &rep );

int option_dialog( const std::string &title,
const std::vector < std::string > &options,
int default_sel=0 );

void splash_message( const std::string &msg,
const std::string &rep,
const std::string &aux );
Expand Down Expand Up @@ -75,11 +79,18 @@ bool FeConfigContextImp::edit_dialog( const std::string &m, std::string &t )
}

bool FeConfigContextImp::confirm_dialog( const std::string &msg,
const std::string &rep )
const std::string &rep )
{
return !m_feo.confirm_dialog( msg, rep );
}

int FeConfigContextImp::option_dialog( const std::string &title,
const std::vector < std::string > &options,
int default_sel )
{
return m_feo.common_list_dialog( title, options, default_sel, default_sel );
}

void FeConfigContextImp::splash_message(
const std::string &msg,
const std::string &rep,
Expand Down
26 changes: 19 additions & 7 deletions src/fe_romlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,10 @@ void FeRomList::get_file_availability()

// NOTE: this function is implemented in fe_settings.cpp
bool internal_resolve_config_file(
const std::string &config_path,
std::string &result,
const char *subdir,
const std::string &name );
const std::string &config_path,
std::string &result,
const char *subdir,
const std::string &name );


FeEmulatorInfo *FeRomList::get_emulator( const std::string & emu )
Expand Down Expand Up @@ -765,7 +765,7 @@ FeEmulatorInfo *FeRomList::get_emulator( const std::string & emu )
return NULL;
}

FeEmulatorInfo *FeRomList::create_emulator( const std::string &emu )
FeEmulatorInfo *FeRomList::create_emulator( const std::string &emu, const std::string &emu_template )
{
// If an emulator with the given name already exists we return it
//
Expand All @@ -779,9 +779,20 @@ FeEmulatorInfo *FeRomList::create_emulator( const std::string &emu )
FeEmulatorInfo new_emu( emu );

std::string defaults_file;
if ( internal_resolve_config_file( m_config_path, defaults_file, NULL, FE_EMULATOR_DEFAULT ) )
if ( !emu_template.empty() )
{
new_emu.load_from_file( defaults_file );
defaults_file = m_config_path;
defaults_file += FE_EMULATOR_TEMPLATES_SUBDIR;
defaults_file += emu_template;
defaults_file += FE_EMULATOR_FILE_EXTENSION;

if ( !new_emu.load_from_file( defaults_file ) )
FeLog() << "Unable to open file: " << defaults_file << std::endl;
}
else if ( internal_resolve_config_file( m_config_path, defaults_file, NULL, FE_EMULATOR_DEFAULT ) )
{
if ( !new_emu.load_from_file( defaults_file ) )
FeLog() << "Unable to open file: " << defaults_file << std::endl;

//
// Find and replace the [emulator] token, replace with the specified
Expand Down Expand Up @@ -822,6 +833,7 @@ void FeRomList::delete_emulator( const std::string & emu )
path += emu;
path += FE_EMULATOR_FILE_EXTENSION;

FeLog() << "Deleting emulator: " << path << std::endl;
delete_file( path );

//
Expand Down
2 changes: 1 addition & 1 deletion src/fe_romlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class FeRomList : public FeBaseConfigurable
void get_file_availability();

FeEmulatorInfo *get_emulator( const std::string & );
FeEmulatorInfo *create_emulator( const std::string & );
FeEmulatorInfo *create_emulator( const std::string &, const std::string & );
void delete_emulator( const std::string & );
void clear_emulators() { m_emulators.clear(); }
};
Expand Down
12 changes: 8 additions & 4 deletions src/fe_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2376,20 +2376,24 @@ FeEmulatorInfo *FeSettings::get_emulator( const std::string &n )
return m_rl.get_emulator( n );
}

FeEmulatorInfo *FeSettings::create_emulator( const std::string &n )
FeEmulatorInfo *FeSettings::create_emulator( const std::string &n, const std::string &t )
{
return m_rl.create_emulator( n );
return m_rl.create_emulator( n, t );
}

void FeSettings::delete_emulator( const std::string &n )
{
m_rl.delete_emulator( n );
}

void FeSettings::get_list_of_emulators( std::vector<std::string> &emu_list )
void FeSettings::get_list_of_emulators( std::vector<std::string> &emu_list, bool get_templates )
{
std::string path = get_config_dir();
path += FE_EMULATOR_SUBDIR;

if ( get_templates )
path += FE_EMULATOR_TEMPLATES_SUBDIR;
else
path += FE_EMULATOR_SUBDIR;

get_basename_from_extension(
emu_list,
Expand Down
4 changes: 2 additions & 2 deletions src/fe_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ class FeSettings : public FeBaseConfigurable
bool scrape_artwork( const std::string &emu_name, UiUpdate uiu, void *uid, std::string &msg );

FeEmulatorInfo *get_emulator( const std::string & );
FeEmulatorInfo *create_emulator( const std::string & );
FeEmulatorInfo *create_emulator( const std::string &, const std::string & );
void delete_emulator( const std::string & );

void get_list_of_emulators( std::vector<std::string> &emu_list );
void get_list_of_emulators( std::vector<std::string> &emu_list, bool get_templates=false );

//
// Functions used for configuration
Expand Down

0 comments on commit d2ffea1

Please sign in to comment.