diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs index 9fa0390546..9b3fe5f050 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Forms.cs @@ -445,6 +445,38 @@ namespace BizHawk.Client.EmuHawk return string.Empty; } + [LuaMethodAttributes( + "setdropdownitems", + "Sets the items for a given dropdown box" + )] + public void SetDropdownItems( + int handle, + LuaTable items) + { + try { + var ptr = new IntPtr(handle); + foreach (var form in _luaForms) { + if (form.Handle == ptr) { + return; + } + + foreach (Control control in form.Controls) { + if (control.Handle == ptr) { + if (control is LuaDropDown) { + var dropdownItems = items.Values.Cast().ToList(); + dropdownItems.Sort(); + (control as LuaDropDown).SetItems(dropdownItems); + } + + return; + } + } + } + } catch (Exception ex) { + ConsoleLuaLibrary.Log(ex.Message); + } + } + [LuaMethodAttributes( "setlocation", "Sets the location of a control or form by passing in the handle of the created object" diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs index d0842aa701..dbff0d558a 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaDropDown.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -14,5 +13,11 @@ namespace BizHawk.Client.EmuHawk SelectedIndex = 0; DropDownStyle = ComboBoxStyle.DropDownList; } + + public void SetItems(List items) { + Items.Clear(); + Items.AddRange(items.Cast().ToArray()); + SelectedIndex = 0; + } } }