BizHawk/BizHawk.Client.EmuHawk/tools/ToolBox.cs

125 lines
3.1 KiB
C#
Raw Normal View History

2011-04-07 00:46:10 +00:00
using System;
using System.Collections.Generic;
2011-04-07 00:46:10 +00:00
using System.Drawing;
using System.Linq;
2011-04-07 00:46:10 +00:00
using System.Windows.Forms;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Calculators;
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;
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
using BizHawk.Client.Common;
using System.Reflection;
namespace BizHawk.Client.EmuHawk
2011-04-07 00:46:10 +00:00
{
public partial class ToolBox : Form, IToolForm
{
public ToolBox()
{
InitializeComponent();
}
private void ToolBox_Load(object sender, EventArgs e)
{
2013-12-21 21:37:00 +00:00
Location = new Point(
Owner.Location.X + Owner.Size.Width,
Owner.Location.Y
2013-12-21 21:37:00 +00:00
);
}
public bool AskSaveChanges() { return true; }
public bool UpdateBefore { get { return false; } }
public void UpdateValues() { }
2013-12-21 21:37:00 +00:00
public void FastUpdate()
{
// Do nothing
}
public void Restart()
{
SetTools();
SetSize();
ToolBoxStrip.Select();
ToolBoxItems.First().Select();
}
private void SetTools()
{
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
.Where(t => BizHawk.Emulation.Common.ServiceInjector.IsAvailable(Global.Emulator.ServiceProvider, t))
.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)
{
var t = new ToolStripButton
{
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);
}
}
private void SetSize()
{
2014-01-08 03:53:53 +00:00
var rows = (int)Math.Ceiling(ToolBoxItems.Count() / 4.0);
Height = 30 + (rows * 30);
}
2014-01-08 03:53:53 +00:00
// Provide LINQ capabilities to an outdated form collection
private IEnumerable<ToolStripItem> ToolBoxItems
{
get
{
return ToolBoxStrip.Items.Cast<ToolStripItem>();
}
}
2013-12-22 03:41:10 +00:00
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
2013-12-22 03:41:10 +00:00
if (keyData == Keys.Escape)
{
Close();
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
}
2011-04-07 00:46:10 +00:00
}