Contextualization of external tools + Basic of ClientApi
We can now specify a context for external tools. Global, specific for a type of emulator / system or specific for a game (If not specified, a tool is global). It should avoid loading something unwanted. Also add ClientApi, a static class that can interract with EmuHawk window (SetPadding is the only thing implemented currently).
This commit is contained in:
parent
d05ddabf5f
commit
c0f7219b06
|
@ -0,0 +1,72 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.ApiHawk
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class hold logic interraction for the BizHawkExternalToolUsageAttribute
|
||||||
|
/// This attribute helps ApiHawk to know how a tool can be enabled or not
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Assembly)]
|
||||||
|
public sealed class BizHawkExternalToolUsageAttribute : Attribute
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
private BizHawkExternalToolUsage _ToolUsage;
|
||||||
|
private string _Parameter;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region cTor(s)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize a new instance of <see cref="BizHawkExternalToolUsageAttribute"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="usage"><see cref="BizHawkExternalToolUsage"/> i.e. what your external tool is for</param>
|
||||||
|
/// <param name="parameter">The parameter; either emulator type or game hash depending of what you want to do</param>
|
||||||
|
public BizHawkExternalToolUsageAttribute(BizHawkExternalToolUsage usage, string parameter)
|
||||||
|
{
|
||||||
|
_ToolUsage = usage;
|
||||||
|
if(usage != BizHawkExternalToolUsage.Global && parameter.Trim() == string.Empty)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("You must specify the parameter. Either emulator type or game hash depending of what you want to do");
|
||||||
|
}
|
||||||
|
_Parameter = parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize a new instance of <see cref="BizHawkExternalToolUsageAttribute"/>
|
||||||
|
/// </summary>
|
||||||
|
public BizHawkExternalToolUsageAttribute()
|
||||||
|
:this(BizHawkExternalToolUsage.Global, string.Empty)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the tool usage
|
||||||
|
/// </summary>
|
||||||
|
public BizHawkExternalToolUsage ToolUsage
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _ToolUsage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the parameter (Emulator or Game hash)
|
||||||
|
/// </summary>
|
||||||
|
public string Parameter
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _Parameter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -96,7 +96,10 @@
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Attributes\BizHawkExternalToolUsageAttribute.cs" />
|
||||||
<Compile Include="Attributes\ExternalToolAttribute.cs" />
|
<Compile Include="Attributes\ExternalToolAttribute.cs" />
|
||||||
|
<Compile Include="Classes\BizHawkExternalToolUsage.cs" />
|
||||||
|
<Compile Include="Classes\ClientApi.cs" />
|
||||||
<Compile Include="Classes\ExternalToolManager.cs" />
|
<Compile Include="Classes\ExternalToolManager.cs" />
|
||||||
<Compile Include="Interfaces\IExternalToolForm.cs" />
|
<Compile Include="Interfaces\IExternalToolForm.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
namespace BizHawk.Client.ApiHawk
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This enum describe how an external tool is handled
|
||||||
|
/// </summary>
|
||||||
|
public enum BizHawkExternalToolUsage : short
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// General usage, works even with null emulator
|
||||||
|
/// </summary>
|
||||||
|
Global = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// Specific to an emulator (NES,SNES,etc...)
|
||||||
|
/// </summary>
|
||||||
|
EmulatorSpecific = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Specific to a Game
|
||||||
|
/// </summary>
|
||||||
|
GameSpecific = 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace BizHawk.Client.ApiHawk
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class contains some methods that
|
||||||
|
/// interract with BizHawk client
|
||||||
|
/// </summary>
|
||||||
|
public static class ClientApi
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
private static readonly Assembly clientAssembly;
|
||||||
|
|
||||||
|
public static event EventHandler RomLoaded;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region cTor(s)
|
||||||
|
|
||||||
|
static ClientApi()
|
||||||
|
{
|
||||||
|
clientAssembly = Assembly.GetEntryAssembly();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raise when a rom is successfully Loaded
|
||||||
|
/// </summary>
|
||||||
|
public static void OnRomLoaded()
|
||||||
|
{
|
||||||
|
if(RomLoaded != null)
|
||||||
|
{
|
||||||
|
RomLoaded(null, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left padding</param>
|
||||||
|
/// <param name="top">Top padding</param>
|
||||||
|
/// <param name="right">Right padding</param>
|
||||||
|
/// <param name="bottom">Bottom padding</param>
|
||||||
|
public static void SetExtraPadding(int left, int top, int right, int bottom)
|
||||||
|
{
|
||||||
|
Type emuLuaLib = clientAssembly.GetType("BizHawk.Client.EmuHawk.EmuHawkLuaLibrary");
|
||||||
|
MethodInfo paddingMethod = emuLuaLib.GetMethod("SetClientExtraPadding");
|
||||||
|
paddingMethod.Invoke(paddingMethod, new object[] { left, top, right, bottom });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left padding</param>
|
||||||
|
public static void SetExtraPadding(int left)
|
||||||
|
{
|
||||||
|
SetExtraPadding(left, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left padding</param>
|
||||||
|
/// <param name="top">Top padding</param>
|
||||||
|
public static void SetExtraPadding(int left, int top)
|
||||||
|
{
|
||||||
|
SetExtraPadding(left, top, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="left">Left padding</param>
|
||||||
|
/// <param name="top">Top padding</param>
|
||||||
|
/// <param name="right">Right padding</param>
|
||||||
|
public static void SetExtraPadding(int left, int top, int right)
|
||||||
|
{
|
||||||
|
SetExtraPadding(left, top, right, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,6 @@ using System.Reflection;
|
||||||
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Client.EmuHawk;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.ApiHawk
|
namespace BizHawk.Client.ApiHawk
|
||||||
{
|
{
|
||||||
|
@ -42,6 +41,8 @@ namespace BizHawk.Client.ApiHawk
|
||||||
directoryMonitor.Created += new FileSystemEventHandler(DirectoryMonitor_Created);
|
directoryMonitor.Created += new FileSystemEventHandler(DirectoryMonitor_Created);
|
||||||
directoryMonitor.EnableRaisingEvents = true;
|
directoryMonitor.EnableRaisingEvents = true;
|
||||||
|
|
||||||
|
ClientApi.RomLoaded += delegate { BuildToolStrip(); };
|
||||||
|
|
||||||
BuildToolStrip();
|
BuildToolStrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +106,27 @@ namespace BizHawk.Client.ApiHawk
|
||||||
item.Enabled = false;
|
item.Enabled = false;
|
||||||
}
|
}
|
||||||
item.Tag = fileName;
|
item.Tag = fileName;
|
||||||
|
|
||||||
|
attributes = externalToolFile.GetCustomAttributes(typeof(BizHawkExternalToolUsageAttribute), false);
|
||||||
|
if (attributes != null && attributes.Count() == 1)
|
||||||
|
{
|
||||||
|
BizHawkExternalToolUsageAttribute attribute2 = (BizHawkExternalToolUsageAttribute)attributes[0];
|
||||||
|
if(Global.Emulator.SystemId == "NULL" && attribute2.ToolUsage != BizHawkExternalToolUsage.Global)
|
||||||
|
{
|
||||||
|
item.ToolTipText = "This tool doesn't work if nothing is loaded";
|
||||||
|
item.Enabled = false;
|
||||||
|
}
|
||||||
|
else if(attribute2.ToolUsage == BizHawkExternalToolUsage.EmulatorSpecific && Global.Emulator.SystemId != attribute2.Parameter)
|
||||||
|
{
|
||||||
|
item.ToolTipText = "This tool doesn't work for current system";
|
||||||
|
item.Enabled = false;
|
||||||
|
}
|
||||||
|
else if (attribute2.ToolUsage == BizHawkExternalToolUsage.GameSpecific && Global.Game.Hash != attribute2.Parameter)
|
||||||
|
{
|
||||||
|
item.ToolTipText = "This tool doesn't work for current game";
|
||||||
|
item.Enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
using System;
|
namespace BizHawk.Client.EmuHawk
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface to implements in order to make a custom tool
|
/// Interface to implements in order to make a custom tool
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IExternalToolForm : IToolForm
|
public interface IExternalToolForm : IToolForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// <see cref="FormClosedEventHandler"/>
|
|
||||||
/// </summary>
|
|
||||||
event FormClosedEventHandler FormClosed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.1.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||||
|
|
|
@ -50,10 +50,24 @@
|
||||||
<FileName>Attributes\ExternalToolAttribute.cs</FileName>
|
<FileName>Attributes\ExternalToolAttribute.cs</FileName>
|
||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
</Class>
|
</Class>
|
||||||
|
<Class Name="BizHawk.Client.ApiHawk.ClientApi">
|
||||||
|
<Position X="4.75" Y="10" Width="4" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAAAAAAAAAAAAAAAAAQAIAAAAAACAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Classes\ClientApi.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="BizHawk.Client.ApiHawk.BizHawkExternalToolUsageAttribute">
|
||||||
|
<Position X="11" Y="5.75" Width="5.75" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AIAAAAAAEAAAAAAAAAAAAAAAAAAQAACAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Attributes\BizHawkExternalToolUsageAttribute.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
<Interface Name="BizHawk.Client.EmuHawk.IExternalToolForm">
|
<Interface Name="BizHawk.Client.EmuHawk.IExternalToolForm">
|
||||||
<Position X="4.5" Y="4.5" Width="2.75" />
|
<Position X="4.5" Y="4.5" Width="2.75" />
|
||||||
<TypeIdentifier>
|
<TypeIdentifier>
|
||||||
<HashCode>gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
<FileName>Interfaces\IExternalToolForm.cs</FileName>
|
<FileName>Interfaces\IExternalToolForm.cs</FileName>
|
||||||
</TypeIdentifier>
|
</TypeIdentifier>
|
||||||
</Interface>
|
</Interface>
|
||||||
|
@ -77,5 +91,12 @@
|
||||||
<Position X="28.5" Y="1" Width="1.5" />
|
<Position X="28.5" Y="1" Width="1.5" />
|
||||||
<TypeIdentifier />
|
<TypeIdentifier />
|
||||||
</Enum>
|
</Enum>
|
||||||
|
<Enum Name="BizHawk.Client.ApiHawk.BizHawkExternalToolUsage">
|
||||||
|
<Position X="28.25" Y="7.25" Width="2.25" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAgAAAABAAA=</HashCode>
|
||||||
|
<FileName>Classes\BizHawkExternalToolUsage.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Enum>
|
||||||
<Font Name="Segoe UI" Size="9" />
|
<Font Name="Segoe UI" Size="9" />
|
||||||
</ClassDiagram>
|
</ClassDiagram>
|
|
@ -3492,6 +3492,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Console.WriteLine(" {0} : {1}", f.FirmwareId, f.Hash);
|
Console.WriteLine(" {0} : {1}", f.FirmwareId, f.Hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ApiHawk.ClientApi.OnRomLoaded();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3502,6 +3503,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
//The ROM has been loaded by a recursive invocation of the LoadROM method.
|
//The ROM has been loaded by a recursive invocation of the LoadROM method.
|
||||||
if (!(Global.Emulator is NullEmulator))
|
if (!(Global.Emulator is NullEmulator))
|
||||||
{
|
{
|
||||||
|
ApiHawk.ClientApi.OnRomLoaded();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue