From c53cef6cf986b94e98ee54793039b1385d461bf0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 1 Jul 2015 19:46:14 -0400 Subject: [PATCH] tastudio/lua - implement tastudio.onqueryitemtext --- .../Lua/Libraries/EmuLuaLibrary.Tastudio.cs | 25 +++++++++++++++++++ .../tools/TAStudio/TAStudio.ListView.cs | 21 +++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs index c4a4b48ba6..5367f1230d 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Tastudio.cs @@ -148,5 +148,30 @@ namespace BizHawk.Client.EmuHawk }; } } + + [LuaMethodAttributes( + "onqueryitemtext", + "called during the text draw event of the tastudio listview" + )] + public void OnQueryItemText(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.QueryItemTextCallback = (int index, string name) => + { + var result = luaf.Call(index, name); + + if (result != null) + { + if (result[0] != null) + { + return result[0].ToString(); + } + } + + return (string)null; + }; + } + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index d98c006000..e3861d91e4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -99,7 +99,7 @@ namespace BizHawk.Client.EmuHawk public Func QueryItemBgColorCallback { get; set; } - public Color? GetColorOverride(int index, InputRoll.RollColumn column) + private Color? GetColorOverride(int index, InputRoll.RollColumn column) { if (QueryItemBgColorCallback != null) { @@ -109,6 +109,18 @@ namespace BizHawk.Client.EmuHawk return null; } + public Func QueryItemTextCallback { get; set; } + + private string GetTextOverride(int index, InputRoll.RollColumn column) + { + if (QueryItemTextCallback != null) + { + return QueryItemTextCallback(index, column.Name); + } + + return null; + } + #endregion private void TasView_QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color) @@ -170,6 +182,13 @@ namespace BizHawk.Client.EmuHawk private void TasView_QueryItemText(int index, InputRoll.RollColumn column, out string text) { + var overrideText = GetTextOverride(index, column); + if (overrideText != null) + { + text = overrideText; + return; + } + try { text = string.Empty;