diff --git a/BizHawk.Client.Common/lua/LuaFile.cs b/BizHawk.Client.Common/lua/LuaFile.cs index 63ae59c75e..dddb59a85d 100644 --- a/BizHawk.Client.Common/lua/LuaFile.cs +++ b/BizHawk.Client.Common/lua/LuaFile.cs @@ -48,6 +48,11 @@ public void Stop() { + if (Thread == null) + { + return; + } + State = RunState.Disabled; //if(NLua.Lua.WhichLua == "NLua") Thread.GetTable("keepalives")[Thread] = null; diff --git a/BizHawk.Client.Common/lua/LuaFileList.cs b/BizHawk.Client.Common/lua/LuaFileList.cs index 678a4c7809..a8148df357 100644 --- a/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/BizHawk.Client.Common/lua/LuaFileList.cs @@ -140,11 +140,19 @@ namespace BizHawk.Client.Common var sb = new StringBuilder(); foreach (var file in this) { - sb - .Append(file.Enabled ? "1" : "0") - .Append(' ') - .Append(PathManager.MakeRelativeTo(PathManager.MakeAbsolutePath(file.Path, ""), Path.GetDirectoryName(path))) - .AppendLine(); + if (file.IsSeparator) + { + sb.AppendLine("---"); + } + else + { + sb + .Append(file.Enabled ? "1" : "0") + .Append(' ') + .Append(PathManager.MakeRelativeTo(PathManager.MakeAbsolutePath(file.Path, "") + , Path.GetDirectoryName(path))) + .AppendLine(); + } } sw.Write(sb.ToString()); diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 4e5ecd01d7..004021caf8 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -1892,6 +1892,7 @@ + diff --git a/BizHawk.Client.EmuHawk/Properties/Resources.Designer.cs b/BizHawk.Client.EmuHawk/Properties/Resources.Designer.cs index d9e97b6eff..022c725cc6 100644 --- a/BizHawk.Client.EmuHawk/Properties/Resources.Designer.cs +++ b/BizHawk.Client.EmuHawk/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -1479,6 +1479,16 @@ namespace BizHawk.Client.EmuHawk.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap StopButton { + get { + object obj = ResourceManager.GetObject("StopButton", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/BizHawk.Client.EmuHawk/Properties/Resources.resx b/BizHawk.Client.EmuHawk/Properties/Resources.resx index 1876bfb3b7..610b6c155b 100644 --- a/BizHawk.Client.EmuHawk/Properties/Resources.resx +++ b/BizHawk.Client.EmuHawk/Properties/Resources.resx @@ -1563,4 +1563,7 @@ ..\Resources\MoveTop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\images\StopButton.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.Designer.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.Designer.cs index 01816fd1c6..f5388aabd7 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.Designer.cs @@ -104,10 +104,7 @@ this.InsertSeparatorToolbarItem = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator10 = new System.Windows.Forms.ToolStripSeparator(); this.EraseToolbarItem = new System.Windows.Forms.ToolStripButton(); - this.LuaListView = new BizHawk.Client.EmuHawk.VirtualListView(); - this.Script = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.PathName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.imageList1 = new System.Windows.Forms.ImageList(this.components); + this.LuaListView = new InputRoll(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.CopyContextItem = new System.Windows.Forms.ToolStripMenuItem(); this.ScriptListContextMenu.SuspendLayout(); @@ -805,47 +802,20 @@ this.LuaListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.LuaListView.BlazingFast = false; - this.LuaListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { - this.Script, - this.PathName}); + this.LuaListView.AllowColumnResize = true; + this.LuaListView.AllowColumnReorder = false; this.LuaListView.ContextMenuStrip = this.ScriptListContextMenu; this.LuaListView.FullRowSelect = true; this.LuaListView.GridLines = true; - this.LuaListView.HideSelection = false; - this.LuaListView.ItemCount = 0; + this.LuaListView.RowCount = 0; this.LuaListView.Location = new System.Drawing.Point(4, 21); this.LuaListView.Name = "LuaListView"; - this.LuaListView.SelectAllInProgress = false; - this.LuaListView.selectedItem = -1; this.LuaListView.Size = new System.Drawing.Size(273, 271); - this.LuaListView.SmallImageList = this.imageList1; this.LuaListView.TabIndex = 0; - this.LuaListView.UseCompatibleStateImageBehavior = false; this.LuaListView.UseCustomBackground = true; - this.LuaListView.View = System.Windows.Forms.View.Details; - this.LuaListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.LuaListView_ColumnClick); - this.LuaListView.ItemActivate += new System.EventHandler(this.LuaListView_ItemActivate); + this.LuaListView.ColumnClick += new BizHawk.Client.EmuHawk.InputRoll.ColumnClickEventHandler(this.LuaListView_ColumnClick); this.LuaListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LuaListView_KeyDown); // - // Script - // - this.Script.Text = "Script"; - this.Script.Width = 92; - // - // PathName - // - this.PathName.Text = "Path"; - this.PathName.Width = 195; - // - // imageList1 - // - this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); - this.imageList1.TransparentColor = System.Drawing.Color.Transparent; - this.imageList1.Images.SetKeyName(0, "StopButton.png"); - this.imageList1.Images.SetKeyName(1, "PlayButton.png"); - this.imageList1.Images.SetKeyName(2, "Pause.png"); - // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -910,8 +880,7 @@ #endregion - private VirtualListView LuaListView; - private System.Windows.Forms.ColumnHeader PathName; + private InputRoll LuaListView; private MenuStripEx menuStrip1; private System.Windows.Forms.ToolStripMenuItem FileSubMenu; private System.Windows.Forms.ToolStripMenuItem SaveSessionMenuItem; @@ -921,7 +890,6 @@ private System.Windows.Forms.ToolStripMenuItem ScriptSubMenu; private System.Windows.Forms.ToolStripMenuItem EditScriptMenuItem; private System.Windows.Forms.ToolStripMenuItem ToggleScriptMenuItem; - public System.Windows.Forms.ColumnHeader Script; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.ToolStripMenuItem NewSessionMenuItem; private System.Windows.Forms.ToolStripMenuItem SettingsSubMenu; @@ -980,7 +948,6 @@ private System.Windows.Forms.ToolStripMenuItem DuplicateScriptMenuItem; private System.Windows.Forms.TextBox InputBox; private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.ToolStripMenuItem ReturnAllIfNoneSelectedMenuItem; private System.Windows.Forms.ToolStripMenuItem RemoveRegisteredFunctionsOnToggleMenuItem; private System.Windows.Forms.ToolStripMenuItem ReloadWhenScriptFileChangesMenuItem; diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 63ff408725..4478babacc 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -18,6 +18,10 @@ namespace BizHawk.Client.EmuHawk { public partial class LuaConsole : ToolFormBase, IToolFormAutoConfig { + private const string IconColumnName = "Icon"; + private const string ScriptColumnName = "Script"; + private const string PathColumnName = "PathName"; + [RequiredService] private IEmulator Emulator { get; set; } @@ -33,14 +37,15 @@ namespace BizHawk.Client.EmuHawk { public LuaConsoleSettings() { - Columns = new ToolDialogSettings.ColumnList + Columns = new List { - new ToolDialogSettings.Column { Name = "Script", Visible = true, Index = 0, Width = 92 }, - new ToolDialogSettings.Column { Name = "PathName", Visible = true, Index = 0, Width = 195 } + new InputRoll.RollColumn { Name = IconColumnName, Text = " ", Visible = true, Width = 22, Type = InputRoll.RollColumn.InputType.Image }, + new InputRoll.RollColumn { Name = ScriptColumnName, Text = "Script", Visible = true, Width = 92, Type = InputRoll.RollColumn.InputType.Text }, + new InputRoll.RollColumn { Name = PathColumnName, Text = "Path", Visible = true, Width = 300, Type = InputRoll.RollColumn.InputType.Text } }; } - public ToolDialogSettings.ColumnList Columns { get; set; } + public List Columns { get; set; } } [ConfigPersist] @@ -58,7 +63,7 @@ namespace BizHawk.Client.EmuHawk { if (AskSaveChanges()) { - SaveColumnInfo(LuaListView, Settings.Columns); + Settings.Columns = LuaListView.AllColumns; GlobalWin.DisplayManager.ClearLuaSurfaces(); @@ -85,9 +90,7 @@ namespace BizHawk.Client.EmuHawk LuaListView.QueryItemText += LuaListView_QueryItemText; LuaListView.QueryItemBkColor += LuaListView_QueryItemBkColor; - LuaListView.QueryItemImage += LuaListView_QueryItemImage; - LuaListView.QueryItemIndent += LuaListView_QueryItemIndent; - LuaListView.VirtualMode = true; + LuaListView.QueryItemIcon += LuaListView_QueryItemImage; // this is bad, in case we ever have more than one gui part running lua.. not sure how much other badness there is like that LuaSandbox.DefaultLogger = ConsoleLog; @@ -99,7 +102,7 @@ namespace BizHawk.Client.EmuHawk private IEnumerable SelectedItems { - get { return LuaListView.SelectedIndices().Select(index => LuaImp.ScriptList[index]); } + get { return LuaListView.SelectedRows.Select(index => LuaImp.ScriptList[index]); } } private IEnumerable SelectedFiles @@ -129,6 +132,12 @@ namespace BizHawk.Client.EmuHawk private void LuaConsole_Load(object sender, EventArgs e) { + // Hack for previous config settings + if (Settings.Columns.Any(c => string.IsNullOrWhiteSpace(c.Text))) + { + Settings = new LuaConsoleSettings(); + } + LuaImp.ScriptList.ChangedCallback = SessionChangedCallback; LuaImp.ScriptList.LoadCallback = ClearOutputWindow; @@ -144,7 +153,7 @@ namespace BizHawk.Client.EmuHawk } } - LoadColumnInfo(LuaListView, Settings.Columns); + SetColumns(); } public void Restart() @@ -217,10 +226,21 @@ namespace BizHawk.Client.EmuHawk private readonly List _watches = new List(); + private void SetColumns() + { + foreach (var column in Settings.Columns) + { + if (LuaListView.AllColumns[column.Name] == null) + { + LuaListView.AllColumns.Add(column); + } + } + } + private void AddFileWatches() { _watches.Clear(); - foreach (var item in LuaImp.ScriptList) + foreach (var item in LuaImp.ScriptList.Where(s => !s.IsSeparator)) { var processedPath = PathManager.TryMakeRelative(item.Path); string pathToLoad = ProcessPath(processedPath); @@ -263,7 +283,7 @@ namespace BizHawk.Client.EmuHawk var luaFile = new LuaFile("", processedPath); LuaImp.ScriptList.Add(luaFile); - LuaListView.ItemCount = LuaImp.ScriptList.Count; + LuaListView.RowCount = LuaImp.ScriptList.Count; Global.Config.RecentLua.Add(processedPath); if (!Global.Config.DisableLuaScriptsOnLoad) @@ -297,7 +317,7 @@ namespace BizHawk.Client.EmuHawk private void UpdateDialog() { - LuaListView.ItemCount = LuaImp.ScriptList.Count; + LuaListView.RowCount = LuaImp.ScriptList.Count; LuaListView.Refresh(); UpdateNumberOfScripts(); UpdateRegisteredFunctionsDialog(); @@ -305,7 +325,7 @@ namespace BizHawk.Client.EmuHawk private void RunLuaScripts() { - foreach (var file in LuaImp.ScriptList) + foreach (var file in LuaImp.ScriptList.Where(s => !s.IsSeparator)) { if (!file.Enabled && file.Thread == null) { @@ -340,62 +360,62 @@ namespace BizHawk.Client.EmuHawk Path.GetFileName(LuaImp.ScriptList.Filename); } - private void LuaListView_QueryItemImage(int item, int subItem, out int imageIndex) + private void LuaListView_QueryItemImage(int index, InputRoll.RollColumn column, ref Bitmap bitmap, ref int offsetX, ref int offsetY) { - imageIndex = -1; - if (subItem != 0) + if (column.Name != IconColumnName) { return; } - if (LuaImp.ScriptList[item].Paused) + if (LuaImp.ScriptList[index].IsSeparator) { - imageIndex = 2; + return; } - else if (LuaImp.ScriptList[item].Enabled) + + if (LuaImp.ScriptList[index].Paused) { - imageIndex = 1; + bitmap = Properties.Resources.Pause; + } + else if (LuaImp.ScriptList[index].Enabled) + { + bitmap = Properties.Resources.ts_h_arrow_green; } else { - imageIndex = 0; + bitmap = Properties.Resources.StopButton; } } - private void LuaListView_QueryItemIndent(int item, out int itemIndent) + private void LuaListView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color) { - itemIndent = 0; - } - - private void LuaListView_QueryItemBkColor(int index, int column, ref Color color) - { - if (column == 0) + if (LuaImp.ScriptList[index].IsSeparator) { - if (LuaImp.ScriptList[index].IsSeparator) - { - color = BackColor; - } - else if (LuaImp.ScriptList[index].Enabled && !LuaImp.ScriptList[index].Paused) - { - color = Color.LightCyan; - } - else if (LuaImp.ScriptList[index].Enabled && LuaImp.ScriptList[index].Paused) - { - color = Color.LightPink; - } + color = BackColor; + } + else if (LuaImp.ScriptList[index].Enabled && !LuaImp.ScriptList[index].Paused) + { + color = Color.LightCyan; + } + else if (LuaImp.ScriptList[index].Enabled && LuaImp.ScriptList[index].Paused) + { + color = Color.LightPink; } - - UpdateNumberOfScripts(); } - private void LuaListView_QueryItemText(int index, int column, out string text) + private void LuaListView_QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY) { text = ""; - if (column == 0) + + if (LuaImp.ScriptList[index].IsSeparator) + { + return; + } + + if (column.Name == ScriptColumnName) { text = Path.GetFileNameWithoutExtension(LuaImp.ScriptList[index].Path); // TODO: how about allow the user to name scripts? } - else if (column == 1) + else if (column.Name == PathColumnName) { text = DressUpRelative(LuaImp.ScriptList[index].Path); } @@ -437,9 +457,9 @@ namespace BizHawk.Client.EmuHawk private void UpdateNumberOfScripts() { var message = ""; - var total = SelectedFiles.Count(); - var active = LuaImp.ScriptList.Count(file => file.Enabled); - var paused = LuaImp.ScriptList.Count(file => file.Enabled && file.Paused); + var total = LuaImp.ScriptList.Count(file => !file.IsSeparator); + var active = LuaImp.ScriptList.Count(file => !file.IsSeparator && file.Enabled); + var paused = LuaImp.ScriptList.Count(file => !file.IsSeparator && file.Enabled && file.Paused); if (total == 1) { @@ -780,7 +800,7 @@ namespace BizHawk.Client.EmuHawk DuplicateScriptMenuItem.Enabled = MoveUpMenuItem.Enabled = MoveDownMenuItem.Enabled = - LuaListView.SelectedIndices().Any(); + LuaListView.SelectedRows.Any(); SelectAllMenuItem.Enabled = LuaImp.ScriptList.Any(); StopAllScriptsMenuItem.Enabled = LuaImp.ScriptList.Any(script => script.Enabled); @@ -946,7 +966,7 @@ namespace BizHawk.Client.EmuHawk private void DuplicateScriptMenuItem_Click(object sender, EventArgs e) { - if (LuaListView.SelectedIndices().Any()) + if (LuaListView.SelectedRows.Any()) { var script = SelectedFiles.First(); @@ -976,7 +996,7 @@ namespace BizHawk.Client.EmuHawk private void InsertSeparatorMenuItem_Click(object sender, EventArgs e) { - var indices = LuaListView.SelectedIndices().ToList(); + var indices = LuaListView.SelectedRows.ToList(); if (indices.Any() && indices.Last() < LuaImp.ScriptList.Count) { LuaImp.ScriptList.Insert(indices.Last(), LuaFile.SeparatorInstance); @@ -991,7 +1011,7 @@ namespace BizHawk.Client.EmuHawk private void MoveUpMenuItem_Click(object sender, EventArgs e) { - var indices = LuaListView.SelectedIndices().ToList(); + var indices = LuaListView.SelectedRows.ToList(); if (indices.Count == 0 || indices[0] == 0) { return; @@ -1006,10 +1026,10 @@ namespace BizHawk.Client.EmuHawk var newIndices = indices.Select(t => t - 1); - LuaListView.SelectedIndices.Clear(); + LuaListView.DeselectAll(); foreach (var i in newIndices) { - LuaListView.SelectItem(i, true); + LuaListView.SelectRow(i, true); } UpdateDialog(); @@ -1017,7 +1037,7 @@ namespace BizHawk.Client.EmuHawk private void MoveDownMenuItem_Click(object sender, EventArgs e) { - var indices = LuaListView.SelectedIndices().ToList(); + var indices = LuaListView.SelectedRows.ToList(); if (indices.Count == 0 || indices.Last() == LuaImp.ScriptList.Count - 1) { return; @@ -1032,10 +1052,10 @@ namespace BizHawk.Client.EmuHawk var newIndices = indices.Select(t => t + 1); - LuaListView.SelectedIndices.Clear(); + LuaListView.DeselectAll(); foreach (var i in newIndices) { - LuaListView.SelectItem(i, true); + LuaListView.SelectRow(i, true); } UpdateDialog(); @@ -1280,11 +1300,6 @@ namespace BizHawk.Client.EmuHawk } } - private void LuaListView_ItemActivate(object sender, EventArgs e) - { - ToggleScriptMenuItem_Click(sender, e); - } - private void OutputBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F12 && !e.Control && !e.Alt && !e.Shift) // F12 @@ -1296,9 +1311,9 @@ namespace BizHawk.Client.EmuHawk /// /// Sorts the column Ascending on the first click and Descending on the second click. /// - private void LuaListView_ColumnClick(object sender, ColumnClickEventArgs e) + private void LuaListView_ColumnClick(object sender, InputRoll.ColumnClickEventArgs e) { - var columnToSort = LuaListView.Columns[e.Column].Text; + var columnToSort = e.Column.Name; var luaListTemp = new List(); if (columnToSort != _lastColumnSorted) {