2011-04-07 00:46:10 +00:00
using System ;
2013-12-22 01:49:52 +00:00
using System.Collections.Generic ;
2011-04-07 00:46:10 +00:00
using System.Drawing ;
2013-12-22 01:49:52 +00:00
using System.Linq ;
2011-04-07 00:46:10 +00:00
using System.Windows.Forms ;
2014-09-01 18:43:41 +00:00
using BizHawk.Emulation.Common.IEmulatorExtensions ;
2013-11-13 03:32:25 +00:00
using BizHawk.Emulation.Cores.Calculators ;
2014-04-13 22:08:46 +00:00
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx ;
2014-01-08 03:53:53 +00:00
using BizHawk.Emulation.Cores.Nintendo.GBA ;
2013-11-14 13:15:41 +00:00
using BizHawk.Emulation.Cores.Nintendo.NES ;
2013-11-13 23:36:21 +00:00
using BizHawk.Emulation.Cores.Nintendo.SNES ;
2013-12-22 02:27:25 +00:00
using BizHawk.Emulation.Cores.PCEngine ;
2014-04-13 19:51:38 +00:00
using BizHawk.Emulation.Cores.Sega.MasterSystem ;
2011-04-07 00:46:10 +00:00
2014-09-01 18:43:41 +00:00
using BizHawk.Client.Common ;
2014-12-17 03:28:10 +00:00
using System.Reflection ;
2014-09-01 18:43:41 +00:00
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2011-04-07 00:46:10 +00:00
{
2013-11-03 00:31:16 +00:00
public partial class ToolBox : Form , IToolForm
2011-09-10 21:48:27 +00:00
{
public ToolBox ( )
{
InitializeComponent ( ) ;
}
2011-04-07 01:30:42 +00:00
2011-09-10 21:48:27 +00:00
private void ToolBox_Load ( object sender , EventArgs e )
{
2013-12-21 21:37:00 +00:00
Location = new Point (
2015-02-22 04:02:30 +00:00
Owner . Location . X + Owner . Size . Width ,
Owner . Location . Y
2013-12-21 21:37:00 +00:00
) ;
2012-01-10 02:11:17 +00:00
}
2014-08-19 19:24:17 +00:00
public bool AskSaveChanges ( ) { return true ; }
2013-11-03 00:31:16 +00:00
public bool UpdateBefore { get { return false ; } }
public void UpdateValues ( ) { }
2013-12-21 21:37:00 +00:00
2014-07-25 01:55:21 +00:00
public void FastUpdate ( )
{
// Do nothing
}
2012-01-10 02:11:17 +00:00
public void Restart ( )
{
2013-12-22 01:49:52 +00:00
SetTools ( ) ;
2014-12-17 03:28:10 +00:00
SetSize ( ) ;
ToolBoxStrip . Select ( ) ;
ToolBoxItems . First ( ) . Select ( ) ;
2012-01-10 02:11:17 +00:00
}
2012-01-10 02:02:11 +00:00
2013-12-22 01:49:52 +00:00
private void SetTools ( )
2012-01-10 02:11:17 +00:00
{
2014-12-17 03:28:10 +00:00
var availableTools = Assembly
. GetAssembly ( typeof ( IToolForm ) )
. GetTypes ( )
. Where ( t = > typeof ( IToolForm ) . IsAssignableFrom ( t ) )
. Where ( t = > typeof ( Form ) . IsAssignableFrom ( t ) )
. Where ( t = > ! ( typeof ( ToolBox ) . IsAssignableFrom ( t ) ) )
. Where ( t = > VersionInfo . DeveloperBuild ? true : ! ( t . GetCustomAttributes ( false )
. OfType < ToolAttributes > ( ) . Any ( a = > ! a . Released ) ) )
. Where ( t = > ! ( t = = typeof ( GBGameGenie ) ) ) // Hack, this tool is specific to a system id and a sub-system (gb and gg) we have no reasonable way to declare a dependency like that
2014-12-17 18:17:16 +00:00
. Where ( t = > BizHawk . Emulation . Common . ServiceInjector . IsAvailable ( Global . Emulator . ServiceProvider , t ) )
2014-12-17 03:28:10 +00:00
. Select ( t = > Activator . CreateInstance ( t ) )
. Select ( instance = > new
{
Type = instance . GetType ( ) ,
Instance = instance ,
Icon = ( instance as Form ) . Icon . ToBitmap ( ) ,
Text = ( instance as Form ) . Text ,
ShowIcon = ( instance as Form ) . ShowIcon
} )
. ToList ( ) ;
foreach ( var tool in availableTools )
2013-12-22 01:49:52 +00:00
{
2014-12-17 03:28:10 +00:00
var t = new ToolStripButton
2013-12-22 03:21:32 +00:00
{
2014-12-17 03:28:10 +00:00
Image = tool . Icon ,
Text = tool . Text ,
DisplayStyle = tool . ShowIcon ? ToolStripItemDisplayStyle . Image : ToolStripItemDisplayStyle . Text
} ;
t . Click + = ( o , e ) = >
{
GlobalWin . Tools . Load ( tool . Type ) ;
Close ( ) ;
} ;
ToolBoxStrip . Items . Add ( t ) ;
2013-12-22 01:49:52 +00:00
}
}
private void SetSize ( )
{
2014-01-08 03:53:53 +00:00
var rows = ( int ) Math . Ceiling ( ToolBoxItems . Count ( ) / 4.0 ) ;
Height = 30 + ( rows * 30 ) ;
2011-09-10 21:48:27 +00:00
}
2011-04-30 21:19:11 +00:00
2014-01-08 03:53:53 +00:00
// Provide LINQ capabilities to an outdated form collection
2013-12-22 01:49:52 +00:00
private IEnumerable < ToolStripItem > ToolBoxItems
{
get
{
2014-12-17 03:28:10 +00:00
return ToolBoxStrip . Items . Cast < ToolStripItem > ( ) ;
2013-12-22 01:49:52 +00:00
}
}
2013-12-22 03:41:10 +00:00
protected override bool ProcessCmdKey ( ref Message msg , Keys keyData )
2013-12-22 01:49:52 +00:00
{
2013-12-22 03:41:10 +00:00
if ( keyData = = Keys . Escape )
{
Close ( ) ;
return true ;
}
else
{
return base . ProcessCmdKey ( ref msg , keyData ) ;
}
2013-12-22 01:49:52 +00:00
}
2011-09-10 21:48:27 +00:00
}
2011-04-07 00:46:10 +00:00
}