Minor revisions to plugin API

This commit is contained in:
upthorn 2018-12-05 11:58:19 -08:00
parent 6eed08f965
commit 9874c496ac
4 changed files with 129 additions and 27 deletions

View File

@ -226,7 +226,90 @@ namespace BizHawk.Client.Common
{
Global.Config.AutoMinimizeSkipping = enabled;
}
public object GetSettings()
{
if (Emulator is GPGX)
{
var gpgx = Emulator as GPGX;
return gpgx.GetSettings();
}
else if (Emulator is LibsnesCore)
{
var snes = Emulator as LibsnesCore;
return snes.GetSettings();
}
else if (Emulator is NES)
{
var nes = Emulator as NES;
return nes.GetSettings();
}
else if (Emulator is QuickNES)
{
var quicknes = Emulator as QuickNES;
return quicknes.GetSettings();
}
else if (Emulator is PCEngine)
{
var pce = Emulator as PCEngine;
return pce.GetSettings();
}
else if (Emulator is SMS)
{
var sms = Emulator as SMS;
return sms.GetSettings();
}
else if (Emulator is WonderSwan)
{
var ws = Emulator as WonderSwan;
return ws.GetSettings();
}
else
{
return null;
}
}
public bool PutSettings(object settings)
{
if (Emulator is GPGX)
{
var gpgx = Emulator as GPGX;
return gpgx.PutSettings(settings as GPGX.GPGXSettings);
}
else if (Emulator is LibsnesCore)
{
var snes = Emulator as LibsnesCore;
return snes.PutSettings(settings as LibsnesCore.SnesSettings);
}
else if (Emulator is NES)
{
var nes = Emulator as NES;
return nes.PutSettings(settings as NES.NESSettings);
}
else if (Emulator is QuickNES)
{
var quicknes = Emulator as QuickNES;
return quicknes.PutSettings(settings as QuickNES.QuickNESSettings);
}
else if (Emulator is PCEngine)
{
var pce = Emulator as PCEngine;
return pce.PutSettings(settings as PCEngine.PCESettings);
}
else if (Emulator is SMS)
{
var sms = Emulator as SMS;
return sms.PutSettings(settings as SMS.SMSSettings);
}
else if (Emulator is WonderSwan)
{
var ws = Emulator as WonderSwan;
return ws.PutSettings(settings as WonderSwan.Settings);
}
else
{
return false;
}
}
public void SetRenderPlanes(params bool[] luaParam)
{
if (Emulator is GPGX)

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.IO;
@ -23,6 +24,22 @@ namespace BizHawk.Client.Common
protected Color? _defaultTextBackground = Color.FromArgb(128, 0, 0, 0);
protected int _defaultPixelFont = 1; // gens
protected Padding _padding = new Padding(0);
protected ImageAttributes _attributes = new ImageAttributes();
private System.Drawing.Drawing2D.CompositingMode _compositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
public virtual void ToggleCompositingMode()
{
_compositingMode = 1 - _compositingMode;
}
public virtual ImageAttributes GetAttributes()
{
return _attributes;
}
public virtual void SetAttributes(ImageAttributes a)
{
_attributes = a;
}
#region Gui API
public virtual void Dispose()
@ -135,6 +152,7 @@ namespace BizHawk.Client.Common
{
try
{
g.CompositingMode = _compositingMode;
g.DrawBezier(GetPen(color ?? _defaultForeground), p1, p2, p3, p4);
}
catch (Exception)
@ -150,6 +168,7 @@ namespace BizHawk.Client.Common
{
try
{
g.CompositingMode = _compositingMode;
g.DrawBeziers(GetPen(color ?? _defaultForeground), points);
}
catch (Exception)
@ -188,6 +207,7 @@ namespace BizHawk.Client.Common
h = Math.Max(y2, 0.1f);
}
g.CompositingMode = _compositingMode;
g.DrawRectangle(GetPen(line ?? _defaultForeground), x, y, w, h);
var bg = background ?? _defaultBackground;
@ -217,6 +237,7 @@ namespace BizHawk.Client.Common
g.FillEllipse(brush, x, y, width, height);
}
g.CompositingMode = _compositingMode;
g.DrawEllipse(GetPen(line ?? _defaultForeground), x, y, width, height);
}
catch (Exception)
@ -249,6 +270,7 @@ namespace BizHawk.Client.Common
icon = new Icon(path);
}
g.CompositingMode = _compositingMode;
g.DrawIcon(icon, x, y);
}
catch (Exception)
@ -281,8 +303,10 @@ namespace BizHawk.Client.Common
_imageCache.Add(path, img);
}
}
var destRect = new Rectangle(x, y, width ?? img.Width, height ?? img.Height);
g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height);
g.CompositingMode = _compositingMode;
g.DrawImage(img, destRect, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, _attributes);
}
}
@ -319,7 +343,8 @@ namespace BizHawk.Client.Common
var destRect = new Rectangle(dest_x, dest_y, dest_width ?? source_width, dest_height ?? source_height);
g.DrawImage(img, destRect, source_x, source_y, source_width, source_height, GraphicsUnit.Pixel);
g.CompositingMode = _compositingMode;
g.DrawImage(img, destRect, source_x, source_y, source_width, source_height, GraphicsUnit.Pixel, _attributes);
}
}
@ -327,6 +352,7 @@ namespace BizHawk.Client.Common
{
using (var g = GetGraphics())
{
g.CompositingMode = _compositingMode;
g.DrawLine(GetPen(color ?? _defaultForeground), x1, y1, x2, y2);
}
}
@ -341,6 +367,7 @@ namespace BizHawk.Client.Common
{
using (var g = GetGraphics())
{
g.CompositingMode = _compositingMode;
var bg = background ?? _defaultBackground;
if (bg.HasValue)
{

View File

@ -145,7 +145,7 @@ namespace BizHawk.Client.Common
/*Eat it*/
}
}
public void Set(string button, bool state, int? controller = null)
public void Set(string button, bool? state = null, int? controller = null)
{
try
{
@ -154,8 +154,10 @@ namespace BizHawk.Client.Common
{
toPress = "P" + controller + " " + button;
}
Global.LuaAndAdaptor.SetButton(toPress, state);
if (state.HasValue)
Global.LuaAndAdaptor.SetButton(toPress, state.Value);
else
Global.LuaAndAdaptor.UnSet(toPress);
Global.ActiveController.Overrides(Global.LuaAndAdaptor);
}
catch
@ -196,7 +198,7 @@ namespace BizHawk.Client.Common
/*Eat it*/
}
}
public void SetAnalog(string control, float value, object controller = null)
public void SetAnalog(string control, float? value = null, object controller = null)
{
try
{

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.EmuHawk
public class PluginLibrary
{
// public LuaDocumentation Docs { get; }
public PluginLibrary(IEmulatorServiceProvider serviceProvider)
private void Register(IEmulatorServiceProvider serviceProvider)
{
// Docs.Clear();
@ -37,23 +37,15 @@ namespace BizHawk.Client.EmuHawk
foreach (var lib in libs)
{
bool addLibrary = true;
//var attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
//if (attributes.Any())
//{
// addLibrary = VersionInfo.DeveloperBuild || (attributes.First() as LuaLibraryAttribute).Released;
//}
if (addLibrary)
{
var instance = (PluginLibraryBase)Activator.CreateInstance(lib);
//instance.LuaRegister(lib, Docs);
//instance.LogOutputCallback = ConsoleLuaLibrary.LogOutput;
ServiceInjector.UpdateServices(serviceProvider, instance);
Libraries.Add(lib, instance);
}
var instance = (PluginLibraryBase)Activator.CreateInstance(lib);
ServiceInjector.UpdateServices(serviceProvider, instance);
Libraries.Add(lib, instance);
}
}
public PluginLibrary(IEmulatorServiceProvider serviceProvider)
{
Register(serviceProvider);
}
private readonly Dictionary<Type, PluginLibraryBase> Libraries = new Dictionary<Type, PluginLibraryBase>();
public List<PluginBase> PluginList { get; } = new List<PluginBase>();
@ -68,10 +60,8 @@ namespace BizHawk.Client.EmuHawk
public void Restart(IEmulatorServiceProvider newServiceProvider)
{
foreach (var lib in Libraries)
{
ServiceInjector.UpdateServices(newServiceProvider, lib.Value);
}
Libraries.Clear();
Register(newServiceProvider);
foreach (var plugin in PluginList)
{
plugin.Init(new PluginAPI(Libraries));