Cleanup EmuHawk lua library code
This commit is contained in:
parent
7f269d25df
commit
31e68a38f9
|
@ -8,7 +8,6 @@ using BizHawk.Common;
|
|||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[Description("A library for manipulating the EmuHawk client UI")]
|
||||
|
@ -35,30 +34,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
public EmuHawkLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
public override string Name { get { return "client"; } }
|
||||
public override string Name => "client";
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"exit",
|
||||
"Closes the emulator"
|
||||
)]
|
||||
[LuaMethodAttributes("exit", "Closes the emulator")]
|
||||
public void CloseEmulator()
|
||||
{
|
||||
GlobalWin.MainForm.CloseEmulator();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"exitCode",
|
||||
"Closes the emulator and returns the provided code"
|
||||
)]
|
||||
[LuaMethodAttributes("exitCode", "Closes the emulator and returns the provided code")]
|
||||
public void CloseEmulatorWithCode(int exitCode)
|
||||
{
|
||||
GlobalWin.MainForm.CloseEmulator(exitCode);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"borderheight",
|
||||
"Gets the current height in pixels of the letter/pillarbox area (top side only) around the emu display surface, excluding the gameExtraPadding you've set. This function (the whole lot of them) should be renamed or refactored since the padding areas have got more complex."
|
||||
)]
|
||||
"borderheight", "Gets the current height in pixels of the letter/pillarbox area (top side only) around the emu display surface, excluding the gameExtraPadding you've set. This function (the whole lot of them) should be renamed or refactored since the padding areas have got more complex.")]
|
||||
public static int BorderHeight()
|
||||
{
|
||||
var point = new System.Drawing.Point(0, 0);
|
||||
|
@ -66,9 +57,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"borderwidth",
|
||||
"Gets the current width in pixels of the letter/pillarbox area (left side only) around the emu display surface, excluding the gameExtraPadding you've set. This function (the whole lot of them) should be renamed or refactored since the padding areas have got more complex."
|
||||
)]
|
||||
"borderwidth", "Gets the current width in pixels of the letter/pillarbox area (left side only) around the emu display surface, excluding the gameExtraPadding you've set. This function (the whole lot of them) should be renamed or refactored since the padding areas have got more complex.")]
|
||||
public static int BorderWidth()
|
||||
{
|
||||
var point = new System.Drawing.Point(0, 0);
|
||||
|
@ -76,57 +65,38 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"bufferheight",
|
||||
"Gets the visible height of the emu display surface (the core video output). This excludes the gameExtraPadding you've set."
|
||||
)]
|
||||
"bufferheight", "Gets the visible height of the emu display surface (the core video output). This excludes the gameExtraPadding you've set.")]
|
||||
public int BufferHeight()
|
||||
{
|
||||
return VideoProvider.BufferHeight;
|
||||
//memento of original behaviour from scepheo's commit -- why?
|
||||
//var point = new System.Drawing.Point(0, height);
|
||||
//return GlobalWin.DisplayManager.TransformPoint(point).Y - BorderHeight();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"bufferwidth",
|
||||
"Gets the visible width of the emu display surface (the core video output). This excludes the gameExtraPadding you've set."
|
||||
)]
|
||||
"bufferwidth", "Gets the visible width of the emu display surface (the core video output). This excludes the gameExtraPadding you've set.")]
|
||||
public int BufferWidth()
|
||||
{
|
||||
return VideoProvider.BufferWidth;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"clearautohold",
|
||||
"Clears all autohold keys"
|
||||
)]
|
||||
[LuaMethodAttributes("clearautohold", "Clears all autohold keys")]
|
||||
public void ClearAutohold()
|
||||
{
|
||||
GlobalWin.MainForm.ClearHolds();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"closerom",
|
||||
"Closes the loaded Rom"
|
||||
)]
|
||||
[LuaMethodAttributes("closerom", "Closes the loaded Rom")]
|
||||
public static void CloseRom()
|
||||
{
|
||||
GlobalWin.MainForm.CloseRom();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"enablerewind",
|
||||
"Sets whether or not the rewind feature is enabled"
|
||||
)]
|
||||
[LuaMethodAttributes("enablerewind", "Sets whether or not the rewind feature is enabled")]
|
||||
public void EnableRewind(bool enabled)
|
||||
{
|
||||
GlobalWin.MainForm.EnableRewind(enabled);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"frameskip",
|
||||
"Sets the frame skip value of the client UI"
|
||||
)]
|
||||
[LuaMethodAttributes("frameskip", "Sets the frame skip value of the client UI")]
|
||||
public void FrameSkip(int numFrames)
|
||||
{
|
||||
if (numFrames > 0)
|
||||
|
@ -140,186 +110,126 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"gettargetscanlineintensity",
|
||||
"Gets the current scanline intensity setting, used for the scanline display filter"
|
||||
)]
|
||||
[LuaMethodAttributes("gettargetscanlineintensity", "Gets the current scanline intensity setting, used for the scanline display filter")]
|
||||
public static int GetTargetScanlineIntensity()
|
||||
{
|
||||
return Global.Config.TargetScanlineFilterIntensity;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getwindowsize",
|
||||
"Gets the main window's size Possible values are 1, 2, 3, 4, 5, and 10"
|
||||
)]
|
||||
[LuaMethodAttributes("getwindowsize", "Gets the main window's size Possible values are 1, 2, 3, 4, 5, and 10")]
|
||||
public int GetWindowSize()
|
||||
{
|
||||
return Global.Config.TargetZoomFactors[Emulator.SystemId];
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"SetGameExtraPadding",
|
||||
"Sets the extra padding added to the 'emu' surface so that you can draw HUD elements in predictable placements"
|
||||
)]
|
||||
[LuaMethodAttributes("SetGameExtraPadding", "Sets the extra padding added to the 'emu' surface so that you can draw HUD elements in predictable placements")]
|
||||
public static void SetGameExtraPadding(int left, int top, int right, int bottom)
|
||||
{
|
||||
GlobalWin.DisplayManager.GameExtraPadding = new System.Windows.Forms.Padding(left, top, right, bottom);
|
||||
GlobalWin.MainForm.FrameBufferResized();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"SetSoundOn",
|
||||
"Sets the state of the Sound On toggle"
|
||||
)]
|
||||
[LuaMethodAttributes("SetSoundOn", "Sets the state of the Sound On toggle")]
|
||||
public static void SetSoundOn(bool enable)
|
||||
{
|
||||
Global.Config.SoundEnabled = enable;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"GetSoundOn",
|
||||
"Gets the state of the Sound On toggle"
|
||||
)]
|
||||
[LuaMethodAttributes("GetSoundOn", "Gets the state of the Sound On toggle")]
|
||||
public static bool GetSoundOn()
|
||||
{
|
||||
return Global.Config.SoundEnabled;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"SetClientExtraPadding",
|
||||
"Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements"
|
||||
)]
|
||||
[LuaMethodAttributes("SetClientExtraPadding", "Sets the extra padding added to the 'native' surface so that you can draw HUD elements in predictable placements")]
|
||||
public static void SetClientExtraPadding(int left, int top, int right, int bottom)
|
||||
{
|
||||
GlobalWin.DisplayManager.ClientExtraPadding = new System.Windows.Forms.Padding(left, top, right, bottom);
|
||||
GlobalWin.MainForm.FrameBufferResized();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"ispaused",
|
||||
"Returns true if emulator is paused, otherwise, false"
|
||||
)]
|
||||
[LuaMethodAttributes("ispaused", "Returns true if emulator is paused, otherwise, false")]
|
||||
public static bool IsPaused()
|
||||
{
|
||||
return GlobalWin.MainForm.EmulatorPaused;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"opencheats",
|
||||
"opens the Cheats dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("opencheats", "opens the Cheats dialog")]
|
||||
public static void OpenCheats()
|
||||
{
|
||||
GlobalWin.Tools.Load<Cheats>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"openhexeditor",
|
||||
"opens the Hex Editor dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("openhexeditor", "opens the Hex Editor dialog")]
|
||||
public static void OpenHexEditor()
|
||||
{
|
||||
GlobalWin.Tools.Load<HexEditor>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"openramwatch",
|
||||
"opens the RAM Watch dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("openramwatch", "opens the RAM Watch dialog")]
|
||||
public static void OpenRamWatch()
|
||||
{
|
||||
GlobalWin.Tools.LoadRamWatch(loadDialog: true);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"openramsearch",
|
||||
"opens the RAM Search dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("openramsearch", "opens the RAM Search dialog")]
|
||||
public static void OpenRamSearch()
|
||||
{
|
||||
GlobalWin.Tools.Load<RamSearch>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"openrom",
|
||||
"opens the Open ROM dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("openrom", "opens the Open ROM dialog")]
|
||||
public static void OpenRom(string path)
|
||||
{
|
||||
GlobalWin.MainForm.LoadRom(path, new MainForm.LoadRomArgs() { OpenAdvanced = new OpenAdvanced_OpenRom() });
|
||||
GlobalWin.MainForm.LoadRom(path, new MainForm.LoadRomArgs { OpenAdvanced = new OpenAdvanced_OpenRom() });
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"opentasstudio",
|
||||
"opens the TAStudio dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("opentasstudio", "opens the TAStudio dialog")]
|
||||
public static void OpenTasStudio()
|
||||
{
|
||||
GlobalWin.Tools.Load<TAStudio>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"opentoolbox",
|
||||
"opens the Toolbox Dialog"
|
||||
)]
|
||||
[LuaMethodAttributes("opentoolbox", "opens the Toolbox Dialog")]
|
||||
public static void OpenToolBox()
|
||||
{
|
||||
GlobalWin.Tools.Load<ToolBox>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"opentracelogger",
|
||||
"opens the tracelogger if it is available for the given core"
|
||||
)]
|
||||
[LuaMethodAttributes("opentracelogger", "opens the tracelogger if it is available for the given core")]
|
||||
public static void OpenTraceLogger()
|
||||
{
|
||||
GlobalWin.Tools.Load<TraceLogger>();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"pause",
|
||||
"Pauses the emulator"
|
||||
)]
|
||||
[LuaMethodAttributes("pause", "Pauses the emulator")]
|
||||
public static void Pause()
|
||||
{
|
||||
GlobalWin.MainForm.PauseEmulator();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"pause_av",
|
||||
"If currently capturing Audio/Video, this will suspend the record. Frames will not be captured into the AV until client.unpause_av() is called"
|
||||
)]
|
||||
[LuaMethodAttributes("pause_av", "If currently capturing Audio/Video, this will suspend the record. Frames will not be captured into the AV until client.unpause_av() is called")]
|
||||
public static void PauseAv()
|
||||
{
|
||||
GlobalWin.MainForm.PauseAVI = true;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"reboot_core",
|
||||
"Reboots the currently loaded core"
|
||||
)]
|
||||
[LuaMethodAttributes("reboot_core", "Reboots the currently loaded core")]
|
||||
public static void RebootCore()
|
||||
{
|
||||
//pretty hacky.. we dont want a lua script to be able to restart itself by rebooting the core
|
||||
// pretty hacky.. we dont want a lua script to be able to restart itself by rebooting the core
|
||||
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).IsRebootingCore = true;
|
||||
GlobalWin.MainForm.RebootCore();
|
||||
((LuaConsole)GlobalWin.Tools.Get<LuaConsole>()).IsRebootingCore = false;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"screenheight",
|
||||
"Gets the current height in pixels of the emulator's drawing area"
|
||||
)]
|
||||
[LuaMethodAttributes("screenheight", "Gets the current height in pixels of the emulator's drawing area")]
|
||||
public static int ScreenHeight()
|
||||
{
|
||||
return GlobalWin.MainForm.PresentationPanel.NativeSize.Height;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"screenshot",
|
||||
"if a parameter is passed it will function as the Screenshot As menu item of EmuHawk, else it will function as the Screenshot menu item"
|
||||
)]
|
||||
[LuaMethodAttributes("screenshot", "if a parameter is passed it will function as the Screenshot As menu item of EmuHawk, else it will function as the Screenshot menu item")]
|
||||
public static void Screenshot(string path = null)
|
||||
{
|
||||
if (path == null)
|
||||
|
@ -332,46 +242,31 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"screenshottoclipboard",
|
||||
"Performs the same function as EmuHawk's Screenshot To Clipboard menu item"
|
||||
)]
|
||||
[LuaMethodAttributes("screenshottoclipboard", "Performs the same function as EmuHawk's Screenshot To Clipboard menu item")]
|
||||
public static void ScreenshotToClipboard()
|
||||
{
|
||||
GlobalWin.MainForm.TakeScreenshotToClipboard();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"settargetscanlineintensity",
|
||||
"Sets the current scanline intensity setting, used for the scanline display filter"
|
||||
)]
|
||||
[LuaMethodAttributes("settargetscanlineintensity", "Sets the current scanline intensity setting, used for the scanline display filter")]
|
||||
public static void SetTargetScanlineIntensity(int val)
|
||||
{
|
||||
Global.Config.TargetScanlineFilterIntensity = val;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setscreenshotosd",
|
||||
"Sets the screenshot Capture OSD property of the client"
|
||||
)]
|
||||
[LuaMethodAttributes("setscreenshotosd", "Sets the screenshot Capture OSD property of the client")]
|
||||
public static void SetScreenshotOSD(bool value)
|
||||
{
|
||||
Global.Config.Screenshot_CaptureOSD = value;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"screenwidth",
|
||||
"Gets the current width in pixels of the emulator's drawing area"
|
||||
)]
|
||||
[LuaMethodAttributes("screenwidth", "Gets the current width in pixels of the emulator's drawing area")]
|
||||
public static int ScreenWidth()
|
||||
{
|
||||
return GlobalWin.MainForm.PresentationPanel.NativeSize.Width;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setwindowsize",
|
||||
"Sets the main window's size to the give value. Accepted values are 1, 2, 3, 4, 5, and 10"
|
||||
)]
|
||||
[LuaMethodAttributes("setwindowsize", "Sets the main window's size to the give value. Accepted values are 1, 2, 3, 4, 5, and 10")]
|
||||
public void SetWindowSize(int size)
|
||||
{
|
||||
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
|
||||
|
@ -386,10 +281,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"speedmode",
|
||||
"Sets the speed of the emulator (in terms of percent)"
|
||||
)]
|
||||
[LuaMethodAttributes("speedmode", "Sets the speed of the emulator (in terms of percent)")]
|
||||
public void SpeedMode(int percent)
|
||||
{
|
||||
if (percent > 0 && percent < 6400)
|
||||
|
@ -402,75 +294,51 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"togglepause",
|
||||
"Toggles the current pause state"
|
||||
)]
|
||||
[LuaMethodAttributes("togglepause", "Toggles the current pause state")]
|
||||
public static void TogglePause()
|
||||
{
|
||||
GlobalWin.MainForm.TogglePause();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"transformPointX",
|
||||
"Transforms an x-coordinate in emulator space to an x-coordinate in client space"
|
||||
)]
|
||||
[LuaMethodAttributes("transformPointX", "Transforms an x-coordinate in emulator space to an x-coordinate in client space")]
|
||||
public static int TransformPointX(int x)
|
||||
{
|
||||
var point = new System.Drawing.Point(x, 0);
|
||||
return GlobalWin.DisplayManager.TransformPoint(point).X;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"transformPointY",
|
||||
"Transforms an y-coordinate in emulator space to an y-coordinate in client space"
|
||||
)]
|
||||
[LuaMethodAttributes("transformPointY", "Transforms an y-coordinate in emulator space to an y-coordinate in client space")]
|
||||
public static int TransformPointY(int y)
|
||||
{
|
||||
var point = new System.Drawing.Point(0, y);
|
||||
return GlobalWin.DisplayManager.TransformPoint(point).Y;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"unpause",
|
||||
"Unpauses the emulator"
|
||||
)]
|
||||
[LuaMethodAttributes("unpause", "Unpauses the emulator")]
|
||||
public static void Unpause()
|
||||
{
|
||||
GlobalWin.MainForm.UnpauseEmulator();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"unpause_av",
|
||||
"If currently capturing Audio/Video this resumes capturing"
|
||||
)]
|
||||
[LuaMethodAttributes("unpause_av", "If currently capturing Audio/Video this resumes capturing")]
|
||||
public static void UnpauseAv()
|
||||
{
|
||||
GlobalWin.MainForm.PauseAVI = false;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"xpos",
|
||||
"Returns the x value of the screen position where the client currently sits"
|
||||
)]
|
||||
[LuaMethodAttributes("xpos", "Returns the x value of the screen position where the client currently sits")]
|
||||
public static int Xpos()
|
||||
{
|
||||
return GlobalWin.MainForm.DesktopLocation.X;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"ypos",
|
||||
"Returns the y value of the screen position where the client currently sits"
|
||||
)]
|
||||
[LuaMethodAttributes("ypos", "Returns the y value of the screen position where the client currently sits")]
|
||||
public static int Ypos()
|
||||
{
|
||||
return GlobalWin.MainForm.DesktopLocation.Y;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getavailabletools",
|
||||
"Returns a list of the tools currently open"
|
||||
)]
|
||||
[LuaMethodAttributes("getavailabletools", "Returns a list of the tools currently open")]
|
||||
public LuaTable GetAvailableTools()
|
||||
{
|
||||
var t = Lua.NewTable();
|
||||
|
@ -484,9 +352,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"gettool",
|
||||
"Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use gettools to get a list of names"
|
||||
)]
|
||||
"gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use gettools to get a list of names")]
|
||||
public LuaTable GetTool(string name)
|
||||
{
|
||||
var toolType = ReflectionUtil.GetTypeByName(name)
|
||||
|
@ -509,9 +375,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"createinstance",
|
||||
"returns a default instance of the given type of object if it exists (not case sensitive). Note: This will only work on objects which have a parameterless constructor. If no suitable type is found, or the type does not have a parameterless constructor, then nil is returned"
|
||||
)]
|
||||
"createinstance", "returns a default instance of the given type of object if it exists (not case sensitive). Note: This will only work on objects which have a parameterless constructor. If no suitable type is found, or the type does not have a parameterless constructor, then nil is returned")]
|
||||
public LuaTable CreateInstance(string name)
|
||||
{
|
||||
var possibleTypes = ReflectionUtil.GetTypeByName(name);
|
||||
|
@ -525,19 +389,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
return null;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"displaymessages",
|
||||
"sets whether or not on screen messages will display"
|
||||
)]
|
||||
[LuaMethodAttributes("displaymessages", "sets whether or not on screen messages will display")]
|
||||
public void DisplayMessages(bool value)
|
||||
{
|
||||
Global.Config.DisplayMessages = value;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"saveram",
|
||||
"flushes save ram to disk"
|
||||
)]
|
||||
[LuaMethodAttributes("saveram", "flushes save ram to disk")]
|
||||
public void SaveRam()
|
||||
{
|
||||
GlobalWin.MainForm.FlushSaveRAM();
|
||||
|
|
|
@ -16,21 +16,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
public ConsoleLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
public override string Name { get { return "console"; } }
|
||||
public override string Name => "console";
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"clear",
|
||||
"clears the output box of the Lua Console window"
|
||||
)]
|
||||
[LuaMethodAttributes("clear", "clears the output box of the Lua Console window")]
|
||||
public static void Clear()
|
||||
{
|
||||
GlobalWin.Tools.LuaConsole.ClearOutputWindow();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getluafunctionslist",
|
||||
"returns a list of implemented functions"
|
||||
)]
|
||||
[LuaMethodAttributes("getluafunctionslist", "returns a list of implemented functions")]
|
||||
public static string GetLuaFunctionsList()
|
||||
{
|
||||
var list = new StringBuilder();
|
||||
|
@ -42,10 +36,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return list.ToString();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"log",
|
||||
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
||||
)]
|
||||
[LuaMethodAttributes("log", "Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable")]
|
||||
public static void Log(params object[] outputs)
|
||||
{
|
||||
LogWithSeparator("\t", "\n", outputs);
|
||||
|
@ -57,19 +48,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
Log(output);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"writeline",
|
||||
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
||||
)]
|
||||
[LuaMethodAttributes("writeline", "Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable")]
|
||||
public static void WriteLine(params object[] outputs)
|
||||
{
|
||||
LogWithSeparator("\n", "\n", outputs);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"write",
|
||||
"Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable"
|
||||
)]
|
||||
[LuaMethodAttributes("write", "Outputs the given object to the output box on the Lua Console dialog. Note: Can accept a LuaTable")]
|
||||
public static void Write(params object[] outputs)
|
||||
{
|
||||
LogWithSeparator("", "", outputs);
|
||||
|
@ -83,6 +68,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow("(no return)" + terminator);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var outIndex = 0; outIndex < outputs.Length; outIndex++)
|
||||
{
|
||||
var output = outputs[outIndex];
|
||||
|
@ -135,6 +121,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlobalWin.Tools.LuaConsole.WriteToOutputWindow(terminator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
: base(lua, logOutputCallback) { }
|
||||
|
||||
// TODO: replace references to ConsoleLuaLibrary.Log with a callback that is passed in
|
||||
public override string Name { get { return "forms"; } }
|
||||
public override string Name => "forms";
|
||||
|
||||
#region Forms Library Helpers
|
||||
|
||||
|
@ -61,10 +61,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
#endregion
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"addclick",
|
||||
"adds the given lua function as a click event to the given control"
|
||||
)]
|
||||
[LuaMethodAttributes("addclick", "adds the given lua function as a click event to the given control")]
|
||||
public void AddClick(int handle, LuaFunction clickEvent)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -81,9 +78,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"button",
|
||||
"Creates a button control on the given form. The caption property will be the text value on the button. clickEvent is the name of a Lua function that will be invoked when the button is clicked. x, and y are the optional location parameters for the position of the button within the given form. The function returns the handle of the created button. Width and Height are optional, if not specified they will be a default size"
|
||||
)]
|
||||
"button", "Creates a button control on the given form. The caption property will be the text value on the button. clickEvent is the name of a Lua function that will be invoked when the button is clicked. x, and y are the optional location parameters for the position of the button within the given form. The function returns the handle of the created button. Width and Height are optional, if not specified they will be a default size")]
|
||||
public int Button(
|
||||
int formHandle,
|
||||
string caption,
|
||||
|
@ -118,9 +113,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"checkbox",
|
||||
"Creates a checkbox control on the given form. The caption property will be the text of the checkbox. x and y are the optional location parameters for the position of the checkbox within the form"
|
||||
)]
|
||||
"checkbox", "Creates a checkbox control on the given form. The caption property will be the text of the checkbox. x and y are the optional location parameters for the position of the checkbox within the form")]
|
||||
public int Checkbox(int formHandle, string caption, int? x = null, int? y = null)
|
||||
{
|
||||
var form = GetForm(formHandle);
|
||||
|
@ -141,10 +134,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return (int)checkbox.Handle;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"clearclicks",
|
||||
"Removes all click events from the given widget at the specified handle"
|
||||
)]
|
||||
[LuaMethodAttributes("clearclicks", "Removes all click events from the given widget at the specified handle")]
|
||||
public void ClearClicks(int handle)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -164,10 +154,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"destroy",
|
||||
"Closes and removes a Lua created form with the specified handle. If a dialog was found and removed true is returned, else false"
|
||||
)]
|
||||
[LuaMethodAttributes("destroy", "Closes and removes a Lua created form with the specified handle. If a dialog was found and removed true is returned, else false")]
|
||||
public bool Destroy(int handle)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -184,10 +171,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return false;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"destroyall",
|
||||
"Closes and removes all Lua created dialogs"
|
||||
)]
|
||||
[LuaMethodAttributes("destroyall", "Closes and removes all Lua created dialogs")]
|
||||
public void DestroyAll()
|
||||
{
|
||||
for (var i = _luaForms.Count - 1; i >= 0; i--)
|
||||
|
@ -197,9 +181,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"dropdown",
|
||||
"Creates a dropdown (with a ComboBoxStyle of DropDownList) control on the given form. Dropdown items are passed via a lua table. Only the values will be pulled for the dropdown items, the keys are irrelevant. Items will be sorted alphabetically. x and y are the optional location parameters, and width and height are the optional size parameters."
|
||||
)]
|
||||
"dropdown", "Creates a dropdown (with a ComboBoxStyle of DropDownList) control on the given form. Dropdown items are passed via a lua table. Only the values will be pulled for the dropdown items, the keys are irrelevant. Items will be sorted alphabetically. x and y are the optional location parameters, and width and height are the optional size parameters.")]
|
||||
public int Dropdown(
|
||||
int formHandle,
|
||||
LuaTable items,
|
||||
|
@ -233,10 +215,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return (int)dropdown.Handle;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getproperty",
|
||||
"returns a string representation of the value of a property of the widget at the given handle"
|
||||
)]
|
||||
[LuaMethodAttributes("getproperty", "returns a string representation of the value of a property of the widget at the given handle")]
|
||||
public string GetProperty(int handle, string property)
|
||||
{
|
||||
try
|
||||
|
@ -266,10 +245,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"gettext",
|
||||
"Returns the text property of a given form or control"
|
||||
)]
|
||||
[LuaMethodAttributes("gettext", "Returns the text property of a given form or control")]
|
||||
public string GetText(int handle)
|
||||
{
|
||||
try
|
||||
|
@ -304,10 +280,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"ischecked",
|
||||
"Returns the given checkbox's checked property"
|
||||
)]
|
||||
[LuaMethodAttributes("ischecked", "Returns the given checkbox's checked property")]
|
||||
public bool IsChecked(int handle)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -336,9 +309,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"label",
|
||||
"Creates a label control on the given form. The caption property is the text of the label. x, and y are the optional location parameters for the position of the label within the given form. The function returns the handle of the created label. Width and Height are optional, if not specified they will be a default size."
|
||||
)]
|
||||
"label", "Creates a label control on the given form. The caption property is the text of the label. x, and y are the optional location parameters for the position of the label within the given form. The function returns the handle of the created label. Width and Height are optional, if not specified they will be a default size.")]
|
||||
public int Label(
|
||||
int formHandle,
|
||||
string caption,
|
||||
|
@ -377,9 +348,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"newform",
|
||||
"creates a new default dialog, if both width and height are specified it will create a dialog of the specified size. If title is specified it will be the caption of the dialog, else the dialog caption will be 'Lua Dialog'. The function will return an int representing the handle of the dialog created."
|
||||
)]
|
||||
"newform", "creates a new default dialog, if both width and height are specified it will create a dialog of the specified size. If title is specified it will be the caption of the dialog, else the dialog caption will be 'Lua Dialog'. The function will return an int representing the handle of the dialog created.")]
|
||||
public int NewForm(int? width = null, int? height = null, string title = null, LuaFunction onClose = null)
|
||||
{
|
||||
var form = new LuaWinform(CurrentThread);
|
||||
|
@ -414,9 +383,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"openfile",
|
||||
"Creates a standard openfile dialog with optional parameters for the filename, directory, and filter. The return value is the directory that the user picked. If they chose to cancel, it will return an empty string"
|
||||
)]
|
||||
"openfile", "Creates a standard openfile dialog with optional parameters for the filename, directory, and filter. The return value is the directory that the user picked. If they chose to cancel, it will return an empty string")]
|
||||
public string OpenFile(string fileName = null, string initialDirectory = null, string filter = "All files (*.*)|*.*")
|
||||
{
|
||||
// filterext format ex: "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
||||
|
@ -445,24 +412,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setdropdownitems",
|
||||
"Sets the items for a given dropdown box"
|
||||
)]
|
||||
public void SetDropdownItems(
|
||||
int handle,
|
||||
LuaTable items)
|
||||
[LuaMethodAttributes("setdropdownitems", "Sets the items for a given dropdown box")]
|
||||
public void SetDropdownItems(int handle, LuaTable items)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
foreach (var form in _luaForms) {
|
||||
if (form.Handle == ptr) {
|
||||
foreach (var form in _luaForms)
|
||||
{
|
||||
if (form.Handle == ptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Control control in form.Controls) {
|
||||
if (control.Handle == ptr) {
|
||||
if (control is LuaDropDown) {
|
||||
foreach (Control control in form.Controls)
|
||||
{
|
||||
if (control.Handle == ptr)
|
||||
{
|
||||
if (control is LuaDropDown)
|
||||
{
|
||||
var dropdownItems = items.Values.Cast<string>().ToList();
|
||||
dropdownItems.Sort();
|
||||
(control as LuaDropDown).SetItems(dropdownItems);
|
||||
|
@ -472,15 +440,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ConsoleLuaLibrary.Log(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setlocation",
|
||||
"Sets the location of a control or form by passing in the handle of the created object"
|
||||
)]
|
||||
[LuaMethodAttributes("setlocation", "Sets the location of a control or form by passing in the handle of the created object")]
|
||||
public void SetLocation(int handle, int x, int y)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -503,10 +470,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setproperty",
|
||||
"Attempts to set the given property of the widget with the given value. Note: not all properties will be able to be represented for the control to accept"
|
||||
)]
|
||||
[LuaMethodAttributes("setproperty", "Attempts to set the given property of the widget with the given value. Note: not all properties will be able to be represented for the control to accept")]
|
||||
public void SetProperty(int handle, string property, object value)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -519,16 +483,25 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
value = Enum.Parse(form.GetType().GetProperty(property).PropertyType, value.ToString(), true);
|
||||
}
|
||||
|
||||
if (pt == typeof(Color))
|
||||
{
|
||||
//relying on exceptions for error handling here
|
||||
// relying on exceptions for error handling here
|
||||
var sval = (string)value;
|
||||
if (sval[0] != '#') throw new Exception("Invalid #aarrggbb color");
|
||||
if (sval.Length != 9) throw new Exception("Invalid #aarrggbb color");
|
||||
if (sval[0] != '#')
|
||||
{
|
||||
throw new Exception("Invalid #aarrggbb color");
|
||||
}
|
||||
|
||||
if (sval.Length != 9)
|
||||
{
|
||||
throw new Exception("Invalid #aarrggbb color");
|
||||
}
|
||||
|
||||
value = Color.FromArgb(int.Parse(sval.Substring(1),System.Globalization.NumberStyles.HexNumber));
|
||||
}
|
||||
form
|
||||
.GetType()
|
||||
|
||||
form.GetType()
|
||||
.GetProperty(property)
|
||||
.SetValue(form, Convert.ChangeType(value, form.GetType().GetProperty(property).PropertyType), null);
|
||||
}
|
||||
|
@ -542,8 +515,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
value = Enum.Parse(control.GetType().GetProperty(property).PropertyType, value.ToString(), true);
|
||||
}
|
||||
control
|
||||
.GetType()
|
||||
|
||||
control.GetType()
|
||||
.GetProperty(property)
|
||||
.SetValue(control, Convert.ChangeType(value, control.GetType().GetProperty(property).PropertyType), null);
|
||||
}
|
||||
|
@ -552,19 +525,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"createcolor",
|
||||
"Creates a color object useful with setproperty"
|
||||
)]
|
||||
[LuaMethodAttributes("createcolor", "Creates a color object useful with setproperty")]
|
||||
public Color CreateColor(int r, int g, int b, int a)
|
||||
{
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setsize",
|
||||
"TODO"
|
||||
)]
|
||||
[LuaMethodAttributes("setsize", "TODO")]
|
||||
public void SetSize(int handle, int width, int height)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -587,10 +554,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"settext",
|
||||
"Sets the text property of a control or form by passing in the handle of the created object"
|
||||
)]
|
||||
[LuaMethodAttributes("settext", "Sets the text property of a control or form by passing in the handle of the created object")]
|
||||
public void Settext(int handle, string caption)
|
||||
{
|
||||
var ptr = new IntPtr(handle);
|
||||
|
@ -614,9 +578,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"textbox",
|
||||
"Creates a textbox control on the given form. The caption property will be the initial value of the textbox (default is empty). Width and Height are option, if not specified they will be a default size of 100, 20. Type is an optional property to restrict the textbox input. The available options are HEX, SIGNED, and UNSIGNED. Passing it null or any other value will set it to no restriction. x, and y are the optional location parameters for the position of the textbox within the given form. The function returns the handle of the created textbox. If true, the multiline will enable the standard winform multi-line property. If true, the fixedWidth options will create a fixed width font. Scrollbars is an optional property to specify which scrollbars to display. The available options are Vertical, Horizontal, Both, and None. Scrollbars are only shown on a multiline textbox"
|
||||
)]
|
||||
"textbox", "Creates a textbox control on the given form. The caption property will be the initial value of the textbox (default is empty). Width and Height are option, if not specified they will be a default size of 100, 20. Type is an optional property to restrict the textbox input. The available options are HEX, SIGNED, and UNSIGNED. Passing it null or any other value will set it to no restriction. x, and y are the optional location parameters for the position of the textbox within the given form. The function returns the handle of the created textbox. If true, the multiline will enable the standard winform multi-line property. If true, the fixedWidth options will create a fixed width font. Scrollbars is an optional property to specify which scrollbars to display. The available options are Vertical, Horizontal, Both, and None. Scrollbars are only shown on a multiline textbox")]
|
||||
public int Textbox(
|
||||
int formHandle,
|
||||
string caption = null,
|
||||
|
@ -662,6 +624,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetText(textbox, caption);
|
||||
|
||||
if (x.HasValue && y.HasValue)
|
||||
|
|
|
@ -21,12 +21,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
public GuiLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
private Color DefaultForeground = Color.White;
|
||||
private Color? DefaultBackground = null;
|
||||
private Color? DefaultTextBackground = Color.FromArgb(128, 0, 0, 0);
|
||||
private int DefaultPixelFont = 1; // gens
|
||||
private Color _defaultForeground = Color.White;
|
||||
private Color? _defaultBackground;
|
||||
private Color? _defaultTextBackground = Color.FromArgb(128, 0, 0, 0);
|
||||
private int _defaultPixelFont = 1; // gens
|
||||
|
||||
public override string Name { get { return "gui"; } }
|
||||
public override string Name => "gui";
|
||||
|
||||
#region Gui API
|
||||
|
||||
|
@ -43,24 +43,16 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public bool SurfaceIsNull
|
||||
{
|
||||
get
|
||||
{
|
||||
return _luaSurface == null;
|
||||
}
|
||||
}
|
||||
public bool SurfaceIsNull => _luaSurface == null;
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"DrawNew",
|
||||
"Changes drawing target to the specified lua surface name. This may clobber any previous drawing to this surface (pass false if you don't want it to)"
|
||||
)]
|
||||
public void DrawNew(string name, bool? clear=true)
|
||||
"DrawNew", "Changes drawing target to the specified lua surface name. This may clobber any previous drawing to this surface (pass false if you don't want it to)")]
|
||||
public void DrawNew(string name, bool? clear = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
DrawFinish();
|
||||
_luaSurface = GlobalWin.DisplayManager.LockLuaSurface(name,clear??true);
|
||||
_luaSurface = GlobalWin.DisplayManager.LockLuaSurface(name, clear ?? true);
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
|
@ -68,25 +60,23 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"DrawFinish",
|
||||
"Finishes drawing to the current lua surface and causes it to get displayed."
|
||||
)]
|
||||
[LuaMethodAttributes("DrawFinish", "Finishes drawing to the current lua surface and causes it to get displayed.")]
|
||||
public void DrawFinish()
|
||||
{
|
||||
if(_luaSurface != null)
|
||||
if (_luaSurface != null)
|
||||
{
|
||||
GlobalWin.DisplayManager.UnlockLuaSurface(_luaSurface);
|
||||
}
|
||||
|
||||
_luaSurface = null;
|
||||
}
|
||||
|
||||
public bool HasLuaSurface
|
||||
{
|
||||
get { return _luaSurface != null; }
|
||||
}
|
||||
public bool HasLuaSurface => _luaSurface != null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
private readonly Dictionary<string, Image> _imageCache = new Dictionary<string, Image>();
|
||||
|
||||
private readonly Dictionary<Color, SolidBrush> _solidBrushes = new Dictionary<Color, SolidBrush>();
|
||||
private readonly Dictionary<Color, Pen> _pens = new Dictionary<Color, Pen>();
|
||||
|
@ -122,7 +112,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var g = _luaSurface == null ? Graphics.FromImage(_nullGraphicsBitmap) : _luaSurface.GetGraphics();
|
||||
|
||||
//we don't like CoreComm, right? Someone should find a different way to do this then.
|
||||
// we don't like CoreComm, right? Someone should find a different way to do this then.
|
||||
var tx = Emulator.CoreComm.ScreenLogicalOffsetX;
|
||||
var ty = Emulator.CoreComm.ScreenLogicalOffsetY;
|
||||
if (tx != 0 || ty != 0)
|
||||
|
@ -137,89 +127,64 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
#endregion
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"addmessage",
|
||||
"Adds a message to the OSD's message area"
|
||||
)]
|
||||
[LuaMethodAttributes("addmessage", "Adds a message to the OSD's message area")]
|
||||
public void AddMessage(string message)
|
||||
{
|
||||
GlobalWin.OSD.AddMessage(message);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"clearGraphics",
|
||||
"clears all lua drawn graphics from the screen"
|
||||
)]
|
||||
[LuaMethodAttributes("clearGraphics", "clears all lua drawn graphics from the screen")]
|
||||
public void ClearGraphics()
|
||||
{
|
||||
_luaSurface.Clear();
|
||||
DrawFinish();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"cleartext",
|
||||
"clears all text created by gui.text()"
|
||||
)]
|
||||
[LuaMethodAttributes("cleartext", "clears all text created by gui.text()")]
|
||||
public static void ClearText()
|
||||
{
|
||||
GlobalWin.OSD.ClearGUIText();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"defaultForeground",
|
||||
"Sets the default foreground color to use in drawing methods, white by default"
|
||||
)]
|
||||
[LuaMethodAttributes("defaultForeground", "Sets the default foreground color to use in drawing methods, white by default")]
|
||||
public void SetDefaultForegroundColor(Color color)
|
||||
{
|
||||
DefaultForeground = color;
|
||||
_defaultForeground = color;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"defaultBackground",
|
||||
"Sets the default background color to use in drawing methods, transparent by default"
|
||||
)]
|
||||
[LuaMethodAttributes("defaultBackground", "Sets the default background color to use in drawing methods, transparent by default")]
|
||||
public void SetDefaultBackgroundColor(Color color)
|
||||
{
|
||||
DefaultBackground = color;
|
||||
_defaultBackground = color;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"defaultTextBackground",
|
||||
"Sets the default backgroiund color to use in text drawing methods, half-transparent black by default"
|
||||
)]
|
||||
[LuaMethodAttributes("defaultTextBackground", "Sets the default backgroiund color to use in text drawing methods, half-transparent black by default")]
|
||||
public void SetDefaultTextBackground(Color color)
|
||||
{
|
||||
DefaultTextBackground = color;
|
||||
_defaultTextBackground = color;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"defaultPixelFont",
|
||||
"Sets the default font to use in gui.pixelText(). Two font families are available, \"fceux\" and \"gens\" (or \"0\" and \"1\" respectively), \"gens\" is used by default"
|
||||
)]
|
||||
"defaultPixelFont", "Sets the default font to use in gui.pixelText(). Two font families are available, \"fceux\" and \"gens\" (or \"0\" and \"1\" respectively), \"gens\" is used by default")]
|
||||
public void SetDefaultTextBackground(string fontfamily)
|
||||
{
|
||||
switch (fontfamily)
|
||||
{
|
||||
case "fceux":
|
||||
case "0":
|
||||
DefaultPixelFont = 0;
|
||||
_defaultPixelFont = 0;
|
||||
break;
|
||||
case "gens":
|
||||
case "1":
|
||||
DefaultPixelFont = 1;
|
||||
_defaultPixelFont = 1;
|
||||
break;
|
||||
default:
|
||||
Log(string.Format("Unable to find font family: {0}", fontfamily));
|
||||
Log($"Unable to find font family: {fontfamily}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawBezier",
|
||||
"Draws a Bezier curve using the table of coordinates provided in the given color"
|
||||
)]
|
||||
[LuaMethodAttributes("drawBezier", "Draws a Bezier curve using the table of coordinates provided in the given color")]
|
||||
public void DrawBezier(LuaTable points, Color color)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
|
@ -249,9 +214,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawBox",
|
||||
"Draws a rectangle on screen from x1/y1 to x2/y2. Same as drawRectangle except it receives two points intead of a point and width/height"
|
||||
)]
|
||||
"drawBox", "Draws a rectangle on screen from x1/y1 to x2/y2. Same as drawRectangle except it receives two points intead of a point and width/height")]
|
||||
public void DrawBox(int x, int y, int x2, int y2, Color? line = null, Color? background = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
|
@ -278,9 +241,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
y -= y2;
|
||||
}
|
||||
|
||||
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, x2, y2);
|
||||
g.DrawRectangle(GetPen(line ?? _defaultForeground), x, y, x2, y2);
|
||||
|
||||
var bg = background ?? DefaultBackground;
|
||||
var bg = background ?? _defaultBackground;
|
||||
if (bg.HasValue)
|
||||
{
|
||||
g.FillRectangle(GetBrush(bg.Value), x + 1, y + 1, x2 - 1, y2 - 1);
|
||||
|
@ -295,23 +258,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawEllipse",
|
||||
"Draws an ellipse at the given coordinates and the given width and height. Line is the color of the ellipse. Background is the optional fill color"
|
||||
)]
|
||||
"drawEllipse", "Draws an ellipse at the given coordinates and the given width and height. Line is the color of the ellipse. Background is the optional fill color")]
|
||||
public void DrawEllipse(int x, int y, int width, int height, Color? line = null, Color? background = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
var bg = background ?? DefaultBackground;
|
||||
var bg = background ?? _defaultBackground;
|
||||
if (bg.HasValue)
|
||||
{
|
||||
var brush = GetBrush(bg.Value);
|
||||
g.FillEllipse(brush, x, y, width, height);
|
||||
}
|
||||
|
||||
g.DrawEllipse(GetPen(line ?? DefaultForeground), x, y, width, height);
|
||||
g.DrawEllipse(GetPen(line ?? _defaultForeground), x, y, width, height);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -322,9 +283,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawIcon",
|
||||
"draws an Icon (.ico) file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly"
|
||||
)]
|
||||
"drawIcon", "draws an Icon (.ico) file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly")]
|
||||
public void DrawIcon(string path, int x, int y, int? width = null, int? height = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
|
@ -350,12 +309,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, Image> ImageCache = new Dictionary<string, Image>();
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawImage",
|
||||
"draws an image file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly"
|
||||
)]
|
||||
"drawImage", "draws an image file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly")]
|
||||
public void DrawImage(string path, int x, int y, int? width = null, int? height = null)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
@ -367,14 +322,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
using (var g = GetGraphics())
|
||||
{
|
||||
Image img;
|
||||
if (ImageCache.ContainsKey(path))
|
||||
if (_imageCache.ContainsKey(path))
|
||||
{
|
||||
img = ImageCache[path];
|
||||
img = _imageCache[path];
|
||||
}
|
||||
else
|
||||
{
|
||||
img = Image.FromFile(path);
|
||||
ImageCache.Add(path, img);
|
||||
_imageCache.Add(path, img);
|
||||
}
|
||||
|
||||
g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height);
|
||||
|
@ -382,9 +337,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawImageRegion",
|
||||
"draws a given region of an image file from the given path at the given coordinate, and optionally with the given size"
|
||||
)]
|
||||
"drawImageRegion", "draws a given region of an image file from the given path at the given coordinate, and optionally with the given size")]
|
||||
public void DrawImageRegion(string path, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int? dest_width = null, int? dest_height = null)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
@ -396,50 +349,40 @@ namespace BizHawk.Client.EmuHawk
|
|||
using (var g = GetGraphics())
|
||||
{
|
||||
Image img;
|
||||
if (ImageCache.ContainsKey(path))
|
||||
if (_imageCache.ContainsKey(path))
|
||||
{
|
||||
img = ImageCache[path];
|
||||
img = _imageCache[path];
|
||||
}
|
||||
else
|
||||
{
|
||||
img = Image.FromFile(path);
|
||||
ImageCache.Add(path, img);
|
||||
_imageCache.Add(path, img);
|
||||
}
|
||||
|
||||
var dest_rect = new Rectangle(dest_x, dest_y, (dest_width ?? source_width), (dest_height ?? source_height));
|
||||
var destRect = new Rectangle(dest_x, dest_y, dest_width ?? source_width, dest_height ?? source_height);
|
||||
|
||||
g.DrawImage(img, dest_rect, source_x, source_y, source_width, source_height, GraphicsUnit.Pixel);
|
||||
g.DrawImage(img, destRect, source_x, source_y, source_width, source_height, GraphicsUnit.Pixel);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawLine",
|
||||
"Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black)"
|
||||
)]
|
||||
"drawLine", "Draws a line from the first coordinate pair to the 2nd. Color is optional (if not specified it will be drawn black)")]
|
||||
public void DrawLine(int x1, int y1, int x2, int y2, Color? color = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
g.DrawLine(GetPen(color ?? DefaultForeground), x1, y1, x2, y2);
|
||||
g.DrawLine(GetPen(color ?? _defaultForeground), x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawAxis",
|
||||
"Draws an axis of the specified size at the coordinate pair.)"
|
||||
)]
|
||||
|
||||
[LuaMethodAttributes("drawAxis", "Draws an axis of the specified size at the coordinate pair.)")]
|
||||
public void DrawAxis(int x, int y, int size, Color? color = null)
|
||||
{
|
||||
DrawLine(x + size, y, x - size, y, color);
|
||||
DrawLine(x, y + size, x, y - size, color);
|
||||
}
|
||||
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawPie",
|
||||
"draws a Pie shape at the given coordinates and the given width and height"
|
||||
)]
|
||||
[LuaMethodAttributes("drawPie", "draws a Pie shape at the given coordinates and the given width and height")]
|
||||
public void DrawPie(
|
||||
int x,
|
||||
int y,
|
||||
|
@ -452,29 +395,26 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
var bg = background ?? DefaultBackground;
|
||||
var bg = background ?? _defaultBackground;
|
||||
if (bg.HasValue)
|
||||
{
|
||||
var brush = GetBrush(bg.Value);
|
||||
g.FillPie(brush, x, y, width, height, startangle, sweepangle);
|
||||
}
|
||||
|
||||
g.DrawPie(GetPen(line ?? DefaultForeground), x + 1, y + 1, width - 1, height - 1, startangle, sweepangle);
|
||||
|
||||
g.DrawPie(GetPen(line ?? _defaultForeground), x + 1, y + 1, width - 1, height - 1, startangle, sweepangle);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawPixel",
|
||||
"Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black)"
|
||||
)]
|
||||
"drawPixel", "Draws a single pixel at the given coordinates in the given color. Color is optional (if not specified it will be drawn black)")]
|
||||
public void DrawPixel(int x, int y, Color? color = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
try
|
||||
{
|
||||
g.DrawLine(GetPen(color ?? DefaultForeground), x, y, x + 0.1F, y);
|
||||
g.DrawLine(GetPen(color ?? _defaultForeground), x, y, x + 0.1F, y);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -484,9 +424,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawPolygon",
|
||||
"Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color"
|
||||
)]
|
||||
"drawPolygon", "Draws a polygon using the table of coordinates specified in points. This should be a table of tables(each of size 2). Line is the color of the polygon. Background is the optional fill color")]
|
||||
public void DrawPolygon(LuaTable points, Color? line = null, Color? background = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
|
@ -501,8 +439,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
i++;
|
||||
}
|
||||
|
||||
g.DrawPolygon(GetPen(line ?? DefaultForeground), pointsArr);
|
||||
var bg = background ?? DefaultBackground;
|
||||
g.DrawPolygon(GetPen(line ?? _defaultForeground), pointsArr);
|
||||
var bg = background ?? _defaultBackground;
|
||||
if (bg.HasValue)
|
||||
{
|
||||
g.FillPolygon(GetBrush(bg.Value), pointsArr);
|
||||
|
@ -516,15 +454,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawRectangle",
|
||||
"Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color"
|
||||
)]
|
||||
"drawRectangle", "Draws a rectangle at the given coordinate and the given width and height. Line is the color of the box. Background is the optional fill color")]
|
||||
public void DrawRectangle(int x, int y, int width, int height, Color? line = null, Color? background = null)
|
||||
{
|
||||
using (var g = GetGraphics())
|
||||
{
|
||||
g.DrawRectangle(GetPen(line ?? DefaultForeground), x, y, width, height);
|
||||
var bg = background ?? DefaultBackground;
|
||||
g.DrawRectangle(GetPen(line ?? _defaultForeground), x, y, width, height);
|
||||
var bg = background ?? _defaultBackground;
|
||||
if (bg.HasValue)
|
||||
{
|
||||
g.FillRectangle(GetBrush(bg.Value), x + 1, y + 1, width - 1, height - 1);
|
||||
|
@ -532,10 +468,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawString",
|
||||
"Alias of gui.drawText()"
|
||||
)]
|
||||
[LuaMethodAttributes("drawString", "Alias of gui.drawText()")]
|
||||
public void DrawString(
|
||||
int x,
|
||||
int y,
|
||||
|
@ -552,9 +485,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"drawText",
|
||||
"Draws the given message in the emulator screen space (like all draw functions) at the given x,y coordinates and the given color. The default color is white. A fontfamily can be specified and is monospace generic if none is specified (font family options are the same as the .NET FontFamily class). The fontsize default is 12. The default font style is regular. Font style options are regular, bold, italic, strikethrough, underline. Horizontal alignment options are left (default), center, or right. Vertical alignment options are bottom (default), middle, or top. Alignment options specify which ends of the text will be drawn at the x and y coordinates."
|
||||
)]
|
||||
"drawText", "Draws the given message in the emulator screen space (like all draw functions) at the given x,y coordinates and the given color. The default color is white. A fontfamily can be specified and is monospace generic if none is specified (font family options are the same as the .NET FontFamily class). The fontsize default is 12. The default font style is regular. Font style options are regular, bold, italic, strikethrough, underline. Horizontal alignment options are left (default), center, or right. Vertical alignment options are bottom (default), middle, or top. Alignment options specify which ends of the text will be drawn at the x and y coordinates.")]
|
||||
public void DrawText(
|
||||
int x,
|
||||
int y,
|
||||
|
@ -602,7 +533,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// The text isn't written out using GenericTypographic, so measuring it using GenericTypographic seemed to make it worse.
|
||||
// And writing it out with GenericTypographic just made it uglier. :p
|
||||
StringFormat f = new StringFormat(StringFormat.GenericDefault);
|
||||
var f = new StringFormat(StringFormat.GenericDefault);
|
||||
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
|
||||
Size sizeOfText = g.MeasureString(message, font, 0, f).ToSize();
|
||||
if (horizalign != null)
|
||||
|
@ -620,6 +551,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (vertalign != null)
|
||||
{
|
||||
switch (vertalign.ToLower())
|
||||
|
@ -635,10 +567,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle rect = new Rectangle(new Point(x, y), sizeOfText);
|
||||
g.FillRectangle(GetBrush(backcolor ?? DefaultTextBackground.Value), rect);
|
||||
g.FillRectangle(GetBrush(backcolor ?? _defaultTextBackground.Value), rect);
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
|
||||
g.DrawString(message, font, GetBrush(forecolor ?? DefaultForeground), x, y);
|
||||
g.DrawString(message, font, GetBrush(forecolor ?? _defaultForeground), x, y);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -649,8 +582,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
[LuaMethodAttributes(
|
||||
"pixelText",
|
||||
"Draws the given message in the emulator screen space (like all draw functions) at the given x,y coordinates and the given color. The default color is white. Two font families are available, \"fceux\" and \"gens\" (or \"0\" and \"1\" respectively), both are monospace and have the same size as in the emulaors they've been taken from. If no font family is specified, it uses \"gens\" font, unless that's overridden via gui.defaultPixelFont()"
|
||||
)]
|
||||
"Draws the given message in the emulator screen space (like all draw functions) at the given x,y coordinates and the given color. The default color is white. Two font families are available, \"fceux\" and \"gens\" (or \"0\" and \"1\" respectively), both are monospace and have the same size as in the emulaors they've been taken from. If no font family is specified, it uses \"gens\" font, unless that's overridden via gui.defaultPixelFont()")]
|
||||
public void DrawText(
|
||||
int x,
|
||||
int y,
|
||||
|
@ -666,7 +598,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
var index = 0;
|
||||
if (string.IsNullOrEmpty(fontfamily))
|
||||
{
|
||||
index = DefaultPixelFont;
|
||||
index = _defaultPixelFont;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -681,20 +613,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
index = 1;
|
||||
break;
|
||||
default:
|
||||
Log(string.Format("Unable to find font family: {0}", fontfamily));
|
||||
Log($"Unable to find font family: {fontfamily}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
StringFormat f = new StringFormat(StringFormat.GenericTypographic)
|
||||
|
||||
var f = new StringFormat(StringFormat.GenericTypographic)
|
||||
{
|
||||
FormatFlags = StringFormatFlags.MeasureTrailingSpaces
|
||||
};
|
||||
var font = new Font(GlobalWin.DisplayManager.CustomFonts.Families[index], 8, FontStyle.Regular, GraphicsUnit.Pixel);
|
||||
Size sizeOfText = g.MeasureString(message, font, 0, f).ToSize();
|
||||
Rectangle rect = new Rectangle(new Point(x, y), sizeOfText + new Size(1, 0));
|
||||
g.FillRectangle(GetBrush(backcolor ?? DefaultTextBackground.Value), rect);
|
||||
var rect = new Rectangle(new Point(x, y), sizeOfText + new Size(1, 0));
|
||||
g.FillRectangle(GetBrush(backcolor ?? _defaultTextBackground.Value), rect);
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
|
||||
g.DrawString(message, font, GetBrush(forecolor ?? DefaultForeground), x, y);
|
||||
g.DrawString(message, font, GetBrush(forecolor ?? _defaultForeground), x, y);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -704,9 +637,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"text",
|
||||
"Displays the given text on the screen at the given coordinates. Optional Foreground color. The optional anchor flag anchors the text to one of the four corners. Anchor flag parameters: topleft, topright, bottomleft, bottomright"
|
||||
)]
|
||||
"text", "Displays the given text on the screen at the given coordinates. Optional Foreground color. The optional anchor flag anchors the text to one of the four corners. Anchor flag parameters: topleft, topright, bottomleft, bottomright")]
|
||||
public void Text(
|
||||
int x,
|
||||
int y,
|
||||
|
@ -747,10 +678,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
GlobalWin.OSD.AddGUIText(message, x, y, Color.Black, forecolor ?? Color.White, a);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"createcanvas",
|
||||
"Creates a canvas of the given size."
|
||||
)]
|
||||
[LuaMethodAttributes("createcanvas", "Creates a canvas of the given size.")]
|
||||
public LuaTable Text(int width, int height)
|
||||
{
|
||||
var canvas = new LuaCanvas(width, height);
|
||||
|
|
|
@ -15,12 +15,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
public InputLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
public override string Name { get { return "input"; } }
|
||||
public override string Name => "input";
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"get",
|
||||
"Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil."
|
||||
)]
|
||||
"get", "Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil.")]
|
||||
public LuaTable Get()
|
||||
{
|
||||
var buttons = Lua.NewTable();
|
||||
|
@ -33,13 +31,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getmouse",
|
||||
"Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel."
|
||||
)]
|
||||
"getmouse", "Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel.")]
|
||||
public LuaTable GetMouse()
|
||||
{
|
||||
var buttons = Lua.NewTable();
|
||||
//TODO - need to specify whether in "emu" or "native" coordinate space.
|
||||
|
||||
// TODO - need to specify whether in "emu" or "native" coordinate space.
|
||||
var p = GlobalWin.DisplayManager.UntransformPoint(Control.MousePosition);
|
||||
buttons["X"] = p.X;
|
||||
buttons["Y"] = p.Y;
|
||||
|
|
|
@ -15,17 +15,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
public SavestateLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
public override string Name { get { return "savestate"; } }
|
||||
public override string Name => "savestate";
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"load",
|
||||
"Loads a savestate with the given path"
|
||||
)]
|
||||
[LuaMethodAttributes("load", "Loads a savestate with the given path")]
|
||||
public void Load(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Log(string.Format("could not find file: {0}", path));
|
||||
Log($"could not find file: {path}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -33,10 +30,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"loadslot",
|
||||
"Loads the savestate at the given slot number (must be an integer between 0 and 9)"
|
||||
)]
|
||||
[LuaMethodAttributes("loadslot", "Loads the savestate at the given slot number (must be an integer between 0 and 9)")]
|
||||
public void LoadSlot(int slotNum)
|
||||
{
|
||||
if (slotNum >= 0 && slotNum <= 9)
|
||||
|
@ -45,19 +39,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"save",
|
||||
"Saves a state at the given path"
|
||||
)]
|
||||
[LuaMethodAttributes("save", "Saves a state at the given path")]
|
||||
public void Save(string path)
|
||||
{
|
||||
GlobalWin.MainForm.SaveState(path, path, true);
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"saveslot",
|
||||
"Saves a state at the given save slot (must be an integer between 0 and 9)"
|
||||
)]
|
||||
[LuaMethodAttributes("saveslot", "Saves a state at the given save slot (must be an integer between 0 and 9)")]
|
||||
public void SaveSlot(int slotNum)
|
||||
{
|
||||
if (slotNum >= 0 && slotNum <= 9)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using LuaInterface;
|
||||
using System.Drawing;
|
||||
|
||||
using LuaInterface;
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
[Description("A library for manipulating the Tastudio dialog of the EmuHawk client")]
|
||||
|
@ -17,58 +17,38 @@ namespace BizHawk.Client.EmuHawk
|
|||
public TastudioLuaLibrary(Lua lua, Action<string> logOutputCallback)
|
||||
: base(lua, logOutputCallback) { }
|
||||
|
||||
public override string Name { get { return "tastudio"; } }
|
||||
public override string Name => "tastudio";
|
||||
|
||||
private TAStudio Tastudio
|
||||
{
|
||||
get
|
||||
{
|
||||
return GlobalWin.Tools.Get<TAStudio>() as TAStudio;
|
||||
}
|
||||
}
|
||||
private TAStudio Tastudio => GlobalWin.Tools.Get<TAStudio>() as TAStudio;
|
||||
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"engaged",
|
||||
"returns whether or not tastudio is currently engaged (active)"
|
||||
)]
|
||||
[LuaMethodAttributes("engaged", "returns whether or not tastudio is currently engaged (active)")]
|
||||
public bool Engaged()
|
||||
{
|
||||
return GlobalWin.Tools.Has<TAStudio>(); // TODO: eventually tastudio should have an engaged flag
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getrecording",
|
||||
"returns whether or not TAStudio is in recording mode"
|
||||
)]
|
||||
[LuaMethodAttributes("getrecording", "returns whether or not TAStudio is in recording mode")]
|
||||
public bool GetRecording()
|
||||
{
|
||||
return Tastudio.TasPlaybackBox.RecordingMode;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setrecording",
|
||||
"sets the recording mode on/off depending on the parameter"
|
||||
)]
|
||||
[LuaMethodAttributes("setrecording", "sets the recording mode on/off depending on the parameter")]
|
||||
public void SetRecording(bool val)
|
||||
{
|
||||
if (Tastudio.TasPlaybackBox.RecordingMode != val)
|
||||
{
|
||||
Tastudio.ToggleReadOnly();
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"togglerecording",
|
||||
"toggles tastudio recording mode on/off depending on its current state"
|
||||
)]
|
||||
[LuaMethodAttributes("togglerecording", "toggles tastudio recording mode on/off depending on its current state")]
|
||||
public void SetRecording()
|
||||
{
|
||||
Tastudio.ToggleReadOnly();
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setbranchtext",
|
||||
"adds the given message to the existing branch, or to the branch that will be created next if branch index is not specified"
|
||||
)]
|
||||
[LuaMethodAttributes("setbranchtext", "adds the given message to the existing branch, or to the branch that will be created next if branch index is not specified")]
|
||||
public void SetBranchText(string text, int? index = null)
|
||||
{
|
||||
if (index != null)
|
||||
|
@ -81,10 +61,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getmarker",
|
||||
"returns the marker text at the given frame, or an empty string if there is no marker for the given frame"
|
||||
)]
|
||||
[LuaMethodAttributes("getmarker", "returns the marker text at the given frame, or an empty string if there is no marker for the given frame")]
|
||||
public string GetMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -99,10 +76,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return "";
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"removemarker",
|
||||
"if there is a marker for the given frame, it will be removed"
|
||||
)]
|
||||
[LuaMethodAttributes("removemarker", "if there is a marker for the given frame, it will be removed")]
|
||||
public void RemoveMarker(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -116,10 +90,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setmarker",
|
||||
"Adds or sets a marker at the given frame, with an optional message"
|
||||
)]
|
||||
[LuaMethodAttributes("setmarker", "Adds or sets a marker at the given frame, with an optional message")]
|
||||
public void SetMarker(int frame, string message = null)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -137,10 +108,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"islag",
|
||||
"Returns whether or not the given frame was a lag frame, null if unknown"
|
||||
)]
|
||||
[LuaMethodAttributes("islag", "Returns whether or not the given frame was a lag frame, null if unknown")]
|
||||
public bool? IsLag(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -154,10 +122,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return null;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setlag",
|
||||
"Sets the lag information for the given frame, if the frame does not exist in the lag log, it will be added. If the value is null, the lag information for that frame will be removed"
|
||||
)]
|
||||
[LuaMethodAttributes("setlag", "Sets the lag information for the given frame, if the frame does not exist in the lag log, it will be added. If the value is null, the lag information for that frame will be removed")]
|
||||
public void SetLag(int frame, bool? value)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -166,10 +131,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"hasstate",
|
||||
"Returns whether or not the given frame has a savestate associated with it"
|
||||
)]
|
||||
[LuaMethodAttributes("hasstate", "Returns whether or not the given frame has a savestate associated with it")]
|
||||
public bool HasState(int frame)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -183,33 +145,36 @@ namespace BizHawk.Client.EmuHawk
|
|||
return false;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setplayback",
|
||||
"Seeks the given frame (a number) or marker (a string)"
|
||||
)]
|
||||
[LuaMethodAttributes("setplayback", "Seeks the given frame (a number) or marker (a string)")]
|
||||
public void SetPlayback(object frame)
|
||||
{
|
||||
if (Engaged())
|
||||
{
|
||||
int f;
|
||||
if (frame is double) f = (int)(double)frame;
|
||||
if (frame is double)
|
||||
{
|
||||
f = (int)(double)frame;
|
||||
}
|
||||
else
|
||||
{
|
||||
f = Tastudio.CurrentTasMovie.Markers.FindIndex((string)frame);
|
||||
if (f == -1) return;
|
||||
if (f == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
f = Tastudio.CurrentTasMovie.Markers[f].Frame;
|
||||
}
|
||||
if (f < Tastudio.CurrentTasMovie.InputLogLength && f>=0)
|
||||
|
||||
if (f < Tastudio.CurrentTasMovie.InputLogLength && f >= 0)
|
||||
{
|
||||
Tastudio.GoToFrame(f,true);
|
||||
Tastudio.GoToFrame(f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"onqueryitembg",
|
||||
"called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)"
|
||||
)]
|
||||
"onqueryitembg", "called during the background draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemBg(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -230,9 +195,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"onqueryitemtext",
|
||||
"called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)"
|
||||
)]
|
||||
"onqueryitemtext", "called during the text draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemText(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -241,23 +204,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
var result = luaf.Call(index, name);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
if (result[0] != null)
|
||||
{
|
||||
return result[0].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return (string)null;
|
||||
return result?[0]?.ToString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"onqueryitemicon",
|
||||
"called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)"
|
||||
)]
|
||||
"onqueryitemicon", "called during the icon draw event of the tastudio listview. luaf must be a function that takes 2 params: index, column. The first is the integer row index of the listview, and the 2nd is the string column name. luaf should return a value that can be parsed into a .NET Color object (string color name, or integer value)")]
|
||||
public void OnQueryItemIcon(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -265,17 +218,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
Tastudio.QueryItemIconCallback = (int index, string name) =>
|
||||
{
|
||||
var result = luaf.Call(index, name);
|
||||
if (result != null)
|
||||
if (result?[0] != null)
|
||||
{
|
||||
if (result[0] != null)
|
||||
{
|
||||
string path = result[0].ToString();
|
||||
Icon icon = new Icon(path);
|
||||
if (icon != null)
|
||||
{
|
||||
return icon.ToBitmap();
|
||||
}
|
||||
}
|
||||
string path = result[0].ToString();
|
||||
Icon icon = new Icon(path);
|
||||
return icon.ToBitmap();
|
||||
}
|
||||
|
||||
return (Bitmap)null;
|
||||
|
@ -283,10 +230,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"ongreenzoneinvalidated",
|
||||
"called whenever the greenzone is invalidated and returns the first frame that was invalidated"
|
||||
)]
|
||||
[LuaMethodAttributes("ongreenzoneinvalidated", "called whenever the greenzone is invalidated and returns the first frame that was invalidated")]
|
||||
public void OnGreenzoneInvalidated(LuaFunction luaf)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -298,10 +242,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"getselection",
|
||||
"gets the currently selected frames"
|
||||
)]
|
||||
[LuaMethodAttributes("getselection", "gets the currently selected frames")]
|
||||
public LuaTable GetSelection()
|
||||
{
|
||||
LuaTable table = Lua.NewTable();
|
||||
|
@ -319,10 +260,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
return table;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"insertframes",
|
||||
"inserts the given number of blank frames at the given insertion frame"
|
||||
)]
|
||||
[LuaMethodAttributes("insertframes", "inserts the given number of blank frames at the given insertion frame")]
|
||||
public void InsertNumFrames(int insertionFrame, int numberOfFrames)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -333,15 +271,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
Log(insertionFrame.ToString() + " is out of range");
|
||||
Log(insertionFrame + " is out of range");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"deleteframes",
|
||||
"deletes the given number of blank frames beginning at the given frame"
|
||||
)]
|
||||
[LuaMethodAttributes("deleteframes", "deletes the given number of blank frames beginning at the given frame")]
|
||||
public void DeleteFrames(int beginningFrame, int numberOfFrames)
|
||||
{
|
||||
if (Engaged())
|
||||
|
@ -352,7 +287,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
Log(beginningFrame.ToString() + " is out of range");
|
||||
Log(beginningFrame + " is out of range");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,25 +26,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
_lua["keepalives"] = _lua.NewTable();
|
||||
}
|
||||
|
||||
private FormsLuaLibrary FormsLibrary
|
||||
{
|
||||
get { return (FormsLuaLibrary)Libraries[typeof(FormsLuaLibrary)]; }
|
||||
}
|
||||
private FormsLuaLibrary FormsLibrary => (FormsLuaLibrary)Libraries[typeof(FormsLuaLibrary)];
|
||||
|
||||
private EventLuaLibrary EventsLibrary
|
||||
{
|
||||
get { return (EventLuaLibrary)Libraries[typeof(EventLuaLibrary)]; }
|
||||
}
|
||||
private EventLuaLibrary EventsLibrary => (EventLuaLibrary)Libraries[typeof(EventLuaLibrary)];
|
||||
|
||||
private EmulatorLuaLibrary EmulatorLuaLibrary
|
||||
{
|
||||
get { return (EmulatorLuaLibrary)Libraries[typeof(EmulatorLuaLibrary)]; }
|
||||
}
|
||||
private EmulatorLuaLibrary EmulatorLuaLibrary => (EmulatorLuaLibrary)Libraries[typeof(EmulatorLuaLibrary)];
|
||||
|
||||
public GuiLuaLibrary GuiLibrary
|
||||
{
|
||||
get { return (GuiLuaLibrary)Libraries[typeof(GuiLuaLibrary)]; }
|
||||
}
|
||||
public GuiLuaLibrary GuiLibrary => (GuiLuaLibrary)Libraries[typeof(GuiLuaLibrary)];
|
||||
|
||||
public EmuLuaLibrary(IEmulatorServiceProvider serviceProvider)
|
||||
: this()
|
||||
|
@ -67,8 +55,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
.GetTypes()
|
||||
.Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t))
|
||||
.Where(t => t.IsSealed)
|
||||
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
|
||||
);
|
||||
.Where(t => ServiceInjector.IsAvailable(serviceProvider, t)));
|
||||
|
||||
foreach (var lib in libs)
|
||||
{
|
||||
|
@ -96,7 +83,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// Add LuaCanvas to Docs
|
||||
Type luaCanvas = typeof(LuaCanvas);
|
||||
var luaAttr = typeof(LuaMethodAttributes);
|
||||
|
||||
var methods = luaCanvas
|
||||
.GetMethods()
|
||||
|
@ -104,9 +90,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
foreach (var method in methods)
|
||||
{
|
||||
var luaMethodAttr = method.GetCustomAttributes(luaAttr, false).First() as LuaMethodAttributes;
|
||||
var luaName = "(Canvas)." + luaMethodAttr.Name;
|
||||
|
||||
Docs.Add(new LibraryFunction(nameof(LuaCanvas), luaCanvas.Description(), method));
|
||||
}
|
||||
}
|
||||
|
@ -119,15 +102,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
public LuaDocumentation Docs { get; private set; }
|
||||
public LuaDocumentation Docs { get; }
|
||||
public bool IsRunning { get; set; }
|
||||
public EventWaitHandle LuaWait { get; private set; }
|
||||
public bool FrameAdvanceRequested { get; private set; }
|
||||
|
||||
public LuaFunctionList RegisteredFunctions
|
||||
{
|
||||
get { return EventsLibrary.RegisteredFunctions; }
|
||||
}
|
||||
public LuaFunctionList RegisteredFunctions => EventsLibrary.RegisteredFunctions;
|
||||
|
||||
public void WindowClosed(IntPtr handle)
|
||||
{
|
||||
|
@ -196,7 +176,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
var execResult = script.Resume(0);
|
||||
|
||||
_lua.RunScheduledDisposes();
|
||||
//not sure how this is going to work out, so do this too
|
||||
|
||||
// not sure how this is going to work out, so do this too
|
||||
script.RunScheduledDisposes();
|
||||
|
||||
_currThread = null;
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -17,7 +11,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public bool IsInstalled(TextEditors editor)
|
||||
{
|
||||
switch(editor)
|
||||
switch (editor)
|
||||
{
|
||||
case TextEditors.Sublime2:
|
||||
return IsSublimeInstalled();
|
||||
|
@ -43,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public void InstallBizLua(TextEditors editor)
|
||||
{
|
||||
switch(editor)
|
||||
switch (editor)
|
||||
{
|
||||
case TextEditors.Sublime2:
|
||||
InstallBizLuaToSublime2();
|
||||
|
@ -56,10 +50,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
#endregion
|
||||
|
||||
private string AppDataFolder
|
||||
{
|
||||
get { return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); }
|
||||
}
|
||||
private string AppDataFolder => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
|
||||
private bool IsSublimeInstalled()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue