From b6efbfe54b8d42a214917c25417438bb28ef80d9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 19 Mar 2024 11:10:15 -0500 Subject: [PATCH] add hotkey to toggle the last used lua script --- src/BizHawk.Client.Common/config/Binding.cs | 1 + src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs | 6 +++++ .../tools/Lua/LuaConsole.cs | 26 +++++++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/BizHawk.Client.Common/config/Binding.cs b/src/BizHawk.Client.Common/config/Binding.cs index dfb3e4d2bd..fe33b59e8d 100644 --- a/src/BizHawk.Client.Common/config/Binding.cs +++ b/src/BizHawk.Client.Common/config/Binding.cs @@ -174,6 +174,7 @@ namespace BizHawk.Client.Common Bind("Analog", "X Down Large", toolTip: "For Virtual Pad"); Bind("Tools", "Toggle All Cheats"); + Bind("Tools", "Toggle Last Lua Script"); Bind("NDS", "Next Screen Layout"); Bind("NDS", "Previous Screen Layout"); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index 0d4719901b..55f60085be 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -311,6 +311,12 @@ namespace BizHawk.Client.EmuHawk case "Lua Console": OpenLuaConsole(); break; + case "Toggle Last Lua Script": + if (Tools.IsLoaded()) + { + Tools.LuaConsole.ToggleLastLuaScript(); + } + break; case "Cheats": Tools.Load(); break; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 08fda9cde3..32833562a0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -11,7 +11,6 @@ using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.ToolExtensions; -using BizHawk.Common; using BizHawk.Common.CollectionExtensions; using BizHawk.Common.PathExtensions; using BizHawk.Common.StringExtensions; @@ -29,15 +28,16 @@ namespace BizHawk.Client.EmuHawk private static readonly FilesystemFilterSet ScriptsAndTextFilesFSFilterSet = new(FilesystemFilter.LuaScripts, FilesystemFilter.TextFiles); - private static readonly FilesystemFilterSet SessionsFSFilterSet = new FilesystemFilterSet(new FilesystemFilter("Lua Session Files", new[] { "luases" })); + private static readonly FilesystemFilterSet SessionsFSFilterSet = new(new FilesystemFilter("Lua Session Files", new[] { "luases" })); public static Icon ToolIcon => Resources.TextDocIcon; - private readonly LuaAutocompleteInstaller _luaAutoInstaller = new LuaAutocompleteInstaller(); + private readonly LuaAutocompleteInstaller _luaAutoInstaller = new(); private readonly Dictionary _watches = new(); private readonly int _defaultSplitDistance; + private LuaFile _lastScriptUsed = null; [RequiredService] private IEmulator Emulator { get; set; } @@ -45,7 +45,7 @@ namespace BizHawk.Client.EmuHawk private bool _sortReverse; private string _lastColumnSorted; - private readonly List _consoleCommandHistory = new List(); + private readonly List _consoleCommandHistory = new(); private int _consoleCommandHistoryIndex = -1; public ToolDialogSettings.ColumnList Columns { get; set; } @@ -56,9 +56,9 @@ namespace BizHawk.Client.EmuHawk { Columns = new List { - new RollColumn { Name = IconColumnName, Text = " ", Visible = true, UnscaledWidth = 22, Type = ColumnType.Image }, - new RollColumn { Name = ScriptColumnName, Text = "Script", Visible = true, UnscaledWidth = 92, Type = ColumnType.Text }, - new RollColumn { Name = PathColumnName, Text = "Path", Visible = true, UnscaledWidth = 300, Type = ColumnType.Text } + new() { Name = IconColumnName, Text = " ", Visible = true, UnscaledWidth = 22, Type = ColumnType.Image }, + new() { Name = ScriptColumnName, Text = "Script", Visible = true, UnscaledWidth = 92, Type = ColumnType.Text }, + new() { Name = PathColumnName, Text = "Path", Visible = true, UnscaledWidth = 300, Type = ColumnType.Text } }; } @@ -247,6 +247,14 @@ namespace BizHawk.Client.EmuHawk UpdateDialog(); } + public void ToggleLastLuaScript() + { + if (_lastScriptUsed is not null) + { + ToggleLuaScript(_lastScriptUsed); + } + } + private void SetColumns() { LuaListView.AllColumns.AddRange(Settings.Columns); @@ -1488,7 +1496,7 @@ namespace BizHawk.Client.EmuHawk } file.Toggle(); - + _lastScriptUsed = file; if (file.Enabled && file.Thread is null) { LuaImp.RegisteredFunctions.RemoveForFile(file, Emulator); // First remove any existing registered functions for this file @@ -1499,6 +1507,8 @@ namespace BizHawk.Client.EmuHawk DisableLuaScript(file); // there used to be a call here which did a redraw of the Gui/OSD, which included a call to `Tools.UpdateToolsAfter` --yoshi } + + LuaListView.Refresh(); } private void DisableLuaScript(LuaFile file)