2013-10-10 21:49:59 +00:00
# include "GuiScraperStart.h"
2013-10-13 19:07:48 +00:00
# include "GuiScraperLog.h"
2013-10-16 22:05:02 +00:00
# include "GuiMsgBoxYesNo.h"
2013-10-10 21:49:59 +00:00
GuiScraperStart : : GuiScraperStart ( Window * window ) : GuiComponent ( window ) ,
mBox ( window , " :/frame.png " ) ,
mList ( window , Eigen : : Vector2i ( 2 , 4 ) ) ,
mFilterLabel ( mWindow ) ,
mSystemsLabel ( mWindow ) ,
mManualLabel ( mWindow ) ,
mFiltersOpt ( mWindow ) ,
2013-10-11 00:55:57 +00:00
mSystemsOpt ( mWindow , true ) ,
mManualSwitch ( mWindow ) ,
mStartButton ( mWindow )
2013-10-10 21:49:59 +00:00
{
mFilterLabel . setText ( " Filter: " ) ;
mSystemsLabel . setText ( " Systems: " ) ;
mManualLabel . setText ( " Manual mode: " ) ;
addChild ( & mBox ) ;
addChild ( & mList ) ;
using namespace Eigen ;
2013-10-11 00:55:57 +00:00
//add filters (with first one selected)
mFiltersOpt . addEntry ( mFiltersOpt . makeEntry ( " All Games " ,
2013-11-06 01:41:49 +00:00
[ ] ( SystemData * , FileData * ) - > bool { return true ; } , true ) ) ;
2013-10-11 00:55:57 +00:00
mFiltersOpt . addEntry ( mFiltersOpt . makeEntry ( " Missing Image " ,
2013-11-06 01:41:49 +00:00
[ ] ( SystemData * , FileData * g ) - > bool { return g - > metadata . get ( " image " ) . empty ( ) ; } ) ) ;
2013-10-11 00:55:57 +00:00
2013-10-10 21:49:59 +00:00
mList . setEntry ( Vector2i ( 0 , 0 ) , Vector2i ( 1 , 1 ) , & mFilterLabel , false , ComponentListComponent : : AlignRight ) ;
2013-10-11 00:55:57 +00:00
mList . setEntry ( Vector2i ( 1 , 0 ) , Vector2i ( 1 , 1 ) , & mFiltersOpt , true , ComponentListComponent : : AlignLeft ) ;
2013-12-10 19:07:50 +00:00
//add systems (all with a platformid specified selected)
2013-10-11 00:55:57 +00:00
std : : vector < SystemData * > sys = SystemData : : sSystemVector ;
mSystemsOpt . populate ( sys ,
[ & ] ( SystemData * s ) {
2013-12-10 19:07:50 +00:00
return mSystemsOpt . makeEntry ( s - > getName ( ) , s , s - > getPlatformId ( ) ! = PlatformIds : : PLATFORM_UNKNOWN ) ;
2013-10-11 00:55:57 +00:00
} ) ;
2013-10-10 21:49:59 +00:00
mList . setEntry ( Vector2i ( 0 , 1 ) , Vector2i ( 1 , 1 ) , & mSystemsLabel , false , ComponentListComponent : : AlignRight ) ;
2013-10-11 00:55:57 +00:00
mList . setEntry ( Vector2i ( 1 , 1 ) , Vector2i ( 1 , 1 ) , & mSystemsOpt , true , ComponentListComponent : : AlignLeft ) ;
2013-10-10 21:49:59 +00:00
mList . setEntry ( Vector2i ( 0 , 2 ) , Vector2i ( 1 , 1 ) , & mManualLabel , false , ComponentListComponent : : AlignRight ) ;
2013-10-11 00:55:57 +00:00
mList . setEntry ( Vector2i ( 1 , 2 ) , Vector2i ( 1 , 1 ) , & mManualSwitch , true , ComponentListComponent : : AlignLeft ) ;
2014-01-25 23:34:29 +00:00
mStartButton . setText ( " GO GO GO GO " , " begin " , 0x00FF00FF ) ;
2013-10-16 22:05:02 +00:00
mStartButton . setPressedFunc ( std : : bind ( & GuiScraperStart : : pressedStart , this ) ) ;
2013-10-11 00:55:57 +00:00
mList . setEntry ( Vector2i ( 0 , 3 ) , Vector2i ( 2 , 1 ) , & mStartButton , true , ComponentListComponent : : AlignCenter ) ;
2013-10-10 21:49:59 +00:00
2013-10-11 00:55:57 +00:00
mList . setPosition ( Renderer : : getScreenWidth ( ) / 2 - mList . getSize ( ) . x ( ) / 2 , Renderer : : getScreenHeight ( ) / 2 - mList . getSize ( ) . y ( ) / 2 ) ;
mBox . setEdgeColor ( 0x333333FF ) ;
mBox . fitTo ( mList . getSize ( ) , mList . getPosition ( ) , Eigen : : Vector2f ( 8 , 8 ) ) ;
}
2013-10-16 22:05:02 +00:00
void GuiScraperStart : : pressedStart ( )
{
std : : vector < SystemData * > sys = mSystemsOpt . getSelectedObjects ( ) ;
for ( auto it = sys . begin ( ) ; it ! = sys . end ( ) ; it + + )
{
if ( ( * it ) - > getPlatformId ( ) = = PlatformIds : : PLATFORM_UNKNOWN )
{
mWindow - > pushGui ( new GuiMsgBoxYesNo ( mWindow , " Warning: some of your selected systems do not have a platform ID set. Results may be even more inaccurate than usual! \n Continue anyway? " ,
std : : bind ( & GuiScraperStart : : start , this ) ) ) ;
return ;
}
}
start ( ) ;
}
2013-10-11 00:55:57 +00:00
void GuiScraperStart : : start ( )
{
std : : queue < ScraperSearchParams > searches = getSearches ( mSystemsOpt . getSelectedObjects ( ) , mFiltersOpt . getSelectedObjects ( ) [ 0 ] ) ;
2013-10-12 20:08:27 +00:00
2013-10-13 19:07:48 +00:00
GuiScraperLog * gsl = new GuiScraperLog ( mWindow , searches , mManualSwitch . getState ( ) ) ;
mWindow - > pushGui ( gsl ) ;
gsl - > start ( ) ;
delete this ;
2013-10-10 21:49:59 +00:00
}
2013-10-11 00:55:57 +00:00
std : : queue < ScraperSearchParams > GuiScraperStart : : getSearches ( std : : vector < SystemData * > systems , GameFilterFunc selector )
{
std : : queue < ScraperSearchParams > queue ;
for ( auto sys = systems . begin ( ) ; sys ! = systems . end ( ) ; sys + + )
{
2013-11-06 01:41:49 +00:00
std : : vector < FileData * > games = ( * sys ) - > getRootFolder ( ) - > getFilesRecursive ( GAME ) ;
2013-10-11 00:55:57 +00:00
for ( auto game = games . begin ( ) ; game ! = games . end ( ) ; game + + )
{
2013-11-06 01:41:49 +00:00
if ( selector ( ( * sys ) , ( * game ) ) )
2013-10-11 00:55:57 +00:00
{
ScraperSearchParams search ;
2013-11-06 01:41:49 +00:00
search . game = * game ;
2013-10-11 00:55:57 +00:00
search . system = * sys ;
queue . push ( search ) ;
}
}
}
return queue ;
}
bool GuiScraperStart : : input ( InputConfig * config , Input input )
{
bool consumed = GuiComponent : : input ( config , input ) ;
if ( consumed )
return true ;
if ( input . value ! = 0 & & config - > isMappedTo ( " b " , input ) )
{
delete this ;
return true ;
}
return false ;
}
2014-01-25 23:34:29 +00:00
std : : vector < HelpPrompt > GuiScraperStart : : getHelpPrompts ( )
{
std : : vector < HelpPrompt > prompts = mList . getHelpPrompts ( ) ;
prompts . push_back ( HelpPrompt ( " b " , " cancel " ) ) ;
return prompts ;
}