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 ;
2016-12-06 16:40:09 +00:00
using System.Reflection ;
2011-04-07 00:46:10 +00:00
using System.Windows.Forms ;
2014-09-01 18:43:41 +00:00
2016-12-06 16:40:09 +00:00
using BizHawk.Emulation.Common ;
2014-09-01 18:43:41 +00:00
using BizHawk.Client.Common ;
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
{
2016-12-06 16:44:37 +00:00
[RequiredService]
private IEmulator Emulator { get ; set ; }
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
}
2016-08-13 20:31:04 +00:00
public void NewUpdate ( ToolFormUpdateType type ) { }
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
{
2015-11-22 16:37:00 +00:00
ToolBoxStrip . Items . Clear ( ) ;
2015-12-10 12:08:00 +00:00
foreach ( var t in Assembly . GetAssembly ( GetType ( ) ) . GetTypes ( ) )
2013-12-22 01:49:52 +00:00
{
2015-12-10 12:08:00 +00:00
if ( ! typeof ( IToolForm ) . IsAssignableFrom ( t ) )
continue ;
if ( ! typeof ( Form ) . IsAssignableFrom ( t ) )
continue ;
if ( typeof ( ToolBox ) . IsAssignableFrom ( t ) ) //yo dawg i head you like toolboxes
continue ;
2017-07-12 19:44:14 +00:00
if ( VersionInfo . DeveloperBuild & & t . GetCustomAttributes ( false ) . OfType < ToolAttribute > ( ) . Any ( a = > ! a . Released ) )
2015-12-10 12:08:00 +00:00
continue ;
if ( 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
continue ;
2016-12-06 16:44:37 +00:00
if ( ! ServiceInjector . IsAvailable ( Emulator . ServiceProvider , t ) )
2015-12-10 12:08:00 +00:00
continue ;
var instance = Activator . CreateInstance ( t ) ;
var tsb = new ToolStripButton
2013-12-22 03:21:32 +00:00
{
2015-12-10 12:08:00 +00:00
Image = ( instance as Form ) . Icon . ToBitmap ( ) ,
Text = ( instance as Form ) . Text ,
DisplayStyle = ( instance as Form ) . ShowIcon ? ToolStripItemDisplayStyle . Image : ToolStripItemDisplayStyle . Text
2014-12-17 03:28:10 +00:00
} ;
2015-12-10 12:08:00 +00:00
tsb . Click + = ( o , e ) = >
2014-12-17 03:28:10 +00:00
{
2015-12-10 12:08:00 +00:00
GlobalWin . Tools . Load ( t ) ;
2014-12-17 03:28:10 +00:00
Close ( ) ;
} ;
2015-12-10 12:08:00 +00:00
ToolBoxStrip . Items . Add ( tsb ) ;
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
}