Skip to content

Commit

Permalink
Issue #372 - Added plugin to change display on joystick input
Browse files Browse the repository at this point in the history
- The frontend now includes the "SpecificDisplay" plugin which can be
configured to show a specific display when particular custom input is
received.
- Exposed the fe.Display and fe.Filters arrays for plugin and layout
access from within the config menu
  • Loading branch information
mickelson committed Oct 15, 2017
1 parent 92dc631 commit 26907a6
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
68 changes: 68 additions & 0 deletions config/plugins/SpecificDisplay.nut
@@ -0,0 +1,68 @@
///////////////////////////////////////////////////
//
// Attract-Mode Frontend - SpecificDisplay plugin
//
///////////////////////////////////////////////////
class UserConfig </ help="Load a specific display on custom input" /> {

</ label="Display to Show", help="The display to be shown when input is recieved", order=1, options="" />
display="";

</ label="Trigger",
help="The custom command that will show this display (see also: Config->Controls->Costom#)",
order=2, options="Custom1,Custom2,Custom3,Custom4,Custom5,Custom6" />
trigger="";
};

local dattr = UserConfig.getattributes("display");
foreach ( d in fe.displays )
{
if ( dattr["options"].len() < 1 )
dattr["options"] = d.name;
else
dattr["options"] += "," + d.name;
}

UserConfig.setattributes("display", dattr);

class SpecificDisplay
{
trigger = "";
display_index = 0;

constructor()
{
local my_config = fe.get_config();

trigger = my_config["trigger"].tolower();

for ( local i=0; i<fe.displays.len(); i++ )
{
if ( fe.displays[i].name == my_config[ "display" ] )
{
display_index = i;
break;
}
}

if ( display_index == -1 )
{
print( "SpecificDisplay plugin: could not find configured display: "
+ my_config["display"] + "\n" );
display_index = 0;
}

fe.add_signal_handler( this, "on_signal" );
}

function on_signal( signal_str )
{
if ( signal_str == trigger )
fe.set_display( display_index );

return false;
}
}

fe.plugin[ "SpecificDisplay" ] <- SpecificDisplay();

45 changes: 45 additions & 0 deletions src/fe_vm.cpp
Expand Up @@ -1431,12 +1431,57 @@ class FeConfigVM

fe.SetInstance( _SC("overlay"), fe_vm );

fe.Bind( _SC("Display"), Sqrat::Class <FeDisplayInfo, Sqrat::NoConstructor>()
.Prop( _SC("name"), &FeDisplayInfo::get_name )
.Prop( _SC("layout"), &FeDisplayInfo::get_layout )
.Prop( _SC("romlist"), &FeDisplayInfo::get_romlist_name )
.Prop( _SC("in_cycle"), &FeDisplayInfo::show_in_cycle )
.Prop( _SC("in_menu"), &FeDisplayInfo::show_in_menu )
);

fe.Bind( _SC("Filter"), Sqrat::Class <FeFilter, Sqrat::NoConstructor>()
.Prop( _SC("name"), &FeFilter::get_name )
.Prop( _SC("index"), &FeFilter::get_rom_index )
.Prop( _SC("size"), &FeFilter::get_size )
.Prop( _SC("sort_by"), &FeFilter::get_sort_by )
.Prop( _SC("reverse_order"), &FeFilter::get_reverse_order )
.Prop( _SC("list_limit"), &FeFilter::get_list_limit )
);

fe.Bind( _SC("Monitor"), Sqrat::Class <FeMonitor, Sqrat::NoConstructor>()
.Prop( _SC("num"), &FeMonitor::get_num )
.Prop( _SC("width"), &FeMonitor::get_width )
.Prop( _SC("height"), &FeMonitor::get_height )
);

//
// fe.displays
//
Sqrat::Table dtab; // hack Table to Array because creating the Array straight up doesn't work
fe.Bind( _SC("displays"), dtab );
Sqrat::Array darray( dtab.GetObject() );

int display_count = fe_vm->m_feSettings->displays_count();
for ( int i=0; i< display_count; i++ )
darray.SetInstance( darray.GetSize(),
fe_vm->m_feSettings->get_display( i ) );

//
// fe.filters
//
FeDisplayInfo *di = fe_vm->m_feSettings->get_display(
fe_vm->m_feSettings->get_current_display_index() );

Sqrat::Table ftab; // hack Table to Array because creating the Array straight up doesn't work
fe.Bind( _SC("filters"), ftab );
Sqrat::Array farray( ftab.GetObject() );

if ( di )
{
for ( int i=0; i < di->get_filter_count(); i++ )
farray.SetInstance( farray.GetSize(), di->get_filter( i ) );
}

// hack Table to Array because creating the Array straight up doesn't work
Sqrat::Table mtab;
fe.Bind( _SC("monitors"), mtab );
Expand Down

0 comments on commit 26907a6

Please sign in to comment.